#include "filesys/directory.h"
#include "devices/disk.h"
-/* The disk that contains the filesystem. */
+/* The disk that contains the file system. */
struct disk *filesys_disk;
static void do_format (void);
-/* Initializes the filesystem module.
- If FORMAT is true, reformats the filesystem. */
+/* Initializes the file system module.
+ If FORMAT is true, reformats the file system. */
void
filesys_init (bool format)
{
filesys_disk = disk_get (0, 1);
if (filesys_disk == NULL)
- PANIC ("hd0:1 (hdb) not present, filesystem initialization failed");
+ PANIC ("hd0:1 (hdb) not present, file system initialization failed");
inode_init ();
free_map_init ();
free_map_open ();
}
-/* Shuts down the filesystem module, writing any unwritten data
+/* Shuts down the file system module, writing any unwritten data
to disk. */
void
filesys_done (void)
bool
filesys_create (const char *name, off_t initial_size)
{
- struct dir *dir;
disk_sector_t inode_sector = 0;
- bool success = (dir_open_root (&dir)
+ struct dir *dir = dir_open_root ();
+ bool success = (dir != NULL
&& free_map_allocate (1, &inode_sector)
&& inode_create (inode_sector, initial_size)
&& dir_add (dir, name, inode_sector));
struct file *
filesys_open (const char *name)
{
- struct dir *dir;
+ struct dir *dir = dir_open_root ();
struct inode *inode = NULL;
- if (dir_open_root (&dir))
+ if (dir != NULL)
dir_lookup (dir, name, &inode);
dir_close (dir);
bool
filesys_remove (const char *name)
{
- struct dir *dir = NULL;
- bool success = (dir_open_root (&dir)
- && dir_remove (dir, name));
+ struct dir *dir = dir_open_root ();
+ bool success = dir != NULL && dir_remove (dir, name);
dir_close (dir);
return success;
}
-
-/* Prints a list of files in the filesystem to the system
- console.
- Returns true if successful, false on failure,
- which occurs only if an internal memory allocation fails. */
-bool
-filesys_list (void)
-{
- struct dir *dir = NULL;
- bool success = dir_open_root (&dir);
- if (success)
- dir_list (dir);
- dir_close (dir);
-
- return success;
-}
\f
static void must_succeed_function (int, bool) NO_INLINE;
#define MUST_SUCCEED(EXPR) must_succeed_function (__LINE__, EXPR)
-/* Performs basic sanity checks on the filesystem.
- The filesystem should not contain a file named `foo' when
+/* Performs basic sanity checks on the file system.
+ The file system should not contain a file named `foo' when
called. */
void
filesys_self_test (void)
PANIC ("filesys_self_test: operation failed on line %d", line_no);
}
\f
-/* Formats the filesystem. */
+/* Formats the file system. */
static void
do_format (void)
{
- printf ("Formatting filesystem...");
+ printf ("Formatting file system...");
free_map_create ();
if (!dir_create (ROOT_DIR_SECTOR, 16))
PANIC ("root directory creation failed");