[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
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 "devices/disk.h"
Include dependency graph for filesys.c:

Functions

static void do_format (void)
 
void filesys_init (bool format)
 
void filesys_done (void)
 
bool filesys_create (const char *name, off_t initial_size)
 
struct filefilesys_open (const char *name)
 
bool filesys_remove (const char *name)
 

Variables

struct diskfilesys_disk
 

Function Documentation

◆ do_format()

static void do_format ( void  )
static
107 {
108 printf ("Formatting file system...");
109
110#ifdef EFILESYS
111 /* Create FAT and save it to the disk. */
112 fat_create ();
113 fat_close ();
114#else
116 if (!dir_create (ROOT_DIR_SECTOR, 16))
117 PANIC ("root directory creation failed");
119#endif
120
121 printf ("done.\n");
122}
#define PANIC(...)
Definition: debug.h:14
bool dir_create(disk_sector_t sector, size_t entry_cnt)
Definition: directory.c:25
void fat_create(void)
Definition: fat.c:117
void fat_close(void)
Definition: fat.c:84
#define ROOT_DIR_SECTOR
Definition: filesys.h:9
void free_map_create(void)
Definition: free-map.c:66
void free_map_close(void)
Definition: free-map.c:59
int printf(const char *,...) PRINTF_FORMAT(1
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 
)
61 {
62 disk_sector_t inode_sector = 0;
63 struct dir *dir = dir_open_root ();
64 bool success = (dir != NULL
65 && free_map_allocate (1, &inode_sector)
66 && inode_create (inode_sector, initial_size)
67 && dir_add (dir, name, inode_sector));
68 if (!success && inode_sector != 0)
69 free_map_release (inode_sector, 1);
70 dir_close (dir);
71
72 return success;
73}
void dir_close(struct dir *dir)
Definition: directory.c:61
bool dir_add(struct dir *dir, const char *name, disk_sector_t inode_sector)
Definition: directory.c:127
struct dir * dir_open_root(void)
Definition: directory.c:48
uint32_t disk_sector_t
Definition: disk.h:12
bool free_map_allocate(size_t cnt, disk_sector_t *sectorp)
Definition: free-map.c:26
void free_map_release(disk_sector_t sector, size_t cnt)
Definition: free-map.c:41
bool inode_create(disk_sector_t sector, off_t length)
Definition: inode.c:68
#define NULL
Definition: stddef.h:4
Definition: directory.c:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesys_done()

void filesys_done ( void  )
47 {
48 /* Original FS */
49#ifdef EFILESYS
50 fat_close ();
51#else
53#endif
54}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesys_init()

void filesys_init ( bool  format)
19 {
20 filesys_disk = disk_get (0, 1);
21 if (filesys_disk == NULL)
22 PANIC ("hd0:1 (hdb) not present, file system initialization failed");
23
24 inode_init ();
25
26#ifdef EFILESYS
27 fat_init ();
28
29 if (format)
30 do_format ();
31
32 fat_open ();
33#else
34 /* Original FS */
36
37 if (format)
38 do_format ();
39
41#endif
42}
struct disk * disk_get(int chan_no, int dev_no)
Definition: disk.c:186
void fat_init(void)
Definition: fat.c:35
void fat_open(void)
Definition: fat.c:55
static void do_format(void)
Definition: filesys.c:107
struct disk * filesys_disk
Definition: filesys.c:12
void free_map_init(void)
Definition: free-map.c:13
void free_map_open(void)
Definition: free-map.c:49
void inode_init(void)
Definition: inode.c:58
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)
81 {
82 struct dir *dir = dir_open_root ();
83 struct inode *inode = NULL;
84
85 if (dir != NULL)
86 dir_lookup (dir, name, &inode);
87 dir_close (dir);
88
89 return file_open (inode);
90}
bool dir_lookup(const struct dir *dir, const char *name, struct inode **inode)
Definition: directory.c:105
struct file * file_open(struct inode *inode)
Definition: file.c:17
Definition: inode.c:30
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesys_remove()

bool filesys_remove ( const char *  name)
97 {
98 struct dir *dir = dir_open_root ();
99 bool success = dir != NULL && dir_remove (dir, name);
100 dir_close (dir);
101
102 return success;
103}
bool dir_remove(struct dir *dir, const char *name)
Definition: directory.c:169
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ filesys_disk

struct disk* filesys_disk