testld.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. #include <fcall.h>
  5. #include <thread.h>
  6. #include <9p.h>
  7. #include "flashfs.h"
  8. static void
  9. usage(void)
  10. {
  11. fprint(2, "usage: %s -n nsect -z sectsize -f file\n", prog);
  12. exits("usage");
  13. }
  14. static ulong
  15. argval(char *arg)
  16. {
  17. long v;
  18. char *extra;
  19. if(arg == nil)
  20. usage();
  21. v = strtol(arg, &extra, 0);
  22. if(*extra || v <= 0)
  23. usage();
  24. return v;
  25. }
  26. void
  27. main(int argc, char **argv)
  28. {
  29. char *file;
  30. prog = "testldfs";
  31. file = nil;
  32. ARGBEGIN {
  33. case 'n':
  34. nsects = argval(ARGF());
  35. break;
  36. case 'z':
  37. sectsize = argval(ARGF());
  38. break;
  39. case 'f':
  40. file = ARGF();
  41. break;
  42. default:
  43. usage();
  44. } ARGEND
  45. if(argc != 0 || nsects == 0 || sectsize == 0 || file == nil)
  46. usage();
  47. if(nsects < 8) {
  48. fprint(2, "%s: unreasonable value for nsects: %lud\n", prog, nsects);
  49. exits("nsects");
  50. }
  51. if(sectsize < 512) {
  52. fprint(2, "%s: unreasonable value for sectsize: %lud\n", prog, sectsize);
  53. exits("sectsize");
  54. }
  55. sectbuff = emalloc9p(sectsize);
  56. initdata(file, 0);
  57. einit();
  58. loadfs(1);
  59. }