|
|
1.1 root 1: /* Bootable program to list files in /.
2: * This is an example of an alternate bootable program.
3: * Here is it's Makefile entry:
4: * newdir: newdir.o $(OBJECTS)
5: * $(LD) -o newdir $(OBJECTS) newdir.o $(LIBS)
6: *
7: * Take great care in selecting routines from libc. In particular,
8: * you can not use ANY of the stdio functions (including sprintf()).
9: * Avoid anything else that might do system calls.
10: *
11: * La Monte H. Yarroll <[email protected]>, October 1991
12: */
13:
14: #include <ctype.h>
15: #include <canon.h>
16: #include <sys/types.h>
17: #include <sys/ino.h>
18: #include <sys/inode.h>
19: #include <sys/dir.h>
20: #include <a_out.h>
21:
22: #define MAIN
23: #include "tboot.h"
24: #undef MAIN
25:
26: main()
27: {
28: int i, j;
29: int fd;
30: uint16 value;
31: char outbuff[LINESIZE]; /* Buffer for outputing numbers. */
32: struct direct dirent;
33:
34: puts("Calling object_nlist().\r\n");
35: /* Look up the name "rootdev" in "/at386". */
36: value = object_nlist(I386MAGIC, "at386", "rootdev");
37:
38: puts("rootdev ");
39: /* Print out what we just found. */
40: puts("value: 0x");
41: itobase((uint16) (value), outbuff, 16);
42: puts(outbuff);
43: puts("\r\n");
44:
45: /* Open "/" and print out the direct block file entries. */
46: if (-1 == (fd = open(".", 0))) {
47: puts("Can't open /.\r\n");
48: return;
49: }
50:
51: /* Read each directory entry one at a time. */
52: /* We are careful to print an even fraction of 80 for each
53: * directory entry, so that everything lines up nicely.
54: */
55: while ( 0 != read(fd, (char *) &dirent, sizeof(struct direct)) ) {
56:
57: /* NUL terminate the name. */
58: strncpy(outbuff,
59: dirent.d_name,
60: DIRSIZ);
61: outbuff[DIRSIZ] = '\0';
62: /* Print the file name. */
63: puts(outbuff);
64: for (j = DIRSIZ - strlen(outbuff); j > 0; --j) {
65: putchar(' ');
66: }
67: puts(" :"); /* Bring total to 16 (80/5) characters. */
68: }
69:
70: close(fd);
71:
72: } /* main() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.