~kris/9p

9hist

ref: ef2dff1dbae69e300b655586233c0b8d2c36676a 9hist/boot/local.c -rw-r--r-- 1.1 KiB
ef2dff1d — David du Colombier Plan 9 from Bell Labs 1993-08-30 33 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <u.h>
#include <libc.h>
#include <../boot/boot.h>

static char *disk;
static char *niob;

void
configlocal(Method *mp)
{
	if(*sys == '/' || *sys == '#')
		disk = sys;
	else
		disk = mp->arg;
	if(niob = strchr(disk, ' '))	/* assign = */
		*niob++ = 0;
	USED(mp);
}

int
authlocal(void)
{
	return -1;
}

int
connectlocal(void)
{
	int p[2];
	char d[DIRLEN];
	char partition[2*NAMELEN];
	char *dev;
	char *args[16], **argp;

	if(stat("/fs", d) < 0)
		return -1;

	dev = disk ? disk : bootdisk;
	sprint(partition, "%sfs", dev);
	if(stat(partition, d) < 0){
		strcpy(partition, dev);
		if(stat(partition, d) < 0)
			return -1;
	}

	print("fs...");
	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:
		dup(p[0], 0);
		dup(p[1], 1);
		close(p[0]);
		close(p[1]);
		argp = args;
		*argp++ = "fs";
		if(niob){
			*argp++ = "-B";
			*argp++ = niob;
		}
		*argp++ = "-f";
		*argp++ = partition;
		*argp++ = "-s";
		*argp = 0;
		exec("/fs", args);
		fatal("can't exec fs");
	default:
		break;
	}

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