From 71ea62eb5b1e49d7828efd54fa5514d8fbc927ac Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Mon, 26 Dec 2016 01:16:31 +0100 Subject: [PATCH] rm -e prints the return value of remove syscalls Some devices return useful info on specific file remove (eg #0/pid, #0/ppid...) so we need a tool to get such info. rm -e '#0/pid' '#0/ppid' #0/pid 65 #0/ppid 59 --- sys/src/cmd/rm.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/sys/src/cmd/rm.c b/sys/src/cmd/rm.c index 36b377f..9a9d9dd 100644 --- a/sys/src/cmd/rm.c +++ b/sys/src/cmd/rm.c @@ -12,11 +12,14 @@ char errbuf[ERRMAX]; int ignerr = 0; +int printerr = 0; void -err(char *f) +err(long e, char *f) { - if(!ignerr){ + if(printerr){ + print("%s %ulld\n", f, e); + } else if(!ignerr){ errbuf[0] = '\0'; errstr(errbuf, sizeof errbuf); fprint(2, "rm: %s: %s\n", f, errbuf); @@ -30,38 +33,39 @@ void rmdir(char *f) { char *name; + long e; int fd, i, j, n, ndir, nname; Dir *dirbuf; fd = open(f, OREAD); if(fd < 0){ - err(f); + err(-1, f); return; } n = dirreadall(fd, &dirbuf); close(fd); if(n < 0){ - err("dirreadall"); + err(-1, "dirreadall"); return; } nname = strlen(f)+1+STATMAX+1; /* plenty! */ name = malloc(nname); if(name == 0){ - err("memory allocation"); + err(-1, "memory allocation"); return; } ndir = 0; for(i=0; iqid.type&QTDIR)) rmdir(f); else - err(f); + err(e, f); free(db); } exits(errbuf);