-#include "filesys.h"
-#include "disk.h"
-#include "directory.h"
-
-static struct disk *disk;
-
-static struct file free_map_file, root_dir_file;
-
-#define FREE_MAP_SECTOR 0
-#define ROOT_DIR_SECTOR 1
-
-#define NUM_DIR_ENTRIES 10
-#define ROOT_DIR_FILE_SIZE (sizeof (struct dir_entry) * NUM_DIR_ENTRIES)
-
-static void
-do_format (void)
-{
- struct bitmap free_map;
- 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. */
- bitmap_init (&free_map, disk_size (disk));
- 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);
-
- /* 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))
- panic ("root directory creation failed");
- filehdr_write (&dir_hdr, FREE_MAP_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_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 (!dir_init (&dir, NUM_DIR_ENTRIES))
- panic ("can't initialize root directory");
- dir_write (root_dir_file);
- dir_destroy (&dir);
- file_close (&free_map_file);
-}
-
+#include "filesys/filesys.h"
+#include <debug.h>
+#include <stdio.h>
+#include <string.h>
+#include "filesys/file.h"
+#include "filesys/free-map.h"
+#include "filesys/inode.h"
+#include "filesys/directory.h"
+#include "devices/disk.h"
+
+/* The disk that contains the filesystem. */
+struct disk *filesys_disk;
+
+static void do_format (void);
+
+/* Initializes the filesystem module.
+ If FORMAT is true, reformats the filesystem. */