sdutil Initialize CHS too (some BIOSes dont like it), libfat Add update callback function
All checks were successful
Build documentation / build-and-deploy (push) Successful in 4m33s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 4m33s
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef _KERNEL_FS_FATFS_CTX_H
|
||||
#define _KERNEL_FS_FATFS_CTX_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct fatfs_ctx {
|
||||
FL_FILE _files[FATFS_MAX_OPEN_FILES];
|
||||
int _filelib_init;
|
||||
@@ -9,6 +11,7 @@ struct fatfs_ctx {
|
||||
struct fat_list _open_file_list;
|
||||
struct fat_list _free_file_list;
|
||||
char device_name[0x100];
|
||||
void (*update_cb) (size_t sector, size_t sector_count);
|
||||
};
|
||||
|
||||
#endif // _KERNEL_FS_FATFS_CTX_H
|
||||
|
||||
@@ -41,6 +41,9 @@ static int fat_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* buf
|
||||
NULL)) < 0)
|
||||
return 0;
|
||||
|
||||
if (ctx->update_cb != NULL)
|
||||
ctx->update_cb (phys_sector, phys_sector_count);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -65,18 +68,20 @@ static int fat_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* bu
|
||||
NULL)) < 0)
|
||||
return 0;
|
||||
|
||||
if (ctx->update_cb != NULL)
|
||||
ctx->update_cb (phys_sector, phys_sector_count);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fat_format_drive (struct fatfs_ctx* ctx, const char* device_key, int fs_type) {
|
||||
memset (ctx, 0, sizeof (*ctx));
|
||||
memcpy (ctx->device_name, device_key, min (sizeof (ctx->device_name) - 1, strlen (device_key)));
|
||||
memcpy (ctx->device_name, device_key, strlen (device_key));
|
||||
|
||||
int r = -1;
|
||||
|
||||
size_t total_size = 0;
|
||||
device_do (device_key, XDRV_GET_SIZE, &total_size, NULL, NULL, NULL);
|
||||
|
||||
if (total_size == 0)
|
||||
return -ST_NOT_FOUND;
|
||||
if ((r = device_do (device_key, XDRV_GET_SIZE, &total_size, NULL, NULL, NULL)) < 0)
|
||||
return r;
|
||||
|
||||
size_t sectors = ((total_size + FAT_SECTOR_SIZE) / FAT_SECTOR_SIZE);
|
||||
|
||||
@@ -84,7 +89,7 @@ int fat_format_drive (struct fatfs_ctx* ctx, const char* device_key, int fs_type
|
||||
ctx->_fs.disk_io.read_media = &fat_diskio_read;
|
||||
ctx->_fs.disk_io.write_media = &fat_diskio_write;
|
||||
|
||||
int r = -1;
|
||||
r = -1;
|
||||
|
||||
switch (fs_type) {
|
||||
case FS_FAT16:
|
||||
|
||||
Reference in New Issue
Block a user