rm.c 764 B

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