-#include "fsutil.h"
-#include <stdbool.h>
-#include "debug.h"
-#include "filesys.h"
-#include "file.h"
-#include "lib.h"
-#include "mmu.h"
-#include "palloc.h"
-
-/* Filename and file size to use for copy operations,
- as "filename:size". */
-char *fsutil_copy_arg;
-
-/* Name of a file print to print to console. */
-char *fsutil_print_file;
-
-/* Name of a file to delete. */
-char *fsutil_remove_file;
-
-/* List all files in the filesystem to the system console? */
-bool fsutil_list_files;
-
-/* Dump full contents of filesystem to the system console? */
-bool fsutil_dump_filesys;
-
-/* Copies from the "scratch" disk, hdc or hd1:0,
- to a file named FILENAME in the filesystem.
- The file will be SIZE bytes in length. */
-static void
-copy (const char *filename, off_t size)
+#include "filesys/fsutil.h"
+#include <debug.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "filesys/file.h"
+#include "filesys/filesys.h"
+#include "devices/disk.h"
+#include "threads/mmu.h"
+#include "threads/malloc.h"
+#include "threads/palloc.h"
+
+/* List files in the root directory. */
+void
+fsutil_ls (char **argv UNUSED)
+{
+ printf ("Files in the root directory:\n");
+ filesys_list ();
+ printf ("End of listing.\n");
+}
+
+/* Prints the contents of file ARGV[1] to the system console as
+ hex and ASCII. */
+void
+fsutil_cat (char **argv)
+{
+ const char *filename = argv[1];
+
+ struct file *file;
+ char *buffer;
+
+ printf ("Printing '%s' to the console...\n", filename);
+ file = filesys_open (filename);
+ if (file == NULL)
+ PANIC ("%s: open failed", filename);
+ buffer = palloc_get_page (PAL_ASSERT);
+ for (;;)
+ {
+ off_t pos = file_tell (file);
+ off_t n = file_read (file, buffer, PGSIZE);
+ if (n == 0)
+ break;
+
+ hex_dump (pos, buffer, n, true);
+ }
+ palloc_free_page (buffer);
+ file_close (file);
+}
+
+/* Deletes file ARGV[1]. */
+void
+fsutil_rm (char **argv)