PKUOS - Pintos
Pintos source browser for PKU Operating System course
Functions | Variables
filesys.c File Reference
#include "filesys/filesys.h"
#include <debug.h>
#include <stdio.h>
#include <string.h>
#include "filesys/file.h"
#include "filesys/free-map.h"
#include "filesys/inode.h"
#include "filesys/directory.h"
Include dependency graph for filesys.c:

Go to the source code of this file.

Functions

static void do_format (void)
 Formats the file system. More...
 
void filesys_init (bool format)
 Initializes the file system module. More...
 
void filesys_done (void)
 Shuts down the file system module, writing any unwritten data to disk. More...
 
bool filesys_create (const char *name, off_t initial_size)
 Creates a file named NAME with the given INITIAL_SIZE. More...
 
struct filefilesys_open (const char *name)
 Opens the file with the given NAME. More...
 
bool filesys_remove (const char *name)
 Deletes the file named NAME. More...
 

Variables

struct blockfs_device
 Partition that contains the file system. More...
 

Function Documentation

◆ do_format()

static void do_format ( void  )
static

Formats the file system.

Definition at line 95 of file filesys.c.

References dir_create(), free_map_close(), free_map_create(), PANIC, printf(), and ROOT_DIR_SECTOR.

Referenced by filesys_init().

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

◆ filesys_create()

bool filesys_create ( const char *  name,
off_t  initial_size 
)

Creates a file named NAME with the given INITIAL_SIZE.

Returns true if successful, false otherwise. Fails if a file named NAME already exists, or if internal memory allocation fails.

Definition at line 46 of file filesys.c.

References dir_add(), dir_close(), dir_open_root(), free_map_allocate(), free_map_release(), inode_create(), name, and NULL.

Referenced by fsutil_extract().

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

◆ filesys_done()

void filesys_done ( void  )

Shuts down the file system module, writing any unwritten data to disk.

Definition at line 36 of file filesys.c.

References free_map_close().

Referenced by shutdown_power_off().

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

◆ filesys_init()

void filesys_init ( bool  format)

Initializes the file system module.

If FORMAT is true, reformats the file system.

Definition at line 18 of file filesys.c.

References BLOCK_FILESYS, block_get_role(), do_format(), free_map_init(), free_map_open(), fs_device, inode_init(), NULL, and PANIC.

Referenced by pintos_init().

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

◆ filesys_open()

struct file * filesys_open ( const char *  name)

Opens the file with the given NAME.

Returns the new file if successful or a null pointer otherwise. Fails if no file named NAME exists, or if an internal memory allocation fails.

Definition at line 67 of file filesys.c.

References dir_close(), dir_lookup(), dir_open_root(), file_open(), name, and NULL.

Referenced by fsutil_append(), fsutil_cat(), fsutil_extract(), and load().

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

◆ filesys_remove()

bool filesys_remove ( const char *  name)

Deletes the file named NAME.

filesys/filesys.h

Returns true if successful, false on failure. Fails if no file named NAME exists, or if an internal memory allocation fails.

Definition at line 84 of file filesys.c.

References dir_close(), dir_open_root(), dir_remove(), name, and NULL.

Referenced by fsutil_rm().

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

Variable Documentation

◆ fs_device

struct block* fs_device

Partition that contains the file system.

Definition at line 11 of file filesys.c.

Referenced by filesys_init(), free_map_init(), inode_create(), inode_open(), inode_read_at(), and inode_write_at().