xref: /csrg-svn/sys/stand.att/ls.c (revision 34462)
123231Smckusick /*
2*34462Sbostic  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
3*34462Sbostic  * All rights reserved.
423231Smckusick  *
5*34462Sbostic  * Redistribution and use in source and binary forms are permitted
6*34462Sbostic  * provided that this notice is preserved and that due credit is given
7*34462Sbostic  * to the University of California at Berkeley. The name of the University
8*34462Sbostic  * may not be used to endorse or promote products derived from this
9*34462Sbostic  * software without specific prior written permission. This software
10*34462Sbostic  * is provided ``as is'' without express or implied warranty.
11*34462Sbostic  *
12*34462Sbostic  *	@(#)ls.c	7.3 (Berkeley) 05/24/88
1323231Smckusick  */
14320Sbill 
1533408Skarels #include "param.h"
1633408Skarels #include "inode.h"
1733408Skarels #include "dir.h"
18*34462Sbostic #include "fs.h"
19320Sbill #include "saio.h"
20320Sbill 
21320Sbill main()
22320Sbill {
23*34462Sbostic 	struct inode *ip;
24*34462Sbostic 	int fd;
25320Sbill 
26*34462Sbostic 	fd = getfile("ls", 0);
27*34462Sbostic 	ip = &iob[fd - 3].i_ino;
28*34462Sbostic 	if ((ip->i_mode & IFMT) != IFDIR)
29*34462Sbostic 		_stop("ls: not a directory");
30*34462Sbostic 	if (ip->i_size == 0)
31*34462Sbostic 		_stop("ls: zero length directory");
32*34462Sbostic 	ls(fd);
33320Sbill }
34320Sbill 
35*34462Sbostic typedef struct direct	DP;
36*34462Sbostic static
37*34462Sbostic ls(fd)
38*34462Sbostic 	register int fd;
39320Sbill {
40*34462Sbostic 	register int size;
41*34462Sbostic 	register char *dp;
42*34462Sbostic 	char dirbuf[DIRBLKSIZ];
43320Sbill 
44*34462Sbostic 	printf("\nname->inode\n");
45*34462Sbostic 	while ((size = read(fd, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ)
46*34462Sbostic 		for(dp = dirbuf; (dp < (dirbuf + size)) &&
47*34462Sbostic 		    (dp + ((DP *)dp)->d_reclen) < (dirbuf + size);
48*34462Sbostic 		    dp += ((DP *)dp)->d_reclen) {
49*34462Sbostic 			if (((DP *)dp)->d_ino == 0)
50*34462Sbostic 				continue;
51*34462Sbostic 			if (((DP *)dp)->d_reclen > DIRSIZ(((DP *)dp)))
52*34462Sbostic 				continue;
53*34462Sbostic 			if (((DP *)dp)->d_namlen > MAXNAMLEN+1)
54*34462Sbostic 				_stop("Corrupt file name length!  Run fsck soon!\n");
55*34462Sbostic 			printf("%s->%d\n", ((DP *)dp)->d_name,
56*34462Sbostic 			    ((DP *)dp)->d_ino);
57320Sbill 		}
58320Sbill }
59