ubifs.h 72 KB

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