|
|
1.1 root 1: /* Copyright (c) 1982 Regents of the University of California */
2: /* and modified by pjw in 1986 */
3: #include <sys/types.h>
4: #include "ndir.h"
5:
6: /*
7: * read any style directory entry and present it as a bsd one
8: */
9: /* classical unix */
10: #define ODIRSIZ 14
11: struct olddirect {
12: ino_t d_ino;
13: char d_name[ODIRSIZ];
14: };
15: /* current cray */
16: #define CDIRSIZ 24
17: struct craydirect {
18: long x;
19: long d_ino;
20: char d_name[CDIRSIZ];
21: };
22:
23: /*
24: * get next entry in a directory.
25: */
26: struct direct *
27: readdir(dirp)
28: register DIR *dirp;
29: {
30: register struct olddirect *dp;
31: register struct craydirect *cp;
32: register struct direct *np;
33: static struct direct dir;
34:
35: loop:
36: if (dirp->dd_loc == 0) {
37: dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
38: DIRBLKSIZ);
39: if (dirp->dd_size <= 0)
40: return NULL;
41: }
42: if (dirp->dd_loc >= dirp->dd_size) {
43: dirp->dd_loc = 0;
44: goto loop;
45: }
46: switch(dirp->dd_type) {
47: case TCRAY:
48: cp = (struct craydirect *) (dirp->dd_buf + dirp->dd_loc);
49: dirp->dd_loc += sizeof(struct craydirect);
50: if(cp->d_ino == 0)
51: goto loop;
52: strncpy(dir.d_name, cp->d_name, CDIRSIZ);
53: dir.d_name[CDIRSIZ] = 0;
54: dir.d_ino = (ino_t) dir_rev4(cp->d_ino);
55: break;
56: default:
57: case TUNK:
58: return(0);
59: case TOLD:
60: dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
61: dirp->dd_loc += sizeof(struct olddirect);
62: if (dp->d_ino == 0)
63: goto loop;
64: dir.d_ino = (ino_t) dp->d_ino;
65: strncpy(dir.d_name, dp->d_name, ODIRSIZ);
66: dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
67: break;
1.1.1.2 ! root 68: case TBSDSWAP:
1.1 root 69: np = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
70: dirp->dd_loc += dir_rev2(np->d_reclen);
71: if(np->d_ino == 0)
72: goto loop;
73: dir.d_ino = (ino_t) dir_rev4(np->d_ino);
74: strcpy(dir.d_name, np->d_name);
75: break;
76: case TBSD:
77: np = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
78: dirp->dd_loc += np->d_reclen;
79: if(np->d_ino == 0)
80: goto loop;
81: dir.d_ino = (ino_t) np->d_ino;
82: strcpy(dir.d_name, np->d_name);
83: break;
1.1.1.2 ! root 84: case TOLDSWAP:
! 85: dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
! 86: dirp->dd_loc += sizeof(struct olddirect);
! 87: if (dp->d_ino == 0)
! 88: goto loop;
! 89: dir.d_ino = (ino_t) dir_rev2(dp->d_ino);
! 90: strncpy(dir.d_name, dp->d_name, ODIRSIZ);
! 91: dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
! 92: break;
1.1 root 93: }
94: dir.d_namlen = strlen(dir.d_name);
95: dir.d_reclen = DIRSIZ(&dir);
96: return (&dir);
97: }
98:
99: dir_rev2(n)
1.1.1.2 ! root 100: {
! 101: return (((n & 0xff) << 8) + ((n >> 8) & 0xff));
1.1 root 102: }
103:
104: dir_rev4(n)
1.1.1.2 ! root 105: {
! 106: return (((n & 0xff) << 24) + ((n & 0xff00) << 8) +
! 107: ((n & 0xff0000) >> 8) + ((n >> 24) & 0xff));
1.1 root 108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.