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

Go to the source code of this file.

Functions

void inode_init (void)
 Initializes the inode module. More...
 
bool inode_create (block_sector_t, off_t)
 Initializes an inode with LENGTH bytes of data and writes the new inode to sector SECTOR on the file system device. More...
 
struct inodeinode_open (block_sector_t)
 Reads an inode from SECTOR and returns a ‘struct inode’ that contains it. More...
 
struct inodeinode_reopen (struct inode *)
 Reopens and returns INODE. More...
 
block_sector_t inode_get_inumber (const struct inode *)
 Returns INODE's inode number. More...
 
void inode_close (struct inode *)
 Closes INODE and writes it to disk. More...
 
void inode_remove (struct inode *)
 Marks INODE to be deleted when it is closed by the last caller who has it open. More...
 
off_t inode_read_at (struct inode *, void *, off_t size, off_t offset)
 Reads SIZE bytes from INODE into BUFFER, starting at position OFFSET. More...
 
off_t inode_write_at (struct inode *, const void *, off_t size, off_t offset)
 Writes SIZE bytes from BUFFER into INODE, starting at OFFSET. More...
 
void inode_deny_write (struct inode *)
 Disables writes to INODE. More...
 
void inode_allow_write (struct inode *)
 Re-enables writes to INODE. More...
 
off_t inode_length (const struct inode *)
 filesys/inode.h More...
 

Function Documentation

◆ inode_allow_write()

void inode_allow_write ( struct inode inode)

Re-enables writes to INODE.

Must be called once by each inode opener who has called inode_deny_write() on the inode, before closing the inode.

Definition at line 333 of file inode.c.

References ASSERT, inode::deny_write_cnt, and inode::open_cnt.

Referenced by file_allow_write().

Here is the caller graph for this function:

◆ inode_close()

void inode_close ( struct inode inode)

Closes INODE and writes it to disk.

If this was the last reference to INODE, frees its memory. If INODE was also a removed inode, frees its blocks.

Definition at line 164 of file inode.c.

References bytes_to_sectors(), inode::data, inode::elem, free(), free_map_release(), inode_disk::length, list_remove(), NULL, inode::open_cnt, inode::removed, inode::sector, and inode_disk::start.

Referenced by dir_close(), dir_open(), dir_remove(), file_close(), and file_open().

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

◆ inode_create()

bool inode_create ( block_sector_t  sector,
off_t  length 
)

Initializes an inode with LENGTH bytes of data and writes the new inode to sector SECTOR on the file system device.

Returns true if successful. Returns false if memory or disk allocation fails.

Definition at line 73 of file inode.c.

References ASSERT, BLOCK_SECTOR_SIZE, block_write(), bytes_to_sectors(), calloc(), free(), free_map_allocate(), fs_device, INODE_MAGIC, inode_disk::length, inode_disk::magic, NULL, and inode_disk::start.

Referenced by dir_create(), filesys_create(), and free_map_create().

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

◆ inode_deny_write()

void inode_deny_write ( struct inode inode)

Disables writes to INODE.

May be called at most once per inode opener.

Definition at line 323 of file inode.c.

References ASSERT, inode::deny_write_cnt, and inode::open_cnt.

Referenced by file_deny_write().

Here is the caller graph for this function:

◆ inode_get_inumber()

block_sector_t inode_get_inumber ( const struct inode inode)

Returns INODE's inode number.

Definition at line 155 of file inode.c.

References inode::sector.

◆ inode_init()

void inode_init ( void  )

Initializes the inode module.

Definition at line 62 of file inode.c.

References list_init(), and open_inodes.

Referenced by filesys_init().

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

◆ inode_length()

off_t inode_length ( const struct inode inode)

filesys/inode.h

filesys/inode.h

Definition at line 342 of file inode.c.

References inode::data, and inode_disk::length.

Referenced by file_length(), inode_read_at(), and inode_write_at().

Here is the caller graph for this function:

◆ inode_open()

struct inode * inode_open ( block_sector_t  sector)

Reads an inode from SECTOR and returns a ‘struct inode’ that contains it.

Returns a null pointer if memory allocation fails.

Definition at line 112 of file inode.c.

References block_read(), inode::data, inode::deny_write_cnt, inode::elem, fs_device, inode_reopen(), list_begin(), list_end(), list_entry, list_next(), list_push_front(), malloc(), NULL, inode::open_cnt, open_inodes, inode::removed, and inode::sector.

Referenced by dir_lookup(), dir_open_root(), dir_remove(), free_map_create(), and free_map_open().

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

◆ inode_read_at()

off_t inode_read_at ( struct inode inode,
void *  buffer_,
off_t  size,
off_t  offset 
)

Reads SIZE bytes from INODE into BUFFER, starting at position OFFSET.

Returns the number of bytes actually read, which may be less than SIZE if an error occurs or end of file is reached.

Definition at line 201 of file inode.c.

References block_read(), BLOCK_SECTOR_SIZE, buffer, byte_to_sector(), free(), fs_device, inode_length(), malloc(), memcpy(), and NULL.

Referenced by dir_add(), dir_readdir(), file_read(), file_read_at(), and lookup().

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

◆ inode_remove()

void inode_remove ( struct inode inode)

Marks INODE to be deleted when it is closed by the last caller who has it open.

Definition at line 191 of file inode.c.

References ASSERT, NULL, and inode::removed.

Referenced by dir_remove().

Here is the caller graph for this function:

◆ inode_reopen()

struct inode * inode_reopen ( struct inode inode)

Reopens and returns INODE.

Definition at line 146 of file inode.c.

References NULL, and inode::open_cnt.

Referenced by dir_reopen(), file_reopen(), and inode_open().

Here is the caller graph for this function:

◆ inode_write_at()

off_t inode_write_at ( struct inode inode,
const void *  buffer_,
off_t  size,
off_t  offset 
)

Writes SIZE bytes from BUFFER into INODE, starting at OFFSET.

Returns the number of bytes actually written, which may be less than SIZE if end of file is reached or an error occurs. (Normally a write at end of file would extend the inode, but growth is not yet implemented.)

Definition at line 258 of file inode.c.

References block_read(), BLOCK_SECTOR_SIZE, block_write(), buffer, byte_to_sector(), inode::deny_write_cnt, free(), fs_device, inode_length(), malloc(), memcpy(), memset(), and NULL.

Referenced by dir_add(), dir_remove(), file_write(), and file_write_at().

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