~kris/9p

9hist

ref: 7beaef922774bae5a96a3dd2518b895473ed19a5 9hist/boot/local.c -rw-r--r-- 836 bytes
7beaef92 — David du Colombier Plan 9 from Bell Labs 1992-08-24 34 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <u.h>
#include <libc.h>
#include <../boot/boot.h>

static char *disk;

void
configlocal(Method *mp)
{
	disk = mp->arg;
	USED(mp);
}

int
authlocal(void)
{
	return -1;
}

int
connectlocal(void)
{
	int p[2];
	char d[DIRLEN];
	char sbuf[32];
	char rbuf[32];
	char partition[2*NAMELEN];

	if(stat("/kfs", d) < 0)
		return -1;
	sprint(partition, "%sfs", disk ? disk : bootdisk);
	if(stat(partition, d) < 0)
		return -1;
	print("kfs...");
	if(bind("#c", "/dev", MREPL) < 0)
		fatal("bind #c");
	if(bind("#p", "/proc", MREPL) < 0)
		fatal("bind #p");
	if(pipe(p)<0)
		fatal("pipe");
	switch(fork()){
	case -1:
		fatal("fork");
	case 0:
		sprint(sbuf, "%d", p[0]);
		sprint(rbuf, "%d", p[1]);
		execl("/kfs", "kfs", "-f", partition, "-s", sbuf, rbuf, 0);
		fatal("can't exec kfs");
	default:
		break;
	}

	close(p[1]);
	return p[0];
}