Add create_file syscall, CE mkfile command, FatFS formatting fixes
All checks were successful
Build documentation / build-and-deploy (push) Successful in 4m16s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 4m16s
This commit is contained in:
@@ -87,7 +87,7 @@ static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* b
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fatfs_mount (struct vfs_volume* volume) {
|
||||
int fatfs_mount (struct vfs_volume* volume, bool format) {
|
||||
struct fatfs_ctx* fatfs_ctx = malloc (sizeof (*fatfs_ctx));
|
||||
int r;
|
||||
|
||||
@@ -99,7 +99,18 @@ int fatfs_mount (struct vfs_volume* volume) {
|
||||
volume->udata = fatfs_ctx;
|
||||
|
||||
fl_init (fatfs_ctx);
|
||||
fl_attach_media (fatfs_ctx, &fat1_diskio_read, &fat1_diskio_write);
|
||||
fatfs_ctx->_fs.disk_io.read_media = &fat1_diskio_read;
|
||||
fatfs_ctx->_fs.disk_io.write_media = &fat1_diskio_write;
|
||||
|
||||
if (format) {
|
||||
r = volume->driver_ops.format (volume);
|
||||
if (r < 0)
|
||||
return -ST_FORMAT_ERROR;
|
||||
}
|
||||
|
||||
r = fl_attach_media (fatfs_ctx, &fat1_diskio_read, &fat1_diskio_write);
|
||||
if (r < 0)
|
||||
return -ST_MOUNT_ERROR;
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
@@ -221,3 +232,15 @@ int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
|
||||
fl_closedir (fatfs_ctx, &dir);
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int fatfs_create_file (struct vfs_volume* volume, const char* path) {
|
||||
struct fatfs_ctx* fatfs_ctx = volume->udata;
|
||||
|
||||
FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+");
|
||||
|
||||
if (file == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
fl_fclose (fatfs_ctx, file);
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
struct vfs_volume;
|
||||
|
||||
int fatfs_mount (struct vfs_volume* volume);
|
||||
int fatfs_mount (struct vfs_volume* volume, bool format);
|
||||
|
||||
int fatfs16_format (struct vfs_volume* volume);
|
||||
|
||||
@@ -27,4 +27,6 @@ int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buff
|
||||
int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
|
||||
size_t entry_num);
|
||||
|
||||
int fatfs_create_file (struct vfs_volume* volume, const char* path);
|
||||
|
||||
#endif // _KERNEL_FS_FATFS_H
|
||||
|
||||
@@ -55,7 +55,9 @@ static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr) {
|
||||
return i;
|
||||
}
|
||||
|
||||
int tarfs_mount (struct vfs_volume* volume) {
|
||||
int tarfs_mount (struct vfs_volume* volume, bool format) {
|
||||
(void)format;
|
||||
|
||||
struct tarfs* tarfs = malloc (sizeof (*tarfs));
|
||||
|
||||
if (tarfs == NULL)
|
||||
@@ -201,3 +203,8 @@ int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buff
|
||||
(void)volume, (void)path, (void)buffer, (void)off, (void)size;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int tarfs_create_file (struct vfs_volume* volume, const char* path) {
|
||||
(void)volume, (void)path;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ struct tarfs {
|
||||
|
||||
struct vfs_volume;
|
||||
|
||||
int tarfs_mount (struct vfs_volume* volume);
|
||||
int tarfs_mount (struct vfs_volume* volume, bool format);
|
||||
|
||||
int tarfs_format (struct vfs_volume* volume);
|
||||
|
||||
@@ -49,4 +49,6 @@ int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buff
|
||||
int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
|
||||
size_t entry_num);
|
||||
|
||||
int tarfs_create_file (struct vfs_volume* volume, const char* path);
|
||||
|
||||
#endif // _KERNEL_FS_TARFS_H
|
||||
|
||||
@@ -36,7 +36,7 @@ static struct vfs_volume* vfs_find_volume (const char* volume) {
|
||||
return hash_entry (found_link, struct vfs_volume, volume_table_link);
|
||||
}
|
||||
|
||||
int vfs_create_volume (const char* key, int fs_type, struct device* back_device) {
|
||||
int vfs_create_volume (const char* key, int fs_type, struct device* back_device, bool format) {
|
||||
if (strlen_null (key) > VOLUME_MAX)
|
||||
return -ST_OOB_ERROR;
|
||||
|
||||
@@ -60,6 +60,7 @@ int vfs_create_volume (const char* key, int fs_type, struct device* back_device)
|
||||
volume->driver_ops.read_file = &tarfs_read_file;
|
||||
volume->driver_ops.write_file = &tarfs_write_file;
|
||||
volume->driver_ops.read_dir_entry = &tarfs_read_dir_entry;
|
||||
volume->driver_ops.create_file = &tarfs_create_file;
|
||||
break;
|
||||
case VFS_FAT16:
|
||||
volume->driver_ops.mount = &fatfs_mount;
|
||||
@@ -68,6 +69,7 @@ int vfs_create_volume (const char* key, int fs_type, struct device* back_device)
|
||||
volume->driver_ops.read_file = &fatfs_read_file;
|
||||
volume->driver_ops.write_file = &fatfs_write_file;
|
||||
volume->driver_ops.read_dir_entry = &fatfs_read_dir_entry;
|
||||
volume->driver_ops.create_file = &fatfs_create_file;
|
||||
break;
|
||||
case VFS_FAT32:
|
||||
volume->driver_ops.mount = &fatfs_mount;
|
||||
@@ -76,13 +78,14 @@ int vfs_create_volume (const char* key, int fs_type, struct device* back_device)
|
||||
volume->driver_ops.read_file = &fatfs_read_file;
|
||||
volume->driver_ops.write_file = &fatfs_write_file;
|
||||
volume->driver_ops.read_dir_entry = &fatfs_read_dir_entry;
|
||||
volume->driver_ops.create_file = &fatfs_create_file;
|
||||
break;
|
||||
default:
|
||||
free (volume);
|
||||
return -ST_MOUNT_ERROR;
|
||||
}
|
||||
|
||||
int ret = volume->driver_ops.mount (volume);
|
||||
int ret = volume->driver_ops.mount (volume, format);
|
||||
|
||||
if (ret < 0) {
|
||||
free (volume);
|
||||
@@ -202,6 +205,24 @@ int vfs_read_file (struct proc* proc, const char* volume_name, const char* path,
|
||||
return volume->driver_ops.read_file (volume, path, buffer, off, size);
|
||||
}
|
||||
|
||||
int vfs_create_file (struct proc* proc, const char* volume_name, const char* path) {
|
||||
struct vfs_volume* volume = vfs_find_volume (volume_name);
|
||||
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
spin_lock (&volume->lock);
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
spin_unlock (&volume->lock);
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
spin_unlock (&volume->lock);
|
||||
|
||||
return volume->driver_ops.create_file (volume, path);
|
||||
}
|
||||
|
||||
int vfs_describe (struct proc* proc, const char* volume_name, const char* path, struct desc* desc) {
|
||||
struct vfs_volume* volume = vfs_find_volume (volume_name);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ struct vfs_volume {
|
||||
bool locked;
|
||||
struct proc_suspension_q sq;
|
||||
struct {
|
||||
int (*mount) (struct vfs_volume* volume);
|
||||
int (*mount) (struct vfs_volume* volume, bool format);
|
||||
|
||||
int (*format) (struct vfs_volume* volume);
|
||||
|
||||
@@ -46,6 +46,8 @@ struct vfs_volume {
|
||||
|
||||
int (*read_dir_entry) (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
|
||||
size_t entry_num);
|
||||
|
||||
int (*create_file) (struct vfs_volume* volume, const char* path);
|
||||
} driver_ops;
|
||||
struct device* back_device;
|
||||
void* udata
|
||||
@@ -56,7 +58,7 @@ struct vfs_volume_table {
|
||||
spin_lock_t lock;
|
||||
};
|
||||
|
||||
int vfs_create_volume (const char* key, int fs_type, struct device* back_device);
|
||||
int vfs_create_volume (const char* key, int fs_type, struct device* back_device, bool format);
|
||||
|
||||
int vfs_volume_open (struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
|
||||
|
||||
@@ -72,6 +74,8 @@ int vfs_describe (struct proc* proc, const char* volume, const char* path, struc
|
||||
int vfs_read_dir_entry (struct proc* proc, const char* volume, const char* path,
|
||||
struct dir_entry* entry, size_t entry_num);
|
||||
|
||||
int vfs_create_file (struct proc* proc, const char* volume_name, const char* path);
|
||||
|
||||
void vfs_init (void);
|
||||
|
||||
void vfs_translate (size_t fs_block, size_t fs_block_count, size_t fs_block_size,
|
||||
|
||||
Reference in New Issue
Block a user