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
This commit is contained in:
parent
31aa85b01a
commit
71ea62eb5b
@ -12,11 +12,14 @@
|
|||||||
|
|
||||||
char errbuf[ERRMAX];
|
char errbuf[ERRMAX];
|
||||||
int ignerr = 0;
|
int ignerr = 0;
|
||||||
|
int printerr = 0;
|
||||||
|
|
||||||
void
|
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';
|
errbuf[0] = '\0';
|
||||||
errstr(errbuf, sizeof errbuf);
|
errstr(errbuf, sizeof errbuf);
|
||||||
fprint(2, "rm: %s: %s\n", f, errbuf);
|
fprint(2, "rm: %s: %s\n", f, errbuf);
|
||||||
@ -30,38 +33,39 @@ void
|
|||||||
rmdir(char *f)
|
rmdir(char *f)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
long e;
|
||||||
int fd, i, j, n, ndir, nname;
|
int fd, i, j, n, ndir, nname;
|
||||||
Dir *dirbuf;
|
Dir *dirbuf;
|
||||||
|
|
||||||
fd = open(f, OREAD);
|
fd = open(f, OREAD);
|
||||||
if(fd < 0){
|
if(fd < 0){
|
||||||
err(f);
|
err(-1, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
n = dirreadall(fd, &dirbuf);
|
n = dirreadall(fd, &dirbuf);
|
||||||
close(fd);
|
close(fd);
|
||||||
if(n < 0){
|
if(n < 0){
|
||||||
err("dirreadall");
|
err(-1, "dirreadall");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nname = strlen(f)+1+STATMAX+1; /* plenty! */
|
nname = strlen(f)+1+STATMAX+1; /* plenty! */
|
||||||
name = malloc(nname);
|
name = malloc(nname);
|
||||||
if(name == 0){
|
if(name == 0){
|
||||||
err("memory allocation");
|
err(-1, "memory allocation");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndir = 0;
|
ndir = 0;
|
||||||
for(i=0; i<n; i++){
|
for(i=0; i<n; i++){
|
||||||
snprint(name, nname, "%s/%s", f, dirbuf[i].name);
|
snprint(name, nname, "%s/%s", f, dirbuf[i].name);
|
||||||
if(remove(name) != -1)
|
if((e = remove(name)) != -1)
|
||||||
dirbuf[i].qid.type = QTFILE; /* so we won't recurse */
|
dirbuf[i].qid.type = QTFILE; /* so we won't recurse */
|
||||||
else{
|
else{
|
||||||
if(dirbuf[i].qid.type & QTDIR)
|
if(dirbuf[i].qid.type & QTDIR)
|
||||||
ndir++;
|
ndir++;
|
||||||
else
|
else
|
||||||
err(name);
|
err(e, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ndir)
|
if(ndir)
|
||||||
@ -70,8 +74,8 @@ rmdir(char *f)
|
|||||||
snprint(name, nname, "%s/%s", f, dirbuf[j].name);
|
snprint(name, nname, "%s/%s", f, dirbuf[j].name);
|
||||||
rmdir(name);
|
rmdir(name);
|
||||||
}
|
}
|
||||||
if(remove(f) == -1)
|
if((e = remove(f)) == -1)
|
||||||
err(f);
|
err(e, f);
|
||||||
free(name);
|
free(name);
|
||||||
free(dirbuf);
|
free(dirbuf);
|
||||||
}
|
}
|
||||||
@ -80,6 +84,7 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int recurse;
|
int recurse;
|
||||||
|
long e;
|
||||||
char *f;
|
char *f;
|
||||||
Dir *db;
|
Dir *db;
|
||||||
|
|
||||||
@ -92,19 +97,25 @@ main(int argc, char *argv[])
|
|||||||
case 'f':
|
case 'f':
|
||||||
ignerr = 1;
|
ignerr = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
printerr = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprint(2, "usage: rm [-fr] file ...\n");
|
fprint(2, "usage: rm [-fr|-e] file ...\n");
|
||||||
exits("usage");
|
exits("usage");
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
if(printerr)
|
||||||
|
ignerr = 0;
|
||||||
for(i=0; i<argc; i++){
|
for(i=0; i<argc; i++){
|
||||||
f = argv[i];
|
f = argv[i];
|
||||||
if(remove(f) != -1)
|
e = remove(f);
|
||||||
|
if(e != -1 && (!printerr || e == 0))
|
||||||
continue;
|
continue;
|
||||||
db = nil;
|
db = nil;
|
||||||
if(recurse && (db=dirstat(f))!=nil && (db->qid.type&QTDIR))
|
if(recurse && (db=dirstat(f))!=nil && (db->qid.type&QTDIR))
|
||||||
rmdir(f);
|
rmdir(f);
|
||||||
else
|
else
|
||||||
err(f);
|
err(e, f);
|
||||||
free(db);
|
free(db);
|
||||||
}
|
}
|
||||||
exits(errbuf);
|
exits(errbuf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user