xref: /plan9/sys/src/9/boot/embed.c (revision 6a9fc400c33447ef5e1cda7185cb4de2c8e8010e)
1 #include <u.h>
2 #include <libc.h>
3 #include <../boot/boot.h>
4 
5 static char *paqfile;
6 
7 void
configembed(Method * m)8 configembed(Method *m)
9 {
10 	if(*sys == '/' || *sys == '#'){
11 		/*
12 		 *  if the user specifies the disk in the boot cmd or
13 		 * 'root is from' prompt, use it
14 		 */
15 		paqfile = sys;
16 	} else if(m->arg){
17 		/*
18 		 *  a default is supplied when the kernel is made
19 		 */
20 		paqfile = m->arg;
21 	}
22 }
23 
24 int
connectembed(void)25 connectembed(void)
26 {
27 	int i, p[2];
28 	Dir *dir;
29 	char **arg, **argp;
30 
31 	dir = dirstat("/boot/paqfs");
32 	if(dir == nil)
33 		return -1;
34 	free(dir);
35 
36 	dir = dirstat(paqfile);
37 	if(dir == nil || dir->mode & DMDIR)
38 		return -1;
39 	free(dir);
40 
41 	print("paqfs...");
42 	if(bind("#c", "/dev", MREPL) < 0)
43 		fatal("bind #c");
44 	if(bind("#p", "/proc", MREPL) < 0)
45 		fatal("bind #p");
46 	if(pipe(p)<0)
47 		fatal("pipe");
48 	switch(fork()){
49 	case -1:
50 		fatal("fork");
51 	case 0:
52 		arg = malloc((bargc+5)*sizeof(char*));
53 		argp = arg;
54 		*argp++ = "/boot/paqfs";
55 		*argp++ = "-iv";
56 		*argp++ = paqfile;
57 		for(i=1; i<bargc; i++)
58 			*argp++ = bargv[i];
59 		*argp = 0;
60 
61 		dup(p[0], 0);
62 		dup(p[1], 1);
63 		close(p[0]);
64 		close(p[1]);
65 		exec("/boot/paqfs", arg);
66 		fatal("can't exec paqfs");
67 	default:
68 		break;
69 	}
70 	waitpid();
71 
72 	close(p[1]);
73 	return p[0];
74 }
75