1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz. 7 * 8 * %sccs.include.noredist.c% 9 * 10 * @(#)ls.c 7.1 (Berkeley) 04/24/90 11 */ 12 13 #include "../h/param.h" 14 #include "../h/inode.h" 15 #include "../h/fs.h" 16 #undef KERNEL 17 #include "../h/dir.h" 18 #include "saio.h" 19 20 char line[100]; 21 22 main() 23 { 24 int i; 25 26 while (1) { 27 printf("\nDirectory: "); 28 gets(line); 29 if ((i = open(line, 0)) < 0) 30 printf("Cant open directory %s\n", line); 31 else { 32 ls(i); 33 close(i); 34 } 35 } 36 } 37 38 ls(io) 39 register io; 40 { 41 char buf[DIRBLKSIZ]; 42 register struct direct *dp; 43 register off; 44 45 while (read(io, buf, DIRBLKSIZ) > 0) { 46 for (off = 0 ; off < DIRBLKSIZ ; off += dp->d_reclen) { 47 dp = (struct direct *)(off + (int) buf); 48 if (dp->d_ino == 0) 49 break; 50 printf("%d\t", dp->d_ino); 51 printf("%s\n", dp->d_name); 52 } 53 } 54 } 55