+ Direct access for single file as needed
–– Requires disk access to load the inode
++ Fast access for random block
++ Support sparse files (holes in file)
– inode table size limits number of unique files
– File size limited by inode TOC size
++ Cached in memory, fast access
– Requires linked list traversal (though it's in memory)
+ File size only limited by FAT size
– FAT size limits number of blocks
Refer to lecture slide 54
| 10 |
| NULL |
| 27 |
| NULL |
| NULL |
| 29 |
| 81 |
| NULL |
| ...... |
+ Direct access for single file as needed
–– Requires disk access to load the inode
++ Fast access for random block
++ Support sparse files (holes in file)
– inode table size limits number of unique files
– File size limited by inode TOC size
++ Cached in memory, fast access
– Requires linked list traversal (though it's in memory)
+ File size only limited by FAT size
– FAT size limits number of blocks
???
???
int fseek(FILE *stream, long int offset, int whence)
/* seek to the position of whence + offset.
whence can be
SEEK_SET (beginning of file),
SEEK_CUR (current pos),
SEEK_END (end of file). */
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
/* read nmemb number of elements, each with size `size` */
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
/* similar to fread */| TOC | Range |
|---|---|
| 15 | 0-2047 |
| 18 | 2048-4095 |
| 12 | 4096-6143 |
| 22 | 6144-8191 |
| Op | Offset | Block number |
|---|---|---|
| fseek(fp, 1121, SEEK_SET) | 1121 | (15) |
| fwrite(buff, sizeof(char), 128, fp) | 1121+128 = 1249 | 15 |
| fseek(fp, 5523, SEEK_SET) | 5523 | (12) |
| fread(buff, sizeof(char), 256, fp) | 5523+256 = 5779 | 12 |
| fseek(fp, 8121, SEEK_SET) | 8121 | (22) |
| fwrite(buff, sizeof(int), 25, fp) | 8121+ 100 = 8221 | 22 + ??? |
Bracket means pointer is at that block
but nothing read / written
| Op | Offset | Block number |
|---|---|---|
| fseek(fp, 1121, SEEK_SET) | ||
| fwrite(buff, sizeof(char), 128, fp) | ||
| fseek(fp, 5523, SEEK_SET) | ||
| fread(buff, sizeof(char), 256, fp) | ||
| fseek(fp, 8121, SEEK_SET) | ||
| fwrite(buff, sizeof(int), 25, fp) |
| Block # | First Byte |
|---|---|
| 0 | 0 |
| 1 | 2048 |
| 2 | 4096 |
| 3 | 6144 |
| 4 | 8192 |
| 5 | 10240 |
| 6 | 12288 |
| 7 | ... |
fwrite(buffer, sizeof(int), 1024, fp);
// sizeof(int) = 4 bytes
fseek(fp, 8897, SEEK_SET);
fwrite(buffer, sizeof(char), 1124, fp);
fseek(fp, 3072, SEEK_SET);
fread(buffer, sizeof(char), 1024, fp);1 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0
1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0
| 1 |
| 4 |
| NULL |
| NULL |
| 5 |
| NULL |
Buffer contains the data in block 4