123231Smckusick /* 234462Sbostic * Copyright (c) 1982, 1986, 1988 Regents of the University of California. 334462Sbostic * All rights reserved. 423231Smckusick * 534462Sbostic * Redistribution and use in source and binary forms are permitted 6*34871Sbostic * provided that the above copyright notice and this paragraph are 7*34871Sbostic * duplicated in all such forms and that any documentation, 8*34871Sbostic * advertising materials, and other materials related to such 9*34871Sbostic * distribution and use acknowledge that the software was developed 10*34871Sbostic * by the University of California, Berkeley. The name of the 11*34871Sbostic * University may not be used to endorse or promote products derived 12*34871Sbostic * from this software without specific prior written permission. 13*34871Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34871Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34871Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1634462Sbostic * 17*34871Sbostic * @(#)ls.c 7.4 (Berkeley) 06/29/88 1823231Smckusick */ 19320Sbill 2033408Skarels #include "param.h" 2133408Skarels #include "inode.h" 2233408Skarels #include "dir.h" 2334462Sbostic #include "fs.h" 24320Sbill #include "saio.h" 25320Sbill 26320Sbill main() 27320Sbill { 2834462Sbostic struct inode *ip; 2934462Sbostic int fd; 30320Sbill 3134462Sbostic fd = getfile("ls", 0); 3234462Sbostic ip = &iob[fd - 3].i_ino; 3334462Sbostic if ((ip->i_mode & IFMT) != IFDIR) 3434462Sbostic _stop("ls: not a directory"); 3534462Sbostic if (ip->i_size == 0) 3634462Sbostic _stop("ls: zero length directory"); 3734462Sbostic ls(fd); 38320Sbill } 39320Sbill 4034462Sbostic typedef struct direct DP; 4134462Sbostic static 4234462Sbostic ls(fd) 4334462Sbostic register int fd; 44320Sbill { 4534462Sbostic register int size; 4634462Sbostic register char *dp; 4734462Sbostic char dirbuf[DIRBLKSIZ]; 48320Sbill 4934462Sbostic printf("\nname->inode\n"); 5034462Sbostic while ((size = read(fd, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ) 5134462Sbostic for(dp = dirbuf; (dp < (dirbuf + size)) && 5234462Sbostic (dp + ((DP *)dp)->d_reclen) < (dirbuf + size); 5334462Sbostic dp += ((DP *)dp)->d_reclen) { 5434462Sbostic if (((DP *)dp)->d_ino == 0) 5534462Sbostic continue; 5634462Sbostic if (((DP *)dp)->d_reclen > DIRSIZ(((DP *)dp))) 5734462Sbostic continue; 5834462Sbostic if (((DP *)dp)->d_namlen > MAXNAMLEN+1) 5934462Sbostic _stop("Corrupt file name length! Run fsck soon!\n"); 6034462Sbostic printf("%s->%d\n", ((DP *)dp)->d_name, 6134462Sbostic ((DP *)dp)->d_ino); 62320Sbill } 63320Sbill } 64