9 filehdr_allocate (struct bitmap *b, off_t length)
17 h = calloc (1, sizeof *h);
22 sector_cnt = (length / DISK_SECTOR_SIZE) + (length % DISK_SECTOR_SIZE > 0);
23 while (h->sector_cnt < sector_cnt)
25 size_t sector = bitmap_find_and_set (b);
26 if (sector == BITMAP_ERROR)
28 filehdr_deallocate (h, b);
31 h->sectors[h->sector_cnt++] = sector;
38 filehdr_deallocate (struct filehdr *h, struct bitmap *b)
45 for (i = 0; i < h->sector_cnt; i++)
46 bitmap_reset (b, h->sectors[i]);
50 filehdr_read (disk_sector_no filehdr_sector)
52 struct filehdr *h = calloc (1, sizeof *h);
56 ASSERT (sizeof *h == DISK_SECTOR_SIZE);
57 disk_read (filesys_disk, filehdr_sector, h);
63 filehdr_write (const struct filehdr *h, disk_sector_no filehdr_sector)
66 ASSERT (sizeof *h == DISK_SECTOR_SIZE);
67 disk_write (filesys_disk, filehdr_sector, h);
71 filehdr_destroy (struct filehdr *h)
77 filehdr_byte_to_sector (const struct filehdr *h, off_t pos)
83 idx = pos / DISK_SECTOR_SIZE;
84 return idx < h->sector_cnt ? h->sectors[idx] : (disk_sector_no) -1;
88 filehdr_length (const struct filehdr *h)
94 void filehdr_print (const struct filehdr *);