spinlock open_files_lock;
file open_files[32];
struct file_descriptor {
int fd;
file* f;
}
struct file {
enum {F_FILE, F_PIPE, F_KB_C} f_type;
unsigned int f_perms; // PERM_READ/PERM_WRITE/PERM_EXEC
unsigned int f_offset;
v_node* f_vnode;
unsigned int f_refcount;
}
struct v_node {
virtual ssize_t read(char* buf, int index, size_t sz);
virtual ssize_t write(char* buf, int index, size_t sz);
virtual int open(struct inode*);
virtual int close();
}
int syscall_dup2(regstate* regs);
int syscall_close(regstate* regs);
We expect v_node
to be subclassed with specific kinds of v_nodes
, and different read()
, write()
, open()
, and close()
methods.
Per process file descriptor table:
Every process will have an eight member long array of struct file descriptors. A member will be present if a file is open. The struct file_descriptor
contains its own index, and a file*
that corresponds to its open file the system-wide open_files
array.
System-Wide open_files
Array:
There will be one system wide file array with 32 members of struct files.
A file
contains
v_node
Struct file
Content
R_PERM
), write (W_PERM
), and/or executable (X_PERM
) permissions.v_node*
:v_node
pointer. Depending on the file type, it would point to different v_nodes (i.e. keyboard console v_node, pipe v_node, …). The v_node
pointer acts as an interface for a file's interaction based function calls (open, read, etc.).file*
pointing to this file. When refcount
becomes 0, we should clear out this file
Struct v_node
Content
Each vnode will have an inode pointer, a lock, and function pointers pointing to the correct implementations dependent upon type of file. These function pointers will be set upon initialization.
v_node
Functions
{open(), read(), write(), close()
}
When a process calls one of these functions from a v_node
, a file descriptor (from per process file descriptor array) and corresponding file (from system wide file array) must be valid. Each of these functions have to be separately implemented for each v_node
subclass.
open_files_lock
protects the global open_files
array that stores the file
open file descriptor objects.
file
s in the open_files
array, it will grab this lock and increment refcountread()
and write()
should block, all other functions should not blockor
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing