PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
Go to the source code of this file.
Data Structures | |
struct | file |
An open file. More... | |
Functions | |
struct file * | file_open (struct inode *inode) |
Opens a file for the given INODE, of which it takes ownership, and returns the new file. More... | |
struct file * | file_reopen (struct file *file) |
Opens and returns a new file for the same inode as FILE. More... | |
void | file_close (struct file *file) |
Closes FILE. More... | |
struct inode * | file_get_inode (struct file *file) |
Returns the inode encapsulated by FILE. More... | |
off_t | file_read (struct file *file, void *buffer, off_t size) |
Reads SIZE bytes from FILE into BUFFER, starting at the file's current position. More... | |
off_t | file_read_at (struct file *file, void *buffer, off_t size, off_t file_ofs) |
Reads SIZE bytes from FILE into BUFFER, starting at offset FILE_OFS in the file. More... | |
off_t | file_write (struct file *file, const void *buffer, off_t size) |
Writes SIZE bytes from BUFFER into FILE, starting at the file's current position. More... | |
off_t | file_write_at (struct file *file, const void *buffer, off_t size, off_t file_ofs) |
Writes SIZE bytes from BUFFER into FILE, starting at offset FILE_OFS in the file. More... | |
void | file_deny_write (struct file *file) |
Prevents write operations on FILE's underlying inode until file_allow_write() is called or FILE is closed. More... | |
void | file_allow_write (struct file *file) |
Re-enables write operations on FILE's underlying inode. More... | |
off_t | file_length (struct file *file) |
Returns the size of FILE in bytes. More... | |
void | file_seek (struct file *file, off_t new_pos) |
Sets the current position in FILE to NEW_POS bytes from the start of the file. More... | |
off_t | file_tell (struct file *file) |
Returns the current position in FILE as a byte offset from the start of the file. More... | |
void file_allow_write | ( | struct file * | file | ) |
Re-enables write operations on FILE's underlying inode.
(Writes might still be denied by some other file that has the same inode open.)
Definition at line 133 of file file.c.
References ASSERT, file::deny_write, file::inode, inode_allow_write(), and NULL.
Referenced by file_close().
void file_close | ( | struct file * | file | ) |
Closes FILE.
Definition at line 46 of file file.c.
References file_allow_write(), free(), file::inode, inode_close(), and NULL.
Referenced by free_map_close(), fsutil_append(), fsutil_cat(), fsutil_extract(), and load().
void file_deny_write | ( | struct file * | file | ) |
Prevents write operations on FILE's underlying inode until file_allow_write() is called or FILE is closed.
Preventing writes.
Definition at line 119 of file file.c.
References ASSERT, file::deny_write, file::inode, inode_deny_write(), and NULL.
Returns the inode encapsulated by FILE.
Definition at line 58 of file file.c.
References file::inode.
Returns the size of FILE in bytes.
Definition at line 145 of file file.c.
References ASSERT, file::inode, inode_length(), and NULL.
Referenced by fsutil_append(), load(), and validate_segment().
Opens a file for the given INODE, of which it takes ownership, and returns the new file.
Opening and closing files.
Returns a null pointer if an allocation fails or if INODE is null.
Definition at line 18 of file file.c.
References calloc(), file::deny_write, free(), file::inode, inode_close(), NULL, and file::pos.
Referenced by file_reopen(), filesys_open(), free_map_create(), and free_map_open().
Reads SIZE bytes from FILE into BUFFER, starting at the file's current position.
Reading and writing.
Returns the number of bytes actually read, which may be less than SIZE if end of file is reached. Advances FILE's position by the number of bytes read.
Definition at line 69 of file file.c.
References buffer, file::inode, inode_read_at(), and file::pos.
Referenced by fsutil_append(), fsutil_cat(), load(), and load_segment().
Reads SIZE bytes from FILE into BUFFER, starting at offset FILE_OFS in the file.
Returns the number of bytes actually read, which may be less than SIZE if end of file is reached. The file's current position is unaffected.
Definition at line 82 of file file.c.
References buffer, file::inode, and inode_read_at().
Opens and returns a new file for the same inode as FILE.
Returns a null pointer if unsuccessful.
Definition at line 39 of file file.c.
References file_open(), file::inode, and inode_reopen().
Writes SIZE bytes from BUFFER into FILE, starting at the file's current position.
Returns the number of bytes actually written, which may be less than SIZE if end of file is reached. (Normally we'd grow the file in that case, but file growth is not yet implemented.) Advances FILE's position by the number of bytes read.
Definition at line 95 of file file.c.
References buffer, file::inode, inode_write_at(), and file::pos.
Referenced by fsutil_extract().
Writes SIZE bytes from BUFFER into FILE, starting at offset FILE_OFS in the file.
Returns the number of bytes actually written, which may be less than SIZE if end of file is reached. (Normally we'd grow the file in that case, but file growth is not yet implemented.) The file's current position is unaffected.
Definition at line 110 of file file.c.
References buffer, file::inode, and inode_write_at().