10 char *fsutil_copy_arg;
11 char *fsutil_print_file;
12 char *fsutil_remove_file;
13 bool fsutil_list_files;
14 bool fsutil_dump_filesys;
17 copy (const char *filename, off_t size)
21 disk_sector_no sector;
24 /* Open source disk. */
27 PANIC ("couldn't open source disk (hdc or ide1:0)");
28 if (size > (off_t) disk_size (src) * DISK_SECTOR_SIZE)
29 PANIC ("source disk is too small for %Ld-byte file",
30 (unsigned long long) size);
32 /* Create destination file. */
33 if (!filesys_create (filename, size))
34 PANIC ("%s: create failed", filename);
35 if (!filesys_open (filename, &dst))
36 PANIC ("%s: open failed", filename);
39 buffer = palloc_get (PAL_ASSERT);
43 int chunk_size = size > DISK_SECTOR_SIZE ? DISK_SECTOR_SIZE : size;
44 disk_read (src, sector++, buffer);
45 if (file_write (&dst, buffer, chunk_size) != chunk_size)
46 PANIC ("%s: write failed with %Ld bytes unwritten",
47 filename, (unsigned long long) size);
58 if (fsutil_copy_arg != NULL)
61 char *filename = strtok_r (fsutil_copy_arg, ":", &save);
62 char *size = strtok_r (NULL, "", &save);
64 if (filename == NULL || size == NULL)
65 PANIC ("bad format for -cp option; use -u for usage");
67 copy (filename, atoi (size));
70 if (fsutil_print_file != NULL)
71 fsutil_print (fsutil_print_file);
73 if (fsutil_remove_file != NULL)
75 if (filesys_remove (fsutil_remove_file))
76 printk ("%s: removed\n", fsutil_remove_file);
78 PANIC ("%s: remove failed\n", fsutil_remove_file);
81 if (fsutil_list_files)
84 if (fsutil_dump_filesys)
89 fsutil_print (const char *filename)
94 if (!filesys_open (filename, &file))
95 PANIC ("%s: open failed", filename);
96 buffer = palloc_get (PAL_ASSERT);
99 off_t n = file_read (&file, buffer, PGSIZE);
103 hex_dump (buffer, n, true);
105 palloc_free (buffer);