embed.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <../boot/boot.h>
  12. static char *paqfile;
  13. void
  14. configembed(Method *m)
  15. {
  16. if(*sys == '/' || *sys == '#'){
  17. /*
  18. * if the user specifies the disk in the boot cmd or
  19. * 'root is from' prompt, use it
  20. */
  21. paqfile = sys;
  22. } else if(m->arg){
  23. /*
  24. * a default is supplied when the kernel is made
  25. */
  26. paqfile = m->arg;
  27. }
  28. }
  29. int
  30. connectembed(void)
  31. {
  32. int i, p[2];
  33. Dir *dir;
  34. char **arg, **argp;
  35. dir = dirstat("/boot/paqfs");
  36. if(dir == nil)
  37. return -1;
  38. free(dir);
  39. dir = dirstat(paqfile);
  40. if(dir == nil || dir->mode & DMDIR)
  41. return -1;
  42. free(dir);
  43. print("paqfs...");
  44. if(bind("#c", "/dev", MREPL) < 0)
  45. fatal("bind #c");
  46. if(bind("#p", "/proc", MREPL) < 0)
  47. fatal("bind #p");
  48. if(pipe(p)<0)
  49. fatal("pipe");
  50. switch(fork()){
  51. case -1:
  52. fatal("fork");
  53. case 0:
  54. arg = malloc((bargc+5)*sizeof(char*));
  55. argp = arg;
  56. *argp++ = "/boot/paqfs";
  57. *argp++ = "-iv";
  58. *argp++ = paqfile;
  59. for(i=1; i<bargc; i++)
  60. *argp++ = bargv[i];
  61. *argp = 0;
  62. dup(p[0], 0);
  63. dup(p[1], 1);
  64. close(p[0]);
  65. close(p[1]);
  66. exec("/boot/paqfs", arg);
  67. fatal("can't exec paqfs");
  68. default:
  69. break;
  70. }
  71. waitpid();
  72. close(p[1]);
  73. return p[0];
  74. }