Annotation of cci/sys/stand/ls.c, revision 1.1.1.1

1.1       root        1: /*     ls.c    6.1     83/07/29        */
                      2: 
                      3: #include "../h/param.h"
                      4: #include "../h/inode.h"
                      5: #include "../h/dir.h"
                      6: #include "../h/fs.h"
                      7: #include "saio.h"
                      8: 
                      9: char line[100];
                     10: 
                     11: main()
                     12: {
                     13:        int io;
                     14:        register char   *ptr;
                     15:        struct inode    *ip;
                     16: 
                     17:        for(;;) {
                     18:                line[0] = 0;
                     19:                printf("\n\nls: ");
                     20:                gets(line);
                     21:                /* scan to end of line */
                     22:                for(ptr=line; *ptr; ptr++)
                     23:                        ;
                     24:                /* check to see if a file was specified */
                     25:                if(ptr == line) {
                     26:                        printf("usage: dev(unit,0)/directory\n");
                     27:                        continue;
                     28:                }
                     29:                /* do one correction first so the raw dev is not opened */
                     30:                if(*(--ptr) == ')') {
                     31:                        *(++ptr) = '/';
                     32:                        *(++ptr) = '.';
                     33:                        *(++ptr) = (char)0;
                     34:                }
                     35:                if(*ptr == '/') {
                     36:                        *(++ptr) = '.';
                     37:                        *(++ptr) = (char)0;
                     38:                }
                     39:                if((io = open(line, 0)) >= 0)
                     40:                        break;
                     41:        }
                     42:        if((io >= NFILES+3) || (io < 3))
                     43:                _stop("open returned corrupt file index!");
                     44:        ip = &iob[io-3].i_ino;
                     45:        if ((ip->i_mode & IFMT) != IFDIR) {
                     46:                printf("%s is not a directory!\n", line);
                     47:                _stop("");
                     48:        }
                     49:        if (ip->i_size == 0) {
                     50:                printf("%s is a zero length directory!\n", line);
                     51:                _stop("");
                     52:        }
                     53:        
                     54:        ls(io);
                     55: }
                     56: 
                     57: ls(io)
                     58: register io;
                     59: {
                     60: 
                     61:        register int    i, size;
                     62:        register char   *dp;
                     63:        static char     dirbuf[DIRBLKSIZ];
                     64: 
                     65:        printf ("\nInode -> Name\n");
                     66:        while ((size = read(io, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ) {
                     67:                for(dp = dirbuf; (dp < (dirbuf + size)) &&
                     68:                    (dp + ((struct direct *)dp)->d_reclen) < (dirbuf + size);
                     69:                    dp += ((struct direct *)dp)->d_reclen) {
                     70:                        if(((struct direct *)dp)->d_ino == 0)
                     71:                                continue;
                     72:                        if(((struct direct *)dp)->d_reclen > 
                     73:                            DIRSIZ(((struct direct *)dp)))
                     74:                                continue;
                     75:                        if(((struct direct *)dp)->d_namlen > MAXNAMLEN+1)
                     76:                                _stop("Corrupt file name length!  Run fsck soon!\n");
                     77:                        printf("%s -> %d\n", ((struct direct *)dp)->d_name,
                     78:                            ((struct direct *)dp)->d_ino);
                     79:                }
                     80:        }
                     81: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.