[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
fat.c File Reference
#include "filesys/fat.h"
#include "devices/disk.h"
#include "filesys/filesys.h"
#include "threads/malloc.h"
#include "threads/synch.h"
#include <stdio.h>
#include <string.h>
Include dependency graph for fat.c:

Classes

struct  fat_boot
 
struct  fat_fs
 

Functions

void fat_boot_create (void)
 
void fat_fs_init (void)
 
void fat_init (void)
 
void fat_open (void)
 
void fat_close (void)
 
void fat_create (void)
 
cluster_t fat_create_chain (cluster_t clst)
 
void fat_remove_chain (cluster_t clst, cluster_t pclst)
 
void fat_put (cluster_t clst, cluster_t val)
 
cluster_t fat_get (cluster_t clst)
 
disk_sector_t cluster_to_sector (cluster_t clst)
 

Variables

static struct fat_fsfat_fs
 

Function Documentation

◆ cluster_to_sector()

disk_sector_t cluster_to_sector ( cluster_t  clst)
191 {
192 /* TODO: Your code goes here. */
193}
Here is the caller graph for this function:

◆ fat_boot_create()

void fat_boot_create ( void  )
139 {
140 unsigned int fat_sectors =
141 (disk_size (filesys_disk) - 1)
142 / (DISK_SECTOR_SIZE / sizeof (cluster_t) * SECTORS_PER_CLUSTER + 1) + 1;
143 fat_fs->bs = (struct fat_boot){
144 .magic = FAT_MAGIC,
145 .sectors_per_cluster = SECTORS_PER_CLUSTER,
146 .total_sectors = disk_size (filesys_disk),
147 .fat_start = 1,
148 .fat_sectors = fat_sectors,
149 .root_dir_cluster = ROOT_DIR_CLUSTER,
150 };
151}
disk_sector_t disk_size(struct disk *d)
Definition: disk.c:200
#define DISK_SECTOR_SIZE
Definition: disk.h:8
#define SECTORS_PER_CLUSTER
Definition: fat.h:17
#define FAT_MAGIC
Definition: fat.h:13
uint32_t cluster_t
Definition: fat.h:11
#define ROOT_DIR_CLUSTER
Definition: fat.h:19
struct disk * filesys_disk
Definition: filesys.c:12
Definition: fat.c:10
unsigned int magic
Definition: fat.c:11
unsigned int fat_sectors
Definition: fat.c:15
Definition: fat.c:20
struct fat_boot bs
Definition: fat.c:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fat_close()

void fat_close ( void  )
84 {
85 // Write FAT boot sector
86 uint8_t *bounce = calloc (1, DISK_SECTOR_SIZE);
87 if (bounce == NULL)
88 PANIC ("FAT close failed");
89 memcpy (bounce, &fat_fs->bs, sizeof (fat_fs->bs));
91 free (bounce);
92
93 // Write FAT directly to the disk
95 off_t bytes_wrote = 0;
96 off_t bytes_left = sizeof (fat_fs->fat);
97 const off_t fat_size_in_bytes = fat_fs->fat_length * sizeof (cluster_t);
98 for (unsigned i = 0; i < fat_fs->bs.fat_sectors; i++) {
99 bytes_left = fat_size_in_bytes - bytes_wrote;
100 if (bytes_left >= DISK_SECTOR_SIZE) {
102 buffer + bytes_wrote);
103 bytes_wrote += DISK_SECTOR_SIZE;
104 } else {
105 bounce = calloc (1, DISK_SECTOR_SIZE);
106 if (bounce == NULL)
107 PANIC ("FAT close failed");
108 memcpy (bounce, buffer + bytes_wrote, bytes_left);
109 disk_write (filesys_disk, fat_fs->bs.fat_start + i, bounce);
110 bytes_wrote += bytes_left;
111 free (bounce);
112 }
113 }
114}
#define PANIC(...)
Definition: debug.h:14
void disk_write(struct disk *d, disk_sector_t sec_no, const void *buffer)
Definition: disk.c:235
#define FAT_BOOT_SECTOR
Definition: fat.h:18
static struct intq buffer
Definition: input.c:7
void * calloc(size_t, size_t) __attribute__((malloc))
Definition: malloc.c:149
void free(void *)
Definition: malloc.c:202
int32_t off_t
Definition: off_t.h:9
#define NULL
Definition: stddef.h:4
unsigned char uint8_t
Definition: stdint.h:20
void * memcpy(void *, const void *, size_t)
Definition: string.c:7
unsigned int fat_start
Definition: fat.c:14
unsigned int fat_length
Definition: fat.c:23
unsigned int * fat
Definition: fat.c:22
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fat_create()

void fat_create ( void  )
117 {
118 // Create FAT boot
120 fat_fs_init ();
121
122 // Create FAT table
123 fat_fs->fat = calloc (fat_fs->fat_length, sizeof (cluster_t));
124 if (fat_fs->fat == NULL)
125 PANIC ("FAT creation failed");
126
127 // Set up ROOT_DIR_CLST
129
130 // Fill up ROOT_DIR_CLUSTER region with 0
131 uint8_t *buf = calloc (1, DISK_SECTOR_SIZE);
132 if (buf == NULL)
133 PANIC ("FAT create failed due to OOM");
135 free (buf);
136}
void fat_boot_create(void)
Definition: fat.c:139
void fat_put(cluster_t clst, cluster_t val)
Definition: fat.c:179
void fat_fs_init(void)
Definition: fat.c:154
disk_sector_t cluster_to_sector(cluster_t clst)
Definition: fat.c:191
#define EOChain
Definition: fat.h:14
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fat_create_chain()

cluster_t fat_create_chain ( cluster_t  clst)
166 {
167 /* TODO: Your code goes here. */
168}

◆ fat_fs_init()

void fat_fs_init ( void  )
154 {
155 /* TODO: Your code goes here. */
156}
Here is the caller graph for this function:

◆ fat_get()

cluster_t fat_get ( cluster_t  clst)
185 {
186 /* TODO: Your code goes here. */
187}

◆ fat_init()

void fat_init ( void  )
35 {
36 fat_fs = calloc (1, sizeof (struct fat_fs));
37 if (fat_fs == NULL)
38 PANIC ("FAT init failed");
39
40 // Read boot sector from the disk
41 unsigned int *bounce = malloc (DISK_SECTOR_SIZE);
42 if (bounce == NULL)
43 PANIC ("FAT init failed");
45 memcpy (&fat_fs->bs, bounce, sizeof (fat_fs->bs));
46 free (bounce);
47
48 // Extract FAT info
49 if (fat_fs->bs.magic != FAT_MAGIC)
51 fat_fs_init ();
52}
void disk_read(struct disk *d, disk_sector_t sec_no, void *buffer)
Definition: disk.c:211
void * malloc(size_t) __attribute__((malloc))
Definition: malloc.c:85
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fat_open()

void fat_open ( void  )
55 {
57 if (fat_fs->fat == NULL)
58 PANIC ("FAT load failed");
59
60 // Load FAT directly from the disk
62 off_t bytes_read = 0;
63 off_t bytes_left = sizeof (fat_fs->fat);
64 const off_t fat_size_in_bytes = fat_fs->fat_length * sizeof (cluster_t);
65 for (unsigned i = 0; i < fat_fs->bs.fat_sectors; i++) {
66 bytes_left = fat_size_in_bytes - bytes_read;
67 if (bytes_left >= DISK_SECTOR_SIZE) {
69 buffer + bytes_read);
70 bytes_read += DISK_SECTOR_SIZE;
71 } else {
73 if (bounce == NULL)
74 PANIC ("FAT load failed");
76 memcpy (buffer + bytes_read, bounce, bytes_left);
77 bytes_read += bytes_left;
78 free (bounce);
79 }
80 }
81}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fat_put()

void fat_put ( cluster_t  clst,
cluster_t  val 
)
179 {
180 /* TODO: Your code goes here. */
181}
Here is the caller graph for this function:

◆ fat_remove_chain()

void fat_remove_chain ( cluster_t  clst,
cluster_t  pclst 
)
173 {
174 /* TODO: Your code goes here. */
175}

Variable Documentation

◆ fat_fs

struct fat_fs* fat_fs
static