- struct dir dir;
- disk_sector_no hdr_sector;
- struct filehdr filehdr;
- struct bitmap free_map;
- bool success = false;
-
- /* Read the root directory. */
- dir_init (&dir, NUM_DIR_ENTRIES);
- dir_read (&dir, &root_dir_file);
- if (!dir_lookup (&dir, name, &hdr_sector))
- goto exit;
-
- /* Read the file header. */
- filehdr_read (&filehdr, hdr_sector);
-
- /* Allocate a block for the file header. */
- bitmap_init (&free_map, disk_size (disk));
- bitmapio_read (&free_map, &free_map_file);
-
- /* Deallocate. */
- 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);
- dir_write (&dir, &root_dir_file);
-
- success = true;
-
- /* Clean up. */
- filehdr_destroy (&filehdr);
- bitmap_destroy (&free_map);
- exit:
- dir_destroy (&dir);