Remove vfs_volume_open() and vfs_volume_close()
This commit is contained in:
@@ -125,7 +125,6 @@ void proc_cleanup(struct proc* proc, struct reschedule_ctx* rctx) {
|
|||||||
|
|
||||||
procgroup_detach(proc->procgroup, proc, rctx);
|
procgroup_detach(proc->procgroup, proc, rctx);
|
||||||
|
|
||||||
vfs_volume_close(proc, proc->cwv, rctx);
|
|
||||||
proc_free_pid(proc->pid);
|
proc_free_pid(proc->pid);
|
||||||
/* clean the process */
|
/* clean the process */
|
||||||
free(proc);
|
free(proc);
|
||||||
|
|||||||
@@ -164,10 +164,6 @@ int vfs_volume_delete(const char* key) {
|
|||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (volume->locked) {
|
|
||||||
return -ST_TRY_AGAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
hash_delete(&volume_table, key, strlen_null(key), hash, lengthof(volume_table.volume_buckets),
|
hash_delete(&volume_table, key, strlen_null(key), hash, lengthof(volume_table.volume_buckets),
|
||||||
volume_buckets, struct vfs_volume, volume_table_link, key, found_link);
|
volume_buckets, struct vfs_volume, volume_table_link, key, found_link);
|
||||||
|
|
||||||
@@ -178,61 +174,12 @@ int vfs_volume_delete(const char* key) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vfs_volume_open(struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) {
|
|
||||||
struct vfs_volume* volume = vfs_find_volume(volume_name);
|
|
||||||
|
|
||||||
if (volume == NULL)
|
|
||||||
return -ST_NOT_FOUND;
|
|
||||||
|
|
||||||
if (!volume->locked) {
|
|
||||||
volume->locked = true;
|
|
||||||
volume->owner = proc;
|
|
||||||
return ST_OK;
|
|
||||||
} else {
|
|
||||||
proc_sq_suspend(proc, &volume->sq, rctx, NULL, NULL);
|
|
||||||
return ST_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int vfs_volume_close(struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) {
|
|
||||||
struct vfs_volume* volume = vfs_find_volume(volume_name);
|
|
||||||
|
|
||||||
if (volume == NULL)
|
|
||||||
return -ST_NOT_FOUND;
|
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list_node_link* node = volume->sq.proc_list;
|
|
||||||
|
|
||||||
if (node) {
|
|
||||||
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
|
|
||||||
struct proc* resumed_proc = sq_entry->proc;
|
|
||||||
|
|
||||||
volume->owner = resumed_proc;
|
|
||||||
volume->locked = true;
|
|
||||||
|
|
||||||
proc_sq_resume(resumed_proc, sq_entry, rctx, 0);
|
|
||||||
return ST_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
volume->locked = false;
|
|
||||||
volume->owner = NULL;
|
|
||||||
|
|
||||||
return ST_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name) {
|
int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name) {
|
||||||
struct vfs_volume* volume = vfs_find_volume(volume_name);
|
struct vfs_volume* volume = vfs_find_volume(volume_name);
|
||||||
|
|
||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.format(volume, proc, rctx);
|
return volume->driver_ops.format(volume, proc, rctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,10 +190,6 @@ int vfs_read_file(struct proc* proc, struct reschedule_ctx* rctx, const char* vo
|
|||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.read_file(volume, proc, rctx, path, buffer, off, size);
|
return volume->driver_ops.read_file(volume, proc, rctx, path, buffer, off, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,10 +200,6 @@ int vfs_write_file(struct proc* proc, struct reschedule_ctx* rctx, const char* v
|
|||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.write_file(volume, proc, rctx, path, buffer, off, size, flags);
|
return volume->driver_ops.write_file(volume, proc, rctx, path, buffer, off, size, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,10 +210,6 @@ int vfs_create_file(struct proc* proc, struct reschedule_ctx* rctx, const char*
|
|||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.create_file(volume, proc, rctx, path);
|
return volume->driver_ops.create_file(volume, proc, rctx, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,10 +220,6 @@ int vfs_describe(struct proc* proc, struct reschedule_ctx* rctx, const char* vol
|
|||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.describe(volume, proc, rctx, path, desc);
|
return volume->driver_ops.describe(volume, proc, rctx, path, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,10 +230,6 @@ int vfs_read_dir_entry(struct proc* proc, struct reschedule_ctx* rctx, const cha
|
|||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.read_dir_entry(volume, proc, rctx, path, entry, entry_num);
|
return volume->driver_ops.read_dir_entry(volume, proc, rctx, path, entry, entry_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,10 +240,6 @@ int vfs_create_dir(struct proc* proc, struct reschedule_ctx* rctx, const char* v
|
|||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.create_dir(volume, proc, rctx, path);
|
return volume->driver_ops.create_dir(volume, proc, rctx, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,10 +250,6 @@ int vfs_remove(struct proc* proc, struct reschedule_ctx* rctx, const char* volum
|
|||||||
if (volume == NULL)
|
if (volume == NULL)
|
||||||
return -ST_NOT_FOUND;
|
return -ST_NOT_FOUND;
|
||||||
|
|
||||||
if (volume->locked && volume->owner != proc) {
|
|
||||||
return -ST_PERMISSION_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume->driver_ops.remove(volume, proc, rctx, path);
|
return volume->driver_ops.remove(volume, proc, rctx, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ struct vfs_volume {
|
|||||||
char key[VOLUME_MAX];
|
char key[VOLUME_MAX];
|
||||||
struct hash_node_link volume_table_link;
|
struct hash_node_link volume_table_link;
|
||||||
int fs_type;
|
int fs_type;
|
||||||
struct proc* owner;
|
|
||||||
bool locked;
|
|
||||||
struct proc_suspension_q sq;
|
|
||||||
struct {
|
struct {
|
||||||
int (*mount)(struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
|
int (*mount)(struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
|
||||||
bool format);
|
bool format);
|
||||||
@@ -68,10 +65,6 @@ int vfs_create_volume(struct proc* proc, struct reschedule_ctx* rctx, const char
|
|||||||
|
|
||||||
int vfs_volume_delete(const char* key);
|
int vfs_volume_delete(const char* key);
|
||||||
|
|
||||||
int vfs_volume_open(struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
|
|
||||||
|
|
||||||
int vfs_volume_close(struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
|
|
||||||
|
|
||||||
int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name);
|
int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name);
|
||||||
|
|
||||||
int vfs_read_file(struct proc* proc, struct reschedule_ctx* rctx, const char* volume,
|
int vfs_read_file(struct proc* proc, struct reschedule_ctx* rctx, const char* volume,
|
||||||
|
|||||||
@@ -173,34 +173,25 @@ struct proc* proc_from_file(struct proc* proc1, const char* volume, const char*
|
|||||||
struct desc desc;
|
struct desc desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((ret = vfs_volume_open(proc1, volume, rctx)) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if ((ret = vfs_describe(proc1, rctx, volume, path, &desc)) < 0) {
|
if ((ret = vfs_describe(proc1, rctx, volume, path, &desc)) < 0) {
|
||||||
vfs_volume_close(proc1, volume, rctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desc.type != FS_FILE) {
|
if (desc.type != FS_FILE) {
|
||||||
vfs_volume_close(proc1, volume, rctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* temp_buffer = malloc(desc.size);
|
uint8_t* temp_buffer = malloc(desc.size);
|
||||||
|
|
||||||
if (temp_buffer == NULL) {
|
if (temp_buffer == NULL) {
|
||||||
vfs_volume_close(proc1, volume, rctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = vfs_read_file(proc1, rctx, volume, path, temp_buffer, 0, desc.size)) < 0) {
|
if ((ret = vfs_read_file(proc1, rctx, volume, path, temp_buffer, 0, desc.size)) < 0) {
|
||||||
free(temp_buffer);
|
free(temp_buffer);
|
||||||
vfs_volume_close(proc1, volume, rctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs_volume_close(proc1, volume, rctx);
|
|
||||||
|
|
||||||
if (!proc_check_elf(temp_buffer)) {
|
if (!proc_check_elf(temp_buffer)) {
|
||||||
free(temp_buffer);
|
free(temp_buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ struct proc {
|
|||||||
struct cpu* cpu;
|
struct cpu* cpu;
|
||||||
int state;
|
int state;
|
||||||
uintptr_t uvaddr_argument;
|
uintptr_t uvaddr_argument;
|
||||||
char cwv[VOLUME_MAX];
|
|
||||||
struct proc_suspension_q done_sq;
|
struct proc_suspension_q done_sq;
|
||||||
char name[PATH_MAX + VOLUME_MAX];
|
char name[PATH_MAX + VOLUME_MAX];
|
||||||
|
char cwv[VOLUME_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
void proc_sched(bool user);
|
void proc_sched(bool user);
|
||||||
|
|||||||
@@ -415,11 +415,6 @@ DEFINE_SYSCALL(sys_volume_open) {
|
|||||||
|
|
||||||
const char* volume = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
const char* volume = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||||
|
|
||||||
int ret = vfs_volume_open(proc, volume, rctx);
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
return SYSRESULT(ret);
|
|
||||||
|
|
||||||
strncpy(proc->cwv, volume, VOLUME_MAX);
|
strncpy(proc->cwv, volume, VOLUME_MAX);
|
||||||
|
|
||||||
return SYSRESULT(ST_OK);
|
return SYSRESULT(ST_OK);
|
||||||
@@ -427,16 +422,9 @@ DEFINE_SYSCALL(sys_volume_open) {
|
|||||||
|
|
||||||
/* int volume_close (void) */
|
/* int volume_close (void) */
|
||||||
DEFINE_SYSCALL(sys_volume_close) {
|
DEFINE_SYSCALL(sys_volume_close) {
|
||||||
char cwv[VOLUME_MAX];
|
memset(proc->cwv, 0, sizeof(proc->cwv));
|
||||||
memcpy(cwv, proc->cwv, sizeof(proc->cwv));
|
|
||||||
|
|
||||||
int ret = vfs_volume_close(proc, cwv, rctx);
|
return SYSRESULT(ST_OK);
|
||||||
|
|
||||||
if (ret == ST_OK) {
|
|
||||||
memset(proc->cwv, 0, sizeof(proc->cwv));
|
|
||||||
}
|
|
||||||
|
|
||||||
return SYSRESULT(ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* int read_file (char* path, size_t off, uint8_t* buffer, size_t size) */
|
/* int read_file (char* path, size_t off, uint8_t* buffer, size_t size) */
|
||||||
|
|||||||
Reference in New Issue
Block a user