rm.c 803 B

123456789101112131415161718192021222324252627282930313233
  1. /* rm command: delete a file. Usage: rm /<device>/<file>. */
  2. #include "fat.h"
  3. #include "io.h"
  4. #include "vfs.h"
  5. void program_rm_main(const char *arg)
  6. {
  7. fat_fs_t *fs;
  8. const char *fs_path;
  9. unsigned int dir_cluster;
  10. char name_8_3[12];
  11. int r;
  12. if (!arg || !arg[0]) {
  13. io_putstr("rm: usage rm /<device>/<file>\n");
  14. return;
  15. }
  16. if (vfs_resolve(arg, &fs, &fs_path) != 0) {
  17. io_putstr("rm: read-only filesystem\n");
  18. return;
  19. }
  20. r = fat_resolve_path(fs, fs_path, &dir_cluster, name_8_3);
  21. if (r == -2) { io_putstr("rm: disk error\n"); return; }
  22. if (r != 0) { io_putstr("rm: not found\n"); return; }
  23. r = fat_delete_file_in(fs, dir_cluster, name_8_3);
  24. if (r == -2) { io_putstr("rm: disk error\n"); return; }
  25. if (r != 0) { io_putstr("rm: file not found\n"); return; }
  26. io_putstr("removed\n");
  27. }