|
|
1.1 root 1: #define __KERNEL__ 1
2: #include <kernel/typed.h>
3: #undef KERNEL
4: #include <fcntl.h>
5:
6: #ifndef T_NULL
7: #define T_NULL ((char *)0)
8: #endif
9:
10: /*
11: * Return name of current kernel.
12: * Usefull for things like ps and drvld that need to read the
13: * kernel's symbol table.
14: *
15: * If we can't open /dev/boot_gift, guess "/coherent".
16: * If boot_gift does not have a command line, guess "/autoboot".
17: * Otherwise, pull the boot file from the command line.
18: */
19: char *
20: kernelName()
21: {
22: int fd;
23: FIFO *ffp;
24: typed_space *tp;
25: int found;
26: TYPED_SPACE(boot_gift, BG_LEN, T_FIFO_SIC);
27:
28: /* 16 characters are for "/", a 14 character name, and a NUL. */
29: static char retval[16];
30:
31: if (-1 == (fd = open("/dev/boot_gift", O_RDONLY))) {
32: /* Can't open boot_gift, guess "/coherent". */
33: strcpy(retval, "/coherent");
34: return(retval);
35: }
36:
37: if (0 == read(fd, &boot_gift, BG_LEN)) {
38: close(fd);
39: /* Can't read boot_gift, guess "/coherent". */
40: strcpy(retval, "/coherent");
41: return(retval);
42: }
43:
44: close(fd);
45:
46: found = 0; /* We are looking for the command line. */
47: if (F_NULL != (ffp = fifo_open(&boot_gift, 0))) {
48: for (; !found && T_NULL != (tp = fifo_read(ffp)); ) {
49: if (T_STR_ARGF == tp->ts_type) {
50: found = 1;
51: break;
52: }
53: }
54: fifo_close(ffp);
55:
56: if (!found) {
57: strcpy(retval, "/autoboot");
58: } else {
59: /* Recast the argument list, so we can read it. */
60: RETYPE(tp, T_FIFO_SIC);
61: ffp = fifo_open(tp, 0);
62: if (T_NULL == (tp = fifo_read(ffp))) {
63: strcpy(retval, "/autoboot");
64: } else {
65: sprintf(retval, "/%.14s", tp->ts_data);
66: }
67: fifo_close(ffp);
68: }
69: } else {
70: strcpy(retval, "/autoboot");
71: }
72:
73: return(retval);
74:
75: } /* pick_nfile() */
76:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.