From: Ben Pfaff Date: Mon, 30 Aug 2004 22:55:39 +0000 (+0000) Subject: Working filesystem. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=621963e2a383d53b2c5eca627102625421b46545;p=pintos-anon Working filesystem. --- diff --git a/src/filesys/directory.c b/src/filesys/directory.c new file mode 100644 index 0000000..43f87f0 --- /dev/null +++ b/src/filesys/directory.c @@ -0,0 +1,120 @@ +#include "directory.h" +#include "file.h" +#include "lib.h" +#include "malloc.h" + +bool +dir_init (struct dir *d, size_t entry_cnt) +{ + d->entry_cnt = entry_cnt; + d->entries = calloc (1, sizeof *d->entries * entry_cnt); + return d->entries != NULL; +} + +void +dir_destroy (struct dir *d) +{ + free (d->entries); +} + +static off_t +dir_size (struct dir *d) +{ + return d->entry_cnt * sizeof *d->entries; +} + +void +dir_read (struct dir *d, struct file *file) +{ + file_read_at (file, d->entries, dir_size (d), 0); +} + +void +dir_write (struct dir *d, struct file *file) +{ + file_write_at (file, d->entries, dir_size (d), 0); +} + +static struct dir_entry * +lookup (const struct dir *d, const char *name) +{ + size_t i; + + ASSERT (d != NULL); + ASSERT (name != NULL); + + if (strlen (name) > FILENAME_LEN_MAX) + return NULL; + + for (i = 0; i < d->entry_cnt; i++) + { + struct dir_entry *e = &d->entries[i]; + if (e->in_use && !strcmp (name, e->name)) + return e; + } + return NULL; +} + +bool +dir_lookup (const struct dir *d, const char *name, + disk_sector_no *filehdr_sector) +{ + const struct dir_entry *e; + + ASSERT (d != NULL); + ASSERT (name != NULL); + + e = lookup (d, name); + if (e != NULL) + { + if (filehdr_sector != NULL) + *filehdr_sector = e->filehdr_sector; + return true; + } + else + return false; +} + +bool +dir_add (struct dir *d, const char *name, disk_sector_no filehdr_sector) +{ + size_t i; + + ASSERT (d != NULL); + ASSERT (name != NULL); + ASSERT (lookup (d, name) == NULL); + + for (i = 0; i < d->entry_cnt; i++) + { + struct dir_entry *e = &d->entries[i]; + if (!e->in_use) + { + e->in_use = true; + strlcpy (e->name, name, sizeof e->name); + e->filehdr_sector = filehdr_sector; + return true; + } + } + return false; +} + +bool +dir_remove (struct dir *d, const char *name) +{ + struct dir_entry *e; + + ASSERT (d != NULL); + ASSERT (name != NULL); + + e = lookup (d, name); + if (e != NULL) + { + e->in_use = false; + return true; + } + else + return false; +} + +void dir_list (const struct dir *); +void dir_print (const struct dir *); diff --git a/src/filesys/directory.h b/src/filesys/directory.h new file mode 100644 index 0000000..fe7f333 --- /dev/null +++ b/src/filesys/directory.h @@ -0,0 +1,36 @@ +#ifndef HEADER_DIRECTORY_H +#define HEADER_DIRECTORY_H 1 + +#include +#include +#include "disk.h" + +/* Maximum length of a filename. + This is the traditional UNIX maximum. */ +#define FILENAME_LEN_MAX 14 + +struct dir_entry + { + bool in_use; + char name[FILENAME_LEN_MAX + 1]; + disk_sector_no filehdr_sector; + }; + +struct dir + { + size_t entry_cnt; + struct dir_entry *entries; + }; + +struct file; +bool dir_init (struct dir *, size_t entry_cnt); +void dir_destroy (struct dir *); +void dir_read (struct dir *, struct file *); +void dir_write (struct dir *, struct file *); +bool dir_lookup (const struct dir *, const char *name, disk_sector_no *); +bool dir_add (struct dir *, const char *name, disk_sector_no); +bool dir_remove (struct dir *, const char *name); +void dir_list (const struct dir *); +void dir_print (const struct dir *); + +#endif /* directory.h */ diff --git a/src/filesys/file.c b/src/filesys/file.c index e6f282f..e16ff5f 100644 --- a/src/filesys/file.c +++ b/src/filesys/file.c @@ -1,82 +1,74 @@ #include "file.h" - -#ifdef FILESYS_STUB #include "debug.h" -#include "filesys-stub.h" #include "lib.h" #include "malloc.h" +#include "directory.h" +#include "filehdr.h" +#include "filesys.h" bool -file_open (struct file *file, const char *name) -{ - struct dir dir; - disk_sector_no hdr_sector; - bool success = false; - - dir_init (&dir, NUM_DIR_ENTRIES); - dir_read (&dir, &root_dir_file); - if (dir_lookup (&dir, name, &hdr_sector)) - success = file_open_sector (file, hdr_sector); - - dir_destroy (&dir); - return success; -} - -bool -file_open_sector (struct file *file, disk_sector_no hdr_sector) +file_open (struct file *file, disk_sector_no hdr_sector) { + file->hdr = filehdr_read (hdr_sector); + file->bounce = malloc (DISK_SECTOR_SIZE); file->pos = 0; - return filehdr_read (&file->hdr, hdr_sector); + if (file->hdr != NULL && file->bounce != NULL) + return true; + else + { + filehdr_destroy (file->hdr); + free (file->bounce); + return false; + } } void file_close (struct file *file) { - filehdr_destroy (file); + filehdr_destroy (file->hdr); } off_t file_read (struct file *file, void *buffer, off_t size) { - off_t retval = file_read_at (file, buffer, size, file->pos); - file->pos += retval; - return retval; + off_t bytes_read = file_read_at (file, buffer, size, file->pos); + file->pos += bytes_read; + return bytes_read; } off_t -file_read_at (struct file *file, void *buffer_, off_t size, off_t start) +file_read_at (struct file *file, void *buffer_, off_t size, + off_t file_ofs) { uint8_t *buffer = buffer_; off_t bytes_read = 0; - uint8_t *bounce; - bounce = malloc (DISK_SECTOR_SIZE); while (size > 0) { /* Disk sector to read, starting byte offset within sector. */ - off_t sector_idx = filehdr_byte_to_sector (file->hdr); - int sector_ofs = start % DISK_SECTOR_SIZE; + off_t sector_idx = filehdr_byte_to_sector (file->hdr, file_ofs); + int sector_ofs = file_ofs % DISK_SECTOR_SIZE; - /* Bytes left in file, bytes left in sector. */ - off_t file_left = filehdr_size (file->hdr) - start; - off_t sector_left = DISK_SECTOR_SIZE - sector_ofs; + /* Bytes left in file, bytes left in sector, lesser of the two. */ + off_t file_left = filehdr_length (file->hdr) - file_ofs; + int sector_left = DISK_SECTOR_SIZE - sector_ofs; + int min_left = file_left < sector_left ? file_left : sector_left; /* Number of bytes to actually copy out of this sector. */ - int chunk_size = file_left < sector_left ? file_left : sector_left; + int chunk_size = size < min_left ? size : min_left; if (chunk_size == 0) break; /* Read sector into bounce buffer, then copy into caller's buffer. */ - disk_read (disk, sector_idx, bounce); - memcpy (buffer + bytes_read, bounce + sector_ofs, chunk_size); + disk_read (filesys_disk, sector_idx, file->bounce); + memcpy (buffer + bytes_read, file->bounce + sector_ofs, chunk_size); /* Advance. */ size -= chunk_size; - start += chunk_size; + file_ofs += chunk_size; bytes_read += chunk_size; } - free (bounce); return bytes_read; } @@ -84,88 +76,72 @@ file_read_at (struct file *file, void *buffer_, off_t size, off_t start) off_t file_write (struct file *file, const void *buffer, off_t size) { - off_t retval = file_write_at (file, buffer, size, file->pos); - file->pos += retval; - return retval; + off_t bytes_written = file_write_at (file, buffer, size, file->pos); + file->pos += bytes_written; + return bytes_written; } off_t file_write_at (struct file *file, const void *buffer_, off_t size, - off_t start) + off_t file_ofs) { - uint8_t *buffer = buffer_; - off_t bytes_read = 0; - uint8_t *bounce; + const uint8_t *buffer = buffer_; + off_t bytes_written = 0; - bounce = malloc (DISK_SECTOR_SIZE); while (size > 0) { - /* Disk sector to read, starting byte offset within sector. */ - off_t sector_idx = filehdr_byte_to_sector (file->hdr); - int sector_ofs = start % DISK_SECTOR_SIZE; + /* Starting byte offset within sector to read. */ + off_t sector_idx = filehdr_byte_to_sector (file->hdr, file_ofs); + int sector_ofs = file_ofs % DISK_SECTOR_SIZE; - /* Bytes left in file, bytes left in sector. */ - off_t file_left = filehdr_size (file->hdr) - start; - off_t sector_left = DISK_SECTOR_SIZE - sector_ofs; + /* Bytes left in file, bytes left in sector, lesser of the two. */ + off_t file_left = filehdr_length (file->hdr) - file_ofs; + int sector_left = DISK_SECTOR_SIZE - sector_ofs; + int min_left = file_left < sector_left ? file_left : sector_left; - /* Number of bytes to actually copy out of this sector. */ - int chunk_size = file_left < sector_left ? file_left : sector_left; + /* Number of bytes to actually writen into this sector. */ + int chunk_size = size < min_left ? size : min_left; if (chunk_size == 0) break; - /* Read sector into bounce buffer, then copy into caller's - buffer. */ - disk_read (disk, sector_idx, bounce); - memcpy (buffer + bytes_read, bounce + sector_ofs, chunk_size); + /* If the sector contains data before or after the chunk + we're writing, then we need to read in the sector + first. Otherwise we start with a sector of all zeros. */ + if (sector_ofs > 0 || chunk_size < sector_ofs) + disk_read (filesys_disk, sector_idx, file->bounce); + else + memset (file->bounce, 0, DISK_SECTOR_SIZE); + memcpy (file->bounce + sector_ofs, buffer + bytes_written, chunk_size); + disk_write (filesys_disk, sector_idx, file->bounce); /* Advance. */ size -= chunk_size; - start += chunk_size; - bytes_read += chunk_size; + file_ofs += chunk_size; + bytes_written += chunk_size; } - free (bounce); + free (file->bounce); - return bytes_read; + return bytes_written; } off_t file_length (struct file *file) { - int32_t length; - - filesys_stub_lock (); - filesys_stub_put_string ("length"); - filesys_stub_put_file (file); - filesys_stub_match_string ("length"); - length = filesys_stub_get_int32 (); - filesys_stub_unlock (); - - return length; + ASSERT (file != NULL); + return filehdr_length (file->hdr); } void -file_seek (struct file *file, off_t pos) +file_seek (struct file *file, off_t file_ofs) { - filesys_stub_lock (); - filesys_stub_put_string ("seek"); - filesys_stub_put_file (file); - filesys_stub_put_uint32 (pos); - filesys_stub_match_string ("seek"); - filesys_stub_unlock (); + ASSERT (file != NULL); + ASSERT (file_ofs >= 0); + file->pos = file_ofs; } off_t file_tell (struct file *file) { - int32_t pos; - - filesys_stub_lock (); - filesys_stub_put_string ("tell"); - filesys_stub_put_file (file); - filesys_stub_match_string ("tell"); - pos = filesys_stub_get_int32 (); - filesys_stub_unlock (); - - return pos; + ASSERT (file != NULL); + return file->pos; } -#endif /* FILESYS_STUB */ diff --git a/src/filesys/file.h b/src/filesys/file.h index d165e80..b29ce33 100644 --- a/src/filesys/file.h +++ b/src/filesys/file.h @@ -1,22 +1,20 @@ #ifndef HEADER_FILE_H #define HEADER_FILE_H 1 +#include #include #include - -#ifndef OFF_T -#define OFF_T -typedef int32_t off_t; -#endif +#include "disk.h" +#include "off_t.h" struct file { struct filehdr *hdr; + void *bounce; off_t pos; }; -bool file_open (struct file *, const char *name); -bool file_open_sector (struct file *, disk_sector_no); +bool file_open (struct file *, disk_sector_no); void file_close (struct file *); off_t file_read (struct file *, void *, off_t); off_t file_read_at (struct file *, void *, off_t size, off_t start); diff --git a/src/filesys/filehdr.c b/src/filesys/filehdr.c new file mode 100644 index 0000000..aad11e5 --- /dev/null +++ b/src/filesys/filehdr.c @@ -0,0 +1,94 @@ +#include "filehdr.h" +#include "bitmap.h" +#include "debug.h" +#include "malloc.h" +#include "filesys.h" +#include "lib.h" + +struct filehdr * +filehdr_allocate (struct bitmap *b, off_t length) +{ + struct filehdr *h; + size_t sector_cnt; + + ASSERT (b != NULL); + ASSERT (length >= 0); + + h = calloc (1, sizeof *h); + if (h == NULL) + return NULL; + + h->length = length; + sector_cnt = (length / DISK_SECTOR_SIZE) + (length % DISK_SECTOR_SIZE > 0); + while (h->sector_cnt < sector_cnt) + { + size_t sector = bitmap_find_and_set (b); + if (sector == BITMAP_ERROR) + { + filehdr_deallocate (h, b); + return NULL; + } + h->sectors[h->sector_cnt++] = sector; + } + + return h; +} + +void +filehdr_deallocate (struct filehdr *h, struct bitmap *b) +{ + size_t i; + + ASSERT (h != NULL); + ASSERT (b != NULL); + + for (i = 0; i < h->sector_cnt; i++) + bitmap_reset (b, h->sectors[i]); +} + +struct filehdr * +filehdr_read (disk_sector_no filehdr_sector) +{ + struct filehdr *h = calloc (1, sizeof *h); + if (h == NULL) + return NULL; + + ASSERT (sizeof *h == DISK_SECTOR_SIZE); + disk_read (filesys_disk, filehdr_sector, h); + + return h; +} + +void +filehdr_write (const struct filehdr *h, disk_sector_no filehdr_sector) +{ + ASSERT (h != NULL); + ASSERT (sizeof *h == DISK_SECTOR_SIZE); + disk_write (filesys_disk, filehdr_sector, h); +} + +void +filehdr_destroy (struct filehdr *h) +{ + free (h); +} + +disk_sector_no +filehdr_byte_to_sector (const struct filehdr *h, off_t pos) +{ + size_t idx; + + ASSERT (h != NULL); + + idx = pos / DISK_SECTOR_SIZE; + return idx < h->sector_cnt ? h->sectors[idx] : (disk_sector_no) -1; +} + +off_t +filehdr_length (const struct filehdr *h) +{ + ASSERT (h != NULL); + return h->length; +} + +void filehdr_print (const struct filehdr *); diff --git a/src/filesys/filehdr.h b/src/filesys/filehdr.h new file mode 100644 index 0000000..7b0ecc2 --- /dev/null +++ b/src/filesys/filehdr.h @@ -0,0 +1,29 @@ +#ifndef HEADER_FILEHDR_H +#define HEADER_FILEHDR_H 1 + +#include +#include +#include "disk.h" +#include "off_t.h" + +#define DIRECT_CNT ((DISK_SECTOR_SIZE - sizeof (off_t) * 2) \ + / sizeof (disk_sector_no)) + +struct filehdr + { + off_t length; + size_t sector_cnt; + disk_sector_no sectors[DIRECT_CNT]; + }; + +struct bitmap; +struct filehdr *filehdr_allocate (struct bitmap *, off_t length); +void filehdr_deallocate (struct filehdr *, struct bitmap *); +struct filehdr *filehdr_read (disk_sector_no); +void filehdr_write (const struct filehdr *, disk_sector_no); +void filehdr_destroy (struct filehdr *); +disk_sector_no filehdr_byte_to_sector (const struct filehdr *, off_t); +off_t filehdr_length (const struct filehdr *); +void filehdr_print (const struct filehdr *); + +#endif /* filehdr.h */ diff --git a/src/filesys/filesys.c b/src/filesys/filesys.c index d0e5c49..2cc0721 100644 --- a/src/filesys/filesys.c +++ b/src/filesys/filesys.c @@ -1,10 +1,11 @@ #include "filesys.h" -#include "disk.h" +#include "bitmap.h" +#include "debug.h" #include "directory.h" - -static struct disk *disk; - -static struct file free_map_file, root_dir_file; +#include "disk.h" +#include "file.h" +#include "filehdr.h" +#include "lib.h" #define FREE_MAP_SECTOR 0 #define ROOT_DIR_SECTOR 1 @@ -12,46 +13,53 @@ static struct file free_map_file, root_dir_file; #define NUM_DIR_ENTRIES 10 #define ROOT_DIR_FILE_SIZE (sizeof (struct dir_entry) * NUM_DIR_ENTRIES) +struct disk *filesys_disk; + +static struct file free_map_file, root_dir_file; + static void do_format (void) { struct bitmap free_map; - struct filehdr map_hdr, dir_hdr; + struct filehdr *map_hdr, *dir_hdr; struct dir dir; /* Create the initial bitmap and reserve sectors for the free map and root directory file headers. */ - if (!bitmap_init (&free_map, disk_size (disk))) - panic ("bitmap creation failed"); + if (!bitmap_init (&free_map, disk_size (filesys_disk))) + panic ("bitmap creation failed--disk is too large"); bitmap_mark (&free_map, FREE_MAP_SECTOR); bitmap_mark (&free_map, ROOT_DIR_SECTOR); /* Allocate data sector(s) for the free map file and write its file header to disk. */ - if (!filehdr_allocate (&map_hdr, bitmap_storage_size (&free_map))) - panic ("free map creation failed"); - filehdr_write (&map_hdr, FREE_MAP_SECTOR); - filehdr_destroy (&map_hdr); + map_hdr = filehdr_allocate (&free_map, bitmap_storage_size (&free_map)); + if (map_hdr == NULL) + panic ("free map creation failed--disk is too large"); + filehdr_write (map_hdr, FREE_MAP_SECTOR); + filehdr_destroy (map_hdr); /* Allocate data sector(s) for the root directory file and write its file header to disk. */ - if (!filehdr_allocate (&dir_hdr, ROOT_DIR_FILE_SIZE)) + dir_hdr = filehdr_allocate (&free_map, ROOT_DIR_FILE_SIZE); + if (dir_hdr == NULL) panic ("root directory creation failed"); - filehdr_write (&dir_hdr, FREE_MAP_SECTOR); - filehdr_destroy (&dir_hdr); + filehdr_write (dir_hdr, ROOT_DIR_SECTOR); + filehdr_destroy (dir_hdr); /* Write out the free map now that we have space reserved for it. */ file_open (&free_map_file, FREE_MAP_SECTOR); - bitmapio_write (&free_map, free_map_file); + bitmap_write (&free_map, &free_map_file); bitmap_destroy (&free_map); file_close (&free_map_file); /* Write out the root directory in the same way. */ - file_open (&root_dir_file, ROOT_DIR_SECTOR); + if (!file_open (&root_dir_file, ROOT_DIR_SECTOR)) + panic ("can't open root directory"); if (!dir_init (&dir, NUM_DIR_ENTRIES)) panic ("can't initialize root directory"); - dir_write (root_dir_file); + dir_write (&dir, &root_dir_file); dir_destroy (&dir); file_close (&free_map_file); } @@ -59,8 +67,8 @@ do_format (void) void filesys_init (bool format) { - disk = disk_get (1); - if (disk == NULL) + filesys_disk = disk_get (1); + if (filesys_disk == NULL) panic ("ide1:1 not present, filesystem initialization failed"); if (format) @@ -76,7 +84,7 @@ filesys_create (const char *name, off_t initial_size) struct dir dir; struct bitmap free_map; disk_sector_no hdr_sector; - struct filehdr filehdr; + struct filehdr *filehdr; bool success = false; /* Read the root directory. */ @@ -86,9 +94,9 @@ filesys_create (const char *name, off_t initial_size) goto exit1; /* Allocate a block for the file header. */ - if (!bitmap_init (&free_map, disk_size (disk))) + if (!bitmap_init (&free_map, disk_size (filesys_disk))) goto exit1; - bitmapio_read (&free_map, &free_map_file); + bitmap_read (&free_map, &free_map_file); hdr_sector = bitmap_find_and_set (&free_map); if (hdr_sector == BITMAP_ERROR) goto exit2; @@ -98,18 +106,19 @@ filesys_create (const char *name, off_t initial_size) goto exit2; /* Allocate space for the file. */ - if (!filehdr_allocate (&filehdr, initial_size)) + filehdr = filehdr_allocate (&free_map, initial_size); + if (filehdr == NULL) goto exit2; /* Write everything back. */ - filehdr_write (&filehdr, hdr_sector); + filehdr_write (filehdr, hdr_sector); dir_write (&dir, &root_dir_file); - bitmapio_write (&free_map, &free_map_file); + bitmap_write (&free_map, &free_map_file); success = true; /* Clean up. */ - filehdr_destroy (&filehdr); + filehdr_destroy (filehdr); exit2: bitmap_destroy (&free_map); exit1: @@ -118,12 +127,28 @@ filesys_create (const char *name, off_t initial_size) return success; } +bool +filesys_open (const char *name, struct file *file) +{ + struct dir dir; + disk_sector_no hdr_sector; + bool success = false; + + dir_init (&dir, NUM_DIR_ENTRIES); + dir_read (&dir, &root_dir_file); + if (dir_lookup (&dir, name, &hdr_sector)) + success = file_open (file, hdr_sector); + + dir_destroy (&dir); + return success; +} + bool filesys_remove (const char *name) { struct dir dir; disk_sector_no hdr_sector; - struct filehdr filehdr; + struct filehdr *filehdr; struct bitmap free_map; bool success = false; @@ -134,21 +159,22 @@ filesys_remove (const char *name) goto exit1; /* Read the file header. */ - if (!filehdr_read (&filehdr, hdr_sector)) + filehdr = filehdr_read (hdr_sector); + if (filehdr == NULL) goto exit1; /* Allocate a block for the file header. */ - if (!bitmap_init (&free_map, disk_size (disk))) + if (!bitmap_init (&free_map, disk_size (filesys_disk))) goto exit2; - bitmapio_read (&free_map, &free_map_file); + bitmap_read (&free_map, &free_map_file); /* Deallocate. */ - filehdr_deallocate (&filehdr, &free_map); + filehdr_deallocate (filehdr, &free_map); bitmap_reset (&free_map, hdr_sector); dir_remove (&dir, name); /* Write everything back. */ - bitmapio_write (&free_map, &free_map_file); + bitmap_write (&free_map, &free_map_file); dir_write (&dir, &root_dir_file); success = true; @@ -156,37 +182,46 @@ filesys_remove (const char *name) /* Clean up. */ bitmap_destroy (&free_map); exit2: - filehdr_destroy (&filehdr); + filehdr_destroy (filehdr); exit1: dir_destroy (&dir); return success; } -#undef NDEBUG -#include "debug.h" -#include "file.h" +static void must_succeed_function (int, int) ATTRIBUTE((noinline)); + +static void +must_succeed_function (int line_no, int success) +{ + if (!success) + panic ("filesys_self_test: operation failed on line %d", line_no); +} + +#define MUST_SUCCEED(EXPR) must_succeed_function (__LINE__, EXPR) void filesys_self_test (void) { static const char s[] = "This is a test string."; - struct file *file; + struct file file; char s2[sizeof s]; - ASSERT (filesys_create ("foo")); - ASSERT ((file = filesys_open ("foo")) != NULL); - ASSERT (file_write (file, s, sizeof s) == sizeof s); - ASSERT (file_tell (file) == sizeof s); - ASSERT (file_length (file) == sizeof s); - file_close (file); - - ASSERT ((file = filesys_open ("foo")) != NULL); - ASSERT (file_read (file, s2, sizeof s2) == sizeof s2); - ASSERT (memcmp (s, s2, sizeof s) == 0); - ASSERT (file_tell (file) == sizeof s2); - ASSERT (file_length (file) == sizeof s2); - file_close (file); - - ASSERT (filesys_remove ("foo")); + MUST_SUCCEED (filesys_create ("foo", sizeof s)); + MUST_SUCCEED (filesys_open ("foo", &file)); + MUST_SUCCEED (file_write (&file, s, sizeof s) == sizeof s); + MUST_SUCCEED (file_tell (&file) == sizeof s); + MUST_SUCCEED (file_length (&file) == sizeof s); + file_close (&file); + + MUST_SUCCEED (filesys_open ("foo", &file)); + MUST_SUCCEED (file_read (&file, s2, sizeof s2) == sizeof s2); + MUST_SUCCEED (memcmp (s, s2, sizeof s) == 0); + MUST_SUCCEED (file_tell (&file) == sizeof s2); + MUST_SUCCEED (file_length (&file) == sizeof s2); + file_close (&file); + + MUST_SUCCEED (filesys_remove ("foo")); + + printk ("filesys: self test ok\n"); } diff --git a/src/filesys/filesys.h b/src/filesys/filesys.h index 3de5f85..73aff31 100644 --- a/src/filesys/filesys.h +++ b/src/filesys/filesys.h @@ -3,17 +3,17 @@ #include #include +#include "off_t.h" -#ifndef OFF_T -#define OFF_T -typedef int32_t off_t; -#endif +struct disk *filesys_disk; struct file; void filesys_init (bool format); bool filesys_create (const char *name, off_t initial_size); +bool filesys_open (const char *name, struct file *); bool filesys_remove (const char *name); void filesys_list (void); +void filesys_print (void); void filesys_self_test (void); diff --git a/src/filesys/off_t.h b/src/filesys/off_t.h new file mode 100644 index 0000000..2b97bca --- /dev/null +++ b/src/filesys/off_t.h @@ -0,0 +1,7 @@ +#ifndef HEADER_OFF_T_H +#define HEADER_OFF_T_H 1 + +#include +typedef int32_t off_t; + +#endif /* off_t.h */