incrementalfs.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Userspace interface for Incremental FS.
  4. *
  5. * Incremental FS is special-purpose Linux virtual file system that allows
  6. * execution of a program while its binary and resource files are still being
  7. * lazily downloaded over the network, USB etc.
  8. *
  9. * Copyright 2019 Google LLC
  10. */
  11. #ifndef _UAPI_LINUX_INCREMENTALFS_H
  12. #define _UAPI_LINUX_INCREMENTALFS_H
  13. #include <linux/limits.h>
  14. #include <linux/ioctl.h>
  15. #include <linux/types.h>
  16. #include <linux/xattr.h>
  17. /* ===== constants ===== */
  18. #define INCFS_NAME "incremental-fs"
  19. #define INCFS_MAGIC_NUMBER (unsigned long)(0x5346434e49ul)
  20. #define INCFS_DATA_FILE_BLOCK_SIZE 4096
  21. #define INCFS_HEADER_VER 1
  22. /* TODO: This value is assumed in incfs_copy_signature_info_from_user to be the
  23. * actual signature length. Set back to 64 when fixed.
  24. */
  25. #define INCFS_MAX_HASH_SIZE 32
  26. #define INCFS_MAX_FILE_ATTR_SIZE 512
  27. #define INCFS_PENDING_READS_FILENAME ".pending_reads"
  28. #define INCFS_LOG_FILENAME ".log"
  29. #define INCFS_XATTR_ID_NAME (XATTR_USER_PREFIX "incfs.id")
  30. #define INCFS_XATTR_SIZE_NAME (XATTR_USER_PREFIX "incfs.size")
  31. #define INCFS_XATTR_METADATA_NAME (XATTR_USER_PREFIX "incfs.metadata")
  32. #define INCFS_MAX_SIGNATURE_SIZE 8096
  33. #define INCFS_SIGNATURE_VERSION 2
  34. #define INCFS_SIGNATURE_SECTIONS 2
  35. #define INCFS_IOCTL_BASE_CODE 'g'
  36. /* ===== ioctl requests on the command dir ===== */
  37. /* Create a new file */
  38. #define INCFS_IOC_CREATE_FILE \
  39. _IOWR(INCFS_IOCTL_BASE_CODE, 30, struct incfs_new_file_args)
  40. /* Read file signature */
  41. #define INCFS_IOC_READ_FILE_SIGNATURE \
  42. _IOR(INCFS_IOCTL_BASE_CODE, 31, struct incfs_get_file_sig_args)
  43. /*
  44. * Fill in one or more data block. This may only be called on a handle
  45. * passed as a parameter to INCFS_IOC_PERMIT_FILLING
  46. *
  47. * Returns number of blocks filled in, or error if none were
  48. */
  49. #define INCFS_IOC_FILL_BLOCKS \
  50. _IOR(INCFS_IOCTL_BASE_CODE, 32, struct incfs_fill_blocks)
  51. /*
  52. * Permit INCFS_IOC_FILL_BLOCKS on the given file descriptor
  53. * May only be called on .pending_reads file
  54. *
  55. * Returns 0 on success or error
  56. */
  57. #define INCFS_IOC_PERMIT_FILL \
  58. _IOW(INCFS_IOCTL_BASE_CODE, 33, struct incfs_permit_fill)
  59. /*
  60. * Fills buffer with ranges of populated blocks
  61. *
  62. * Returns 0 if all ranges written
  63. * error otherwise
  64. *
  65. * Either way, range_buffer_size_out is set to the number
  66. * of bytes written. Should be set to 0 by caller. The ranges
  67. * filled are valid, but if an error was returned there might
  68. * be more ranges to come.
  69. *
  70. * Ranges are ranges of filled blocks:
  71. *
  72. * 1 2 7 9
  73. *
  74. * means blocks 1, 2, 7, 8, 9 are filled, 0, 3, 4, 5, 6 and 10 on
  75. * are not
  76. *
  77. * If hashing is enabled for the file, the hash blocks are simply
  78. * treated as though they immediately followed the data blocks.
  79. */
  80. #define INCFS_IOC_GET_FILLED_BLOCKS \
  81. _IOR(INCFS_IOCTL_BASE_CODE, 34, struct incfs_get_filled_blocks_args)
  82. enum incfs_compression_alg {
  83. COMPRESSION_NONE = 0,
  84. COMPRESSION_LZ4 = 1
  85. };
  86. enum incfs_block_flags {
  87. INCFS_BLOCK_FLAGS_NONE = 0,
  88. INCFS_BLOCK_FLAGS_HASH = 1,
  89. };
  90. typedef struct {
  91. __u8 bytes[16];
  92. } incfs_uuid_t __attribute__((aligned (8)));
  93. /*
  94. * Description of a pending read. A pending read - a read call by
  95. * a userspace program for which the filesystem currently doesn't have data.
  96. */
  97. struct incfs_pending_read_info {
  98. /* Id of a file that is being read from. */
  99. incfs_uuid_t file_id;
  100. /* A number of microseconds since system boot to the read. */
  101. __aligned_u64 timestamp_us;
  102. /* Index of a file block that is being read. */
  103. __u32 block_index;
  104. /* A serial number of this pending read. */
  105. __u32 serial_number;
  106. };
  107. /*
  108. * Description of a data or hash block to add to a data file.
  109. */
  110. struct incfs_fill_block {
  111. /* Index of a data block. */
  112. __u32 block_index;
  113. /* Length of data */
  114. __u32 data_len;
  115. /*
  116. * A pointer to an actual data for the block.
  117. *
  118. * Equivalent to: __u8 *data;
  119. */
  120. __aligned_u64 data;
  121. /*
  122. * Compression algorithm used to compress the data block.
  123. * Values from enum incfs_compression_alg.
  124. */
  125. __u8 compression;
  126. /* Values from enum incfs_block_flags */
  127. __u8 flags;
  128. __u16 reserved1;
  129. __u32 reserved2;
  130. __aligned_u64 reserved3;
  131. };
  132. /*
  133. * Description of a number of blocks to add to a data file
  134. *
  135. * Argument for INCFS_IOC_FILL_BLOCKS
  136. */
  137. struct incfs_fill_blocks {
  138. /* Number of blocks */
  139. __u64 count;
  140. /* A pointer to an array of incfs_fill_block structs */
  141. __aligned_u64 fill_blocks;
  142. };
  143. /*
  144. * Permit INCFS_IOC_FILL_BLOCKS on the given file descriptor
  145. * May only be called on .pending_reads file
  146. *
  147. * Argument for INCFS_IOC_PERMIT_FILL
  148. */
  149. struct incfs_permit_fill {
  150. /* File to permit fills on */
  151. __u32 file_descriptor;
  152. };
  153. enum incfs_hash_tree_algorithm {
  154. INCFS_HASH_TREE_NONE = 0,
  155. INCFS_HASH_TREE_SHA256 = 1
  156. };
  157. /*
  158. * Create a new file or directory.
  159. */
  160. struct incfs_new_file_args {
  161. /* Id of a file to create. */
  162. incfs_uuid_t file_id;
  163. /*
  164. * Total size of the new file. Ignored if S_ISDIR(mode).
  165. */
  166. __aligned_u64 size;
  167. /*
  168. * File mode. Permissions and dir flag.
  169. */
  170. __u16 mode;
  171. __u16 reserved1;
  172. __u32 reserved2;
  173. /*
  174. * A pointer to a null-terminated relative path to the file's parent
  175. * dir.
  176. * Max length: PATH_MAX
  177. *
  178. * Equivalent to: char *directory_path;
  179. */
  180. __aligned_u64 directory_path;
  181. /*
  182. * A pointer to a null-terminated file's name.
  183. * Max length: PATH_MAX
  184. *
  185. * Equivalent to: char *file_name;
  186. */
  187. __aligned_u64 file_name;
  188. /*
  189. * A pointer to a file attribute to be set on creation.
  190. *
  191. * Equivalent to: u8 *file_attr;
  192. */
  193. __aligned_u64 file_attr;
  194. /*
  195. * Length of the data buffer specfied by file_attr.
  196. * Max value: INCFS_MAX_FILE_ATTR_SIZE
  197. */
  198. __u32 file_attr_len;
  199. __u32 reserved4;
  200. /*
  201. * Points to an APK V4 Signature data blob
  202. * Signature must have two sections
  203. * Format is:
  204. * u32 version
  205. * u32 size_of_hash_info_section
  206. * u8 hash_info_section[]
  207. * u32 size_of_signing_info_section
  208. * u8 signing_info_section[]
  209. *
  210. * Note that incfs does not care about what is in signing_info_section
  211. *
  212. * hash_info_section has following format:
  213. * u32 hash_algorithm; // Must be SHA256 == 1
  214. * u8 log2_blocksize; // Must be 12 for 4096 byte blocks
  215. * u32 salt_size;
  216. * u8 salt[];
  217. * u32 hash_size;
  218. * u8 root_hash[];
  219. */
  220. __aligned_u64 signature_info;
  221. /* Size of signature_info */
  222. __aligned_u64 signature_size;
  223. __aligned_u64 reserved6;
  224. };
  225. /*
  226. * Request a digital signature blob for a given file.
  227. * Argument for INCFS_IOC_READ_FILE_SIGNATURE ioctl
  228. */
  229. struct incfs_get_file_sig_args {
  230. /*
  231. * A pointer to the data buffer to save an signature blob to.
  232. *
  233. * Equivalent to: u8 *file_signature;
  234. */
  235. __aligned_u64 file_signature;
  236. /* Size of the buffer at file_signature. */
  237. __u32 file_signature_buf_size;
  238. /*
  239. * Number of bytes save file_signature buffer.
  240. * It is set after ioctl done.
  241. */
  242. __u32 file_signature_len_out;
  243. };
  244. struct incfs_filled_range {
  245. __u32 begin;
  246. __u32 end;
  247. };
  248. /*
  249. * Request ranges of filled blocks
  250. * Argument for INCFS_IOC_GET_FILLED_BLOCKS
  251. */
  252. struct incfs_get_filled_blocks_args {
  253. /*
  254. * A buffer to populate with ranges of filled blocks
  255. *
  256. * Equivalent to struct incfs_filled_ranges *range_buffer
  257. */
  258. __aligned_u64 range_buffer;
  259. /* Size of range_buffer */
  260. __u32 range_buffer_size;
  261. /* Start index to read from */
  262. __u32 start_index;
  263. /*
  264. * End index to read to. 0 means read to end. This is a range,
  265. * so incfs will read from start_index to end_index - 1
  266. */
  267. __u32 end_index;
  268. /* Actual number of blocks in file */
  269. __u32 total_blocks_out;
  270. /* The number of data blocks in file */
  271. __u32 data_blocks_out;
  272. /* Number of bytes written to range buffer */
  273. __u32 range_buffer_size_out;
  274. /* Sector scanned up to, if the call was interrupted */
  275. __u32 index_out;
  276. };
  277. #endif /* _UAPI_LINUX_INCREMENTALFS_H */