paq.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. char *fparts[] =
  13. {
  14. "add bootldr 0x0000000 0x0040000",
  15. "add params 0x0040000 0x0080000",
  16. "add kernel 0x0080000 0x0140000",
  17. "add user 0x0140000 0x0200000",
  18. "add ramdisk 0x0200000 0x0600000",
  19. };
  20. void
  21. configpaq(Method* m)
  22. {
  23. int fd;
  24. int i;
  25. if(bind("#F", "/dev", MAFTER) < 0)
  26. fatal("bind #c");
  27. if(bind("#p", "/proc", MREPL) < 0)
  28. fatal("bind #p");
  29. fd = open("/dev/flash/flashctl", OWRITE);
  30. if(fd < 0)
  31. fatal("opening flashctl");
  32. for(i = 0; i < nelem(fparts); i++)
  33. if(fprint(fd, fparts[i]) < 0)
  34. fatal(fparts[i]);
  35. close(fd);
  36. }
  37. int
  38. connectpaq(void)
  39. {
  40. int p[2];
  41. char **arg, **argp;
  42. print("paq...");
  43. if(pipe(p)<0)
  44. fatal("pipe");
  45. switch(fork()){
  46. case -1:
  47. fatal("fork");
  48. case 0:
  49. arg = malloc(10*sizeof(char*));
  50. argp = arg;
  51. *argp++ = "paqfs";
  52. *argp++ = "-v";
  53. *argp++ = "-i";
  54. *argp++ = "/dev/flash/ramdisk";
  55. *argp = 0;
  56. dup(p[0], 0);
  57. dup(p[1], 1);
  58. close(p[0]);
  59. close(p[1]);
  60. exec("/boot/paqfs", arg);
  61. fatal("can't exec paqfs");
  62. default:
  63. break;
  64. }
  65. waitpid();
  66. close(p[1]);
  67. return p[0];
  68. }