ucmd_rm.c 660 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* rm: ring-3 command. Deletes a file. */
  2. #include "ucmd_lib.h"
  3. void _start(const char *path)
  4. {
  5. int r;
  6. if (!path || !path[0]) {
  7. u_puts("rm: usage rm /<device>/<file>\n");
  8. u_exit(1);
  9. }
  10. r = u_syscall1(SYS_UNLINK, (int)path);
  11. if (r == SYS_ENODEV || r == SYS_ENOFS) {
  12. u_puts("rm: unknown device or invalid path\n");
  13. u_exit(1);
  14. }
  15. if (r == SYS_EIO) {
  16. u_puts("rm: disk error\n");
  17. u_exit(1);
  18. }
  19. if (r == SYS_ENOENT) {
  20. u_puts("rm: not found\n");
  21. u_exit(1);
  22. }
  23. if (r == SYS_EROFS) {
  24. u_puts("rm: read-only filesystem\n");
  25. u_exit(1);
  26. }
  27. if (r != 0) {
  28. u_puts("rm: file not found\n");
  29. u_exit(1);
  30. }
  31. u_puts("removed\n");
  32. u_exit(0);
  33. }