PKUOS - Pintos
Pintos source browser for PKU Operating System course
Functions
file.h File Reference
#include "filesys/off_t.h"
Include dependency graph for file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct filefile_open (struct inode *)
 Opening and closing files. More...
 
struct filefile_reopen (struct file *)
 Opens and returns a new file for the same inode as FILE. More...
 
void file_close (struct file *)
 Closes FILE. More...
 
struct inodefile_get_inode (struct file *)
 Returns the inode encapsulated by FILE. More...
 
off_t file_read (struct file *, void *, off_t)
 Reading and writing. More...
 
off_t file_read_at (struct file *, void *, off_t size, off_t start)
 Reads SIZE bytes from FILE into BUFFER, starting at offset FILE_OFS in the file. More...
 
off_t file_write (struct file *, const void *, off_t)
 Writes SIZE bytes from BUFFER into FILE, starting at the file's current position. More...
 
off_t file_write_at (struct file *, const void *, off_t size, off_t start)
 Writes SIZE bytes from BUFFER into FILE, starting at offset FILE_OFS in the file. More...
 
void file_deny_write (struct file *)
 Preventing writes. More...
 
void file_allow_write (struct file *)
 Re-enables write operations on FILE's underlying inode. More...
 
void file_seek (struct file *, off_t)
 File position. More...
 
off_t file_tell (struct file *)
 Returns the current position in FILE as a byte offset from the start of the file. More...
 
off_t file_length (struct file *)
 filesys/file.h More...
 

Function Documentation

◆ file_allow_write()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_deny_write()

void file_deny_write ( struct file file)

Preventing writes.

Preventing writes.

Definition at line 119 of file file.c.

References ASSERT, file::deny_write, file::inode, inode_deny_write(), and NULL.

Here is the call graph for this function:

◆ file_get_inode()

struct inode * file_get_inode ( struct file file)

Returns the inode encapsulated by FILE.

Definition at line 58 of file file.c.

References file::inode.

◆ file_length()

off_t file_length ( struct file file)

filesys/file.h

filesys/file.h

Definition at line 145 of file file.c.

References ASSERT, file::inode, inode_length(), and NULL.

Referenced by fsutil_append(), load(), and validate_segment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_open()

struct file * file_open ( struct inode inode)

Opening and closing files.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_read()

off_t file_read ( struct file file,
void *  buffer,
off_t  size 
)

Reading and writing.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_read_at()

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.

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().

Here is the call graph for this function:

◆ file_reopen()

struct file * file_reopen ( struct file file)

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().

Here is the call graph for this function:

◆ file_seek()

void file_seek ( struct file file,
off_t  new_pos 
)

File position.

File position.

Definition at line 154 of file file.c.

References ASSERT, NULL, and file::pos.

Referenced by load(), and load_segment().

Here is the caller graph for this function:

◆ file_tell()

off_t file_tell ( struct file file)

Returns the current position in FILE as a byte offset from the start of the file.

Definition at line 164 of file file.c.

References ASSERT, NULL, and file::pos.

Referenced by fsutil_cat().

Here is the caller graph for this function:

◆ file_write()

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.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_write_at()

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.

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().

Here is the call graph for this function: