rmdir.c 797 B

1234567891011121314151617181920212223242526272829
  1. /* rmdir command: remove an empty subdirectory. Usage: rmdir <path>. */
  2. #include "fat.h"
  3. #include "io.h"
  4. void program_rmdir_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("rmdir: usage rmdir <dir>\n");
  11. return;
  12. }
  13. r = fat_init();
  14. if (r == -2) { io_putstr("rmdir: disk read error\n"); return; }
  15. if (r != 0) { io_putstr("rmdir: no FAT filesystem found\n"); return; }
  16. r = fat_resolve_path(arg, &dir_cluster, name_8_3);
  17. if (r == -2) { io_putstr("rmdir: disk error\n"); return; }
  18. if (r != 0) { io_putstr("rmdir: invalid path\n"); return; }
  19. r = fat_rmdir(dir_cluster, name_8_3);
  20. if (r == -2) { io_putstr("rmdir: disk error\n"); return; }
  21. if (r != 0) return; /* fat_rmdir already printed */
  22. io_putstr("rmdir ok\n");
  23. }