rm.c 821 B

12345678910111213141516171819202122232425262728293031323334
  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. vfs_mount_all();
  17. if (vfs_resolve(arg, &fs, &fs_path) != 0) {
  18. io_putstr("rm: read-only filesystem\n");
  19. return;
  20. }
  21. r = fat_resolve_path(fs, fs_path, &dir_cluster, name_8_3);
  22. if (r == -2) { io_putstr("rm: disk error\n"); return; }
  23. if (r != 0) { io_putstr("rm: not found\n"); return; }
  24. r = fat_delete_file_in(fs, dir_cluster, name_8_3);
  25. if (r == -2) { io_putstr("rm: disk error\n"); return; }
  26. if (r != 0) { io_putstr("rm: file not found\n"); return; }
  27. io_putstr("removed\n");
  28. }