21 printf (
"Files in the root directory:\n");
24 PANIC (
"root dir open failed");
28 printf (
"End of listing.\n");
84 PANIC (
"couldn't allocate buffers");
89 PANIC (
"couldn't open scratch device");
91 printf (
"Extracting ustar archive from scratch device "
92 "into file system...\n");
105 PANIC (
"bad ustar header in sector %"PRDSNu" (%s)", sector - 1, error);
134 if (
file_write (dst, data, chunk_size) != chunk_size)
135 PANIC (
"%s: write failed with %d bytes unwritten",
149 printf (
"Erasing ustar archive...\n");
177 printf (
"Appending '%s' to ustar archive on scratch device...\n",
file_name);
182 PANIC (
"couldn't allocate buffer");
193 PANIC (
"couldn't open scratch device");
struct block * block_get_role(enum block_type role)
Returns the block device fulfilling the given ROLE, or a null pointer if no block device has been ass...
block_sector_t block_size(struct block *block)
Returns the number of sectors in BLOCK.
void block_read(struct block *block, block_sector_t sector, void *buffer)
Reads sector SECTOR from BLOCK into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes.
void block_write(struct block *block, block_sector_t sector, const void *buffer)
Write sector SECTOR to BLOCK from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes.
uint32_t block_sector_t
Index of a block device sector.
#define BLOCK_SECTOR_SIZE
Size of a block device sector in bytes.
#define PRDSNu
Format specifier for printf(), e.g.
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
void dir_close(struct dir *dir)
Destroys DIR and frees associated resources.
bool dir_readdir(struct dir *dir, char name[NAME_MAX+1])
Reads the next directory entry in DIR and stores the name in NAME.
struct dir * dir_open_root(void)
Opens the root directory and returns a directory for it.
#define NAME_MAX
Maximum length of a file name component.
void file_close(struct file *file)
Closes FILE.
off_t file_write(struct file *file, const void *buffer, off_t size)
Writes SIZE bytes from BUFFER into FILE, starting at the file's current position.
off_t file_length(struct file *file)
Returns the size of FILE in bytes.
off_t file_read(struct file *file, void *buffer, off_t size)
Reads SIZE bytes from FILE into BUFFER, starting at the file's current position.
off_t file_tell(struct file *file)
Returns the current position in FILE as a byte offset from the start of the file.
struct file * filesys_open(const char *name)
Opens the file with the given NAME.
bool filesys_remove(const char *name)
Deletes the file named NAME.
bool filesys_create(const char *name, off_t initial_size)
Creates a file named NAME with the given INITIAL_SIZE.
void fsutil_cat(char **argv)
Prints the contents of file ARGV[1] to the system console as hex and ASCII.
void fsutil_ls(char **argv UNUSED)
List files in the root directory.
void fsutil_append(char **argv)
Copies file FILE_NAME from the file system to the scratch device, in ustar format.
void fsutil_extract(char **argv UNUSED)
Extracts a ustar-format tar archive from the scratch block device into the Pintos file system.
void fsutil_rm(char **argv)
Deletes file ARGV[1].
int printf(const char *format,...)
Writes formatted output to the console.
void hex_dump(uintptr_t ofs, const void *buf_, size_t size, bool ascii)
Dumps the SIZE bytes in BUF to the console as hex bytes arranged 16 per line.
void * malloc(size_t size)
Obtains and returns a new block of at least SIZE bytes.
void free(void *p)
Frees block P, which must have been previously allocated with malloc(), calloc(), or realloc().
#define PROTd
Format specifier for printf(), e.g.
int32_t off_t
An offset within a file.
void * palloc_get_page(enum palloc_flags flags)
Obtains a single free page and returns its kernel virtual address.
void palloc_free_page(void *page)
Frees the page at PAGE.
@ PAL_ASSERT
Panic on failure.
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
enum block_type type
Type of block device.
block_sector_t size
Size in sectors.
off_t pos
Current position.
static const char file_name[]
tests/filesys/base/syn-read.h
bool ustar_make_header(const char *file_name, enum ustar_type type, int size, char header[USTAR_HEADER_SIZE])
Composes HEADER as a USTAR_HEADER_SIZE (512)-byte archive header in ustar format for a SIZE-byte file...
const char * ustar_parse_header(const char header[USTAR_HEADER_SIZE], const char **file_name, enum ustar_type *type, int *size)
Parses HEADER as a ustar-format archive header for a regular file or directory.
ustar_type
Support for the standard Posix "ustar" format.
@ USTAR_REGULAR
Ordinary file.
@ USTAR_EOF
End of archive (not an official value).
@ USTAR_DIRECTORY
Directory.
#define PGSIZE
Bytes in a page.