embed.c 1.2 KB

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