Skip to content

Commit

Permalink
kernel: add table to name for ht_t variables (hash table)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjwang committed Sep 20, 2024
1 parent e8e6357 commit d66ba6a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion kernel/fs/filebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ vfs_node_desc_t *vfs_handle_to_fd(vfs_handle_t handle)
{
task_t *t = sched_get_current_task();
if (t != NULL) {
vfs_node_desc_t* nd = (vfs_node_desc_t*)ht_search(&(t->openfiles), handle);
vfs_node_desc_t* nd = (vfs_node_desc_t*)ht_search(&(t->open_files_table), handle);
if (nd != NULL) return nd;
klogw("VFS: cannot locate %d (0x%x) in file list of task %d, "
"maybe we need to increase hash table's size.\n",
Expand Down
4 changes: 2 additions & 2 deletions kernel/fs/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ vfs_handle_t vfs_open(char *path, vfs_openmode_t mode)
/* Add to current task */
task_t *t = sched_get_current_task();
if (t != NULL) {
ht_insert(&(t->openfiles), fh, nd);
ht_insert(&(t->open_files_table), fh, nd);
} else {
kloge("VFS: cannot insert \"%s\" because of invalid task\n", path);
}
Expand Down Expand Up @@ -567,7 +567,7 @@ int64_t vfs_close(vfs_handle_t handle)

task_t *t = sched_get_current_task();
if (t != NULL) {
ht_delete(&(t->openfiles), handle);
ht_delete(&(t->open_files_table), handle);
} else {
kloge("VFS: cannot remove file %d because of invalid task\n", handle);
}
Expand Down
16 changes: 8 additions & 8 deletions kernel/proc/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,20 +597,20 @@ task_t *sched_execve(
}

/* Increase refcount of all open files */
ht_init(&tc->openfiles, tp->openfiles.size);
for (i = 0; i < tp->openfiles.size; i++) {
if (tp->openfiles.array[i].key == -1
|| tp->openfiles.array[i].data == NULL)
ht_init(&tc->open_files_table, tp->open_files_table.size);
for (i = 0; i < tp->open_files_table.size; i++) {
if (tp->open_files_table.array[i].key == -1
|| tp->open_files_table.array[i].data == NULL)
{
continue;
}
vfs_node_desc_t* nd = (vfs_node_desc_t*)kmalloc(sizeof(vfs_node_desc_t));
memcpy(nd, tp->openfiles.array[i].data, sizeof(vfs_node_desc_t));
tc->openfiles.array[i] = tp->openfiles.array[i];
tc->openfiles.array[i].data = nd;
memcpy(nd, tp->open_files_table.array[i].data, sizeof(vfs_node_desc_t));
tc->open_files_table.array[i] = tp->open_files_table.array[i];
tc->open_files_table.array[i].data = nd;
nd->inode->refcount++;
klogd("SCHED: copy fd %d from tid %d to tid %d\n",
tc->openfiles.array[i].key, tp->tid, tc->tid);
tc->open_files_table.array[i].key, tp->tid, tc->tid);
}
}

Expand Down
18 changes: 9 additions & 9 deletions kernel/proc/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ task_t *task_make(
strcpy(ntask->cwd, "/");
strncpy(ntask->name, name, sizeof(ntask->name));

ht_init(&ntask->openfiles, HT_DEFAULT_ARRAY_SIZE);
ht_init(&ntask->open_files_table, HT_DEFAULT_ARRAY_SIZE);

klogi("TASK: Create tid %d with name \"%s\" (task 0x%x)\n",
ntask->tid, name, ntask);
Expand Down Expand Up @@ -253,20 +253,20 @@ task_t *task_fork(task_t *tp)
}

/* Increase refcount of all open files */
ht_init(&tc->openfiles, tp->openfiles.size);
for (i = 0; i < tp->openfiles.size; i++) {
if (tp->openfiles.array[i].key == -1
|| tp->openfiles.array[i].data == NULL)
ht_init(&tc->open_files_table, tp->open_files_table.size);
for (i = 0; i < tp->open_files_table.size; i++) {
if (tp->open_files_table.array[i].key == -1
|| tp->open_files_table.array[i].data == NULL)
{
continue;
}
vfs_node_desc_t* nd = (vfs_node_desc_t*)kmalloc(sizeof(vfs_node_desc_t));
memcpy(nd, tp->openfiles.array[i].data, sizeof(vfs_node_desc_t));
tc->openfiles.array[i].key = tp->openfiles.array[i].key;
tc->openfiles.array[i].data = nd;
memcpy(nd, tp->open_files_table.array[i].data, sizeof(vfs_node_desc_t));
tc->open_files_table.array[i].key = tp->open_files_table.array[i].key;
tc->open_files_table.array[i].data = nd;
nd->inode->refcount++;
klogd("TASK: copy fd %d from tid %d to tid %d\n",
tc->openfiles.array[i].key, tp->tid, tc->tid);
tc->open_files_table.array[i].key, tp->tid, tc->tid);
}

task_debug(tc, false);
Expand Down
2 changes: 1 addition & 1 deletion kernel/proc/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ typedef struct _task_t {
auxval_t aux;
vec_struct(task_id_t) child_list;

ht_t openfiles;
ht_t open_files_table;
vec_struct(file_dup_t) dup_list;

int64_t errno;
Expand Down

0 comments on commit d66ba6a

Please sign in to comment.