X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=cprogs%2Fsummer.c;h=12419210d74eafa295584e4a74c3eb3d409fd5ba;hb=refs%2Ftags%2Fdebian_version_4_1_20;hp=2c4f9df197995beba1cf04d10ffbed101459906d;hpb=11633c3162005c1ce29fdd88b5db4d08a104d07a;p=chiark-utils.git diff --git a/cprogs/summer.c b/cprogs/summer.c index 2c4f9df..1241921 100644 --- a/cprogs/summer.c +++ b/cprogs/summer.c @@ -26,11 +26,13 @@ #define MAXDEPTH 1024 #define CSUMXL 32 -static int quiet=0, hidectime=0, hideatime=0; -static int hidedirsize=0, hidelinkmtime=0; +static int quiet=0, hidectime=0, hideatime=0, hidemtime=0; +static int hidedirsize=0, hidelinkmtime=0, onefilesystem=0; static int filenamefieldsep=' '; static FILE *errfile; +#define nodeflag_fsvalid 1u + static void malloc_fail(void) { perror("summer: alloc failed"); exit(12); } static void *mmalloc(size_t sz) { @@ -156,14 +158,14 @@ static int hardlink_compar(const void *av, const void *bv) { return b->dev - a->dev; } -static void recurse(const char *path); +static void recurse(const char *path, unsigned nodeflags, dev_t fs); -static void node(const char *path) { +static void node(const char *path, unsigned nodeflags, dev_t fs) { char linktarg[MAXFN+1]; struct hardlink *foundhl; const struct stat *stab; struct stat stabuf; - int r; + int r, mountpoint=0; r= lstat(path, &stabuf); stab= r ? 0 : &stabuf; @@ -185,15 +187,22 @@ static void node(const char *path) { } } + if (stab) { + if ((nodeflags & nodeflag_fsvalid) && stab->st_dev != fs) + mountpoint= 1; + fs= stab->st_dev; + nodeflags |= nodeflag_fsvalid; + } + if (!stab) problem_e(path,CSUMXL,"inaccessible"); else if (foundhl) csum_str("hardlink"); else if (S_ISREG(stab->st_mode)) csum_file(path); - else if (S_ISDIR(stab->st_mode)) csum_str("dir"); else if (S_ISCHR(stab->st_mode)) csum_dev('c',stab); else if (S_ISBLK(stab->st_mode)) csum_dev('b',stab); else if (S_ISFIFO(stab->st_mode)) csum_str("pipe"); else if (S_ISLNK(stab->st_mode)) csum_str("symlink"); else if (S_ISSOCK(stab->st_mode)) csum_str("sock"); + else if (S_ISDIR(stab->st_mode)) csum_str(mountpoint ? "mountpoint" : "dir"); else problem(path,CSUMXL,"badobj: 0x%lx", (unsigned long)stab->st_mode); if (stab && S_ISLNK(stab->st_mode)) { @@ -229,14 +238,16 @@ static void node(const char *path) { pu10(); } - if (stab) - if (S_ISLNK(stab->st_mode) && hidelinkmtime) - printf(" %10s","link"); + if (!hidemtime) { + if (stab) + if (S_ISLNK(stab->st_mode) && hidelinkmtime) + printf(" %10s","link"); + else + printf(" %10lu", + (unsigned long)stab->st_mtime); else - printf(" %10lu", - (unsigned long)stab->st_mtime); - else - pu10(); + pu10(); + } if (!hidectime) { if (stab) @@ -256,14 +267,14 @@ static void node(const char *path) { if (ferror(stdout)) { perror("summer: stdout"); exit(12); } - if (stab && S_ISDIR(stab->st_mode)) - recurse(path); + if (stab && S_ISDIR(stab->st_mode) && !(mountpoint && onefilesystem)) + recurse(path, nodeflags, fs); } static void process(const char *startpoint) { if (!quiet) fprintf(stderr,"summer: processing: %s\n",startpoint); - node(startpoint); + node(startpoint, 0,0); tdestroy(hardlinks,free); hardlinks= 0; } @@ -287,12 +298,11 @@ static int recurse_compar(const void *av, const void *bv) { return strcmp((*a)->d_name, (*b)->d_name); } -static void recurse(const char *path_or_buf) { +static void recurse(const char *path_or_buf, unsigned nodeflags, dev_t fs) { static char *buf; static int buf_allocd; struct dirent **namelist, *const *de; - char *subpathp; const char *path_or_0= path_or_buf==buf ? 0 : path_or_buf; int nentries, pathl, esave, buf_want, i; @@ -311,18 +321,16 @@ static void recurse(const char *path_or_buf) { if (path_or_0) strcpy(buf,path_or_0); buf[pathl]= '/'; - subpathp= buf+pathl+1; + pathl++; if (nentries < 0) { - strcpy(subpathp,"\\?"); errno= esave; - problem_e(buf,-1,"scandir failed"); + buf[pathl]= 0; errno= esave; + problem_e(buf,CSUMXL+72,"scandir failed"); + fn_escaped(stdout,buf); putchar('\n'); return; } for (i=0, de=namelist; id_name); - strcpy(subpathp, (*de)->d_name); - node(buf); + strcpy(buf+pathl, (*de)->d_name); + node(buf, nodeflags, fs); free(*de); } free(namelist); @@ -353,7 +361,7 @@ int main(int argc, const char *const *argv) { errfile= stderr; - if ((arg=argv[1]) && *arg++=='-') { + while ((arg=argv[1]) && *arg++=='-') { while ((c=*arg++)) { switch (c) { case 'h': @@ -373,12 +381,18 @@ int main(int argc, const char *const *argv) { case 'b': hidelinkmtime= 1; break; + case 'x': + onefilesystem= 1; + break; case 'C': hidectime= 1; break; case 'A': hideatime= 1; break; + case 'M': + hidemtime= 1; + break; case 'f': errfile= stdout; break;