From 23f1e6963ab695c52a10afba10d1b489bff0fba8 Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Mon, 13 Sep 1982 02:29:03 -0800 Subject: [PATCH] update to new directory routines SCCS-vsn: old/berknet/net.c 4.2 SCCS-vsn: old/berknet/netdaemon.c 4.2 SCCS-vsn: old/berknet/netq.c 4.2 SCCS-vsn: old/berknet/netrm.c 4.2 SCCS-vsn: old/berknet/mach.h 4.2 --- usr/src/old/berknet/mach.h | 22 ++------------ usr/src/old/berknet/net.c | 30 +++++++++++++------ usr/src/old/berknet/netdaemon.c | 30 +++++++++---------- usr/src/old/berknet/netq.c | 51 ++++++++++++++++----------------- usr/src/old/berknet/netrm.c | 23 +++++++-------- 5 files changed, 73 insertions(+), 83 deletions(-) diff --git a/usr/src/old/berknet/mach.h b/usr/src/old/berknet/mach.h index 68d46ca4a7..e0d6c8afeb 100644 --- a/usr/src/old/berknet/mach.h +++ b/usr/src/old/berknet/mach.h @@ -1,4 +1,4 @@ -/* @(#)mach.h 4.1 (Berkeley) %G% */ +/* @(#)mach.h 4.2 (Berkeley) %G% */ /* sccs id variable */ static char *mach_h_sid = "@(#)mach.h 1.11"; @@ -59,7 +59,7 @@ definition for "VANILLA7" which indicates the v7 UNIX options. */ /* be sure to include before these defns */ -# include +# include "whoami.h" # include /* note NUID is only used in mmail.c */ @@ -390,7 +390,6 @@ int (*signal())(); # define ANYP 0300 # define ECHO 010 # define ROOTINO 1 -# define DIRSIZ 14 # define TIOCEXCL 0 # define SIGHUP 1 # define SIGINT 2 @@ -406,23 +405,6 @@ int (*signal())(); # define setjmp(a) setexit() -struct stat { - int st_dev; - int st_ino; - int st_mode; - char st_nlink:8; - char st_uid:8; - char st_gid:8; - char st_size0; - int st_size1; - int st_addr[8]; - long st_atime; - long st_mtime; - }; -struct direct { - int d_ino; - char d_name[DIRSIZ]; - }; struct tms { /* see times - sect 2 */ int tms_utime; /* user time */ int tms_stime; /* system time */ diff --git a/usr/src/old/berknet/net.c b/usr/src/old/berknet/net.c index 6a44d94dee..d7863cf167 100644 --- a/usr/src/old/berknet/net.c +++ b/usr/src/old/berknet/net.c @@ -1,4 +1,4 @@ -static char sccsid[] = "@(#)net.c 4.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)net.c 4.2 (Berkeley) %G%"; /* sccs id variable */ static char *net_sid = "@(#)net.c 1.8"; @@ -412,13 +412,14 @@ register struct header *phd; static struct stat x; static struct direct y; -static FILE *file; static int off = -1; /* these three routines gwd, cat, ckroot and data structures x, y, off, do a pwd to string name */ #ifdef V6 +static FILE *file; + gwd(name) register char *name; { *name = 0; @@ -459,12 +460,14 @@ ckroot(name) return; } #else +static DIR *file; static struct stat xx; gwd(name) register char *name; { int rdev, rino; register int i; + register struct direct *dp; *name = 0; stat("/", &x); @@ -474,24 +477,25 @@ gwd(name) stat(".", &x); if (x.st_ino == rino && x.st_dev == rdev) break; - if ((file = fopen("..", "r")) == NULL) + if ((file = opendir("..")) == NULL) break; - fstat(fileno(file), &xx); + fstat(file->dd_fd, &xx); chdir(".."); if (x.st_dev == xx.st_dev) { if (x.st_ino == xx.st_ino) break; do - if (fread((char *)&y, 1, sizeof y, file) != sizeof y) + if ((dp = readdir(file)) == NULL) break; - while (y.d_ino != x.st_ino); + while (dp->d_ino != x.st_ino); } else do { - if (fread((char *)&y, 1, sizeof y, file) != sizeof y) + if ((dp = readdir(file)) == NULL) break; - stat(y.d_name, &xx); + stat(dp->d_name, &xx); } while (xx.st_ino != x.st_ino || xx.st_dev != x.st_dev); - fclose(file); + blkcpy(dp, &y, DIRSIZ(dp)); + closedir(file); if (cat(name)) break; } @@ -541,3 +545,11 @@ isdirectory(fn) } return(ret); } + +blkcpy(from, to, size) + register *from, *to; + register int size; +{ + while (size-- > 0) + *to++ = *from++; +} diff --git a/usr/src/old/berknet/netdaemon.c b/usr/src/old/berknet/netdaemon.c index eadc7180d5..7d51ff62b2 100644 --- a/usr/src/old/berknet/netdaemon.c +++ b/usr/src/old/berknet/netdaemon.c @@ -1,4 +1,4 @@ -static char sccsid[] = "@(#)netdaemon.c 4.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)netdaemon.c 4.2 (Berkeley) %G%"; /* sccs id variable */ static char *netdaemon_sid = "@(#)netdaemon.c 1.10"; @@ -45,12 +45,11 @@ struct userinfo status; /* local variables */ static long length; -static FILE *dir; +static DIR *dir; /* static char sheader[] = "ABCDE"; */ static char tempfile[]= TEMPFILE; static char publogfile[]= PUBLOGFILE; static struct stat statbuf; -static struct direct dirbuf; int handlekill(); static char frommach; long linechars(); @@ -86,7 +85,7 @@ main(argc,argv) perror(senddir); exit(EX_OSFILE); } - dir = fopen(senddir,"r"); + dir = opendir(senddir); if(dir == NULL){ perror(senddir); exit(EX_OSFILE); @@ -154,6 +153,7 @@ netsend(){ register int i; char stemp[20]; static char jname[FNS]; + register struct direct *dp; debug("ck send"); if(stat(senddir,&statbuf) < 0){ @@ -162,19 +162,18 @@ netsend(){ } if(statbuf.st_mtime == lasttime && nleft == 0)return; /* no need to search */ lasttime = statbuf.st_mtime; - fseek(dir,0L,0); + rewinddir(dir); lFileLen = 10000000L; nleft = 0; - while(fread(&dirbuf,1,sizeof dirbuf,dir) == sizeof dirbuf){ - if(dirbuf.d_ino == 0 - || dirbuf.d_name[0] != 'c' - || dirbuf.d_name[1] != 'f' - || dirbuf.d_name[2] != remote - || stat(dirbuf.d_name,&statbuf) < 0 + while((dp = readdir(dir)) != NULL){ + if(dp->d_name[0] != 'c' + || dp->d_name[1] != 'f' + || dp->d_name[2] != remote + || stat(dp->d_name,&statbuf) < 0 || statbuf.st_mode == 0) continue; - dirbuf.d_name[0] = 'd'; - if(stat(dirbuf.d_name,&statbuf) < 0 || statbuf.st_mode == 0) + dp->d_name[0] = 'd'; + if(stat(dp->d_name,&statbuf) < 0 || statbuf.st_mode == 0) continue; uid = guid(statbuf.st_uid,statbuf.st_gid); if(netd.dp_onlyuid != 0 && uid != netd.dp_onlyuid && uid != SUPERUSER @@ -186,13 +185,12 @@ netsend(){ if( !debugflg ) continue; else - debug("sending large file %s\n", dirbuf.d_name ); + debug("sending large file %s\n", dp->d_name ); } #endif DONTHOLDBIG if(lFileLen > filesize){ lFileLen = filesize; - for(i=0; id_name); uidBest = uid; } # ifdef MAXSENDQ diff --git a/usr/src/old/berknet/netq.c b/usr/src/old/berknet/netq.c index 9fd49ea5b0..1bc1ceffad 100644 --- a/usr/src/old/berknet/netq.c +++ b/usr/src/old/berknet/netq.c @@ -1,4 +1,4 @@ -static char sccsid[] = "@(#)netq.c 4.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)netq.c 4.2 (Berkeley) %G%"; /* netq - print the netq send queue */ /* netq [-] [mach] */ @@ -12,7 +12,7 @@ static char *netq_sid = "@(#)netq.c 1.5"; be sorted correctly */ # define STSIZE 150 -static FILE *df; +static DIR *df; static char jname[16], printlong; static struct table { char name[16]; @@ -24,7 +24,6 @@ static char netcmd1[] = NETCMD1; static int hisuid,sumj,nsumj; static long sumb, nsumb; static struct stat statbuf; -static struct direct dirbuf; char _sobuf[BUFSIZ]; main(argc,argv) @@ -82,21 +81,21 @@ static pdir(str) char listrest = 0; int (*compar)(); char printhead = 0; - df = fopen(str,"r"); + register struct direct *dp; + df = opendir(str); if(df == NULL){ perror(str); exit(EX_OSFILE); } stptr = 0; - while(fread(&dirbuf,1,sizeof dirbuf,df)==sizeof dirbuf){ - if(dirbuf.d_ino == 0 - || dirbuf.d_name[0] != 'c' - || dirbuf.d_name[1] != 'f' - || stat(dirbuf.d_name,&statbuf) < 0) + while((dp = readdir(df)) != NULL){ + if(dp->d_name[0] != 'c' + || dp->d_name[1] != 'f' + || stat(dp->d_name,&statbuf) < 0) continue; - if(mach != dirbuf.d_name[2])continue; - dirbuf.d_name[0] = 'd'; - if(stat(dirbuf.d_name,&statbuf) < 0)continue; + if(mach != dp->d_name[2])continue; + dp->d_name[0] = 'd'; + if(stat(dp->d_name,&statbuf) < 0)continue; #ifdef MAXSENDQ if( stptr >= MAXSENDQ ) { listrest++; @@ -104,13 +103,14 @@ static pdir(str) } #endif - if(!insert(dirbuf.d_name,getsize(&statbuf))){ + if(!insert(dp->d_name,getsize(&statbuf))){ more++; break; } } if(stptr == 0){ printf("Network queue to/thru %s is empty.\n",longname(mach)); + closedir(df); return; } cp = (char *)&(stack[0].name[0]); @@ -132,8 +132,9 @@ static pdir(str) } # ifdef MAXSENDQ if( listrest ) - listem(); + listem(dp); # endif + closedir(df); printsum(); if(more)printf(" ... more ...\n"); } @@ -309,26 +310,24 @@ swap(a,b) b->filesize = t; } # ifdef MAXSENDQ -listem() { +listem(dp) +register struct direct *dp; { - fseek( df, -(long)(sizeof dirbuf), 1 ); /* backspace over already read entry */ - - while( fread( &dirbuf, 1, sizeof dirbuf, df ) == sizeof dirbuf ) { - if( dirbuf.d_ino == 0 - || dirbuf.d_name[0] != 'c' - || dirbuf.d_name[1] != 'f' - || stat( dirbuf.d_name, &statbuf ) < 0 ) + do { + if(dp->d_name[0] != 'c' + || dp->d_name[1] != 'f' + || stat( dp->d_name, &statbuf ) < 0 ) continue; - if( mach != dirbuf.d_name[2] ) + if( mach != dp->d_name[2] ) continue; - dirbuf.d_name[0] = 'd'; - if( stat( dirbuf.d_name, &statbuf ) < 0 ) + dp->d_name[0] = 'd'; + if( stat( dp->d_name, &statbuf ) < 0 ) continue; if( printlong || guid( statbuf.st_uid, statbuf.st_gid) == hisuid ) process(); else summarize( getsize( &statbuf ) ); - } + } while((dp = readdir(df)) != NULL); return; } diff --git a/usr/src/old/berknet/netrm.c b/usr/src/old/berknet/netrm.c index 8f9aa8cf44..e9434b6a4d 100644 --- a/usr/src/old/berknet/netrm.c +++ b/usr/src/old/berknet/netrm.c @@ -1,4 +1,4 @@ -static char sccsid[] = "@(#)netrm.c 4.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)netrm.c 4.2 (Berkeley) %G%"; # include "defs.h" /* sccs id variable */ @@ -20,7 +20,6 @@ char pathname[]= NETRMNAME; int hisuid, hisgid; static char visit[26]; static struct stat statbuf; -static struct direct dirbuf; main(argc,argv) char *argv[]; @@ -60,25 +59,25 @@ char *argv[]; } static pdir(str) char *str; { - FILE *df; - df = fopen(str,"r"); + DIR *df; + register struct direct *dp; + df = opendir(str); if(df == NULL){ perror(str); exit(EX_OSFILE); } - while(fread(&dirbuf,1,sizeof dirbuf,df) == sizeof dirbuf){ - if(dirbuf.d_ino == 0 - || dirbuf.d_name[0] != 'd' - || dirbuf.d_name[1] != 'f' - || stat(dirbuf.d_name,&statbuf) < 0) + while((dp = readdir(df)) != NULL){ + if(dp->d_name[0] != 'd' + || dp->d_name[1] != 'f' + || stat(dp->d_name,&statbuf) < 0) continue; if(guid(statbuf.st_uid,statbuf.st_gid) != hisuid) continue; /* kludge in file name */ - dirbuf.d_name[3] = dirbuf.d_name[2]; - rmfile(dirbuf.d_name+3); + dp->d_name[3] = dp->d_name[2]; + rmfile(dp->d_name+3); } - fclose(df); + closedir(df); } rmfile(str) char *str; -- 2.20.1