ubi-user.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2006
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Author: Artem Bityutskiy (Битюцкий Артём)
  19. */
  20. #ifndef __UBI_USER_H__
  21. #define __UBI_USER_H__
  22. /*
  23. * UBI volume creation
  24. * ~~~~~~~~~~~~~~~~~~~
  25. *
  26. * UBI volumes are created via the %UBI_IOCMKVOL IOCTL command of UBI character
  27. * device. A &struct ubi_mkvol_req object has to be properly filled and a
  28. * pointer to it has to be passed to the IOCTL.
  29. *
  30. * UBI volume deletion
  31. * ~~~~~~~~~~~~~~~~~~~
  32. *
  33. * To delete a volume, the %UBI_IOCRMVOL IOCTL command of the UBI character
  34. * device should be used. A pointer to the 32-bit volume ID hast to be passed
  35. * to the IOCTL.
  36. *
  37. * UBI volume re-size
  38. * ~~~~~~~~~~~~~~~~~~
  39. *
  40. * To re-size a volume, the %UBI_IOCRSVOL IOCTL command of the UBI character
  41. * device should be used. A &struct ubi_rsvol_req object has to be properly
  42. * filled and a pointer to it has to be passed to the IOCTL.
  43. *
  44. * UBI volume update
  45. * ~~~~~~~~~~~~~~~~~
  46. *
  47. * Volume update should be done via the %UBI_IOCVOLUP IOCTL command of the
  48. * corresponding UBI volume character device. A pointer to a 64-bit update
  49. * size should be passed to the IOCTL. After then, UBI expects user to write
  50. * this number of bytes to the volume character device. The update is finished
  51. * when the claimed number of bytes is passed. So, the volume update sequence
  52. * is something like:
  53. *
  54. * fd = open("/dev/my_volume");
  55. * ioctl(fd, UBI_IOCVOLUP, &image_size);
  56. * write(fd, buf, image_size);
  57. * close(fd);
  58. */
  59. /*
  60. * When a new volume is created, users may either specify the volume number they
  61. * want to create or to let UBI automatically assign a volume number using this
  62. * constant.
  63. */
  64. #define UBI_VOL_NUM_AUTO (-1)
  65. /* Maximum volume name length */
  66. #define UBI_MAX_VOLUME_NAME 127
  67. /* IOCTL commands of UBI character devices */
  68. #define UBI_IOC_MAGIC 'o'
  69. /* Create an UBI volume */
  70. #define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)
  71. /* Remove an UBI volume */
  72. #define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, int32_t)
  73. /* Re-size an UBI volume */
  74. #define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)
  75. /* IOCTL commands of UBI volume character devices */
  76. #define UBI_VOL_IOC_MAGIC 'O'
  77. /* Start UBI volume update */
  78. #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t)
  79. /* An eraseblock erasure command, used for debugging, disabled by default */
  80. #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, int32_t)
  81. /*
  82. * UBI volume type constants.
  83. *
  84. * @UBI_DYNAMIC_VOLUME: dynamic volume
  85. * @UBI_STATIC_VOLUME: static volume
  86. */
  87. enum {
  88. UBI_DYNAMIC_VOLUME = 3,
  89. UBI_STATIC_VOLUME = 4
  90. };
  91. /**
  92. * struct ubi_mkvol_req - volume description data structure used in
  93. * volume creation requests.
  94. * @vol_id: volume number
  95. * @alignment: volume alignment
  96. * @bytes: volume size in bytes
  97. * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
  98. * @padding1: reserved for future, not used
  99. * @name_len: volume name length
  100. * @padding2: reserved for future, not used
  101. * @name: volume name
  102. *
  103. * This structure is used by userspace programs when creating new volumes. The
  104. * @used_bytes field is only necessary when creating static volumes.
  105. *
  106. * The @alignment field specifies the required alignment of the volume logical
  107. * eraseblock. This means, that the size of logical eraseblocks will be aligned
  108. * to this number, i.e.,
  109. * (UBI device logical eraseblock size) mod (@alignment) = 0.
  110. *
  111. * To put it differently, the logical eraseblock of this volume may be slightly
  112. * shortened in order to make it properly aligned. The alignment has to be
  113. * multiple of the flash minimal input/output unit, or %1 to utilize the entire
  114. * available space of logical eraseblocks.
  115. *
  116. * The @alignment field may be useful, for example, when one wants to maintain
  117. * a block device on top of an UBI volume. In this case, it is desirable to fit
  118. * an integer number of blocks in logical eraseblocks of this UBI volume. With
  119. * alignment it is possible to update this volume using plane UBI volume image
  120. * BLOBs, without caring about how to properly align them.
  121. */
  122. struct ubi_mkvol_req {
  123. int32_t vol_id;
  124. int32_t alignment;
  125. int64_t bytes;
  126. int8_t vol_type;
  127. int8_t padding1;
  128. int16_t name_len;
  129. int8_t padding2[4];
  130. char name[UBI_MAX_VOLUME_NAME+1];
  131. } __attribute__ ((packed));
  132. /**
  133. * struct ubi_rsvol_req - a data structure used in volume re-size requests.
  134. * @vol_id: ID of the volume to re-size
  135. * @bytes: new size of the volume in bytes
  136. *
  137. * Re-sizing is possible for both dynamic and static volumes. But while dynamic
  138. * volumes may be re-sized arbitrarily, static volumes cannot be made to be
  139. * smaller then the number of bytes they bear. To arbitrarily shrink a static
  140. * volume, it must be wiped out first (by means of volume update operation with
  141. * zero number of bytes).
  142. */
  143. struct ubi_rsvol_req {
  144. int64_t bytes;
  145. int32_t vol_id;
  146. } __attribute__ ((packed));
  147. #endif /* __UBI_USER_H__ */