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:
@@ -59,16 +59,13 @@ void bootmain (void) {
|
||||
struct reschedule_ctx rctx = {.cpu = NULL, .reschedule = false};
|
||||
|
||||
struct device* ramdisk = device_find ("RD");
|
||||
vfs_create_volume ("RD", VFS_TARFS, ramdisk);
|
||||
vfs_create_volume ("RD", VFS_TARFS, ramdisk, false);
|
||||
|
||||
struct device* vdisk = device_find ("VD");
|
||||
device_probe_partitions (vdisk);
|
||||
|
||||
struct device* vdp0 = device_find ("VDp0");
|
||||
vfs_create_volume ("VD", VFS_FAT32, vdp0);
|
||||
vfs_volume_open (VFS_KERNEL, "VD", &rctx);
|
||||
vfs_format (VFS_KERNEL, "VD");
|
||||
vfs_volume_close (VFS_KERNEL, "VD", &rctx);
|
||||
vfs_create_volume ("VD", VFS_FAT32, vdp0, true);
|
||||
|
||||
proc_pid_alloc_init ();
|
||||
procgroup_pgid_alloc_init ();
|
||||
|
||||
@@ -138,8 +138,9 @@ void vdisk_device_init (void) {
|
||||
|
||||
mbr.valid_sign[0] = 0x55;
|
||||
mbr.valid_sign[1] = 0xAA;
|
||||
mbr.ptes[0].start_lba = 0;
|
||||
mbr.ptes[0].sector_count = div_align_up (init.total_size, init.sector_size);
|
||||
mbr.ptes[0].drive_attrs = (1 << 7);
|
||||
mbr.ptes[0].start_lba = 1;
|
||||
mbr.ptes[0].sector_count = div_align_up (init.total_size, init.sector_size) - 1;
|
||||
|
||||
struct device* vdisk =
|
||||
device_create ("VD", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -459,6 +459,30 @@ DEFINE_SYSCALL (sys_read_dir_entry) {
|
||||
return SYSRESULT (ret);
|
||||
}
|
||||
|
||||
/* int create_file (char* path) */
|
||||
DEFINE_SYSCALL (sys_create_file) {
|
||||
uintptr_t uvaddr_path = a1;
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
uintptr_t out_paddr;
|
||||
|
||||
spin_lock (&proc->procgroup->lock);
|
||||
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
|
||||
spin_unlock (&proc->procgroup->lock);
|
||||
|
||||
if (out_paddr == 0)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||
|
||||
spin_lock (&proc->lock);
|
||||
int ret = vfs_create_file (proc, proc->cwv, path);
|
||||
spin_unlock (&proc->lock);
|
||||
|
||||
return SYSRESULT (ret);
|
||||
}
|
||||
|
||||
/* int get_exec_pid (void) */
|
||||
DEFINE_SYSCALL (sys_get_exec_pid) { return SYSRESULT (proc->exec_pid); }
|
||||
|
||||
@@ -485,6 +509,7 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_GET_PROCGROUP] = &sys_get_procgroup,
|
||||
[SYS_GET_EXEC_PID] = &sys_get_exec_pid,
|
||||
[SYS_READ_DIR_ENTRY] = &sys_read_dir_entry,
|
||||
[SYS_CREATE_FILE] = &sys_create_file,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
|
||||
Reference in New Issue
Block a user