ubifs.h 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * This file is part of UBIFS.
  4. *
  5. * Copyright (C) 2006-2008 Nokia Corporation
  6. *
  7. * Authors: Artem Bityutskiy (Битюцкий Артём)
  8. * Adrian Hunter
  9. */
  10. #ifndef __UBIFS_H__
  11. #define __UBIFS_H__
  12. #include <asm/div64.h>
  13. #include <linux/statfs.h>
  14. #include <linux/fs.h>
  15. #include <linux/err.h>
  16. #include <linux/sched.h>
  17. #include <linux/slab.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/mutex.h>
  21. #include <linux/rwsem.h>
  22. #include <linux/mtd/ubi.h>
  23. #include <linux/pagemap.h>
  24. #include <linux/backing-dev.h>
  25. #include <linux/security.h>
  26. #include <linux/xattr.h>
  27. #include <linux/random.h>
  28. #include <crypto/hash_info.h>
  29. #include <crypto/hash.h>
  30. #include <crypto/algapi.h>
  31. #include <linux/fscrypt.h>
  32. #include "ubifs-media.h"
  33. /* Version of this UBIFS implementation */
  34. #define UBIFS_VERSION 1
  35. /* UBIFS file system VFS magic number */
  36. #define UBIFS_SUPER_MAGIC 0x24051905
  37. /* Number of UBIFS blocks per VFS page */
  38. #define UBIFS_BLOCKS_PER_PAGE (PAGE_SIZE / UBIFS_BLOCK_SIZE)
  39. #define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_SHIFT - UBIFS_BLOCK_SHIFT)
  40. /* "File system end of life" sequence number watermark */
  41. #define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL
  42. #define SQNUM_WATERMARK 0xFFFFFFFFFF000000ULL
  43. /*
  44. * Minimum amount of LEBs reserved for the index. At present the index needs at
  45. * least 2 LEBs: one for the index head and one for in-the-gaps method (which
  46. * currently does not cater for the index head and so excludes it from
  47. * consideration).
  48. */
  49. #define MIN_INDEX_LEBS 2
  50. /* Minimum amount of data UBIFS writes to the flash */
  51. #define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8)
  52. /*
  53. * Currently we do not support inode number overlapping and re-using, so this
  54. * watermark defines dangerous inode number level. This should be fixed later,
  55. * although it is difficult to exceed current limit. Another option is to use
  56. * 64-bit inode numbers, but this means more overhead.
  57. */
  58. #define INUM_WARN_WATERMARK 0xFFF00000
  59. #define INUM_WATERMARK 0xFFFFFF00
  60. /* Maximum number of entries in each LPT (LEB category) heap */
  61. #define LPT_HEAP_SZ 256
  62. /*
  63. * Background thread name pattern. The numbers are UBI device and volume
  64. * numbers.
  65. */
  66. #define BGT_NAME_PATTERN "ubifs_bgt%d_%d"
  67. /* Maximum possible inode number (only 32-bit inodes are supported now) */
  68. #define MAX_INUM 0xFFFFFFFF
  69. /* Number of non-data journal heads */
  70. #define NONDATA_JHEADS_CNT 2
  71. /* Shorter names for journal head numbers for internal usage */
  72. #define GCHD UBIFS_GC_HEAD
  73. #define BASEHD UBIFS_BASE_HEAD
  74. #define DATAHD UBIFS_DATA_HEAD
  75. /* 'No change' value for 'ubifs_change_lp()' */
  76. #define LPROPS_NC 0x80000001
  77. /*
  78. * There is no notion of truncation key because truncation nodes do not exist
  79. * in TNC. However, when replaying, it is handy to introduce fake "truncation"
  80. * keys for truncation nodes because the code becomes simpler. So we define
  81. * %UBIFS_TRUN_KEY type.
  82. *
  83. * But otherwise, out of the journal reply scope, the truncation keys are
  84. * invalid.
  85. */
  86. #define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT
  87. #define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT
  88. /*
  89. * How much a directory entry/extended attribute entry adds to the parent/host
  90. * inode.
  91. */
  92. #define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8)
  93. /* How much an extended attribute adds to the host inode */
  94. #define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8)
  95. /*
  96. * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered
  97. * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are
  98. * considered "young". This is used by shrinker when selecting znode to trim
  99. * off.
  100. */
  101. #define OLD_ZNODE_AGE 20
  102. #define YOUNG_ZNODE_AGE 5
  103. /*
  104. * Some compressors, like LZO, may end up with more data then the input buffer.
  105. * So UBIFS always allocates larger output buffer, to be sure the compressor
  106. * will not corrupt memory in case of worst case compression.
  107. */
  108. #define WORST_COMPR_FACTOR 2
  109. #ifdef CONFIG_FS_ENCRYPTION
  110. #define UBIFS_CIPHER_BLOCK_SIZE FS_CRYPTO_BLOCK_SIZE
  111. #else
  112. #define UBIFS_CIPHER_BLOCK_SIZE 0
  113. #endif
  114. /*
  115. * How much memory is needed for a buffer where we compress a data node.
  116. */
  117. #define COMPRESSED_DATA_NODE_BUF_SZ \
  118. (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR)
  119. /* Maximum expected tree height for use by bottom_up_buf */
  120. #define BOTTOM_UP_HEIGHT 64
  121. /* Maximum number of data nodes to bulk-read */
  122. #define UBIFS_MAX_BULK_READ 32
  123. #ifdef CONFIG_UBIFS_FS_AUTHENTICATION
  124. #define UBIFS_HASH_ARR_SZ UBIFS_MAX_HASH_LEN
  125. #define UBIFS_HMAC_ARR_SZ UBIFS_MAX_HMAC_LEN
  126. #else
  127. #define UBIFS_HASH_ARR_SZ 0
  128. #define UBIFS_HMAC_ARR_SZ 0
  129. #endif
  130. /*
  131. * Lockdep classes for UBIFS inode @ui_mutex.
  132. */
  133. enum {
  134. WB_MUTEX_1 = 0,
  135. WB_MUTEX_2 = 1,
  136. WB_MUTEX_3 = 2,
  137. WB_MUTEX_4 = 3,
  138. };
  139. /*
  140. * Znode flags (actually, bit numbers which store the flags).
  141. *
  142. * DIRTY_ZNODE: znode is dirty
  143. * COW_ZNODE: znode is being committed and a new instance of this znode has to
  144. * be created before changing this znode
  145. * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is
  146. * still in the commit list and the ongoing commit operation
  147. * will commit it, and delete this znode after it is done
  148. */
  149. enum {
  150. DIRTY_ZNODE = 0,
  151. COW_ZNODE = 1,
  152. OBSOLETE_ZNODE = 2,
  153. };
  154. /*
  155. * Commit states.
  156. *
  157. * COMMIT_RESTING: commit is not wanted
  158. * COMMIT_BACKGROUND: background commit has been requested
  159. * COMMIT_REQUIRED: commit is required
  160. * COMMIT_RUNNING_BACKGROUND: background commit is running
  161. * COMMIT_RUNNING_REQUIRED: commit is running and it is required
  162. * COMMIT_BROKEN: commit failed
  163. */
  164. enum {
  165. COMMIT_RESTING = 0,
  166. COMMIT_BACKGROUND,
  167. COMMIT_REQUIRED,
  168. COMMIT_RUNNING_BACKGROUND,
  169. COMMIT_RUNNING_REQUIRED,
  170. COMMIT_BROKEN,
  171. };
  172. /*
  173. * 'ubifs_scan_a_node()' return values.
  174. *
  175. * SCANNED_GARBAGE: scanned garbage
  176. * SCANNED_EMPTY_SPACE: scanned empty space
  177. * SCANNED_A_NODE: scanned a valid node
  178. * SCANNED_A_CORRUPT_NODE: scanned a corrupted node
  179. * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length
  180. *
  181. * Greater than zero means: 'scanned that number of padding bytes'
  182. */
  183. enum {
  184. SCANNED_GARBAGE = 0,
  185. SCANNED_EMPTY_SPACE = -1,
  186. SCANNED_A_NODE = -2,
  187. SCANNED_A_CORRUPT_NODE = -3,
  188. SCANNED_A_BAD_PAD_NODE = -4,
  189. };
  190. /*
  191. * LPT cnode flag bits.
  192. *
  193. * DIRTY_CNODE: cnode is dirty
  194. * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted),
  195. * so it can (and must) be freed when the commit is finished
  196. * COW_CNODE: cnode is being committed and must be copied before writing
  197. */
  198. enum {
  199. DIRTY_CNODE = 0,
  200. OBSOLETE_CNODE = 1,
  201. COW_CNODE = 2,
  202. };
  203. /*
  204. * Dirty flag bits (lpt_drty_flgs) for LPT special nodes.
  205. *
  206. * LTAB_DIRTY: ltab node is dirty
  207. * LSAVE_DIRTY: lsave node is dirty
  208. */
  209. enum {
  210. LTAB_DIRTY = 1,
  211. LSAVE_DIRTY = 2,
  212. };
  213. /*
  214. * Return codes used by the garbage collector.
  215. * @LEB_FREED: the logical eraseblock was freed and is ready to use
  216. * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit
  217. * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes
  218. */
  219. enum {
  220. LEB_FREED,
  221. LEB_FREED_IDX,
  222. LEB_RETAINED,
  223. };
  224. /*
  225. * Action taken upon a failed ubifs_assert().
  226. * @ASSACT_REPORT: just report the failed assertion
  227. * @ASSACT_RO: switch to read-only mode
  228. * @ASSACT_PANIC: call BUG() and possible panic the kernel
  229. */
  230. enum {
  231. ASSACT_REPORT = 0,
  232. ASSACT_RO,
  233. ASSACT_PANIC,
  234. };
  235. /**
  236. * struct ubifs_old_idx - index node obsoleted since last commit start.
  237. * @rb: rb-tree node
  238. * @lnum: LEB number of obsoleted index node
  239. * @offs: offset of obsoleted index node
  240. */
  241. struct ubifs_old_idx {
  242. struct rb_node rb;
  243. int lnum;
  244. int offs;
  245. };
  246. /* The below union makes it easier to deal with keys */
  247. union ubifs_key {
  248. uint8_t u8[UBIFS_SK_LEN];
  249. uint32_t u32[UBIFS_SK_LEN/4];
  250. uint64_t u64[UBIFS_SK_LEN/8];
  251. __le32 j32[UBIFS_SK_LEN/4];
  252. };
  253. /**
  254. * struct ubifs_scan_node - UBIFS scanned node information.
  255. * @list: list of scanned nodes
  256. * @key: key of node scanned (if it has one)
  257. * @sqnum: sequence number
  258. * @type: type of node scanned
  259. * @offs: offset with LEB of node scanned
  260. * @len: length of node scanned
  261. * @node: raw node
  262. */
  263. struct ubifs_scan_node {
  264. struct list_head list;
  265. union ubifs_key key;
  266. unsigned long long sqnum;
  267. int type;
  268. int offs;
  269. int len;
  270. void *node;
  271. };
  272. /**
  273. * struct ubifs_scan_leb - UBIFS scanned LEB information.
  274. * @lnum: logical eraseblock number
  275. * @nodes_cnt: number of nodes scanned
  276. * @nodes: list of struct ubifs_scan_node
  277. * @endpt: end point (and therefore the start of empty space)
  278. * @buf: buffer containing entire LEB scanned
  279. */
  280. struct ubifs_scan_leb {
  281. int lnum;
  282. int nodes_cnt;
  283. struct list_head nodes;
  284. int endpt;
  285. void *buf;
  286. };
  287. /**
  288. * struct ubifs_gced_idx_leb - garbage-collected indexing LEB.
  289. * @list: list
  290. * @lnum: LEB number
  291. * @unmap: OK to unmap this LEB
  292. *
  293. * This data structure is used to temporary store garbage-collected indexing
  294. * LEBs - they are not released immediately, but only after the next commit.
  295. * This is needed to guarantee recoverability.
  296. */
  297. struct ubifs_gced_idx_leb {
  298. struct list_head list;
  299. int lnum;
  300. int unmap;
  301. };
  302. /**
  303. * struct ubifs_inode - UBIFS in-memory inode description.
  304. * @vfs_inode: VFS inode description object
  305. * @creat_sqnum: sequence number at time of creation
  306. * @del_cmtno: commit number corresponding to the time the inode was deleted,
  307. * protected by @c->commit_sem;
  308. * @xattr_size: summarized size of all extended attributes in bytes
  309. * @xattr_cnt: count of extended attributes this inode has
  310. * @xattr_names: sum of lengths of all extended attribute names belonging to
  311. * this inode
  312. * @dirty: non-zero if the inode is dirty
  313. * @xattr: non-zero if this is an extended attribute inode
  314. * @bulk_read: non-zero if bulk-read should be used
  315. * @ui_mutex: serializes inode write-back with the rest of VFS operations,
  316. * serializes "clean <-> dirty" state changes, serializes bulk-read,
  317. * protects @dirty, @bulk_read, @ui_size, and @xattr_size
  318. * @xattr_sem: serilizes write operations (remove|set|create) on xattr
  319. * @ui_lock: protects @synced_i_size
  320. * @synced_i_size: synchronized size of inode, i.e. the value of inode size
  321. * currently stored on the flash; used only for regular file
  322. * inodes
  323. * @ui_size: inode size used by UBIFS when writing to flash
  324. * @flags: inode flags (@UBIFS_COMPR_FL, etc)
  325. * @compr_type: default compression type used for this inode
  326. * @last_page_read: page number of last page read (for bulk read)
  327. * @read_in_a_row: number of consecutive pages read in a row (for bulk read)
  328. * @data_len: length of the data attached to the inode
  329. * @data: inode's data
  330. *
  331. * @ui_mutex exists for two main reasons. At first it prevents inodes from
  332. * being written back while UBIFS changing them, being in the middle of an VFS
  333. * operation. This way UBIFS makes sure the inode fields are consistent. For
  334. * example, in 'ubifs_rename()' we change 3 inodes simultaneously, and
  335. * write-back must not write any of them before we have finished.
  336. *
  337. * The second reason is budgeting - UBIFS has to budget all operations. If an
  338. * operation is going to mark an inode dirty, it has to allocate budget for
  339. * this. It cannot just mark it dirty because there is no guarantee there will
  340. * be enough flash space to write the inode back later. This means UBIFS has
  341. * to have full control over inode "clean <-> dirty" transitions (and pages
  342. * actually). But unfortunately, VFS marks inodes dirty in many places, and it
  343. * does not ask the file-system if it is allowed to do so (there is a notifier,
  344. * but it is not enough), i.e., there is no mechanism to synchronize with this.
  345. * So UBIFS has its own inode dirty flag and its own mutex to serialize
  346. * "clean <-> dirty" transitions.
  347. *
  348. * The @synced_i_size field is used to make sure we never write pages which are
  349. * beyond last synchronized inode size. See 'ubifs_writepage()' for more
  350. * information.
  351. *
  352. * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses
  353. * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot
  354. * make sure @inode->i_size is always changed under @ui_mutex, because it
  355. * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
  356. * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
  357. * are changed under @ui_mutex, so they do not need "shadow" fields. Note, one
  358. * could consider to rework locking and base it on "shadow" fields.
  359. */
  360. struct ubifs_inode {
  361. struct inode vfs_inode;
  362. unsigned long long creat_sqnum;
  363. unsigned long long del_cmtno;
  364. unsigned int xattr_size;
  365. unsigned int xattr_cnt;
  366. unsigned int xattr_names;
  367. unsigned int dirty:1;
  368. unsigned int xattr:1;
  369. unsigned int bulk_read:1;
  370. unsigned int compr_type:2;
  371. struct mutex ui_mutex;
  372. struct rw_semaphore xattr_sem;
  373. spinlock_t ui_lock;
  374. loff_t synced_i_size;
  375. loff_t ui_size;
  376. int flags;
  377. pgoff_t last_page_read;
  378. pgoff_t read_in_a_row;
  379. int data_len;
  380. void *data;
  381. };
  382. /**
  383. * struct ubifs_unclean_leb - records a LEB recovered under read-only mode.
  384. * @list: list
  385. * @lnum: LEB number of recovered LEB
  386. * @endpt: offset where recovery ended
  387. *
  388. * This structure records a LEB identified during recovery that needs to be
  389. * cleaned but was not because UBIFS was mounted read-only. The information
  390. * is used to clean the LEB when remounting to read-write mode.
  391. */
  392. struct ubifs_unclean_leb {
  393. struct list_head list;
  394. int lnum;
  395. int endpt;
  396. };
  397. /*
  398. * LEB properties flags.
  399. *
  400. * LPROPS_UNCAT: not categorized
  401. * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index
  402. * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index
  403. * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index
  404. * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs
  405. * LPROPS_EMPTY: LEB is empty, not taken
  406. * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken
  407. * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken
  408. * LPROPS_CAT_MASK: mask for the LEB categories above
  409. * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media)
  410. * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash)
  411. */
  412. enum {
  413. LPROPS_UNCAT = 0,
  414. LPROPS_DIRTY = 1,
  415. LPROPS_DIRTY_IDX = 2,
  416. LPROPS_FREE = 3,
  417. LPROPS_HEAP_CNT = 3,
  418. LPROPS_EMPTY = 4,
  419. LPROPS_FREEABLE = 5,
  420. LPROPS_FRDI_IDX = 6,
  421. LPROPS_CAT_MASK = 15,
  422. LPROPS_TAKEN = 16,
  423. LPROPS_INDEX = 32,
  424. };
  425. /**
  426. * struct ubifs_lprops - logical eraseblock properties.
  427. * @free: amount of free space in bytes
  428. * @dirty: amount of dirty space in bytes
  429. * @flags: LEB properties flags (see above)
  430. * @lnum: LEB number
  431. * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE)
  432. * @hpos: heap position in heap of same-category lprops (other categories)
  433. */
  434. struct ubifs_lprops {
  435. int free;
  436. int dirty;
  437. int flags;
  438. int lnum;
  439. union {
  440. struct list_head list;
  441. int hpos;
  442. };
  443. };
  444. /**
  445. * struct ubifs_lpt_lprops - LPT logical eraseblock properties.
  446. * @free: amount of free space in bytes
  447. * @dirty: amount of dirty space in bytes
  448. * @tgc: trivial GC flag (1 => unmap after commit end)
  449. * @cmt: commit flag (1 => reserved for commit)
  450. */
  451. struct ubifs_lpt_lprops {
  452. int free;
  453. int dirty;
  454. unsigned tgc:1;
  455. unsigned cmt:1;
  456. };
  457. /**
  458. * struct ubifs_lp_stats - statistics of eraseblocks in the main area.
  459. * @empty_lebs: number of empty LEBs
  460. * @taken_empty_lebs: number of taken LEBs
  461. * @idx_lebs: number of indexing LEBs
  462. * @total_free: total free space in bytes (includes all LEBs)
  463. * @total_dirty: total dirty space in bytes (includes all LEBs)
  464. * @total_used: total used space in bytes (does not include index LEBs)
  465. * @total_dead: total dead space in bytes (does not include index LEBs)
  466. * @total_dark: total dark space in bytes (does not include index LEBs)
  467. *
  468. * The @taken_empty_lebs field counts the LEBs that are in the transient state
  469. * of having been "taken" for use but not yet written to. @taken_empty_lebs is
  470. * needed to account correctly for @gc_lnum, otherwise @empty_lebs could be
  471. * used by itself (in which case 'unused_lebs' would be a better name). In the
  472. * case of @gc_lnum, it is "taken" at mount time or whenever a LEB is retained
  473. * by GC, but unlike other empty LEBs that are "taken", it may not be written
  474. * straight away (i.e. before the next commit start or unmount), so either
  475. * @gc_lnum must be specially accounted for, or the current approach followed
  476. * i.e. count it under @taken_empty_lebs.
  477. *
  478. * @empty_lebs includes @taken_empty_lebs.
  479. *
  480. * @total_used, @total_dead and @total_dark fields do not account indexing
  481. * LEBs.
  482. */
  483. struct ubifs_lp_stats {
  484. int empty_lebs;
  485. int taken_empty_lebs;
  486. int idx_lebs;
  487. long long total_free;
  488. long long total_dirty;
  489. long long total_used;
  490. long long total_dead;
  491. long long total_dark;
  492. };
  493. struct ubifs_nnode;
  494. /**
  495. * struct ubifs_cnode - LEB Properties Tree common node.
  496. * @parent: parent nnode
  497. * @cnext: next cnode to commit
  498. * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
  499. * @iip: index in parent
  500. * @level: level in the tree (zero for pnodes, greater than zero for nnodes)
  501. * @num: node number
  502. */
  503. struct ubifs_cnode {
  504. struct ubifs_nnode *parent;
  505. struct ubifs_cnode *cnext;
  506. unsigned long flags;
  507. int iip;
  508. int level;
  509. int num;
  510. };
  511. /**
  512. * struct ubifs_pnode - LEB Properties Tree leaf node.
  513. * @parent: parent nnode
  514. * @cnext: next cnode to commit
  515. * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
  516. * @iip: index in parent
  517. * @level: level in the tree (always zero for pnodes)
  518. * @num: node number
  519. * @lprops: LEB properties array
  520. */
  521. struct ubifs_pnode {
  522. struct ubifs_nnode *parent;
  523. struct ubifs_cnode *cnext;
  524. unsigned long flags;
  525. int iip;
  526. int level;
  527. int num;
  528. struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
  529. };
  530. /**
  531. * struct ubifs_nbranch - LEB Properties Tree internal node branch.
  532. * @lnum: LEB number of child
  533. * @offs: offset of child
  534. * @nnode: nnode child
  535. * @pnode: pnode child
  536. * @cnode: cnode child
  537. */
  538. struct ubifs_nbranch {
  539. int lnum;
  540. int offs;
  541. union {
  542. struct ubifs_nnode *nnode;
  543. struct ubifs_pnode *pnode;
  544. struct ubifs_cnode *cnode;
  545. };
  546. };
  547. /**
  548. * struct ubifs_nnode - LEB Properties Tree internal node.
  549. * @parent: parent nnode
  550. * @cnext: next cnode to commit
  551. * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
  552. * @iip: index in parent
  553. * @level: level in the tree (always greater than zero for nnodes)
  554. * @num: node number
  555. * @nbranch: branches to child nodes
  556. */
  557. struct ubifs_nnode {
  558. struct ubifs_nnode *parent;
  559. struct ubifs_cnode *cnext;
  560. unsigned long flags;
  561. int iip;
  562. int level;
  563. int num;
  564. struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
  565. };
  566. /**
  567. * struct ubifs_lpt_heap - heap of categorized lprops.
  568. * @arr: heap array
  569. * @cnt: number in heap
  570. * @max_cnt: maximum number allowed in heap
  571. *
  572. * There are %LPROPS_HEAP_CNT heaps.
  573. */
  574. struct ubifs_lpt_heap {
  575. struct ubifs_lprops **arr;
  576. int cnt;
  577. int max_cnt;
  578. };
  579. /*
  580. * Return codes for LPT scan callback function.
  581. *
  582. * LPT_SCAN_CONTINUE: continue scanning
  583. * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory
  584. * LPT_SCAN_STOP: stop scanning
  585. */
  586. enum {
  587. LPT_SCAN_CONTINUE = 0,
  588. LPT_SCAN_ADD = 1,
  589. LPT_SCAN_STOP = 2,
  590. };
  591. struct ubifs_info;
  592. /* Callback used by the 'ubifs_lpt_scan_nolock()' function */
  593. typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
  594. const struct ubifs_lprops *lprops,
  595. int in_tree, void *data);
  596. /**
  597. * struct ubifs_wbuf - UBIFS write-buffer.
  598. * @c: UBIFS file-system description object
  599. * @buf: write-buffer (of min. flash I/O unit size)
  600. * @lnum: logical eraseblock number the write-buffer points to
  601. * @offs: write-buffer offset in this logical eraseblock
  602. * @avail: number of bytes available in the write-buffer
  603. * @used: number of used bytes in the write-buffer
  604. * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range)
  605. * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep
  606. * up by 'mutex_lock_nested()).
  607. * @sync_callback: write-buffer synchronization callback
  608. * @io_mutex: serializes write-buffer I/O
  609. * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes
  610. * fields
  611. * @timer: write-buffer timer
  612. * @no_timer: non-zero if this write-buffer does not have a timer
  613. * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing
  614. * @next_ino: points to the next position of the following inode number
  615. * @inodes: stores the inode numbers of the nodes which are in wbuf
  616. *
  617. * The write-buffer synchronization callback is called when the write-buffer is
  618. * synchronized in order to notify how much space was wasted due to
  619. * write-buffer padding and how much free space is left in the LEB.
  620. *
  621. * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under
  622. * spin-lock or mutex because they are written under both mutex and spin-lock.
  623. * @buf is appended to under mutex but overwritten under both mutex and
  624. * spin-lock. Thus the data between @buf and @buf + @used can be read under
  625. * spinlock.
  626. */
  627. struct ubifs_wbuf {
  628. struct ubifs_info *c;
  629. void *buf;
  630. int lnum;
  631. int offs;
  632. int avail;
  633. int used;
  634. int size;
  635. int jhead;
  636. int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
  637. struct mutex io_mutex;
  638. spinlock_t lock;
  639. struct hrtimer timer;
  640. unsigned int no_timer:1;
  641. unsigned int need_sync:1;
  642. int next_ino;
  643. ino_t *inodes;
  644. };
  645. /**
  646. * struct ubifs_bud - bud logical eraseblock.
  647. * @lnum: logical eraseblock number
  648. * @start: where the (uncommitted) bud data starts
  649. * @jhead: journal head number this bud belongs to
  650. * @list: link in the list buds belonging to the same journal head
  651. * @rb: link in the tree of all buds
  652. * @log_hash: the log hash from the commit start node up to this bud
  653. */
  654. struct ubifs_bud {
  655. int lnum;
  656. int start;
  657. int jhead;
  658. struct list_head list;
  659. struct rb_node rb;
  660. struct shash_desc *log_hash;
  661. };
  662. /**
  663. * struct ubifs_jhead - journal head.
  664. * @wbuf: head's write-buffer
  665. * @buds_list: list of bud LEBs belonging to this journal head
  666. * @grouped: non-zero if UBIFS groups nodes when writing to this journal head
  667. * @log_hash: the log hash from the commit start node up to this journal head
  668. *
  669. * Note, the @buds list is protected by the @c->buds_lock.
  670. */
  671. struct ubifs_jhead {
  672. struct ubifs_wbuf wbuf;
  673. struct list_head buds_list;
  674. unsigned int grouped:1;
  675. struct shash_desc *log_hash;
  676. };
  677. /**
  678. * struct ubifs_zbranch - key/coordinate/length branch stored in znodes.
  679. * @key: key
  680. * @znode: znode address in memory
  681. * @lnum: LEB number of the target node (indexing node or data node)
  682. * @offs: target node offset within @lnum
  683. * @len: target node length
  684. * @hash: the hash of the target node
  685. */
  686. struct ubifs_zbranch {
  687. union ubifs_key key;
  688. union {
  689. struct ubifs_znode *znode;
  690. void *leaf;
  691. };
  692. int lnum;
  693. int offs;
  694. int len;
  695. u8 hash[UBIFS_HASH_ARR_SZ];
  696. };
  697. /**
  698. * struct ubifs_znode - in-memory representation of an indexing node.
  699. * @parent: parent znode or NULL if it is the root
  700. * @cnext: next znode to commit
  701. * @cparent: parent node for this commit
  702. * @ciip: index in cparent's zbranch array
  703. * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE)
  704. * @time: last access time (seconds)
  705. * @level: level of the entry in the TNC tree
  706. * @child_cnt: count of child znodes
  707. * @iip: index in parent's zbranch array
  708. * @alt: lower bound of key range has altered i.e. child inserted at slot 0
  709. * @lnum: LEB number of the corresponding indexing node
  710. * @offs: offset of the corresponding indexing node
  711. * @len: length of the corresponding indexing node
  712. * @zbranch: array of znode branches (@c->fanout elements)
  713. *
  714. * Note! The @lnum, @offs, and @len fields are not really needed - we have them
  715. * only for internal consistency check. They could be removed to save some RAM.
  716. */
  717. struct ubifs_znode {
  718. struct ubifs_znode *parent;
  719. struct ubifs_znode *cnext;
  720. struct ubifs_znode *cparent;
  721. int ciip;
  722. unsigned long flags;
  723. time64_t time;
  724. int level;
  725. int child_cnt;
  726. int iip;
  727. int alt;
  728. int lnum;
  729. int offs;
  730. int len;
  731. struct ubifs_zbranch zbranch[];
  732. };
  733. /**
  734. * struct bu_info - bulk-read information.
  735. * @key: first data node key
  736. * @zbranch: zbranches of data nodes to bulk read
  737. * @buf: buffer to read into
  738. * @buf_len: buffer length
  739. * @gc_seq: GC sequence number to detect races with GC
  740. * @cnt: number of data nodes for bulk read
  741. * @blk_cnt: number of data blocks including holes
  742. * @oef: end of file reached
  743. */
  744. struct bu_info {
  745. union ubifs_key key;
  746. struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
  747. void *buf;
  748. int buf_len;
  749. int gc_seq;
  750. int cnt;
  751. int blk_cnt;
  752. int eof;
  753. };
  754. /**
  755. * struct ubifs_node_range - node length range description data structure.
  756. * @len: fixed node length
  757. * @min_len: minimum possible node length
  758. * @max_len: maximum possible node length
  759. *
  760. * If @max_len is %0, the node has fixed length @len.
  761. */
  762. struct ubifs_node_range {
  763. union {
  764. int len;
  765. int min_len;
  766. };
  767. int max_len;
  768. };
  769. /**
  770. * struct ubifs_compressor - UBIFS compressor description structure.
  771. * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc)
  772. * @cc: cryptoapi compressor handle
  773. * @comp_mutex: mutex used during compression
  774. * @decomp_mutex: mutex used during decompression
  775. * @name: compressor name
  776. * @capi_name: cryptoapi compressor name
  777. */
  778. struct ubifs_compressor {
  779. int compr_type;
  780. struct crypto_comp *cc;
  781. struct mutex *comp_mutex;
  782. struct mutex *decomp_mutex;
  783. const char *name;
  784. const char *capi_name;
  785. };
  786. /**
  787. * struct ubifs_budget_req - budget requirements of an operation.
  788. *
  789. * @fast: non-zero if the budgeting should try to acquire budget quickly and
  790. * should not try to call write-back
  791. * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields
  792. * have to be re-calculated
  793. * @new_page: non-zero if the operation adds a new page
  794. * @dirtied_page: non-zero if the operation makes a page dirty
  795. * @new_dent: non-zero if the operation adds a new directory entry
  796. * @mod_dent: non-zero if the operation removes or modifies an existing
  797. * directory entry
  798. * @new_ino: non-zero if the operation adds a new inode
  799. * @new_ino_d: how much data newly created inode contains
  800. * @dirtied_ino: how many inodes the operation makes dirty
  801. * @dirtied_ino_d: how much data dirtied inode contains
  802. * @idx_growth: how much the index will supposedly grow
  803. * @data_growth: how much new data the operation will supposedly add
  804. * @dd_growth: how much data that makes other data dirty the operation will
  805. * supposedly add
  806. *
  807. * @idx_growth, @data_growth and @dd_growth are not used in budget request. The
  808. * budgeting subsystem caches index and data growth values there to avoid
  809. * re-calculating them when the budget is released. However, if @idx_growth is
  810. * %-1, it is calculated by the release function using other fields.
  811. *
  812. * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d
  813. * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made
  814. * dirty by the re-name operation.
  815. *
  816. * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to
  817. * make sure the amount of inode data which contribute to @new_ino_d and
  818. * @dirtied_ino_d fields are aligned.
  819. */
  820. struct ubifs_budget_req {
  821. unsigned int fast:1;
  822. unsigned int recalculate:1;
  823. #ifndef UBIFS_DEBUG
  824. unsigned int new_page:1;
  825. unsigned int dirtied_page:1;
  826. unsigned int new_dent:1;
  827. unsigned int mod_dent:1;
  828. unsigned int new_ino:1;
  829. unsigned int new_ino_d:13;
  830. unsigned int dirtied_ino:4;
  831. unsigned int dirtied_ino_d:15;
  832. #else
  833. /* Not bit-fields to check for overflows */
  834. unsigned int new_page;
  835. unsigned int dirtied_page;
  836. unsigned int new_dent;
  837. unsigned int mod_dent;
  838. unsigned int new_ino;
  839. unsigned int new_ino_d;
  840. unsigned int dirtied_ino;
  841. unsigned int dirtied_ino_d;
  842. #endif
  843. int idx_growth;
  844. int data_growth;
  845. int dd_growth;
  846. };
  847. /**
  848. * struct ubifs_orphan - stores the inode number of an orphan.
  849. * @rb: rb-tree node of rb-tree of orphans sorted by inode number
  850. * @list: list head of list of orphans in order added
  851. * @new_list: list head of list of orphans added since the last commit
  852. * @child_list: list of xattr childs if this orphan hosts xattrs, list head
  853. * if this orphan is a xattr, not used otherwise.
  854. * @cnext: next orphan to commit
  855. * @dnext: next orphan to delete
  856. * @inum: inode number
  857. * @new: %1 => added since the last commit, otherwise %0
  858. * @cmt: %1 => commit pending, otherwise %0
  859. * @del: %1 => delete pending, otherwise %0
  860. */
  861. struct ubifs_orphan {
  862. struct rb_node rb;
  863. struct list_head list;
  864. struct list_head new_list;
  865. struct list_head child_list;
  866. struct ubifs_orphan *cnext;
  867. struct ubifs_orphan *dnext;
  868. ino_t inum;
  869. unsigned new:1;
  870. unsigned cmt:1;
  871. unsigned del:1;
  872. };
  873. /**
  874. * struct ubifs_mount_opts - UBIFS-specific mount options information.
  875. * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast)
  876. * @bulk_read: enable/disable bulk-reads (%0 default, %1 disable, %2 enable)
  877. * @chk_data_crc: enable/disable CRC data checking when reading data nodes
  878. * (%0 default, %1 disable, %2 enable)
  879. * @override_compr: override default compressor (%0 - do not override and use
  880. * superblock compressor, %1 - override and use compressor
  881. * specified in @compr_type)
  882. * @compr_type: compressor type to override the superblock compressor with
  883. * (%UBIFS_COMPR_NONE, etc)
  884. */
  885. struct ubifs_mount_opts {
  886. unsigned int unmount_mode:2;
  887. unsigned int bulk_read:2;
  888. unsigned int chk_data_crc:2;
  889. unsigned int override_compr:1;
  890. unsigned int compr_type:2;
  891. };
  892. /**
  893. * struct ubifs_budg_info - UBIFS budgeting information.
  894. * @idx_growth: amount of bytes budgeted for index growth
  895. * @data_growth: amount of bytes budgeted for cached data
  896. * @dd_growth: amount of bytes budgeted for cached data that will make
  897. * other data dirty
  898. * @uncommitted_idx: amount of bytes were budgeted for growth of the index, but
  899. * which still have to be taken into account because the index
  900. * has not been committed so far
  901. * @old_idx_sz: size of index on flash
  902. * @min_idx_lebs: minimum number of LEBs required for the index
  903. * @nospace: non-zero if the file-system does not have flash space (used as
  904. * optimization)
  905. * @nospace_rp: the same as @nospace, but additionally means that even reserved
  906. * pool is full
  907. * @page_budget: budget for a page (constant, never changed after mount)
  908. * @inode_budget: budget for an inode (constant, never changed after mount)
  909. * @dent_budget: budget for a directory entry (constant, never changed after
  910. * mount)
  911. */
  912. struct ubifs_budg_info {
  913. long long idx_growth;
  914. long long data_growth;
  915. long long dd_growth;
  916. long long uncommitted_idx;
  917. unsigned long long old_idx_sz;
  918. int min_idx_lebs;
  919. unsigned int nospace:1;
  920. unsigned int nospace_rp:1;
  921. int page_budget;
  922. int inode_budget;
  923. int dent_budget;
  924. };
  925. struct ubifs_debug_info;
  926. /**
  927. * struct ubifs_info - UBIFS file-system description data structure
  928. * (per-superblock).
  929. * @vfs_sb: VFS @struct super_block object
  930. * @sup_node: The super block node as read from the device
  931. *
  932. * @highest_inum: highest used inode number
  933. * @max_sqnum: current global sequence number
  934. * @cmt_no: commit number of the last successfully completed commit, protected
  935. * by @commit_sem
  936. * @cnt_lock: protects @highest_inum and @max_sqnum counters
  937. * @fmt_version: UBIFS on-flash format version
  938. * @ro_compat_version: R/O compatibility version
  939. * @uuid: UUID from super block
  940. *
  941. * @lhead_lnum: log head logical eraseblock number
  942. * @lhead_offs: log head offset
  943. * @ltail_lnum: log tail logical eraseblock number (offset is always 0)
  944. * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and
  945. * @bud_bytes
  946. * @min_log_bytes: minimum required number of bytes in the log
  947. * @cmt_bud_bytes: used during commit to temporarily amount of bytes in
  948. * committed buds
  949. *
  950. * @buds: tree of all buds indexed by bud LEB number
  951. * @bud_bytes: how many bytes of flash is used by buds
  952. * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud
  953. * lists
  954. * @jhead_cnt: count of journal heads
  955. * @jheads: journal heads (head zero is base head)
  956. * @max_bud_bytes: maximum number of bytes allowed in buds
  957. * @bg_bud_bytes: number of bud bytes when background commit is initiated
  958. * @old_buds: buds to be released after commit ends
  959. * @max_bud_cnt: maximum number of buds
  960. *
  961. * @commit_sem: synchronizes committer with other processes
  962. * @cmt_state: commit state
  963. * @cs_lock: commit state lock
  964. * @cmt_wq: wait queue to sleep on if the log is full and a commit is running
  965. *
  966. * @big_lpt: flag that LPT is too big to write whole during commit
  967. * @space_fixup: flag indicating that free space in LEBs needs to be cleaned up
  968. * @double_hash: flag indicating that we can do lookups by hash
  969. * @encrypted: flag indicating that this file system contains encrypted files
  970. * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
  971. * recovery)
  972. * @bulk_read: enable bulk-reads
  973. * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
  974. * @rw_incompat: the media is not R/W compatible
  975. * @assert_action: action to take when a ubifs_assert() fails
  976. * @authenticated: flag indigating the FS is mounted in authenticated mode
  977. *
  978. * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
  979. * @calc_idx_sz
  980. * @zroot: zbranch which points to the root index node and znode
  981. * @cnext: next znode to commit
  982. * @enext: next znode to commit to empty space
  983. * @gap_lebs: array of LEBs used by the in-gaps commit method
  984. * @cbuf: commit buffer
  985. * @ileb_buf: buffer for commit in-the-gaps method
  986. * @ileb_len: length of data in ileb_buf
  987. * @ihead_lnum: LEB number of index head
  988. * @ihead_offs: offset of index head
  989. * @ilebs: pre-allocated index LEBs
  990. * @ileb_cnt: number of pre-allocated index LEBs
  991. * @ileb_nxt: next pre-allocated index LEBs
  992. * @old_idx: tree of index nodes obsoleted since the last commit start
  993. * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c
  994. *
  995. * @mst_node: master node
  996. * @mst_offs: offset of valid master node
  997. *
  998. * @max_bu_buf_len: maximum bulk-read buffer length
  999. * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu
  1000. * @bu: pre-allocated bulk-read information
  1001. *
  1002. * @write_reserve_mutex: protects @write_reserve_buf
  1003. * @write_reserve_buf: on the write path we allocate memory, which might
  1004. * sometimes be unavailable, in which case we use this
  1005. * write reserve buffer
  1006. *
  1007. * @log_lebs: number of logical eraseblocks in the log
  1008. * @log_bytes: log size in bytes
  1009. * @log_last: last LEB of the log
  1010. * @lpt_lebs: number of LEBs used for lprops table
  1011. * @lpt_first: first LEB of the lprops table area
  1012. * @lpt_last: last LEB of the lprops table area
  1013. * @orph_lebs: number of LEBs used for the orphan area
  1014. * @orph_first: first LEB of the orphan area
  1015. * @orph_last: last LEB of the orphan area
  1016. * @main_lebs: count of LEBs in the main area
  1017. * @main_first: first LEB of the main area
  1018. * @main_bytes: main area size in bytes
  1019. *
  1020. * @key_hash_type: type of the key hash
  1021. * @key_hash: direntry key hash function
  1022. * @key_fmt: key format
  1023. * @key_len: key length
  1024. * @hash_len: The length of the index node hashes
  1025. * @fanout: fanout of the index tree (number of links per indexing node)
  1026. *
  1027. * @min_io_size: minimal input/output unit size
  1028. * @min_io_shift: number of bits in @min_io_size minus one
  1029. * @max_write_size: maximum amount of bytes the underlying flash can write at a
  1030. * time (MTD write buffer size)
  1031. * @max_write_shift: number of bits in @max_write_size minus one
  1032. * @leb_size: logical eraseblock size in bytes
  1033. * @leb_start: starting offset of logical eraseblocks within physical
  1034. * eraseblocks
  1035. * @half_leb_size: half LEB size
  1036. * @idx_leb_size: how many bytes of an LEB are effectively available when it is
  1037. * used to store indexing nodes (@leb_size - @max_idx_node_sz)
  1038. * @leb_cnt: count of logical eraseblocks
  1039. * @max_leb_cnt: maximum count of logical eraseblocks
  1040. * @ro_media: the underlying UBI volume is read-only
  1041. * @ro_mount: the file-system was mounted as read-only
  1042. * @ro_error: UBIFS switched to R/O mode because an error happened
  1043. *
  1044. * @dirty_pg_cnt: number of dirty pages (not used)
  1045. * @dirty_zn_cnt: number of dirty znodes
  1046. * @clean_zn_cnt: number of clean znodes
  1047. *
  1048. * @space_lock: protects @bi and @lst
  1049. * @lst: lprops statistics
  1050. * @bi: budgeting information
  1051. * @calc_idx_sz: temporary variable which is used to calculate new index size
  1052. * (contains accurate new index size at end of TNC commit start)
  1053. *
  1054. * @ref_node_alsz: size of the LEB reference node aligned to the min. flash
  1055. * I/O unit
  1056. * @mst_node_alsz: master node aligned size
  1057. * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary
  1058. * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary
  1059. * @max_inode_sz: maximum possible inode size in bytes
  1060. * @max_znode_sz: size of znode in bytes
  1061. *
  1062. * @leb_overhead: how many bytes are wasted in an LEB when it is filled with
  1063. * data nodes of maximum size - used in free space reporting
  1064. * @dead_wm: LEB dead space watermark
  1065. * @dark_wm: LEB dark space watermark
  1066. * @block_cnt: count of 4KiB blocks on the FS
  1067. *
  1068. * @ranges: UBIFS node length ranges
  1069. * @ubi: UBI volume descriptor
  1070. * @di: UBI device information
  1071. * @vi: UBI volume information
  1072. *
  1073. * @orph_tree: rb-tree of orphan inode numbers
  1074. * @orph_list: list of orphan inode numbers in order added
  1075. * @orph_new: list of orphan inode numbers added since last commit
  1076. * @orph_cnext: next orphan to commit
  1077. * @orph_dnext: next orphan to delete
  1078. * @orphan_lock: lock for orph_tree and orph_new
  1079. * @orph_buf: buffer for orphan nodes
  1080. * @new_orphans: number of orphans since last commit
  1081. * @cmt_orphans: number of orphans being committed
  1082. * @tot_orphans: number of orphans in the rb_tree
  1083. * @max_orphans: maximum number of orphans allowed
  1084. * @ohead_lnum: orphan head LEB number
  1085. * @ohead_offs: orphan head offset
  1086. * @no_orphs: non-zero if there are no orphans
  1087. *
  1088. * @bgt: UBIFS background thread
  1089. * @bgt_name: background thread name
  1090. * @need_bgt: if background thread should run
  1091. * @need_wbuf_sync: if write-buffers have to be synchronized
  1092. *
  1093. * @gc_lnum: LEB number used for garbage collection
  1094. * @sbuf: a buffer of LEB size used by GC and replay for scanning
  1095. * @idx_gc: list of index LEBs that have been garbage collected
  1096. * @idx_gc_cnt: number of elements on the idx_gc list
  1097. * @gc_seq: incremented for every non-index LEB garbage collected
  1098. * @gced_lnum: last non-index LEB that was garbage collected
  1099. *
  1100. * @infos_list: links all 'ubifs_info' objects
  1101. * @umount_mutex: serializes shrinker and un-mount
  1102. * @shrinker_run_no: shrinker run number
  1103. *
  1104. * @space_bits: number of bits needed to record free or dirty space
  1105. * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT
  1106. * @lpt_offs_bits: number of bits needed to record an offset in the LPT
  1107. * @lpt_spc_bits: number of bits needed to space in the LPT
  1108. * @pcnt_bits: number of bits needed to record pnode or nnode number
  1109. * @lnum_bits: number of bits needed to record LEB number
  1110. * @nnode_sz: size of on-flash nnode
  1111. * @pnode_sz: size of on-flash pnode
  1112. * @ltab_sz: size of on-flash LPT lprops table
  1113. * @lsave_sz: size of on-flash LPT save table
  1114. * @pnode_cnt: number of pnodes
  1115. * @nnode_cnt: number of nnodes
  1116. * @lpt_hght: height of the LPT
  1117. * @pnodes_have: number of pnodes in memory
  1118. *
  1119. * @lp_mutex: protects lprops table and all the other lprops-related fields
  1120. * @lpt_lnum: LEB number of the root nnode of the LPT
  1121. * @lpt_offs: offset of the root nnode of the LPT
  1122. * @nhead_lnum: LEB number of LPT head
  1123. * @nhead_offs: offset of LPT head
  1124. * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab
  1125. * @dirty_nn_cnt: number of dirty nnodes
  1126. * @dirty_pn_cnt: number of dirty pnodes
  1127. * @check_lpt_free: flag that indicates LPT GC may be needed
  1128. * @lpt_sz: LPT size
  1129. * @lpt_nod_buf: buffer for an on-flash nnode or pnode
  1130. * @lpt_buf: buffer of LEB size used by LPT
  1131. * @nroot: address in memory of the root nnode of the LPT
  1132. * @lpt_cnext: next LPT node to commit
  1133. * @lpt_heap: array of heaps of categorized lprops
  1134. * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at
  1135. * previous commit start
  1136. * @uncat_list: list of un-categorized LEBs
  1137. * @empty_list: list of empty LEBs
  1138. * @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size)
  1139. * @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size)
  1140. * @freeable_cnt: number of freeable LEBs in @freeable_list
  1141. * @in_a_category_cnt: count of lprops which are in a certain category, which
  1142. * basically meants that they were loaded from the flash
  1143. *
  1144. * @ltab_lnum: LEB number of LPT's own lprops table
  1145. * @ltab_offs: offset of LPT's own lprops table
  1146. * @ltab: LPT's own lprops table
  1147. * @ltab_cmt: LPT's own lprops table (commit copy)
  1148. * @lsave_cnt: number of LEB numbers in LPT's save table
  1149. * @lsave_lnum: LEB number of LPT's save table
  1150. * @lsave_offs: offset of LPT's save table
  1151. * @lsave: LPT's save table
  1152. * @lscan_lnum: LEB number of last LPT scan
  1153. *
  1154. * @rp_size: size of the reserved pool in bytes
  1155. * @report_rp_size: size of the reserved pool reported to user-space
  1156. * @rp_uid: reserved pool user ID
  1157. * @rp_gid: reserved pool group ID
  1158. *
  1159. * @hash_tfm: the hash transformation used for hashing nodes
  1160. * @hmac_tfm: the HMAC transformation for this filesystem
  1161. * @hmac_desc_len: length of the HMAC used for authentication
  1162. * @auth_key_name: the authentication key name
  1163. * @auth_hash_name: the name of the hash algorithm used for authentication
  1164. * @auth_hash_algo: the authentication hash used for this fs
  1165. * @log_hash: the log hash from the commit start node up to the latest reference
  1166. * node.
  1167. *
  1168. * @empty: %1 if the UBI device is empty
  1169. * @need_recovery: %1 if the file-system needs recovery
  1170. * @replaying: %1 during journal replay
  1171. * @mounting: %1 while mounting
  1172. * @probing: %1 while attempting to mount if SB_SILENT mount flag is set
  1173. * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode
  1174. * @replay_list: temporary list used during journal replay
  1175. * @replay_buds: list of buds to replay
  1176. * @cs_sqnum: sequence number of first node in the log (commit start node)
  1177. * @unclean_leb_list: LEBs to recover when re-mounting R/O mounted FS to R/W
  1178. * mode
  1179. * @rcvrd_mst_node: recovered master node to write when re-mounting R/O mounted
  1180. * FS to R/W mode
  1181. * @size_tree: inode size information for recovery
  1182. * @mount_opts: UBIFS-specific mount options
  1183. *
  1184. * @dbg: debugging-related information
  1185. */
  1186. struct ubifs_info {
  1187. struct super_block *vfs_sb;
  1188. struct ubifs_sb_node *sup_node;
  1189. ino_t highest_inum;
  1190. unsigned long long max_sqnum;
  1191. unsigned long long cmt_no;
  1192. spinlock_t cnt_lock;
  1193. int fmt_version;
  1194. int ro_compat_version;
  1195. unsigned char uuid[16];
  1196. int lhead_lnum;
  1197. int lhead_offs;
  1198. int ltail_lnum;
  1199. struct mutex log_mutex;
  1200. int min_log_bytes;
  1201. long long cmt_bud_bytes;
  1202. struct rb_root buds;
  1203. long long bud_bytes;
  1204. spinlock_t buds_lock;
  1205. int jhead_cnt;
  1206. struct ubifs_jhead *jheads;
  1207. long long max_bud_bytes;
  1208. long long bg_bud_bytes;
  1209. struct list_head old_buds;
  1210. int max_bud_cnt;
  1211. struct rw_semaphore commit_sem;
  1212. int cmt_state;
  1213. spinlock_t cs_lock;
  1214. wait_queue_head_t cmt_wq;
  1215. unsigned int big_lpt:1;
  1216. unsigned int space_fixup:1;
  1217. unsigned int double_hash:1;
  1218. unsigned int encrypted:1;
  1219. unsigned int no_chk_data_crc:1;
  1220. unsigned int bulk_read:1;
  1221. unsigned int default_compr:2;
  1222. unsigned int rw_incompat:1;
  1223. unsigned int assert_action:2;
  1224. unsigned int authenticated:1;
  1225. unsigned int superblock_need_write:1;
  1226. struct mutex tnc_mutex;
  1227. struct ubifs_zbranch zroot;
  1228. struct ubifs_znode *cnext;
  1229. struct ubifs_znode *enext;
  1230. int *gap_lebs;
  1231. void *cbuf;
  1232. void *ileb_buf;
  1233. int ileb_len;
  1234. int ihead_lnum;
  1235. int ihead_offs;
  1236. int *ilebs;
  1237. int ileb_cnt;
  1238. int ileb_nxt;
  1239. struct rb_root old_idx;
  1240. int *bottom_up_buf;
  1241. struct ubifs_mst_node *mst_node;
  1242. int mst_offs;
  1243. int max_bu_buf_len;
  1244. struct mutex bu_mutex;
  1245. struct bu_info bu;
  1246. struct mutex write_reserve_mutex;
  1247. void *write_reserve_buf;
  1248. int log_lebs;
  1249. long long log_bytes;
  1250. int log_last;
  1251. int lpt_lebs;
  1252. int lpt_first;
  1253. int lpt_last;
  1254. int orph_lebs;
  1255. int orph_first;
  1256. int orph_last;
  1257. int main_lebs;
  1258. int main_first;
  1259. long long main_bytes;
  1260. uint8_t key_hash_type;
  1261. uint32_t (*key_hash)(const char *str, int len);
  1262. int key_fmt;
  1263. int key_len;
  1264. int hash_len;
  1265. int fanout;
  1266. int min_io_size;
  1267. int min_io_shift;
  1268. int max_write_size;
  1269. int max_write_shift;
  1270. int leb_size;
  1271. int leb_start;
  1272. int half_leb_size;
  1273. int idx_leb_size;
  1274. int leb_cnt;
  1275. int max_leb_cnt;
  1276. unsigned int ro_media:1;
  1277. unsigned int ro_mount:1;
  1278. unsigned int ro_error:1;
  1279. atomic_long_t dirty_pg_cnt;
  1280. atomic_long_t dirty_zn_cnt;
  1281. atomic_long_t clean_zn_cnt;
  1282. spinlock_t space_lock;
  1283. struct ubifs_lp_stats lst;
  1284. struct ubifs_budg_info bi;
  1285. unsigned long long calc_idx_sz;
  1286. int ref_node_alsz;
  1287. int mst_node_alsz;
  1288. int min_idx_node_sz;
  1289. int max_idx_node_sz;
  1290. long long max_inode_sz;
  1291. int max_znode_sz;
  1292. int leb_overhead;
  1293. int dead_wm;
  1294. int dark_wm;
  1295. int block_cnt;
  1296. struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
  1297. struct ubi_volume_desc *ubi;
  1298. struct ubi_device_info di;
  1299. struct ubi_volume_info vi;
  1300. struct rb_root orph_tree;
  1301. struct list_head orph_list;
  1302. struct list_head orph_new;
  1303. struct ubifs_orphan *orph_cnext;
  1304. struct ubifs_orphan *orph_dnext;
  1305. spinlock_t orphan_lock;
  1306. void *orph_buf;
  1307. int new_orphans;
  1308. int cmt_orphans;
  1309. int tot_orphans;
  1310. int max_orphans;
  1311. int ohead_lnum;
  1312. int ohead_offs;
  1313. int no_orphs;
  1314. struct task_struct *bgt;
  1315. char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
  1316. int need_bgt;
  1317. int need_wbuf_sync;
  1318. int gc_lnum;
  1319. void *sbuf;
  1320. struct list_head idx_gc;
  1321. int idx_gc_cnt;
  1322. int gc_seq;
  1323. int gced_lnum;
  1324. struct list_head infos_list;
  1325. struct mutex umount_mutex;
  1326. unsigned int shrinker_run_no;
  1327. int space_bits;
  1328. int lpt_lnum_bits;
  1329. int lpt_offs_bits;
  1330. int lpt_spc_bits;
  1331. int pcnt_bits;
  1332. int lnum_bits;
  1333. int nnode_sz;
  1334. int pnode_sz;
  1335. int ltab_sz;
  1336. int lsave_sz;
  1337. int pnode_cnt;
  1338. int nnode_cnt;
  1339. int lpt_hght;
  1340. int pnodes_have;
  1341. struct mutex lp_mutex;
  1342. int lpt_lnum;
  1343. int lpt_offs;
  1344. int nhead_lnum;
  1345. int nhead_offs;
  1346. int lpt_drty_flgs;
  1347. int dirty_nn_cnt;
  1348. int dirty_pn_cnt;
  1349. int check_lpt_free;
  1350. long long lpt_sz;
  1351. void *lpt_nod_buf;
  1352. void *lpt_buf;
  1353. struct ubifs_nnode *nroot;
  1354. struct ubifs_cnode *lpt_cnext;
  1355. struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
  1356. struct ubifs_lpt_heap dirty_idx;
  1357. struct list_head uncat_list;
  1358. struct list_head empty_list;
  1359. struct list_head freeable_list;
  1360. struct list_head frdi_idx_list;
  1361. int freeable_cnt;
  1362. int in_a_category_cnt;
  1363. int ltab_lnum;
  1364. int ltab_offs;
  1365. struct ubifs_lpt_lprops *ltab;
  1366. struct ubifs_lpt_lprops *ltab_cmt;
  1367. int lsave_cnt;
  1368. int lsave_lnum;
  1369. int lsave_offs;
  1370. int *lsave;
  1371. int lscan_lnum;
  1372. long long rp_size;
  1373. long long report_rp_size;
  1374. kuid_t rp_uid;
  1375. kgid_t rp_gid;
  1376. struct crypto_shash *hash_tfm;
  1377. struct crypto_shash *hmac_tfm;
  1378. int hmac_desc_len;
  1379. char *auth_key_name;
  1380. char *auth_hash_name;
  1381. enum hash_algo auth_hash_algo;
  1382. struct shash_desc *log_hash;
  1383. /* The below fields are used only during mounting and re-mounting */
  1384. unsigned int empty:1;
  1385. unsigned int need_recovery:1;
  1386. unsigned int replaying:1;
  1387. unsigned int mounting:1;
  1388. unsigned int remounting_rw:1;
  1389. unsigned int probing:1;
  1390. struct list_head replay_list;
  1391. struct list_head replay_buds;
  1392. unsigned long long cs_sqnum;
  1393. struct list_head unclean_leb_list;
  1394. struct ubifs_mst_node *rcvrd_mst_node;
  1395. struct rb_root size_tree;
  1396. struct ubifs_mount_opts mount_opts;
  1397. struct ubifs_debug_info *dbg;
  1398. };
  1399. extern struct list_head ubifs_infos;
  1400. extern spinlock_t ubifs_infos_lock;
  1401. extern atomic_long_t ubifs_clean_zn_cnt;
  1402. extern const struct super_operations ubifs_super_operations;
  1403. extern const struct address_space_operations ubifs_file_address_operations;
  1404. extern const struct file_operations ubifs_file_operations;
  1405. extern const struct inode_operations ubifs_file_inode_operations;
  1406. extern const struct file_operations ubifs_dir_operations;
  1407. extern const struct inode_operations ubifs_dir_inode_operations;
  1408. extern const struct inode_operations ubifs_symlink_inode_operations;
  1409. extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
  1410. extern int ubifs_default_version;
  1411. /* auth.c */
  1412. static inline int ubifs_authenticated(const struct ubifs_info *c)
  1413. {
  1414. return (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) && c->authenticated;
  1415. }
  1416. struct shash_desc *__ubifs_hash_get_desc(const struct ubifs_info *c);
  1417. static inline struct shash_desc *ubifs_hash_get_desc(const struct ubifs_info *c)
  1418. {
  1419. return ubifs_authenticated(c) ? __ubifs_hash_get_desc(c) : NULL;
  1420. }
  1421. static inline int ubifs_shash_init(const struct ubifs_info *c,
  1422. struct shash_desc *desc)
  1423. {
  1424. if (ubifs_authenticated(c))
  1425. return crypto_shash_init(desc);
  1426. else
  1427. return 0;
  1428. }
  1429. static inline int ubifs_shash_update(const struct ubifs_info *c,
  1430. struct shash_desc *desc, const void *buf,
  1431. unsigned int len)
  1432. {
  1433. int err = 0;
  1434. if (ubifs_authenticated(c)) {
  1435. err = crypto_shash_update(desc, buf, len);
  1436. if (err < 0)
  1437. return err;
  1438. }
  1439. return 0;
  1440. }
  1441. static inline int ubifs_shash_final(const struct ubifs_info *c,
  1442. struct shash_desc *desc, u8 *out)
  1443. {
  1444. return ubifs_authenticated(c) ? crypto_shash_final(desc, out) : 0;
  1445. }
  1446. int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *buf,
  1447. u8 *hash);
  1448. static inline int ubifs_node_calc_hash(const struct ubifs_info *c,
  1449. const void *buf, u8 *hash)
  1450. {
  1451. if (ubifs_authenticated(c))
  1452. return __ubifs_node_calc_hash(c, buf, hash);
  1453. else
  1454. return 0;
  1455. }
  1456. int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
  1457. struct shash_desc *inhash);
  1458. /**
  1459. * ubifs_check_hash - compare two hashes
  1460. * @c: UBIFS file-system description object
  1461. * @expected: first hash
  1462. * @got: second hash
  1463. *
  1464. * Compare two hashes @expected and @got. Returns 0 when they are equal, a
  1465. * negative error code otherwise.
  1466. */
  1467. static inline int ubifs_check_hash(const struct ubifs_info *c,
  1468. const u8 *expected, const u8 *got)
  1469. {
  1470. return crypto_memneq(expected, got, c->hash_len);
  1471. }
  1472. /**
  1473. * ubifs_check_hmac - compare two HMACs
  1474. * @c: UBIFS file-system description object
  1475. * @expected: first HMAC
  1476. * @got: second HMAC
  1477. *
  1478. * Compare two hashes @expected and @got. Returns 0 when they are equal, a
  1479. * negative error code otherwise.
  1480. */
  1481. static inline int ubifs_check_hmac(const struct ubifs_info *c,
  1482. const u8 *expected, const u8 *got)
  1483. {
  1484. return crypto_memneq(expected, got, c->hmac_desc_len);
  1485. }
  1486. void ubifs_bad_hash(const struct ubifs_info *c, const void *node,
  1487. const u8 *hash, int lnum, int offs);
  1488. int __ubifs_node_check_hash(const struct ubifs_info *c, const void *buf,
  1489. const u8 *expected);
  1490. static inline int ubifs_node_check_hash(const struct ubifs_info *c,
  1491. const void *buf, const u8 *expected)
  1492. {
  1493. if (ubifs_authenticated(c))
  1494. return __ubifs_node_check_hash(c, buf, expected);
  1495. else
  1496. return 0;
  1497. }
  1498. int ubifs_init_authentication(struct ubifs_info *c);
  1499. void __ubifs_exit_authentication(struct ubifs_info *c);
  1500. static inline void ubifs_exit_authentication(struct ubifs_info *c)
  1501. {
  1502. if (ubifs_authenticated(c))
  1503. __ubifs_exit_authentication(c);
  1504. }
  1505. /**
  1506. * ubifs_branch_hash - returns a pointer to the hash of a branch
  1507. * @c: UBIFS file-system description object
  1508. * @br: branch to get the hash from
  1509. *
  1510. * This returns a pointer to the hash of a branch. Since the key already is a
  1511. * dynamically sized object we cannot use a struct member here.
  1512. */
  1513. static inline u8 *ubifs_branch_hash(struct ubifs_info *c,
  1514. struct ubifs_branch *br)
  1515. {
  1516. return (void *)br + sizeof(*br) + c->key_len;
  1517. }
  1518. /**
  1519. * ubifs_copy_hash - copy a hash
  1520. * @c: UBIFS file-system description object
  1521. * @from: source hash
  1522. * @to: destination hash
  1523. *
  1524. * With authentication this copies a hash, otherwise does nothing.
  1525. */
  1526. static inline void ubifs_copy_hash(const struct ubifs_info *c, const u8 *from,
  1527. u8 *to)
  1528. {
  1529. if (ubifs_authenticated(c))
  1530. memcpy(to, from, c->hash_len);
  1531. }
  1532. int __ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
  1533. int len, int ofs_hmac);
  1534. static inline int ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
  1535. int len, int ofs_hmac)
  1536. {
  1537. if (ubifs_authenticated(c))
  1538. return __ubifs_node_insert_hmac(c, buf, len, ofs_hmac);
  1539. else
  1540. return 0;
  1541. }
  1542. int __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *buf,
  1543. int len, int ofs_hmac);
  1544. static inline int ubifs_node_verify_hmac(const struct ubifs_info *c,
  1545. const void *buf, int len, int ofs_hmac)
  1546. {
  1547. if (ubifs_authenticated(c))
  1548. return __ubifs_node_verify_hmac(c, buf, len, ofs_hmac);
  1549. else
  1550. return 0;
  1551. }
  1552. /**
  1553. * ubifs_auth_node_sz - returns the size of an authentication node
  1554. * @c: UBIFS file-system description object
  1555. *
  1556. * This function returns the size of an authentication node which can
  1557. * be 0 for unauthenticated filesystems or the real size of an auth node
  1558. * authentication is enabled.
  1559. */
  1560. static inline int ubifs_auth_node_sz(const struct ubifs_info *c)
  1561. {
  1562. if (ubifs_authenticated(c))
  1563. return sizeof(struct ubifs_auth_node) + c->hmac_desc_len;
  1564. else
  1565. return 0;
  1566. }
  1567. int ubifs_sb_verify_signature(struct ubifs_info *c,
  1568. const struct ubifs_sb_node *sup);
  1569. bool ubifs_hmac_zero(struct ubifs_info *c, const u8 *hmac);
  1570. int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac);
  1571. int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
  1572. struct shash_desc *target);
  1573. static inline int ubifs_shash_copy_state(const struct ubifs_info *c,
  1574. struct shash_desc *src,
  1575. struct shash_desc *target)
  1576. {
  1577. if (ubifs_authenticated(c))
  1578. return __ubifs_shash_copy_state(c, src, target);
  1579. else
  1580. return 0;
  1581. }
  1582. /* io.c */
  1583. void ubifs_ro_mode(struct ubifs_info *c, int err);
  1584. int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
  1585. int len, int even_ebadmsg);
  1586. int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
  1587. int len);
  1588. int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
  1589. int ubifs_leb_unmap(struct ubifs_info *c, int lnum);
  1590. int ubifs_leb_map(struct ubifs_info *c, int lnum);
  1591. int ubifs_is_mapped(const struct ubifs_info *c, int lnum);
  1592. int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
  1593. int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs);
  1594. int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
  1595. int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
  1596. int lnum, int offs);
  1597. int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
  1598. int lnum, int offs);
  1599. int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
  1600. int offs);
  1601. int ubifs_write_node_hmac(struct ubifs_info *c, void *buf, int len, int lnum,
  1602. int offs, int hmac_offs);
  1603. int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
  1604. int offs, int quiet, int must_chk_crc);
  1605. void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad);
  1606. void ubifs_crc_node(struct ubifs_info *c, void *buf, int len);
  1607. void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
  1608. int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
  1609. int hmac_offs, int pad);
  1610. void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
  1611. int ubifs_io_init(struct ubifs_info *c);
  1612. void ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
  1613. int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
  1614. int ubifs_bg_wbufs_sync(struct ubifs_info *c);
  1615. void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
  1616. int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
  1617. /* scan.c */
  1618. struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
  1619. int offs, void *sbuf, int quiet);
  1620. void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
  1621. int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
  1622. int offs, int quiet);
  1623. struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
  1624. int offs, void *sbuf);
  1625. void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
  1626. int lnum, int offs);
  1627. int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
  1628. void *buf, int offs);
  1629. void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
  1630. void *buf);
  1631. /* log.c */
  1632. void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
  1633. void ubifs_create_buds_lists(struct ubifs_info *c);
  1634. int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
  1635. struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
  1636. struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
  1637. int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
  1638. int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
  1639. int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
  1640. int ubifs_consolidate_log(struct ubifs_info *c);
  1641. /* journal.c */
  1642. int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
  1643. const struct fscrypt_name *nm, const struct inode *inode,
  1644. int deletion, int xent);
  1645. int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
  1646. const union ubifs_key *key, const void *buf, int len);
  1647. int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
  1648. int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
  1649. int ubifs_jnl_xrename(struct ubifs_info *c, const struct inode *fst_dir,
  1650. const struct inode *fst_inode,
  1651. const struct fscrypt_name *fst_nm,
  1652. const struct inode *snd_dir,
  1653. const struct inode *snd_inode,
  1654. const struct fscrypt_name *snd_nm, int sync);
  1655. int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
  1656. const struct inode *old_inode,
  1657. const struct fscrypt_name *old_nm,
  1658. const struct inode *new_dir,
  1659. const struct inode *new_inode,
  1660. const struct fscrypt_name *new_nm,
  1661. const struct inode *whiteout, int sync);
  1662. int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
  1663. loff_t old_size, loff_t new_size);
  1664. int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
  1665. const struct inode *inode, const struct fscrypt_name *nm);
  1666. int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
  1667. const struct inode *inode2);
  1668. /* budget.c */
  1669. int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
  1670. void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
  1671. void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
  1672. struct ubifs_inode *ui);
  1673. int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
  1674. struct ubifs_budget_req *req);
  1675. void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
  1676. struct ubifs_budget_req *req);
  1677. void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
  1678. struct ubifs_budget_req *req);
  1679. long long ubifs_get_free_space(struct ubifs_info *c);
  1680. long long ubifs_get_free_space_nolock(struct ubifs_info *c);
  1681. int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
  1682. void ubifs_convert_page_budget(struct ubifs_info *c);
  1683. long long ubifs_reported_space(const struct ubifs_info *c, long long free);
  1684. long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
  1685. /* find.c */
  1686. int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
  1687. int squeeze);
  1688. int ubifs_find_free_leb_for_idx(struct ubifs_info *c);
  1689. int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
  1690. int min_space, int pick_free);
  1691. int ubifs_find_dirty_idx_leb(struct ubifs_info *c);
  1692. int ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
  1693. /* tnc.c */
  1694. int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
  1695. struct ubifs_znode **zn, int *n);
  1696. int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
  1697. void *node, const struct fscrypt_name *nm);
  1698. int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key,
  1699. void *node, uint32_t secondary_hash);
  1700. int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
  1701. void *node, int *lnum, int *offs);
  1702. int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
  1703. int offs, int len, const u8 *hash);
  1704. int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
  1705. int old_lnum, int old_offs, int lnum, int offs, int len);
  1706. int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
  1707. int lnum, int offs, int len, const u8 *hash,
  1708. const struct fscrypt_name *nm);
  1709. int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
  1710. int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
  1711. const struct fscrypt_name *nm);
  1712. int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key,
  1713. uint32_t cookie);
  1714. int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
  1715. union ubifs_key *to_key);
  1716. int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
  1717. struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
  1718. union ubifs_key *key,
  1719. const struct fscrypt_name *nm);
  1720. void ubifs_tnc_close(struct ubifs_info *c);
  1721. int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
  1722. int lnum, int offs, int is_idx);
  1723. int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
  1724. int lnum, int offs);
  1725. /* Shared by tnc.c for tnc_commit.c */
  1726. void destroy_old_idx(struct ubifs_info *c);
  1727. int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
  1728. int lnum, int offs);
  1729. int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
  1730. int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
  1731. int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
  1732. /* tnc_misc.c */
  1733. struct ubifs_znode *ubifs_tnc_levelorder_next(const struct ubifs_info *c,
  1734. struct ubifs_znode *zr,
  1735. struct ubifs_znode *znode);
  1736. int ubifs_search_zbranch(const struct ubifs_info *c,
  1737. const struct ubifs_znode *znode,
  1738. const union ubifs_key *key, int *n);
  1739. struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
  1740. struct ubifs_znode *ubifs_tnc_postorder_next(const struct ubifs_info *c,
  1741. struct ubifs_znode *znode);
  1742. long ubifs_destroy_tnc_subtree(const struct ubifs_info *c,
  1743. struct ubifs_znode *zr);
  1744. struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
  1745. struct ubifs_zbranch *zbr,
  1746. struct ubifs_znode *parent, int iip);
  1747. int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
  1748. void *node);
  1749. /* tnc_commit.c */
  1750. int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
  1751. int ubifs_tnc_end_commit(struct ubifs_info *c);
  1752. /* shrinker.c */
  1753. unsigned long ubifs_shrink_scan(struct shrinker *shrink,
  1754. struct shrink_control *sc);
  1755. unsigned long ubifs_shrink_count(struct shrinker *shrink,
  1756. struct shrink_control *sc);
  1757. /* commit.c */
  1758. int ubifs_bg_thread(void *info);
  1759. void ubifs_commit_required(struct ubifs_info *c);
  1760. void ubifs_request_bg_commit(struct ubifs_info *c);
  1761. int ubifs_run_commit(struct ubifs_info *c);
  1762. void ubifs_recovery_commit(struct ubifs_info *c);
  1763. int ubifs_gc_should_commit(struct ubifs_info *c);
  1764. void ubifs_wait_for_commit(struct ubifs_info *c);
  1765. /* master.c */
  1766. int ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2);
  1767. int ubifs_read_master(struct ubifs_info *c);
  1768. int ubifs_write_master(struct ubifs_info *c);
  1769. /* sb.c */
  1770. int ubifs_read_superblock(struct ubifs_info *c);
  1771. int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
  1772. int ubifs_fixup_free_space(struct ubifs_info *c);
  1773. int ubifs_enable_encryption(struct ubifs_info *c);
  1774. /* replay.c */
  1775. int ubifs_validate_entry(struct ubifs_info *c,
  1776. const struct ubifs_dent_node *dent);
  1777. int ubifs_replay_journal(struct ubifs_info *c);
  1778. /* gc.c */
  1779. int ubifs_garbage_collect(struct ubifs_info *c, int anyway);
  1780. int ubifs_gc_start_commit(struct ubifs_info *c);
  1781. int ubifs_gc_end_commit(struct ubifs_info *c);
  1782. void ubifs_destroy_idx_gc(struct ubifs_info *c);
  1783. int ubifs_get_idx_gc_leb(struct ubifs_info *c);
  1784. int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
  1785. /* orphan.c */
  1786. int ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
  1787. void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
  1788. int ubifs_orphan_start_commit(struct ubifs_info *c);
  1789. int ubifs_orphan_end_commit(struct ubifs_info *c);
  1790. int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
  1791. int ubifs_clear_orphans(struct ubifs_info *c);
  1792. /* lpt.c */
  1793. int ubifs_calc_lpt_geom(struct ubifs_info *c);
  1794. int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
  1795. int *lpt_lebs, int *big_lpt, u8 *hash);
  1796. int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
  1797. struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
  1798. struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
  1799. int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
  1800. ubifs_lpt_scan_callback scan_cb, void *data);
  1801. /* Shared by lpt.c for lpt_commit.c */
  1802. void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
  1803. void ubifs_pack_ltab(struct ubifs_info *c, void *buf,
  1804. struct ubifs_lpt_lprops *ltab);
  1805. void ubifs_pack_pnode(struct ubifs_info *c, void *buf,
  1806. struct ubifs_pnode *pnode);
  1807. void ubifs_pack_nnode(struct ubifs_info *c, void *buf,
  1808. struct ubifs_nnode *nnode);
  1809. struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
  1810. struct ubifs_nnode *parent, int iip);
  1811. struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
  1812. struct ubifs_nnode *parent, int iip);
  1813. struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i);
  1814. int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
  1815. void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
  1816. void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
  1817. uint32_t ubifs_unpack_bits(const struct ubifs_info *c, uint8_t **addr, int *pos, int nrbits);
  1818. struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
  1819. /* Needed only in debugging code in lpt_commit.c */
  1820. int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
  1821. struct ubifs_nnode *nnode);
  1822. int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash);
  1823. /* lpt_commit.c */
  1824. int ubifs_lpt_start_commit(struct ubifs_info *c);
  1825. int ubifs_lpt_end_commit(struct ubifs_info *c);
  1826. int ubifs_lpt_post_commit(struct ubifs_info *c);
  1827. void ubifs_lpt_free(struct ubifs_info *c, int wr_only);
  1828. /* lprops.c */
  1829. const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
  1830. const struct ubifs_lprops *lp,
  1831. int free, int dirty, int flags,
  1832. int idx_gc_cnt);
  1833. void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst);
  1834. void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
  1835. int cat);
  1836. void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
  1837. struct ubifs_lprops *new_lprops);
  1838. void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
  1839. int ubifs_categorize_lprops(const struct ubifs_info *c,
  1840. const struct ubifs_lprops *lprops);
  1841. int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
  1842. int flags_set, int flags_clean, int idx_gc_cnt);
  1843. int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
  1844. int flags_set, int flags_clean);
  1845. int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
  1846. const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
  1847. const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
  1848. const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
  1849. const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
  1850. int ubifs_calc_dark(const struct ubifs_info *c, int spc);
  1851. /* file.c */
  1852. int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
  1853. int ubifs_setattr(struct dentry *dentry, struct iattr *attr);
  1854. int ubifs_update_time(struct inode *inode, struct timespec64 *time, int flags);
  1855. /* dir.c */
  1856. struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
  1857. umode_t mode);
  1858. int ubifs_getattr(const struct path *path, struct kstat *stat,
  1859. u32 request_mask, unsigned int flags);
  1860. int ubifs_check_dir_empty(struct inode *dir);
  1861. /* xattr.c */
  1862. extern const struct xattr_handler *ubifs_xattr_handlers[];
  1863. ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  1864. int ubifs_xattr_set(struct inode *host, const char *name, const void *value,
  1865. size_t size, int flags, bool check_lock);
  1866. ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
  1867. size_t size);
  1868. #ifdef CONFIG_UBIFS_FS_XATTR
  1869. void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum);
  1870. int ubifs_purge_xattrs(struct inode *host);
  1871. #else
  1872. static inline void ubifs_evict_xattr_inode(struct ubifs_info *c,
  1873. ino_t xattr_inum) { }
  1874. static inline int ubifs_purge_xattrs(struct inode *host)
  1875. {
  1876. return 0;
  1877. }
  1878. #endif
  1879. #ifdef CONFIG_UBIFS_FS_SECURITY
  1880. extern int ubifs_init_security(struct inode *dentry, struct inode *inode,
  1881. const struct qstr *qstr);
  1882. #else
  1883. static inline int ubifs_init_security(struct inode *dentry,
  1884. struct inode *inode, const struct qstr *qstr)
  1885. {
  1886. return 0;
  1887. }
  1888. #endif
  1889. /* super.c */
  1890. struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
  1891. /* recovery.c */
  1892. int ubifs_recover_master_node(struct ubifs_info *c);
  1893. int ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
  1894. struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
  1895. int offs, void *sbuf, int jhead);
  1896. struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
  1897. int offs, void *sbuf);
  1898. int ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf);
  1899. int ubifs_clean_lebs(struct ubifs_info *c, void *sbuf);
  1900. int ubifs_rcvry_gc_commit(struct ubifs_info *c);
  1901. int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
  1902. int deletion, loff_t new_size);
  1903. int ubifs_recover_size(struct ubifs_info *c, bool in_place);
  1904. void ubifs_destroy_size_tree(struct ubifs_info *c);
  1905. /* ioctl.c */
  1906. long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1907. void ubifs_set_inode_flags(struct inode *inode);
  1908. #ifdef CONFIG_COMPAT
  1909. long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1910. #endif
  1911. /* compressor.c */
  1912. int __init ubifs_compressors_init(void);
  1913. void ubifs_compressors_exit(void);
  1914. void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
  1915. void *out_buf, int *out_len, int *compr_type);
  1916. int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
  1917. void *out, int *out_len, int compr_type);
  1918. #include "debug.h"
  1919. #include "misc.h"
  1920. #include "key.h"
  1921. #ifndef CONFIG_FS_ENCRYPTION
  1922. static inline int ubifs_encrypt(const struct inode *inode,
  1923. struct ubifs_data_node *dn,
  1924. unsigned int in_len, unsigned int *out_len,
  1925. int block)
  1926. {
  1927. struct ubifs_info *c = inode->i_sb->s_fs_info;
  1928. ubifs_assert(c, 0);
  1929. return -EOPNOTSUPP;
  1930. }
  1931. static inline int ubifs_decrypt(const struct inode *inode,
  1932. struct ubifs_data_node *dn,
  1933. unsigned int *out_len, int block)
  1934. {
  1935. struct ubifs_info *c = inode->i_sb->s_fs_info;
  1936. ubifs_assert(c, 0);
  1937. return -EOPNOTSUPP;
  1938. }
  1939. #else
  1940. /* crypto.c */
  1941. int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn,
  1942. unsigned int in_len, unsigned int *out_len, int block);
  1943. int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
  1944. unsigned int *out_len, int block);
  1945. #endif
  1946. extern const struct fscrypt_operations ubifs_crypt_operations;
  1947. /* Normal UBIFS messages */
  1948. __printf(2, 3)
  1949. void ubifs_msg(const struct ubifs_info *c, const char *fmt, ...);
  1950. __printf(2, 3)
  1951. void ubifs_err(const struct ubifs_info *c, const char *fmt, ...);
  1952. __printf(2, 3)
  1953. void ubifs_warn(const struct ubifs_info *c, const char *fmt, ...);
  1954. /*
  1955. * A conditional variant of 'ubifs_err()' which doesn't output anything
  1956. * if probing (ie. SB_SILENT set).
  1957. */
  1958. #define ubifs_errc(c, fmt, ...) \
  1959. do { \
  1960. if (!(c)->probing) \
  1961. ubifs_err(c, fmt, ##__VA_ARGS__); \
  1962. } while (0)
  1963. #endif /* !__UBIFS_H__ */