diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /pintos-progos/filesys/free-map.c | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'pintos-progos/filesys/free-map.c')
| -rw-r--r-- | pintos-progos/filesys/free-map.c | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/pintos-progos/filesys/free-map.c b/pintos-progos/filesys/free-map.c deleted file mode 100644 index 29ea4df..0000000 --- a/pintos-progos/filesys/free-map.c +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | #include "filesys/free-map.h" | ||
| 2 | #include <bitmap.h> | ||
| 3 | #include <debug.h> | ||
| 4 | #include "filesys/file.h" | ||
| 5 | #include "filesys/filesys.h" | ||
| 6 | #include "filesys/inode.h" | ||
| 7 | |||
| 8 | static struct file *free_map_file; /* Free map file. */ | ||
| 9 | static struct bitmap *free_map; /* Free map, one bit per sector. */ | ||
| 10 | |||
| 11 | /* Initializes the free map. */ | ||
| 12 | void | ||
| 13 | free_map_init (void) | ||
| 14 | { | ||
| 15 | free_map = bitmap_create (block_size (fs_device)); | ||
| 16 | if (free_map == NULL) | ||
| 17 | PANIC ("bitmap creation failed--file system device is too large"); | ||
| 18 | bitmap_mark (free_map, FREE_MAP_SECTOR); | ||
| 19 | bitmap_mark (free_map, ROOT_DIR_SECTOR); | ||
| 20 | } | ||
| 21 | |||
| 22 | /* Allocates CNT consecutive sectors from the free map and stores | ||
| 23 | the first into *SECTORP. | ||
| 24 | Returns true if successful, false if not enough consecutive | ||
| 25 | sectors were available or if the free_map file could not be | ||
| 26 | written. */ | ||
| 27 | bool | ||
| 28 | free_map_allocate (size_t cnt, block_sector_t *sectorp) | ||
| 29 | { | ||
| 30 | block_sector_t sector = bitmap_scan_and_flip (free_map, 0, cnt, false); | ||
| 31 | if (sector != BITMAP_ERROR | ||
| 32 | && free_map_file != NULL | ||
| 33 | && !bitmap_write (free_map, free_map_file)) | ||
| 34 | { | ||
| 35 | bitmap_set_multiple (free_map, sector, cnt, false); | ||
| 36 | sector = BITMAP_ERROR; | ||
| 37 | } | ||
| 38 | if (sector != BITMAP_ERROR) | ||
| 39 | *sectorp = sector; | ||
| 40 | return sector != BITMAP_ERROR; | ||
| 41 | } | ||
| 42 | |||
| 43 | /* Makes CNT sectors starting at SECTOR available for use. */ | ||
| 44 | void | ||
| 45 | free_map_release (block_sector_t sector, size_t cnt) | ||
| 46 | { | ||
| 47 | ASSERT (bitmap_all (free_map, sector, cnt)); | ||
| 48 | bitmap_set_multiple (free_map, sector, cnt, false); | ||
| 49 | bitmap_write (free_map, free_map_file); | ||
| 50 | } | ||
| 51 | |||
| 52 | /* Opens the free map file and reads it from disk. */ | ||
| 53 | void | ||
| 54 | free_map_open (void) | ||
| 55 | { | ||
| 56 | free_map_file = file_open (inode_open (FREE_MAP_SECTOR)); | ||
| 57 | if (free_map_file == NULL) | ||
| 58 | PANIC ("can't open free map"); | ||
| 59 | if (!bitmap_read (free_map, free_map_file)) | ||
| 60 | PANIC ("can't read free map"); | ||
| 61 | } | ||
| 62 | |||
| 63 | /* Writes the free map to disk and closes the free map file. */ | ||
| 64 | void | ||
| 65 | free_map_close (void) | ||
| 66 | { | ||
| 67 | file_close (free_map_file); | ||
| 68 | } | ||
| 69 | |||
| 70 | /* Creates a new free map file on disk and writes the free map to | ||
| 71 | it. */ | ||
| 72 | void | ||
| 73 | free_map_create (void) | ||
| 74 | { | ||
| 75 | /* Create inode. */ | ||
| 76 | if (!inode_create (FREE_MAP_SECTOR, bitmap_file_size (free_map))) | ||
| 77 | PANIC ("free map creation failed"); | ||
| 78 | |||
| 79 | /* Write bitmap to file. */ | ||
| 80 | free_map_file = file_open (inode_open (FREE_MAP_SECTOR)); | ||
| 81 | if (free_map_file == NULL) | ||
| 82 | PANIC ("can't open free map"); | ||
| 83 | if (!bitmap_write (free_map, free_map_file)) | ||
| 84 | PANIC ("can't write free map"); | ||
| 85 | } | ||
