update to new directory routines
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 13 Sep 1982 10:29:03 +0000 (02:29 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 13 Sep 1982 10:29:03 +0000 (02:29 -0800)
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
usr/src/old/berknet/net.c
usr/src/old/berknet/netdaemon.c
usr/src/old/berknet/netq.c
usr/src/old/berknet/netrm.c

index 68d46ca..e0d6c8a 100644 (file)
@@ -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";
 
 /* 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 <stdio.h> before these defns */
 
 */
 /* be sure to include <stdio.h> before these defns */
 
-# include <whoami.h>
+# include "whoami.h"
 # include <sysexits.h>
 
 /* note NUID is only used in mmail.c */
 # include <sysexits.h>
 
 /* note NUID is only used in mmail.c */
@@ -390,7 +390,6 @@ int (*signal())();
 # define ANYP 0300
 # define ECHO 010
 # define ROOTINO 1
 # define ANYP 0300
 # define ECHO 010
 # define ROOTINO 1
-# define DIRSIZ 14
 # define TIOCEXCL 0
 # define SIGHUP                1
 # define SIGINT        2
 # define TIOCEXCL 0
 # define SIGHUP                1
 # define SIGINT        2
@@ -406,23 +405,6 @@ int        (*signal())();
 # define setjmp(a) setexit()
 
 
 # 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 */
 struct tms {                           /* see times - sect 2 */
        int     tms_utime;              /* user time */
        int     tms_stime;              /* system time */
index 6a44d94..d7863cf 100644 (file)
@@ -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";
 
 /* 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 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 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;
 gwd(name)
   register char *name; {
        *name = 0;
@@ -459,12 +460,14 @@ ckroot(name)
        return;
        }
 #else
        return;
        }
 #else
+static DIR *file;
 static struct stat xx;
 
 gwd(name)
   register char *name;  {
        int rdev, rino;
        register int i;
 static struct stat xx;
 
 gwd(name)
   register char *name;  {
        int rdev, rino;
        register int i;
+       register struct direct *dp;
 
        *name = 0;
        stat("/", &x);
 
        *name = 0;
        stat("/", &x);
@@ -474,24 +477,25 @@ gwd(name)
                stat(".", &x);
                if (x.st_ino == rino && x.st_dev == rdev)
                        break;
                stat(".", &x);
                if (x.st_ino == rino && x.st_dev == rdev)
                        break;
-               if ((file = fopen("..", "r")) == NULL)
+               if ((file = opendir("..")) == NULL)
                        break;
                        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
                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;
                                        break;
-                       while (y.d_ino != x.st_ino);
+                       while (dp->d_ino != x.st_ino);
                }
                else do {
                }
                else do {
-                       if (fread((char *)&y, 1, sizeof y, file) != sizeof y)
+                       if ((dp = readdir(file)) == NULL)
                                break;
                                break;
-                       stat(y.d_name, &xx);
+                       stat(dp->d_name, &xx);
                } while (xx.st_ino != x.st_ino || xx.st_dev != x.st_dev);
                } 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;
        }
                if (cat(name))
                        break;
        }
@@ -541,3 +545,11 @@ isdirectory(fn)
        }
        return(ret);
 }
        }
        return(ret);
 }
+
+blkcpy(from, to, size)
+       register *from, *to;
+       register int size;
+{
+       while (size-- > 0)
+               *to++ = *from++;
+}
index eadc718..7d51ff6 100644 (file)
@@ -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";
 
 /* sccs id variable */
 static char *netdaemon_sid = "@(#)netdaemon.c  1.10";
@@ -45,12 +45,11 @@ struct userinfo status;
 
 /* local variables */
 static long length;
 
 /* 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 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();
 int handlekill();
 static char frommach;
 long linechars();
@@ -86,7 +85,7 @@ main(argc,argv)
                perror(senddir);
                exit(EX_OSFILE);
                }
                perror(senddir);
                exit(EX_OSFILE);
                }
-       dir = fopen(senddir,"r");
+       dir = opendir(senddir);
        if(dir == NULL){
                perror(senddir);
                exit(EX_OSFILE);
        if(dir == NULL){
                perror(senddir);
                exit(EX_OSFILE);
@@ -154,6 +153,7 @@ netsend(){
        register int i;
        char stemp[20];
        static char jname[FNS];
        register int i;
        char stemp[20];
        static char jname[FNS];
+       register struct direct *dp;
 
        debug("ck send");
        if(stat(senddir,&statbuf) < 0){
 
        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;
                }
        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;
        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;
                   || 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
                        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
                        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;
                }
 #endif DONTHOLDBIG
                if(lFileLen > filesize){
                        lFileLen = filesize;
-                       for(i=0; i<DIRSIZ; i++)
-                               jname[i] = dirbuf.d_name[i];
+                       strcpy(jname,dp->d_name);
                        uidBest = uid;
                }
 # ifdef MAXSENDQ
                        uidBest = uid;
                }
 # ifdef MAXSENDQ
index 9fd49ea..1bc1cef 100644 (file)
@@ -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] */
 
 /* 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
 
        be sorted correctly */
 # define STSIZE 150
 
-static FILE *df;
+static DIR *df;
 static char jname[16], printlong;
 static struct table {
        char name[16];
 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 int hisuid,sumj,nsumj;
 static long sumb, nsumb;
 static struct stat statbuf;
-static struct direct dirbuf;
 
 char _sobuf[BUFSIZ];
 main(argc,argv)
 
 char _sobuf[BUFSIZ];
 main(argc,argv)
@@ -82,21 +81,21 @@ static pdir(str)
        char listrest = 0;
        int (*compar)();
        char printhead = 0;
        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;
        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;
                        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++;
 #ifdef MAXSENDQ
                if( stptr >= MAXSENDQ ) {
                        listrest++;
@@ -104,13 +103,14 @@ static pdir(str)
                }
 #endif
 
                }
 #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));
                        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]);
                return;
                }
        cp = (char *)&(stack[0].name[0]);
@@ -132,8 +132,9 @@ static pdir(str)
                }
 # ifdef MAXSENDQ
        if( listrest )
                }
 # ifdef MAXSENDQ
        if( listrest )
-               listem();
+               listem(dp);
 # endif
 # endif
+       closedir(df);
        printsum();
        if(more)printf("   ... more ...\n");
        }
        printsum();
        if(more)printf("   ... more ...\n");
        }
@@ -309,26 +310,24 @@ swap(a,b)
        b->filesize = t;
        }
 # ifdef MAXSENDQ
        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;
                        continue;
-               if( mach != dirbuf.d_name[2] )
+               if( mach != dp->d_name[2] )
                        continue;
                        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 ) );
                        continue;
                if( printlong || guid( statbuf.st_uid, statbuf.st_gid) == hisuid )
                        process();
                else
                        summarize( getsize( &statbuf ) );
-       }
+       } while((dp = readdir(df)) != NULL);
 
        return;
 }
 
        return;
 }
index 8f9aa8c..e9434b6 100644 (file)
@@ -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 */
 
 # include "defs.h"
 /* sccs id variable */
@@ -20,7 +20,6 @@ char  pathname[]=     NETRMNAME;
 int hisuid, hisgid;
 static char visit[26];
 static struct stat statbuf;
 int hisuid, hisgid;
 static char visit[26];
 static struct stat statbuf;
-static struct direct dirbuf;
 
 main(argc,argv)
 char   *argv[];
 
 main(argc,argv)
 char   *argv[];
@@ -60,25 +59,25 @@ char        *argv[];
 }
 static pdir(str)
   char *str; {
 }
 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);
                }
        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 */
                         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;
        }
 rmfile(str)
   char *str;