Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ubi.c 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <fcntl.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <termios.h>
  6. #include <unistd.h>
  7. #include <sys/ioctl.h>
  8. #include <mtd/ubi-user.h>
  9. #define zero(x) memset(&x, 0, sizeof(x))
  10. int
  11. main(void)
  12. {
  13. int fd = open("/dev/null", 0);
  14. struct ubi_mkvol_req mkvol = {
  15. .vol_id = 3,
  16. .alignment = 124,
  17. .bytes = 1125899906842624ULL,
  18. .vol_type = 3,
  19. .name_len = 7,
  20. .name = "foobar",
  21. };
  22. struct ubi_rsvol_req rsvol = {
  23. .bytes = 1125899906842624ULL,
  24. .vol_id = -3,
  25. };
  26. struct ubi_rnvol_req rnvol = {
  27. .count = 300,
  28. };
  29. struct ubi_attach_req attach;
  30. struct ubi_map_req map;
  31. struct ubi_set_vol_prop_req prop = {
  32. .property = 1,
  33. .value = 1125899906842624ULL,
  34. };
  35. uint64_t bytes = ((uint64_t)1 << 50) | 0x123;
  36. ioctl(fd, UBI_IOCMKVOL, &mkvol);
  37. ioctl(fd, UBI_IOCRSVOL, &rsvol);
  38. ioctl(fd, UBI_IOCRNVOL, &rnvol);
  39. ioctl(fd, UBI_IOCATT, &attach);
  40. ioctl(fd, UBI_IOCVOLUP, &bytes);
  41. ioctl(fd, UBI_IOCEBMAP, &map);
  42. ioctl(fd, UBI_IOCSETVOLPROP, &prop);
  43. zero(prop);
  44. ioctl(fd, UBI_IOCSETVOLPROP, &prop);
  45. ioctl(fd, UBI_IOCRMVOL, 1);
  46. ioctl(fd, UBI_IOCDET, 2);
  47. ioctl(fd, UBI_IOCEBER, 3);
  48. ioctl(fd, UBI_IOCEBCH, 4);
  49. ioctl(fd, UBI_IOCEBUNMAP, 5);
  50. ioctl(fd, UBI_IOCEBISMAP, 6);
  51. return 0;
  52. }