|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1982, 1986, 1988 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution is only permitted until one year after the first shipment ! 6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and ! 7: * binary forms are permitted provided that: (1) source distributions retain ! 8: * this entire copyright notice and comment, and (2) distributions including ! 9: * binaries display the following acknowledgement: This product includes ! 10: * software developed by the University of California, Berkeley and its ! 11: * contributors'' in the documentation or other materials provided with the ! 12: * distribution and in all advertising materials mentioning features or use ! 13: * of this software. Neither the name of the University nor the names of ! 14: * its contributors may be used to endorse or promote products derived from ! 15: * this software without specific prior written permission. ! 16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 19: * ! 20: * @(#)ls.c 7.9 (Berkeley) 6/28/90 ! 21: */ ! 22: ! 23: #include "sys/param.h" ! 24: #include "ufs/dir.h" ! 25: #include "saio.h" ! 26: #include "sys/ttychars.h" ! 27: ! 28: main() ! 29: { ! 30: struct dinode *ip; ! 31: int fd; ! 32: ! 33: for (;;) { ! 34: if ((fd = getfile("ls", 0)) == -1) ! 35: exit(); ! 36: ip = &iob[fd - 3].i_ino; ! 37: if ((ip->di_mode & IFMT) != IFDIR) { ! 38: printf("ls: not a directory\n"); ! 39: continue; ! 40: } ! 41: if (ip->di_size == 0) { ! 42: printf("ls: zero length directory\n"); ! 43: continue; ! 44: } ! 45: ls(fd); ! 46: } ! 47: } ! 48: ! 49: #define CTRL(x) (x&037) ! 50: ! 51: getfile(prompt, mode) ! 52: char *prompt; ! 53: int mode; ! 54: { ! 55: int fd; ! 56: char buf[100]; ! 57: ! 58: do { ! 59: printf("%s: ", prompt); ! 60: gets(buf); ! 61: if (buf[0] == CTRL('d') && buf[1] == 0) ! 62: return (-1); ! 63: } while ((fd = open(buf, mode)) <= 0); ! 64: return(fd); ! 65: } ! 66: ! 67: typedef struct direct DP; ! 68: static ! 69: ls(fd) ! 70: register int fd; ! 71: { ! 72: register int size; ! 73: register char *dp; ! 74: char dirbuf[DIRBLKSIZ]; ! 75: ! 76: printf("\ninode\tname\n"); ! 77: while ((size = read(fd, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ) ! 78: for(dp = dirbuf; (dp < (dirbuf + size)) && ! 79: (dp + ((DP *)dp)->d_reclen) < (dirbuf + size); ! 80: dp += ((DP *)dp)->d_reclen) { ! 81: if (((DP *)dp)->d_ino == 0) ! 82: continue; ! 83: if (((DP *)dp)->d_namlen > MAXNAMLEN+1) { ! 84: printf("Corrupt file name length! Run fsck soon!\n"); ! 85: return; ! 86: } ! 87: printf("%d\t%s\n", ((DP *)dp)->d_ino, ! 88: ((DP *)dp)->d_name); ! 89: } ! 90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.