ubifs.h 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * This file is part of UBIFS.
  4. *
  5. * Copyright (C) 2006-2008 Nokia Corporation
  6. *
  7. * (C) Copyright 2008-2009
  8. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  9. *
  10. * Authors: Artem Bityutskiy (Битюцкий Артём)
  11. * Adrian Hunter
  12. */
  13. #ifndef __UBIFS_H__
  14. #define __UBIFS_H__
  15. #ifndef __UBOOT__
  16. #include <asm/div64.h>
  17. #include <linux/statfs.h>
  18. #include <linux/fs.h>
  19. #include <linux/err.h>
  20. #include <linux/sched.h>
  21. #include <linux/slab.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/mutex.h>
  25. #include <linux/rwsem.h>
  26. #include <linux/mtd/ubi.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/backing-dev.h>
  29. #include <linux/security.h>
  30. #include "ubifs-media.h"
  31. #else
  32. #include <asm/atomic.h>
  33. #include <asm-generic/atomic-long.h>
  34. #include <ubi_uboot.h>
  35. #include <ubifs_uboot.h>
  36. #include <linux/ctype.h>
  37. #include <linux/time.h>
  38. #include <linux/math64.h>
  39. #include "ubifs-media.h"
  40. struct dentry;
  41. struct file;
  42. struct iattr;
  43. struct kstat;
  44. struct vfsmount;
  45. extern struct super_block *ubifs_sb;
  46. extern unsigned int ubifs_msg_flags;
  47. extern unsigned int ubifs_chk_flags;
  48. extern unsigned int ubifs_tst_flags;
  49. #define pgoff_t unsigned long
  50. /*
  51. * We "simulate" the Linux page struct much simpler here
  52. */
  53. struct page {
  54. pgoff_t index;
  55. void *addr;
  56. struct inode *inode;
  57. };
  58. void iput(struct inode *inode);
  59. /* linux/include/time.h */
  60. #define NSEC_PER_SEC 1000000000L
  61. #define get_seconds() 0
  62. #define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 })
  63. struct timespec {
  64. time_t tv_sec; /* seconds */
  65. long tv_nsec; /* nanoseconds */
  66. };
  67. static struct timespec current_fs_time(struct super_block *sb)
  68. {
  69. struct timespec now;
  70. now.tv_sec = 0;
  71. now.tv_nsec = 0;
  72. return now;
  73. };
  74. /* linux/include/dcache.h */
  75. /*
  76. * "quick string" -- eases parameter passing, but more importantly
  77. * saves "metadata" about the string (ie length and the hash).
  78. *
  79. * hash comes first so it snuggles against d_parent in the
  80. * dentry.
  81. */
  82. struct qstr {
  83. unsigned int hash;
  84. unsigned int len;
  85. #ifndef __UBOOT__
  86. const char *name;
  87. #else
  88. char *name;
  89. #endif
  90. };
  91. /* include/linux/fs.h */
  92. /* Possible states of 'frozen' field */
  93. enum {
  94. SB_UNFROZEN = 0, /* FS is unfrozen */
  95. SB_FREEZE_WRITE = 1, /* Writes, dir ops, ioctls frozen */
  96. SB_FREEZE_PAGEFAULT = 2, /* Page faults stopped as well */
  97. SB_FREEZE_FS = 3, /* For internal FS use (e.g. to stop
  98. * internal threads if needed) */
  99. SB_FREEZE_COMPLETE = 4, /* ->freeze_fs finished successfully */
  100. };
  101. #define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1)
  102. struct sb_writers {
  103. #ifndef __UBOOT__
  104. /* Counters for counting writers at each level */
  105. struct percpu_counter counter[SB_FREEZE_LEVELS];
  106. #endif
  107. wait_queue_head_t wait; /* queue for waiting for
  108. writers / faults to finish */
  109. int frozen; /* Is sb frozen? */
  110. wait_queue_head_t wait_unfrozen; /* queue for waiting for
  111. sb to be thawed */
  112. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  113. struct lockdep_map lock_map[SB_FREEZE_LEVELS];
  114. #endif
  115. };
  116. struct address_space {
  117. struct inode *host; /* owner: inode, block_device */
  118. #ifndef __UBOOT__
  119. struct radix_tree_root page_tree; /* radix tree of all pages */
  120. #endif
  121. spinlock_t tree_lock; /* and lock protecting it */
  122. unsigned int i_mmap_writable;/* count VM_SHARED mappings */
  123. struct rb_root i_mmap; /* tree of private and shared mappings */
  124. struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
  125. struct mutex i_mmap_mutex; /* protect tree, count, list */
  126. /* Protected by tree_lock together with the radix tree */
  127. unsigned long nrpages; /* number of total pages */
  128. pgoff_t writeback_index;/* writeback starts here */
  129. const struct address_space_operations *a_ops; /* methods */
  130. unsigned long flags; /* error bits/gfp mask */
  131. #ifndef __UBOOT__
  132. struct backing_dev_info *backing_dev_info; /* device readahead, etc */
  133. #endif
  134. spinlock_t private_lock; /* for use by the address_space */
  135. struct list_head private_list; /* ditto */
  136. void *private_data; /* ditto */
  137. } __attribute__((aligned(sizeof(long))));
  138. /*
  139. * Keep mostly read-only and often accessed (especially for
  140. * the RCU path lookup and 'stat' data) fields at the beginning
  141. * of the 'struct inode'
  142. */
  143. struct inode {
  144. umode_t i_mode;
  145. unsigned short i_opflags;
  146. kuid_t i_uid;
  147. kgid_t i_gid;
  148. unsigned int i_flags;
  149. #ifdef CONFIG_FS_POSIX_ACL
  150. struct posix_acl *i_acl;
  151. struct posix_acl *i_default_acl;
  152. #endif
  153. const struct inode_operations *i_op;
  154. struct super_block *i_sb;
  155. struct address_space *i_mapping;
  156. #ifdef CONFIG_SECURITY
  157. void *i_security;
  158. #endif
  159. /* Stat data, not accessed from path walking */
  160. unsigned long i_ino;
  161. /*
  162. * Filesystems may only read i_nlink directly. They shall use the
  163. * following functions for modification:
  164. *
  165. * (set|clear|inc|drop)_nlink
  166. * inode_(inc|dec)_link_count
  167. */
  168. union {
  169. const unsigned int i_nlink;
  170. unsigned int __i_nlink;
  171. };
  172. dev_t i_rdev;
  173. loff_t i_size;
  174. struct timespec i_atime;
  175. struct timespec i_mtime;
  176. struct timespec i_ctime;
  177. spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
  178. unsigned short i_bytes;
  179. unsigned int i_blkbits;
  180. blkcnt_t i_blocks;
  181. #ifdef __NEED_I_SIZE_ORDERED
  182. seqcount_t i_size_seqcount;
  183. #endif
  184. /* Misc */
  185. unsigned long i_state;
  186. struct mutex i_mutex;
  187. unsigned long dirtied_when; /* jiffies of first dirtying */
  188. struct hlist_node i_hash;
  189. struct list_head i_wb_list; /* backing dev IO list */
  190. struct list_head i_lru; /* inode LRU list */
  191. struct list_head i_sb_list;
  192. union {
  193. struct hlist_head i_dentry;
  194. struct rcu_head i_rcu;
  195. };
  196. u64 i_version;
  197. atomic_t i_count;
  198. atomic_t i_dio_count;
  199. atomic_t i_writecount;
  200. const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
  201. struct file_lock *i_flock;
  202. struct address_space i_data;
  203. #ifdef CONFIG_QUOTA
  204. struct dquot *i_dquot[MAXQUOTAS];
  205. #endif
  206. struct list_head i_devices;
  207. union {
  208. struct pipe_inode_info *i_pipe;
  209. struct block_device *i_bdev;
  210. struct cdev *i_cdev;
  211. };
  212. __u32 i_generation;
  213. #ifdef CONFIG_FSNOTIFY
  214. __u32 i_fsnotify_mask; /* all events this inode cares about */
  215. struct hlist_head i_fsnotify_marks;
  216. #endif
  217. #ifdef CONFIG_IMA
  218. atomic_t i_readcount; /* struct files open RO */
  219. #endif
  220. void *i_private; /* fs or device private pointer */
  221. };
  222. struct super_operations {
  223. struct inode *(*alloc_inode)(struct super_block *sb);
  224. void (*destroy_inode)(struct inode *);
  225. void (*dirty_inode) (struct inode *, int flags);
  226. int (*write_inode) (struct inode *, struct writeback_control *wbc);
  227. int (*drop_inode) (struct inode *);
  228. void (*evict_inode) (struct inode *);
  229. void (*put_super) (struct super_block *);
  230. int (*sync_fs)(struct super_block *sb, int wait);
  231. int (*freeze_fs) (struct super_block *);
  232. int (*unfreeze_fs) (struct super_block *);
  233. #ifndef __UBOOT__
  234. int (*statfs) (struct dentry *, struct kstatfs *);
  235. #endif
  236. int (*remount_fs) (struct super_block *, int *, char *);
  237. void (*umount_begin) (struct super_block *);
  238. #ifndef __UBOOT__
  239. int (*show_options)(struct seq_file *, struct dentry *);
  240. int (*show_devname)(struct seq_file *, struct dentry *);
  241. int (*show_path)(struct seq_file *, struct dentry *);
  242. int (*show_stats)(struct seq_file *, struct dentry *);
  243. #endif
  244. #ifdef CONFIG_QUOTA
  245. ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
  246. ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
  247. #endif
  248. int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
  249. long (*nr_cached_objects)(struct super_block *, int);
  250. long (*free_cached_objects)(struct super_block *, long, int);
  251. };
  252. struct super_block {
  253. struct list_head s_list; /* Keep this first */
  254. dev_t s_dev; /* search index; _not_ kdev_t */
  255. unsigned char s_blocksize_bits;
  256. unsigned long s_blocksize;
  257. loff_t s_maxbytes; /* Max file size */
  258. struct file_system_type *s_type;
  259. const struct super_operations *s_op;
  260. const struct dquot_operations *dq_op;
  261. const struct quotactl_ops *s_qcop;
  262. const struct export_operations *s_export_op;
  263. unsigned long s_flags;
  264. unsigned long s_magic;
  265. struct dentry *s_root;
  266. struct rw_semaphore s_umount;
  267. int s_count;
  268. atomic_t s_active;
  269. #ifdef CONFIG_SECURITY
  270. void *s_security;
  271. #endif
  272. const struct xattr_handler **s_xattr;
  273. struct list_head s_inodes; /* all inodes */
  274. #ifndef __UBOOT__
  275. struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */
  276. #endif
  277. struct list_head s_mounts; /* list of mounts; _not_ for fs use */
  278. struct block_device *s_bdev;
  279. #ifndef __UBOOT__
  280. struct backing_dev_info *s_bdi;
  281. #endif
  282. struct mtd_info *s_mtd;
  283. #ifndef __UBOOT__
  284. struct hlist_node s_instances;
  285. struct quota_info s_dquot; /* Diskquota specific options */
  286. #endif
  287. struct sb_writers s_writers;
  288. char s_id[32]; /* Informational name */
  289. u8 s_uuid[16]; /* UUID */
  290. void *s_fs_info; /* Filesystem private info */
  291. unsigned int s_max_links;
  292. #ifndef __UBOOT__
  293. fmode_t s_mode;
  294. #endif
  295. /* Granularity of c/m/atime in ns.
  296. Cannot be worse than a second */
  297. u32 s_time_gran;
  298. /*
  299. * The next field is for VFS *only*. No filesystems have any business
  300. * even looking at it. You had been warned.
  301. */
  302. struct mutex s_vfs_rename_mutex; /* Kludge */
  303. /*
  304. * Filesystem subtype. If non-empty the filesystem type field
  305. * in /proc/mounts will be "type.subtype"
  306. */
  307. char *s_subtype;
  308. #ifndef __UBOOT__
  309. /*
  310. * Saved mount options for lazy filesystems using
  311. * generic_show_options()
  312. */
  313. char __rcu *s_options;
  314. #endif
  315. const struct dentry_operations *s_d_op; /* default d_op for dentries */
  316. /*
  317. * Saved pool identifier for cleancache (-1 means none)
  318. */
  319. int cleancache_poolid;
  320. #ifndef __UBOOT__
  321. struct shrinker s_shrink; /* per-sb shrinker handle */
  322. #endif
  323. /* Number of inodes with nlink == 0 but still referenced */
  324. atomic_long_t s_remove_count;
  325. /* Being remounted read-only */
  326. int s_readonly_remount;
  327. /* AIO completions deferred from interrupt context */
  328. struct workqueue_struct *s_dio_done_wq;
  329. #ifndef __UBOOT__
  330. /*
  331. * Keep the lru lists last in the structure so they always sit on their
  332. * own individual cachelines.
  333. */
  334. struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
  335. struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
  336. #endif
  337. struct rcu_head rcu;
  338. };
  339. struct file_system_type {
  340. const char *name;
  341. int fs_flags;
  342. #define FS_REQUIRES_DEV 1
  343. #define FS_BINARY_MOUNTDATA 2
  344. #define FS_HAS_SUBTYPE 4
  345. #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
  346. #define FS_USERNS_DEV_MOUNT 16 /* A userns mount does not imply MNT_NODEV */
  347. #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
  348. struct dentry *(*mount) (struct file_system_type *, int,
  349. const char *, void *);
  350. void (*kill_sb) (struct super_block *);
  351. struct module *owner;
  352. struct file_system_type * next;
  353. struct hlist_head fs_supers;
  354. #ifndef __UBOOT__
  355. struct lock_class_key s_lock_key;
  356. struct lock_class_key s_umount_key;
  357. struct lock_class_key s_vfs_rename_key;
  358. struct lock_class_key s_writers_key[SB_FREEZE_LEVELS];
  359. struct lock_class_key i_lock_key;
  360. struct lock_class_key i_mutex_key;
  361. struct lock_class_key i_mutex_dir_key;
  362. #endif
  363. };
  364. /* include/linux/mount.h */
  365. struct vfsmount {
  366. struct dentry *mnt_root; /* root of the mounted tree */
  367. struct super_block *mnt_sb; /* pointer to superblock */
  368. int mnt_flags;
  369. };
  370. struct path {
  371. struct vfsmount *mnt;
  372. struct dentry *dentry;
  373. };
  374. struct file {
  375. struct path f_path;
  376. #define f_dentry f_path.dentry
  377. #define f_vfsmnt f_path.mnt
  378. const struct file_operations *f_op;
  379. unsigned int f_flags;
  380. loff_t f_pos;
  381. unsigned int f_uid, f_gid;
  382. u64 f_version;
  383. #ifdef CONFIG_SECURITY
  384. void *f_security;
  385. #endif
  386. /* needed for tty driver, and maybe others */
  387. void *private_data;
  388. #ifdef CONFIG_EPOLL
  389. /* Used by fs/eventpoll.c to link all the hooks to this file */
  390. struct list_head f_ep_links;
  391. spinlock_t f_ep_lock;
  392. #endif /* #ifdef CONFIG_EPOLL */
  393. #ifdef CONFIG_DEBUG_WRITECOUNT
  394. unsigned long f_mnt_write_state;
  395. #endif
  396. };
  397. /*
  398. * get_seconds() not really needed in the read-only implmentation
  399. */
  400. #define get_seconds() 0
  401. /* 4k page size */
  402. #define PAGE_CACHE_SHIFT 12
  403. #define PAGE_CACHE_SIZE (1 << PAGE_CACHE_SHIFT)
  404. /* Page cache limit. The filesystems should put that into their s_maxbytes
  405. limits, otherwise bad things can happen in VM. */
  406. #if BITS_PER_LONG==32
  407. #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  408. #elif BITS_PER_LONG==64
  409. #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL
  410. #endif
  411. /*
  412. * These are the fs-independent mount-flags: up to 32 flags are supported
  413. */
  414. #define MS_RDONLY 1 /* Mount read-only */
  415. #define MS_NOSUID 2 /* Ignore suid and sgid bits */
  416. #define MS_NODEV 4 /* Disallow access to device special files */
  417. #define MS_NOEXEC 8 /* Disallow program execution */
  418. #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
  419. #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
  420. #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
  421. #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
  422. #define MS_NOATIME 1024 /* Do not update access times. */
  423. #define MS_NODIRATIME 2048 /* Do not update directory access times */
  424. #define MS_BIND 4096
  425. #define MS_MOVE 8192
  426. #define MS_REC 16384
  427. #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence.
  428. MS_VERBOSE is deprecated. */
  429. #define MS_SILENT 32768
  430. #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
  431. #define MS_UNBINDABLE (1<<17) /* change to unbindable */
  432. #define MS_PRIVATE (1<<18) /* change to private */
  433. #define MS_SLAVE (1<<19) /* change to slave */
  434. #define MS_SHARED (1<<20) /* change to shared */
  435. #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */
  436. #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
  437. #define MS_I_VERSION (1<<23) /* Update inode I_version field */
  438. #define MS_ACTIVE (1<<30)
  439. #define MS_NOUSER (1<<31)
  440. #define I_NEW 8
  441. /* Inode flags - they have nothing to superblock flags now */
  442. #define S_SYNC 1 /* Writes are synced at once */
  443. #define S_NOATIME 2 /* Do not update access times */
  444. #define S_APPEND 4 /* Append-only file */
  445. #define S_IMMUTABLE 8 /* Immutable file */
  446. #define S_DEAD 16 /* removed, but still open directory */
  447. #define S_NOQUOTA 32 /* Inode is not counted to quota */
  448. #define S_DIRSYNC 64 /* Directory modifications are synchronous */
  449. #define S_NOCMTIME 128 /* Do not update file c/mtime */
  450. #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */
  451. #define S_PRIVATE 512 /* Inode is fs-internal */
  452. /* include/linux/stat.h */
  453. #define S_IFMT 00170000
  454. #define S_IFSOCK 0140000
  455. #define S_IFLNK 0120000
  456. #define S_IFREG 0100000
  457. #define S_IFBLK 0060000
  458. #define S_IFDIR 0040000
  459. #define S_IFCHR 0020000
  460. #define S_IFIFO 0010000
  461. #define S_ISUID 0004000
  462. #define S_ISGID 0002000
  463. #define S_ISVTX 0001000
  464. /* include/linux/fs.h */
  465. /*
  466. * File types
  467. *
  468. * NOTE! These match bits 12..15 of stat.st_mode
  469. * (ie "(i_mode >> 12) & 15").
  470. */
  471. #define DT_UNKNOWN 0
  472. #define DT_FIFO 1
  473. #define DT_CHR 2
  474. #define DT_DIR 4
  475. #define DT_BLK 6
  476. #define DT_REG 8
  477. #define DT_LNK 10
  478. #define DT_SOCK 12
  479. #define DT_WHT 14
  480. #define I_DIRTY_SYNC 1
  481. #define I_DIRTY_DATASYNC 2
  482. #define I_DIRTY_PAGES 4
  483. #define I_NEW 8
  484. #define I_WILL_FREE 16
  485. #define I_FREEING 32
  486. #define I_CLEAR 64
  487. #define __I_LOCK 7
  488. #define I_LOCK (1 << __I_LOCK)
  489. #define __I_SYNC 8
  490. #define I_SYNC (1 << __I_SYNC)
  491. #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
  492. /* linux/include/dcache.h */
  493. #define DNAME_INLINE_LEN_MIN 36
  494. struct dentry {
  495. unsigned int d_flags; /* protected by d_lock */
  496. spinlock_t d_lock; /* per dentry lock */
  497. struct inode *d_inode; /* Where the name belongs to - NULL is
  498. * negative */
  499. /*
  500. * The next three fields are touched by __d_lookup. Place them here
  501. * so they all fit in a cache line.
  502. */
  503. struct hlist_node d_hash; /* lookup hash list */
  504. struct dentry *d_parent; /* parent directory */
  505. struct qstr d_name;
  506. struct list_head d_lru; /* LRU list */
  507. /*
  508. * d_child and d_rcu can share memory
  509. */
  510. struct list_head d_subdirs; /* our children */
  511. struct list_head d_alias; /* inode alias list */
  512. unsigned long d_time; /* used by d_revalidate */
  513. struct super_block *d_sb; /* The root of the dentry tree */
  514. void *d_fsdata; /* fs-specific data */
  515. #ifdef CONFIG_PROFILING
  516. struct dcookie_struct *d_cookie; /* cookie, if any */
  517. #endif
  518. int d_mounted;
  519. unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
  520. };
  521. static inline ino_t parent_ino(struct dentry *dentry)
  522. {
  523. ino_t res;
  524. spin_lock(&dentry->d_lock);
  525. res = dentry->d_parent->d_inode->i_ino;
  526. spin_unlock(&dentry->d_lock);
  527. return res;
  528. }
  529. /* debug.c */
  530. #define module_param_named(...)
  531. /* misc.h */
  532. #define mutex_lock_nested(...)
  533. #define mutex_unlock_nested(...)
  534. #define mutex_is_locked(...) 1
  535. #endif
  536. /* Version of this UBIFS implementation */
  537. #define UBIFS_VERSION 1
  538. /* Normal UBIFS messages */
  539. #ifdef CONFIG_UBIFS_SILENCE_MSG
  540. #define ubifs_msg(c, fmt, ...)
  541. #else
  542. #define ubifs_msg(c, fmt, ...) \
  543. pr_notice("UBIFS (ubi%d:%d): " fmt "\n", \
  544. (c)->vi.ubi_num, (c)->vi.vol_id, ##__VA_ARGS__)
  545. #endif
  546. /* UBIFS error messages */
  547. #ifndef __UBOOT__
  548. #define ubifs_err(c, fmt, ...) \
  549. pr_err("UBIFS error (ubi%d:%d pid %d): %s: " fmt "\n", \
  550. (c)->vi.ubi_num, (c)->vi.vol_id, current->pid, \
  551. __func__, ##__VA_ARGS__)
  552. /* UBIFS warning messages */
  553. #define ubifs_warn(c, fmt, ...) \
  554. pr_warn("UBIFS warning (ubi%d:%d pid %d): %s: " fmt "\n", \
  555. (c)->vi.ubi_num, (c)->vi.vol_id, current->pid, \
  556. __func__, ##__VA_ARGS__)
  557. #else
  558. #define ubifs_err(c, fmt, ...) \
  559. pr_err("UBIFS error (ubi%d:%d pid %d): %s: " fmt "\n", \
  560. (c)->vi.ubi_num, (c)->vi.vol_id, 0, \
  561. __func__, ##__VA_ARGS__)
  562. /* UBIFS warning messages */
  563. #define ubifs_warn(c, fmt, ...) \
  564. pr_warn("UBIFS warning (ubi%d:%d pid %d): %s: " fmt "\n", \
  565. (c)->vi.ubi_num, (c)->vi.vol_id, 0, \
  566. __func__, ##__VA_ARGS__)
  567. #endif
  568. /*
  569. * A variant of 'ubifs_err()' which takes the UBIFS file-sytem description
  570. * object as an argument.
  571. */
  572. #define ubifs_errc(c, fmt, ...) \
  573. do { \
  574. if (!(c)->probing) \
  575. ubifs_err(c, fmt, ##__VA_ARGS__); \
  576. } while (0)
  577. /* UBIFS file system VFS magic number */
  578. #define UBIFS_SUPER_MAGIC 0x24051905
  579. /* Number of UBIFS blocks per VFS page */
  580. #define UBIFS_BLOCKS_PER_PAGE (PAGE_CACHE_SIZE / UBIFS_BLOCK_SIZE)
  581. #define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_CACHE_SHIFT - UBIFS_BLOCK_SHIFT)
  582. /* "File system end of life" sequence number watermark */
  583. #define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL
  584. #define SQNUM_WATERMARK 0xFFFFFFFFFF000000ULL
  585. /*
  586. * Minimum amount of LEBs reserved for the index. At present the index needs at
  587. * least 2 LEBs: one for the index head and one for in-the-gaps method (which
  588. * currently does not cater for the index head and so excludes it from
  589. * consideration).
  590. */
  591. #define MIN_INDEX_LEBS 2
  592. /* Minimum amount of data UBIFS writes to the flash */
  593. #define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8)
  594. /*
  595. * Currently we do not support inode number overlapping and re-using, so this
  596. * watermark defines dangerous inode number level. This should be fixed later,
  597. * although it is difficult to exceed current limit. Another option is to use
  598. * 64-bit inode numbers, but this means more overhead.
  599. */
  600. #define INUM_WARN_WATERMARK 0xFFF00000
  601. #define INUM_WATERMARK 0xFFFFFF00
  602. /* Maximum number of entries in each LPT (LEB category) heap */
  603. #define LPT_HEAP_SZ 256
  604. /*
  605. * Background thread name pattern. The numbers are UBI device and volume
  606. * numbers.
  607. */
  608. #define BGT_NAME_PATTERN "ubifs_bgt%d_%d"
  609. /* Write-buffer synchronization timeout interval in seconds */
  610. #define WBUF_TIMEOUT_SOFTLIMIT 3
  611. #define WBUF_TIMEOUT_HARDLIMIT 5
  612. /* Maximum possible inode number (only 32-bit inodes are supported now) */
  613. #define MAX_INUM 0xFFFFFFFF
  614. /* Number of non-data journal heads */
  615. #define NONDATA_JHEADS_CNT 2
  616. /* Shorter names for journal head numbers for internal usage */
  617. #define GCHD UBIFS_GC_HEAD
  618. #define BASEHD UBIFS_BASE_HEAD
  619. #define DATAHD UBIFS_DATA_HEAD
  620. /* 'No change' value for 'ubifs_change_lp()' */
  621. #define LPROPS_NC 0x80000001
  622. /*
  623. * There is no notion of truncation key because truncation nodes do not exist
  624. * in TNC. However, when replaying, it is handy to introduce fake "truncation"
  625. * keys for truncation nodes because the code becomes simpler. So we define
  626. * %UBIFS_TRUN_KEY type.
  627. *
  628. * But otherwise, out of the journal reply scope, the truncation keys are
  629. * invalid.
  630. */
  631. #define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT
  632. #define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT
  633. /*
  634. * How much a directory entry/extended attribute entry adds to the parent/host
  635. * inode.
  636. */
  637. #define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8)
  638. /* How much an extended attribute adds to the host inode */
  639. #define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8)
  640. /*
  641. * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered
  642. * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are
  643. * considered "young". This is used by shrinker when selecting znode to trim
  644. * off.
  645. */
  646. #define OLD_ZNODE_AGE 20
  647. #define YOUNG_ZNODE_AGE 5
  648. /*
  649. * Some compressors, like LZO, may end up with more data then the input buffer.
  650. * So UBIFS always allocates larger output buffer, to be sure the compressor
  651. * will not corrupt memory in case of worst case compression.
  652. */
  653. #define WORST_COMPR_FACTOR 2
  654. /*
  655. * How much memory is needed for a buffer where we compress a data node.
  656. */
  657. #define COMPRESSED_DATA_NODE_BUF_SZ \
  658. (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR)
  659. /* Maximum expected tree height for use by bottom_up_buf */
  660. #define BOTTOM_UP_HEIGHT 64
  661. /* Maximum number of data nodes to bulk-read */
  662. #define UBIFS_MAX_BULK_READ 32
  663. /*
  664. * Lockdep classes for UBIFS inode @ui_mutex.
  665. */
  666. enum {
  667. WB_MUTEX_1 = 0,
  668. WB_MUTEX_2 = 1,
  669. WB_MUTEX_3 = 2,
  670. };
  671. /*
  672. * Znode flags (actually, bit numbers which store the flags).
  673. *
  674. * DIRTY_ZNODE: znode is dirty
  675. * COW_ZNODE: znode is being committed and a new instance of this znode has to
  676. * be created before changing this znode
  677. * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is
  678. * still in the commit list and the ongoing commit operation
  679. * will commit it, and delete this znode after it is done
  680. */
  681. enum {
  682. DIRTY_ZNODE = 0,
  683. COW_ZNODE = 1,
  684. OBSOLETE_ZNODE = 2,
  685. };
  686. /*
  687. * Commit states.
  688. *
  689. * COMMIT_RESTING: commit is not wanted
  690. * COMMIT_BACKGROUND: background commit has been requested
  691. * COMMIT_REQUIRED: commit is required
  692. * COMMIT_RUNNING_BACKGROUND: background commit is running
  693. * COMMIT_RUNNING_REQUIRED: commit is running and it is required
  694. * COMMIT_BROKEN: commit failed
  695. */
  696. enum {
  697. COMMIT_RESTING = 0,
  698. COMMIT_BACKGROUND,
  699. COMMIT_REQUIRED,
  700. COMMIT_RUNNING_BACKGROUND,
  701. COMMIT_RUNNING_REQUIRED,
  702. COMMIT_BROKEN,
  703. };
  704. /*
  705. * 'ubifs_scan_a_node()' return values.
  706. *
  707. * SCANNED_GARBAGE: scanned garbage
  708. * SCANNED_EMPTY_SPACE: scanned empty space
  709. * SCANNED_A_NODE: scanned a valid node
  710. * SCANNED_A_CORRUPT_NODE: scanned a corrupted node
  711. * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length
  712. *
  713. * Greater than zero means: 'scanned that number of padding bytes'
  714. */
  715. enum {
  716. SCANNED_GARBAGE = 0,
  717. SCANNED_EMPTY_SPACE = -1,
  718. SCANNED_A_NODE = -2,
  719. SCANNED_A_CORRUPT_NODE = -3,
  720. SCANNED_A_BAD_PAD_NODE = -4,
  721. };
  722. /*
  723. * LPT cnode flag bits.
  724. *
  725. * DIRTY_CNODE: cnode is dirty
  726. * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted),
  727. * so it can (and must) be freed when the commit is finished
  728. * COW_CNODE: cnode is being committed and must be copied before writing
  729. */
  730. enum {
  731. DIRTY_CNODE = 0,
  732. OBSOLETE_CNODE = 1,
  733. COW_CNODE = 2,
  734. };
  735. /*
  736. * Dirty flag bits (lpt_drty_flgs) for LPT special nodes.
  737. *
  738. * LTAB_DIRTY: ltab node is dirty
  739. * LSAVE_DIRTY: lsave node is dirty
  740. */
  741. enum {
  742. LTAB_DIRTY = 1,
  743. LSAVE_DIRTY = 2,
  744. };
  745. /*
  746. * Return codes used by the garbage collector.
  747. * @LEB_FREED: the logical eraseblock was freed and is ready to use
  748. * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit
  749. * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes
  750. */
  751. enum {
  752. LEB_FREED,
  753. LEB_FREED_IDX,
  754. LEB_RETAINED,
  755. };
  756. /**
  757. * struct ubifs_old_idx - index node obsoleted since last commit start.
  758. * @rb: rb-tree node
  759. * @lnum: LEB number of obsoleted index node
  760. * @offs: offset of obsoleted index node
  761. */
  762. struct ubifs_old_idx {
  763. struct rb_node rb;
  764. int lnum;
  765. int offs;
  766. };
  767. /* The below union makes it easier to deal with keys */
  768. union ubifs_key {
  769. uint8_t u8[UBIFS_SK_LEN];
  770. uint32_t u32[UBIFS_SK_LEN/4];
  771. uint64_t u64[UBIFS_SK_LEN/8];
  772. __le32 j32[UBIFS_SK_LEN/4];
  773. };
  774. /**
  775. * struct ubifs_scan_node - UBIFS scanned node information.
  776. * @list: list of scanned nodes
  777. * @key: key of node scanned (if it has one)
  778. * @sqnum: sequence number
  779. * @type: type of node scanned
  780. * @offs: offset with LEB of node scanned
  781. * @len: length of node scanned
  782. * @node: raw node
  783. */
  784. struct ubifs_scan_node {
  785. struct list_head list;
  786. union ubifs_key key;
  787. unsigned long long sqnum;
  788. int type;
  789. int offs;
  790. int len;
  791. void *node;
  792. };
  793. /**
  794. * struct ubifs_scan_leb - UBIFS scanned LEB information.
  795. * @lnum: logical eraseblock number
  796. * @nodes_cnt: number of nodes scanned
  797. * @nodes: list of struct ubifs_scan_node
  798. * @endpt: end point (and therefore the start of empty space)
  799. * @buf: buffer containing entire LEB scanned
  800. */
  801. struct ubifs_scan_leb {
  802. int lnum;
  803. int nodes_cnt;
  804. struct list_head nodes;
  805. int endpt;
  806. void *buf;
  807. };
  808. /**
  809. * struct ubifs_gced_idx_leb - garbage-collected indexing LEB.
  810. * @list: list
  811. * @lnum: LEB number
  812. * @unmap: OK to unmap this LEB
  813. *
  814. * This data structure is used to temporary store garbage-collected indexing
  815. * LEBs - they are not released immediately, but only after the next commit.
  816. * This is needed to guarantee recoverability.
  817. */
  818. struct ubifs_gced_idx_leb {
  819. struct list_head list;
  820. int lnum;
  821. int unmap;
  822. };
  823. /**
  824. * struct ubifs_inode - UBIFS in-memory inode description.
  825. * @vfs_inode: VFS inode description object
  826. * @creat_sqnum: sequence number at time of creation
  827. * @del_cmtno: commit number corresponding to the time the inode was deleted,
  828. * protected by @c->commit_sem;
  829. * @xattr_size: summarized size of all extended attributes in bytes
  830. * @xattr_cnt: count of extended attributes this inode has
  831. * @xattr_names: sum of lengths of all extended attribute names belonging to
  832. * this inode
  833. * @dirty: non-zero if the inode is dirty
  834. * @xattr: non-zero if this is an extended attribute inode
  835. * @bulk_read: non-zero if bulk-read should be used
  836. * @ui_mutex: serializes inode write-back with the rest of VFS operations,
  837. * serializes "clean <-> dirty" state changes, serializes bulk-read,
  838. * protects @dirty, @bulk_read, @ui_size, and @xattr_size
  839. * @ui_lock: protects @synced_i_size
  840. * @synced_i_size: synchronized size of inode, i.e. the value of inode size
  841. * currently stored on the flash; used only for regular file
  842. * inodes
  843. * @ui_size: inode size used by UBIFS when writing to flash
  844. * @flags: inode flags (@UBIFS_COMPR_FL, etc)
  845. * @compr_type: default compression type used for this inode
  846. * @last_page_read: page number of last page read (for bulk read)
  847. * @read_in_a_row: number of consecutive pages read in a row (for bulk read)
  848. * @data_len: length of the data attached to the inode
  849. * @data: inode's data
  850. *
  851. * @ui_mutex exists for two main reasons. At first it prevents inodes from
  852. * being written back while UBIFS changing them, being in the middle of an VFS
  853. * operation. This way UBIFS makes sure the inode fields are consistent. For
  854. * example, in 'ubifs_rename()' we change 3 inodes simultaneously, and
  855. * write-back must not write any of them before we have finished.
  856. *
  857. * The second reason is budgeting - UBIFS has to budget all operations. If an
  858. * operation is going to mark an inode dirty, it has to allocate budget for
  859. * this. It cannot just mark it dirty because there is no guarantee there will
  860. * be enough flash space to write the inode back later. This means UBIFS has
  861. * to have full control over inode "clean <-> dirty" transitions (and pages
  862. * actually). But unfortunately, VFS marks inodes dirty in many places, and it
  863. * does not ask the file-system if it is allowed to do so (there is a notifier,
  864. * but it is not enough), i.e., there is no mechanism to synchronize with this.
  865. * So UBIFS has its own inode dirty flag and its own mutex to serialize
  866. * "clean <-> dirty" transitions.
  867. *
  868. * The @synced_i_size field is used to make sure we never write pages which are
  869. * beyond last synchronized inode size. See 'ubifs_writepage()' for more
  870. * information.
  871. *
  872. * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses
  873. * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot
  874. * make sure @inode->i_size is always changed under @ui_mutex, because it
  875. * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
  876. * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
  877. * are changed under @ui_mutex, so they do not need "shadow" fields. Note, one
  878. * could consider to rework locking and base it on "shadow" fields.
  879. */
  880. struct ubifs_inode {
  881. struct inode vfs_inode;
  882. unsigned long long creat_sqnum;
  883. unsigned long long del_cmtno;
  884. unsigned int xattr_size;
  885. unsigned int xattr_cnt;
  886. unsigned int xattr_names;
  887. unsigned int dirty:1;
  888. unsigned int xattr:1;
  889. unsigned int bulk_read:1;
  890. unsigned int compr_type:2;
  891. struct mutex ui_mutex;
  892. spinlock_t ui_lock;
  893. loff_t synced_i_size;
  894. loff_t ui_size;
  895. int flags;
  896. pgoff_t last_page_read;
  897. pgoff_t read_in_a_row;
  898. int data_len;
  899. void *data;
  900. };
  901. /**
  902. * struct ubifs_unclean_leb - records a LEB recovered under read-only mode.
  903. * @list: list
  904. * @lnum: LEB number of recovered LEB
  905. * @endpt: offset where recovery ended
  906. *
  907. * This structure records a LEB identified during recovery that needs to be
  908. * cleaned but was not because UBIFS was mounted read-only. The information
  909. * is used to clean the LEB when remounting to read-write mode.
  910. */
  911. struct ubifs_unclean_leb {
  912. struct list_head list;
  913. int lnum;
  914. int endpt;
  915. };
  916. /*
  917. * LEB properties flags.
  918. *
  919. * LPROPS_UNCAT: not categorized
  920. * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index
  921. * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index
  922. * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index
  923. * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs
  924. * LPROPS_EMPTY: LEB is empty, not taken
  925. * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken
  926. * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken
  927. * LPROPS_CAT_MASK: mask for the LEB categories above
  928. * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media)
  929. * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash)
  930. */
  931. enum {
  932. LPROPS_UNCAT = 0,
  933. LPROPS_DIRTY = 1,
  934. LPROPS_DIRTY_IDX = 2,
  935. LPROPS_FREE = 3,
  936. LPROPS_HEAP_CNT = 3,
  937. LPROPS_EMPTY = 4,
  938. LPROPS_FREEABLE = 5,
  939. LPROPS_FRDI_IDX = 6,
  940. LPROPS_CAT_MASK = 15,
  941. LPROPS_TAKEN = 16,
  942. LPROPS_INDEX = 32,
  943. };
  944. /**
  945. * struct ubifs_lprops - logical eraseblock properties.
  946. * @free: amount of free space in bytes
  947. * @dirty: amount of dirty space in bytes
  948. * @flags: LEB properties flags (see above)
  949. * @lnum: LEB number
  950. * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE)
  951. * @hpos: heap position in heap of same-category lprops (other categories)
  952. */
  953. struct ubifs_lprops {
  954. int free;
  955. int dirty;
  956. int flags;
  957. int lnum;
  958. union {
  959. struct list_head list;
  960. int hpos;
  961. };
  962. };
  963. /**
  964. * struct ubifs_lpt_lprops - LPT logical eraseblock properties.
  965. * @free: amount of free space in bytes
  966. * @dirty: amount of dirty space in bytes
  967. * @tgc: trivial GC flag (1 => unmap after commit end)
  968. * @cmt: commit flag (1 => reserved for commit)
  969. */
  970. struct ubifs_lpt_lprops {
  971. int free;
  972. int dirty;
  973. unsigned tgc:1;
  974. unsigned cmt:1;
  975. };
  976. /**
  977. * struct ubifs_lp_stats - statistics of eraseblocks in the main area.
  978. * @empty_lebs: number of empty LEBs
  979. * @taken_empty_lebs: number of taken LEBs
  980. * @idx_lebs: number of indexing LEBs
  981. * @total_free: total free space in bytes (includes all LEBs)
  982. * @total_dirty: total dirty space in bytes (includes all LEBs)
  983. * @total_used: total used space in bytes (does not include index LEBs)
  984. * @total_dead: total dead space in bytes (does not include index LEBs)
  985. * @total_dark: total dark space in bytes (does not include index LEBs)
  986. *
  987. * The @taken_empty_lebs field counts the LEBs that are in the transient state
  988. * of having been "taken" for use but not yet written to. @taken_empty_lebs is
  989. * needed to account correctly for @gc_lnum, otherwise @empty_lebs could be
  990. * used by itself (in which case 'unused_lebs' would be a better name). In the
  991. * case of @gc_lnum, it is "taken" at mount time or whenever a LEB is retained
  992. * by GC, but unlike other empty LEBs that are "taken", it may not be written
  993. * straight away (i.e. before the next commit start or unmount), so either
  994. * @gc_lnum must be specially accounted for, or the current approach followed
  995. * i.e. count it under @taken_empty_lebs.
  996. *
  997. * @empty_lebs includes @taken_empty_lebs.
  998. *
  999. * @total_used, @total_dead and @total_dark fields do not account indexing
  1000. * LEBs.
  1001. */
  1002. struct ubifs_lp_stats {
  1003. int empty_lebs;
  1004. int taken_empty_lebs;
  1005. int idx_lebs;
  1006. long long total_free;
  1007. long long total_dirty;
  1008. long long total_used;
  1009. long long total_dead;
  1010. long long total_dark;
  1011. };
  1012. struct ubifs_nnode;
  1013. /**
  1014. * struct ubifs_cnode - LEB Properties Tree common node.
  1015. * @parent: parent nnode
  1016. * @cnext: next cnode to commit
  1017. * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
  1018. * @iip: index in parent
  1019. * @level: level in the tree (zero for pnodes, greater than zero for nnodes)
  1020. * @num: node number
  1021. */
  1022. struct ubifs_cnode {
  1023. struct ubifs_nnode *parent;
  1024. struct ubifs_cnode *cnext;
  1025. unsigned long flags;
  1026. int iip;
  1027. int level;
  1028. int num;
  1029. };
  1030. /**
  1031. * struct ubifs_pnode - LEB Properties Tree leaf node.
  1032. * @parent: parent nnode
  1033. * @cnext: next cnode to commit
  1034. * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
  1035. * @iip: index in parent
  1036. * @level: level in the tree (always zero for pnodes)
  1037. * @num: node number
  1038. * @lprops: LEB properties array
  1039. */
  1040. struct ubifs_pnode {
  1041. struct ubifs_nnode *parent;
  1042. struct ubifs_cnode *cnext;
  1043. unsigned long flags;
  1044. int iip;
  1045. int level;
  1046. int num;
  1047. struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
  1048. };
  1049. /**
  1050. * struct ubifs_nbranch - LEB Properties Tree internal node branch.
  1051. * @lnum: LEB number of child
  1052. * @offs: offset of child
  1053. * @nnode: nnode child
  1054. * @pnode: pnode child
  1055. * @cnode: cnode child
  1056. */
  1057. struct ubifs_nbranch {
  1058. int lnum;
  1059. int offs;
  1060. union {
  1061. struct ubifs_nnode *nnode;
  1062. struct ubifs_pnode *pnode;
  1063. struct ubifs_cnode *cnode;
  1064. };
  1065. };
  1066. /**
  1067. * struct ubifs_nnode - LEB Properties Tree internal node.
  1068. * @parent: parent nnode
  1069. * @cnext: next cnode to commit
  1070. * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
  1071. * @iip: index in parent
  1072. * @level: level in the tree (always greater than zero for nnodes)
  1073. * @num: node number
  1074. * @nbranch: branches to child nodes
  1075. */
  1076. struct ubifs_nnode {
  1077. struct ubifs_nnode *parent;
  1078. struct ubifs_cnode *cnext;
  1079. unsigned long flags;
  1080. int iip;
  1081. int level;
  1082. int num;
  1083. struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
  1084. };
  1085. /**
  1086. * struct ubifs_lpt_heap - heap of categorized lprops.
  1087. * @arr: heap array
  1088. * @cnt: number in heap
  1089. * @max_cnt: maximum number allowed in heap
  1090. *
  1091. * There are %LPROPS_HEAP_CNT heaps.
  1092. */
  1093. struct ubifs_lpt_heap {
  1094. struct ubifs_lprops **arr;
  1095. int cnt;
  1096. int max_cnt;
  1097. };
  1098. /*
  1099. * Return codes for LPT scan callback function.
  1100. *
  1101. * LPT_SCAN_CONTINUE: continue scanning
  1102. * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory
  1103. * LPT_SCAN_STOP: stop scanning
  1104. */
  1105. enum {
  1106. LPT_SCAN_CONTINUE = 0,
  1107. LPT_SCAN_ADD = 1,
  1108. LPT_SCAN_STOP = 2,
  1109. };
  1110. struct ubifs_info;
  1111. /* Callback used by the 'ubifs_lpt_scan_nolock()' function */
  1112. typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
  1113. const struct ubifs_lprops *lprops,
  1114. int in_tree, void *data);
  1115. /**
  1116. * struct ubifs_wbuf - UBIFS write-buffer.
  1117. * @c: UBIFS file-system description object
  1118. * @buf: write-buffer (of min. flash I/O unit size)
  1119. * @lnum: logical eraseblock number the write-buffer points to
  1120. * @offs: write-buffer offset in this logical eraseblock
  1121. * @avail: number of bytes available in the write-buffer
  1122. * @used: number of used bytes in the write-buffer
  1123. * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range)
  1124. * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep
  1125. * up by 'mutex_lock_nested()).
  1126. * @sync_callback: write-buffer synchronization callback
  1127. * @io_mutex: serializes write-buffer I/O
  1128. * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes
  1129. * fields
  1130. * @softlimit: soft write-buffer timeout interval
  1131. * @delta: hard and soft timeouts delta (the timer expire interval is @softlimit
  1132. * and @softlimit + @delta)
  1133. * @timer: write-buffer timer
  1134. * @no_timer: non-zero if this write-buffer does not have a timer
  1135. * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing
  1136. * @next_ino: points to the next position of the following inode number
  1137. * @inodes: stores the inode numbers of the nodes which are in wbuf
  1138. *
  1139. * The write-buffer synchronization callback is called when the write-buffer is
  1140. * synchronized in order to notify how much space was wasted due to
  1141. * write-buffer padding and how much free space is left in the LEB.
  1142. *
  1143. * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under
  1144. * spin-lock or mutex because they are written under both mutex and spin-lock.
  1145. * @buf is appended to under mutex but overwritten under both mutex and
  1146. * spin-lock. Thus the data between @buf and @buf + @used can be read under
  1147. * spinlock.
  1148. */
  1149. struct ubifs_wbuf {
  1150. struct ubifs_info *c;
  1151. void *buf;
  1152. int lnum;
  1153. int offs;
  1154. int avail;
  1155. int used;
  1156. int size;
  1157. int jhead;
  1158. int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
  1159. struct mutex io_mutex;
  1160. spinlock_t lock;
  1161. // ktime_t softlimit;
  1162. // unsigned long long delta;
  1163. // struct hrtimer timer;
  1164. unsigned int no_timer:1;
  1165. unsigned int need_sync:1;
  1166. int next_ino;
  1167. ino_t *inodes;
  1168. };
  1169. /**
  1170. * struct ubifs_bud - bud logical eraseblock.
  1171. * @lnum: logical eraseblock number
  1172. * @start: where the (uncommitted) bud data starts
  1173. * @jhead: journal head number this bud belongs to
  1174. * @list: link in the list buds belonging to the same journal head
  1175. * @rb: link in the tree of all buds
  1176. */
  1177. struct ubifs_bud {
  1178. int lnum;
  1179. int start;
  1180. int jhead;
  1181. struct list_head list;
  1182. struct rb_node rb;
  1183. };
  1184. /**
  1185. * struct ubifs_jhead - journal head.
  1186. * @wbuf: head's write-buffer
  1187. * @buds_list: list of bud LEBs belonging to this journal head
  1188. * @grouped: non-zero if UBIFS groups nodes when writing to this journal head
  1189. *
  1190. * Note, the @buds list is protected by the @c->buds_lock.
  1191. */
  1192. struct ubifs_jhead {
  1193. struct ubifs_wbuf wbuf;
  1194. struct list_head buds_list;
  1195. unsigned int grouped:1;
  1196. };
  1197. /**
  1198. * struct ubifs_zbranch - key/coordinate/length branch stored in znodes.
  1199. * @key: key
  1200. * @znode: znode address in memory
  1201. * @lnum: LEB number of the target node (indexing node or data node)
  1202. * @offs: target node offset within @lnum
  1203. * @len: target node length
  1204. */
  1205. struct ubifs_zbranch {
  1206. union ubifs_key key;
  1207. union {
  1208. struct ubifs_znode *znode;
  1209. void *leaf;
  1210. };
  1211. int lnum;
  1212. int offs;
  1213. int len;
  1214. };
  1215. /**
  1216. * struct ubifs_znode - in-memory representation of an indexing node.
  1217. * @parent: parent znode or NULL if it is the root
  1218. * @cnext: next znode to commit
  1219. * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE)
  1220. * @time: last access time (seconds)
  1221. * @level: level of the entry in the TNC tree
  1222. * @child_cnt: count of child znodes
  1223. * @iip: index in parent's zbranch array
  1224. * @alt: lower bound of key range has altered i.e. child inserted at slot 0
  1225. * @lnum: LEB number of the corresponding indexing node
  1226. * @offs: offset of the corresponding indexing node
  1227. * @len: length of the corresponding indexing node
  1228. * @zbranch: array of znode branches (@c->fanout elements)
  1229. *
  1230. * Note! The @lnum, @offs, and @len fields are not really needed - we have them
  1231. * only for internal consistency check. They could be removed to save some RAM.
  1232. */
  1233. struct ubifs_znode {
  1234. struct ubifs_znode *parent;
  1235. struct ubifs_znode *cnext;
  1236. unsigned long flags;
  1237. unsigned long time;
  1238. int level;
  1239. int child_cnt;
  1240. int iip;
  1241. int alt;
  1242. int lnum;
  1243. int offs;
  1244. int len;
  1245. struct ubifs_zbranch zbranch[];
  1246. };
  1247. /**
  1248. * struct bu_info - bulk-read information.
  1249. * @key: first data node key
  1250. * @zbranch: zbranches of data nodes to bulk read
  1251. * @buf: buffer to read into
  1252. * @buf_len: buffer length
  1253. * @gc_seq: GC sequence number to detect races with GC
  1254. * @cnt: number of data nodes for bulk read
  1255. * @blk_cnt: number of data blocks including holes
  1256. * @oef: end of file reached
  1257. */
  1258. struct bu_info {
  1259. union ubifs_key key;
  1260. struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
  1261. void *buf;
  1262. int buf_len;
  1263. int gc_seq;
  1264. int cnt;
  1265. int blk_cnt;
  1266. int eof;
  1267. };
  1268. /**
  1269. * struct ubifs_node_range - node length range description data structure.
  1270. * @len: fixed node length
  1271. * @min_len: minimum possible node length
  1272. * @max_len: maximum possible node length
  1273. *
  1274. * If @max_len is %0, the node has fixed length @len.
  1275. */
  1276. struct ubifs_node_range {
  1277. union {
  1278. int len;
  1279. int min_len;
  1280. };
  1281. int max_len;
  1282. };
  1283. /**
  1284. * struct ubifs_compressor - UBIFS compressor description structure.
  1285. * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc)
  1286. * @cc: cryptoapi compressor handle
  1287. * @comp_mutex: mutex used during compression
  1288. * @decomp_mutex: mutex used during decompression
  1289. * @name: compressor name
  1290. * @capi_name: cryptoapi compressor name
  1291. */
  1292. struct ubifs_compressor {
  1293. int compr_type;
  1294. struct crypto_comp *cc;
  1295. struct mutex *comp_mutex;
  1296. struct mutex *decomp_mutex;
  1297. const char *name;
  1298. const char *capi_name;
  1299. #ifdef __UBOOT__
  1300. int (*decompress)(const unsigned char *in, size_t in_len,
  1301. unsigned char *out, size_t *out_len);
  1302. #endif
  1303. };
  1304. /**
  1305. * struct ubifs_budget_req - budget requirements of an operation.
  1306. *
  1307. * @fast: non-zero if the budgeting should try to acquire budget quickly and
  1308. * should not try to call write-back
  1309. * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields
  1310. * have to be re-calculated
  1311. * @new_page: non-zero if the operation adds a new page
  1312. * @dirtied_page: non-zero if the operation makes a page dirty
  1313. * @new_dent: non-zero if the operation adds a new directory entry
  1314. * @mod_dent: non-zero if the operation removes or modifies an existing
  1315. * directory entry
  1316. * @new_ino: non-zero if the operation adds a new inode
  1317. * @new_ino_d: now much data newly created inode contains
  1318. * @dirtied_ino: how many inodes the operation makes dirty
  1319. * @dirtied_ino_d: now much data dirtied inode contains
  1320. * @idx_growth: how much the index will supposedly grow
  1321. * @data_growth: how much new data the operation will supposedly add
  1322. * @dd_growth: how much data that makes other data dirty the operation will
  1323. * supposedly add
  1324. *
  1325. * @idx_growth, @data_growth and @dd_growth are not used in budget request. The
  1326. * budgeting subsystem caches index and data growth values there to avoid
  1327. * re-calculating them when the budget is released. However, if @idx_growth is
  1328. * %-1, it is calculated by the release function using other fields.
  1329. *
  1330. * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d
  1331. * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made
  1332. * dirty by the re-name operation.
  1333. *
  1334. * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to
  1335. * make sure the amount of inode data which contribute to @new_ino_d and
  1336. * @dirtied_ino_d fields are aligned.
  1337. */
  1338. struct ubifs_budget_req {
  1339. unsigned int fast:1;
  1340. unsigned int recalculate:1;
  1341. #ifndef UBIFS_DEBUG
  1342. unsigned int new_page:1;
  1343. unsigned int dirtied_page:1;
  1344. unsigned int new_dent:1;
  1345. unsigned int mod_dent:1;
  1346. unsigned int new_ino:1;
  1347. unsigned int new_ino_d:13;
  1348. unsigned int dirtied_ino:4;
  1349. unsigned int dirtied_ino_d:15;
  1350. #else
  1351. /* Not bit-fields to check for overflows */
  1352. unsigned int new_page;
  1353. unsigned int dirtied_page;
  1354. unsigned int new_dent;
  1355. unsigned int mod_dent;
  1356. unsigned int new_ino;
  1357. unsigned int new_ino_d;
  1358. unsigned int dirtied_ino;
  1359. unsigned int dirtied_ino_d;
  1360. #endif
  1361. int idx_growth;
  1362. int data_growth;
  1363. int dd_growth;
  1364. };
  1365. /**
  1366. * struct ubifs_orphan - stores the inode number of an orphan.
  1367. * @rb: rb-tree node of rb-tree of orphans sorted by inode number
  1368. * @list: list head of list of orphans in order added
  1369. * @new_list: list head of list of orphans added since the last commit
  1370. * @cnext: next orphan to commit
  1371. * @dnext: next orphan to delete
  1372. * @inum: inode number
  1373. * @new: %1 => added since the last commit, otherwise %0
  1374. * @cmt: %1 => commit pending, otherwise %0
  1375. * @del: %1 => delete pending, otherwise %0
  1376. */
  1377. struct ubifs_orphan {
  1378. struct rb_node rb;
  1379. struct list_head list;
  1380. struct list_head new_list;
  1381. struct ubifs_orphan *cnext;
  1382. struct ubifs_orphan *dnext;
  1383. ino_t inum;
  1384. unsigned new:1;
  1385. unsigned cmt:1;
  1386. unsigned del:1;
  1387. };
  1388. /**
  1389. * struct ubifs_mount_opts - UBIFS-specific mount options information.
  1390. * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast)
  1391. * @bulk_read: enable/disable bulk-reads (%0 default, %1 disable, %2 enable)
  1392. * @chk_data_crc: enable/disable CRC data checking when reading data nodes
  1393. * (%0 default, %1 disable, %2 enable)
  1394. * @override_compr: override default compressor (%0 - do not override and use
  1395. * superblock compressor, %1 - override and use compressor
  1396. * specified in @compr_type)
  1397. * @compr_type: compressor type to override the superblock compressor with
  1398. * (%UBIFS_COMPR_NONE, etc)
  1399. */
  1400. struct ubifs_mount_opts {
  1401. unsigned int unmount_mode:2;
  1402. unsigned int bulk_read:2;
  1403. unsigned int chk_data_crc:2;
  1404. unsigned int override_compr:1;
  1405. unsigned int compr_type:2;
  1406. };
  1407. /**
  1408. * struct ubifs_budg_info - UBIFS budgeting information.
  1409. * @idx_growth: amount of bytes budgeted for index growth
  1410. * @data_growth: amount of bytes budgeted for cached data
  1411. * @dd_growth: amount of bytes budgeted for cached data that will make
  1412. * other data dirty
  1413. * @uncommitted_idx: amount of bytes were budgeted for growth of the index, but
  1414. * which still have to be taken into account because the index
  1415. * has not been committed so far
  1416. * @old_idx_sz: size of index on flash
  1417. * @min_idx_lebs: minimum number of LEBs required for the index
  1418. * @nospace: non-zero if the file-system does not have flash space (used as
  1419. * optimization)
  1420. * @nospace_rp: the same as @nospace, but additionally means that even reserved
  1421. * pool is full
  1422. * @page_budget: budget for a page (constant, never changed after mount)
  1423. * @inode_budget: budget for an inode (constant, never changed after mount)
  1424. * @dent_budget: budget for a directory entry (constant, never changed after
  1425. * mount)
  1426. */
  1427. struct ubifs_budg_info {
  1428. long long idx_growth;
  1429. long long data_growth;
  1430. long long dd_growth;
  1431. long long uncommitted_idx;
  1432. unsigned long long old_idx_sz;
  1433. int min_idx_lebs;
  1434. unsigned int nospace:1;
  1435. unsigned int nospace_rp:1;
  1436. int page_budget;
  1437. int inode_budget;
  1438. int dent_budget;
  1439. };
  1440. struct ubifs_debug_info;
  1441. /**
  1442. * struct ubifs_info - UBIFS file-system description data structure
  1443. * (per-superblock).
  1444. * @vfs_sb: VFS @struct super_block object
  1445. * @bdi: backing device info object to make VFS happy and disable read-ahead
  1446. *
  1447. * @highest_inum: highest used inode number
  1448. * @max_sqnum: current global sequence number
  1449. * @cmt_no: commit number of the last successfully completed commit, protected
  1450. * by @commit_sem
  1451. * @cnt_lock: protects @highest_inum and @max_sqnum counters
  1452. * @fmt_version: UBIFS on-flash format version
  1453. * @ro_compat_version: R/O compatibility version
  1454. * @uuid: UUID from super block
  1455. *
  1456. * @lhead_lnum: log head logical eraseblock number
  1457. * @lhead_offs: log head offset
  1458. * @ltail_lnum: log tail logical eraseblock number (offset is always 0)
  1459. * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and
  1460. * @bud_bytes
  1461. * @min_log_bytes: minimum required number of bytes in the log
  1462. * @cmt_bud_bytes: used during commit to temporarily amount of bytes in
  1463. * committed buds
  1464. *
  1465. * @buds: tree of all buds indexed by bud LEB number
  1466. * @bud_bytes: how many bytes of flash is used by buds
  1467. * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud
  1468. * lists
  1469. * @jhead_cnt: count of journal heads
  1470. * @jheads: journal heads (head zero is base head)
  1471. * @max_bud_bytes: maximum number of bytes allowed in buds
  1472. * @bg_bud_bytes: number of bud bytes when background commit is initiated
  1473. * @old_buds: buds to be released after commit ends
  1474. * @max_bud_cnt: maximum number of buds
  1475. *
  1476. * @commit_sem: synchronizes committer with other processes
  1477. * @cmt_state: commit state
  1478. * @cs_lock: commit state lock
  1479. * @cmt_wq: wait queue to sleep on if the log is full and a commit is running
  1480. *
  1481. * @big_lpt: flag that LPT is too big to write whole during commit
  1482. * @space_fixup: flag indicating that free space in LEBs needs to be cleaned up
  1483. * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
  1484. * recovery)
  1485. * @bulk_read: enable bulk-reads
  1486. * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
  1487. * @rw_incompat: the media is not R/W compatible
  1488. *
  1489. * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
  1490. * @calc_idx_sz
  1491. * @zroot: zbranch which points to the root index node and znode
  1492. * @cnext: next znode to commit
  1493. * @enext: next znode to commit to empty space
  1494. * @gap_lebs: array of LEBs used by the in-gaps commit method
  1495. * @cbuf: commit buffer
  1496. * @ileb_buf: buffer for commit in-the-gaps method
  1497. * @ileb_len: length of data in ileb_buf
  1498. * @ihead_lnum: LEB number of index head
  1499. * @ihead_offs: offset of index head
  1500. * @ilebs: pre-allocated index LEBs
  1501. * @ileb_cnt: number of pre-allocated index LEBs
  1502. * @ileb_nxt: next pre-allocated index LEBs
  1503. * @old_idx: tree of index nodes obsoleted since the last commit start
  1504. * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c
  1505. *
  1506. * @mst_node: master node
  1507. * @mst_offs: offset of valid master node
  1508. *
  1509. * @max_bu_buf_len: maximum bulk-read buffer length
  1510. * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu
  1511. * @bu: pre-allocated bulk-read information
  1512. *
  1513. * @write_reserve_mutex: protects @write_reserve_buf
  1514. * @write_reserve_buf: on the write path we allocate memory, which might
  1515. * sometimes be unavailable, in which case we use this
  1516. * write reserve buffer
  1517. *
  1518. * @log_lebs: number of logical eraseblocks in the log
  1519. * @log_bytes: log size in bytes
  1520. * @log_last: last LEB of the log
  1521. * @lpt_lebs: number of LEBs used for lprops table
  1522. * @lpt_first: first LEB of the lprops table area
  1523. * @lpt_last: last LEB of the lprops table area
  1524. * @orph_lebs: number of LEBs used for the orphan area
  1525. * @orph_first: first LEB of the orphan area
  1526. * @orph_last: last LEB of the orphan area
  1527. * @main_lebs: count of LEBs in the main area
  1528. * @main_first: first LEB of the main area
  1529. * @main_bytes: main area size in bytes
  1530. *
  1531. * @key_hash_type: type of the key hash
  1532. * @key_hash: direntry key hash function
  1533. * @key_fmt: key format
  1534. * @key_len: key length
  1535. * @fanout: fanout of the index tree (number of links per indexing node)
  1536. *
  1537. * @min_io_size: minimal input/output unit size
  1538. * @min_io_shift: number of bits in @min_io_size minus one
  1539. * @max_write_size: maximum amount of bytes the underlying flash can write at a
  1540. * time (MTD write buffer size)
  1541. * @max_write_shift: number of bits in @max_write_size minus one
  1542. * @leb_size: logical eraseblock size in bytes
  1543. * @leb_start: starting offset of logical eraseblocks within physical
  1544. * eraseblocks
  1545. * @half_leb_size: half LEB size
  1546. * @idx_leb_size: how many bytes of an LEB are effectively available when it is
  1547. * used to store indexing nodes (@leb_size - @max_idx_node_sz)
  1548. * @leb_cnt: count of logical eraseblocks
  1549. * @max_leb_cnt: maximum count of logical eraseblocks
  1550. * @old_leb_cnt: count of logical eraseblocks before re-size
  1551. * @ro_media: the underlying UBI volume is read-only
  1552. * @ro_mount: the file-system was mounted as read-only
  1553. * @ro_error: UBIFS switched to R/O mode because an error happened
  1554. *
  1555. * @dirty_pg_cnt: number of dirty pages (not used)
  1556. * @dirty_zn_cnt: number of dirty znodes
  1557. * @clean_zn_cnt: number of clean znodes
  1558. *
  1559. * @space_lock: protects @bi and @lst
  1560. * @lst: lprops statistics
  1561. * @bi: budgeting information
  1562. * @calc_idx_sz: temporary variable which is used to calculate new index size
  1563. * (contains accurate new index size at end of TNC commit start)
  1564. *
  1565. * @ref_node_alsz: size of the LEB reference node aligned to the min. flash
  1566. * I/O unit
  1567. * @mst_node_alsz: master node aligned size
  1568. * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary
  1569. * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary
  1570. * @max_inode_sz: maximum possible inode size in bytes
  1571. * @max_znode_sz: size of znode in bytes
  1572. *
  1573. * @leb_overhead: how many bytes are wasted in an LEB when it is filled with
  1574. * data nodes of maximum size - used in free space reporting
  1575. * @dead_wm: LEB dead space watermark
  1576. * @dark_wm: LEB dark space watermark
  1577. * @block_cnt: count of 4KiB blocks on the FS
  1578. *
  1579. * @ranges: UBIFS node length ranges
  1580. * @ubi: UBI volume descriptor
  1581. * @di: UBI device information
  1582. * @vi: UBI volume information
  1583. *
  1584. * @orph_tree: rb-tree of orphan inode numbers
  1585. * @orph_list: list of orphan inode numbers in order added
  1586. * @orph_new: list of orphan inode numbers added since last commit
  1587. * @orph_cnext: next orphan to commit
  1588. * @orph_dnext: next orphan to delete
  1589. * @orphan_lock: lock for orph_tree and orph_new
  1590. * @orph_buf: buffer for orphan nodes
  1591. * @new_orphans: number of orphans since last commit
  1592. * @cmt_orphans: number of orphans being committed
  1593. * @tot_orphans: number of orphans in the rb_tree
  1594. * @max_orphans: maximum number of orphans allowed
  1595. * @ohead_lnum: orphan head LEB number
  1596. * @ohead_offs: orphan head offset
  1597. * @no_orphs: non-zero if there are no orphans
  1598. *
  1599. * @bgt: UBIFS background thread
  1600. * @bgt_name: background thread name
  1601. * @need_bgt: if background thread should run
  1602. * @need_wbuf_sync: if write-buffers have to be synchronized
  1603. *
  1604. * @gc_lnum: LEB number used for garbage collection
  1605. * @sbuf: a buffer of LEB size used by GC and replay for scanning
  1606. * @idx_gc: list of index LEBs that have been garbage collected
  1607. * @idx_gc_cnt: number of elements on the idx_gc list
  1608. * @gc_seq: incremented for every non-index LEB garbage collected
  1609. * @gced_lnum: last non-index LEB that was garbage collected
  1610. *
  1611. * @infos_list: links all 'ubifs_info' objects
  1612. * @umount_mutex: serializes shrinker and un-mount
  1613. * @shrinker_run_no: shrinker run number
  1614. *
  1615. * @space_bits: number of bits needed to record free or dirty space
  1616. * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT
  1617. * @lpt_offs_bits: number of bits needed to record an offset in the LPT
  1618. * @lpt_spc_bits: number of bits needed to space in the LPT
  1619. * @pcnt_bits: number of bits needed to record pnode or nnode number
  1620. * @lnum_bits: number of bits needed to record LEB number
  1621. * @nnode_sz: size of on-flash nnode
  1622. * @pnode_sz: size of on-flash pnode
  1623. * @ltab_sz: size of on-flash LPT lprops table
  1624. * @lsave_sz: size of on-flash LPT save table
  1625. * @pnode_cnt: number of pnodes
  1626. * @nnode_cnt: number of nnodes
  1627. * @lpt_hght: height of the LPT
  1628. * @pnodes_have: number of pnodes in memory
  1629. *
  1630. * @lp_mutex: protects lprops table and all the other lprops-related fields
  1631. * @lpt_lnum: LEB number of the root nnode of the LPT
  1632. * @lpt_offs: offset of the root nnode of the LPT
  1633. * @nhead_lnum: LEB number of LPT head
  1634. * @nhead_offs: offset of LPT head
  1635. * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab
  1636. * @dirty_nn_cnt: number of dirty nnodes
  1637. * @dirty_pn_cnt: number of dirty pnodes
  1638. * @check_lpt_free: flag that indicates LPT GC may be needed
  1639. * @lpt_sz: LPT size
  1640. * @lpt_nod_buf: buffer for an on-flash nnode or pnode
  1641. * @lpt_buf: buffer of LEB size used by LPT
  1642. * @nroot: address in memory of the root nnode of the LPT
  1643. * @lpt_cnext: next LPT node to commit
  1644. * @lpt_heap: array of heaps of categorized lprops
  1645. * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at
  1646. * previous commit start
  1647. * @uncat_list: list of un-categorized LEBs
  1648. * @empty_list: list of empty LEBs
  1649. * @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size)
  1650. * @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size)
  1651. * @freeable_cnt: number of freeable LEBs in @freeable_list
  1652. * @in_a_category_cnt: count of lprops which are in a certain category, which
  1653. * basically meants that they were loaded from the flash
  1654. *
  1655. * @ltab_lnum: LEB number of LPT's own lprops table
  1656. * @ltab_offs: offset of LPT's own lprops table
  1657. * @ltab: LPT's own lprops table
  1658. * @ltab_cmt: LPT's own lprops table (commit copy)
  1659. * @lsave_cnt: number of LEB numbers in LPT's save table
  1660. * @lsave_lnum: LEB number of LPT's save table
  1661. * @lsave_offs: offset of LPT's save table
  1662. * @lsave: LPT's save table
  1663. * @lscan_lnum: LEB number of last LPT scan
  1664. *
  1665. * @rp_size: size of the reserved pool in bytes
  1666. * @report_rp_size: size of the reserved pool reported to user-space
  1667. * @rp_uid: reserved pool user ID
  1668. * @rp_gid: reserved pool group ID
  1669. *
  1670. * @empty: %1 if the UBI device is empty
  1671. * @need_recovery: %1 if the file-system needs recovery
  1672. * @replaying: %1 during journal replay
  1673. * @mounting: %1 while mounting
  1674. * @probing: %1 while attempting to mount if MS_SILENT mount flag is set
  1675. * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode
  1676. * @replay_list: temporary list used during journal replay
  1677. * @replay_buds: list of buds to replay
  1678. * @cs_sqnum: sequence number of first node in the log (commit start node)
  1679. * @replay_sqnum: sequence number of node currently being replayed
  1680. * @unclean_leb_list: LEBs to recover when re-mounting R/O mounted FS to R/W
  1681. * mode
  1682. * @rcvrd_mst_node: recovered master node to write when re-mounting R/O mounted
  1683. * FS to R/W mode
  1684. * @size_tree: inode size information for recovery
  1685. * @mount_opts: UBIFS-specific mount options
  1686. *
  1687. * @dbg: debugging-related information
  1688. */
  1689. struct ubifs_info {
  1690. struct super_block *vfs_sb;
  1691. #ifndef __UBOOT__
  1692. struct backing_dev_info bdi;
  1693. #endif
  1694. ino_t highest_inum;
  1695. unsigned long long max_sqnum;
  1696. unsigned long long cmt_no;
  1697. spinlock_t cnt_lock;
  1698. int fmt_version;
  1699. int ro_compat_version;
  1700. unsigned char uuid[16];
  1701. int lhead_lnum;
  1702. int lhead_offs;
  1703. int ltail_lnum;
  1704. struct mutex log_mutex;
  1705. int min_log_bytes;
  1706. long long cmt_bud_bytes;
  1707. struct rb_root buds;
  1708. long long bud_bytes;
  1709. spinlock_t buds_lock;
  1710. int jhead_cnt;
  1711. struct ubifs_jhead *jheads;
  1712. long long max_bud_bytes;
  1713. long long bg_bud_bytes;
  1714. struct list_head old_buds;
  1715. int max_bud_cnt;
  1716. struct rw_semaphore commit_sem;
  1717. int cmt_state;
  1718. spinlock_t cs_lock;
  1719. wait_queue_head_t cmt_wq;
  1720. unsigned int big_lpt:1;
  1721. unsigned int space_fixup:1;
  1722. unsigned int no_chk_data_crc:1;
  1723. unsigned int bulk_read:1;
  1724. unsigned int default_compr:2;
  1725. unsigned int rw_incompat:1;
  1726. struct mutex tnc_mutex;
  1727. struct ubifs_zbranch zroot;
  1728. struct ubifs_znode *cnext;
  1729. struct ubifs_znode *enext;
  1730. int *gap_lebs;
  1731. void *cbuf;
  1732. void *ileb_buf;
  1733. int ileb_len;
  1734. int ihead_lnum;
  1735. int ihead_offs;
  1736. int *ilebs;
  1737. int ileb_cnt;
  1738. int ileb_nxt;
  1739. struct rb_root old_idx;
  1740. int *bottom_up_buf;
  1741. struct ubifs_mst_node *mst_node;
  1742. int mst_offs;
  1743. int max_bu_buf_len;
  1744. struct mutex bu_mutex;
  1745. struct bu_info bu;
  1746. struct mutex write_reserve_mutex;
  1747. void *write_reserve_buf;
  1748. int log_lebs;
  1749. long long log_bytes;
  1750. int log_last;
  1751. int lpt_lebs;
  1752. int lpt_first;
  1753. int lpt_last;
  1754. int orph_lebs;
  1755. int orph_first;
  1756. int orph_last;
  1757. int main_lebs;
  1758. int main_first;
  1759. long long main_bytes;
  1760. uint8_t key_hash_type;
  1761. uint32_t (*key_hash)(const char *str, int len);
  1762. int key_fmt;
  1763. int key_len;
  1764. int fanout;
  1765. int min_io_size;
  1766. int min_io_shift;
  1767. int max_write_size;
  1768. int max_write_shift;
  1769. int leb_size;
  1770. int leb_start;
  1771. int half_leb_size;
  1772. int idx_leb_size;
  1773. int leb_cnt;
  1774. int max_leb_cnt;
  1775. int old_leb_cnt;
  1776. unsigned int ro_media:1;
  1777. unsigned int ro_mount:1;
  1778. unsigned int ro_error:1;
  1779. atomic_long_t dirty_pg_cnt;
  1780. atomic_long_t dirty_zn_cnt;
  1781. atomic_long_t clean_zn_cnt;
  1782. spinlock_t space_lock;
  1783. struct ubifs_lp_stats lst;
  1784. struct ubifs_budg_info bi;
  1785. unsigned long long calc_idx_sz;
  1786. int ref_node_alsz;
  1787. int mst_node_alsz;
  1788. int min_idx_node_sz;
  1789. int max_idx_node_sz;
  1790. long long max_inode_sz;
  1791. int max_znode_sz;
  1792. int leb_overhead;
  1793. int dead_wm;
  1794. int dark_wm;
  1795. int block_cnt;
  1796. struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
  1797. struct ubi_volume_desc *ubi;
  1798. struct ubi_device_info di;
  1799. struct ubi_volume_info vi;
  1800. struct rb_root orph_tree;
  1801. struct list_head orph_list;
  1802. struct list_head orph_new;
  1803. struct ubifs_orphan *orph_cnext;
  1804. struct ubifs_orphan *orph_dnext;
  1805. spinlock_t orphan_lock;
  1806. void *orph_buf;
  1807. int new_orphans;
  1808. int cmt_orphans;
  1809. int tot_orphans;
  1810. int max_orphans;
  1811. int ohead_lnum;
  1812. int ohead_offs;
  1813. int no_orphs;
  1814. struct task_struct *bgt;
  1815. char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
  1816. int need_bgt;
  1817. int need_wbuf_sync;
  1818. int gc_lnum;
  1819. void *sbuf;
  1820. struct list_head idx_gc;
  1821. int idx_gc_cnt;
  1822. int gc_seq;
  1823. int gced_lnum;
  1824. struct list_head infos_list;
  1825. struct mutex umount_mutex;
  1826. unsigned int shrinker_run_no;
  1827. int space_bits;
  1828. int lpt_lnum_bits;
  1829. int lpt_offs_bits;
  1830. int lpt_spc_bits;
  1831. int pcnt_bits;
  1832. int lnum_bits;
  1833. int nnode_sz;
  1834. int pnode_sz;
  1835. int ltab_sz;
  1836. int lsave_sz;
  1837. int pnode_cnt;
  1838. int nnode_cnt;
  1839. int lpt_hght;
  1840. int pnodes_have;
  1841. struct mutex lp_mutex;
  1842. int lpt_lnum;
  1843. int lpt_offs;
  1844. int nhead_lnum;
  1845. int nhead_offs;
  1846. int lpt_drty_flgs;
  1847. int dirty_nn_cnt;
  1848. int dirty_pn_cnt;
  1849. int check_lpt_free;
  1850. long long lpt_sz;
  1851. void *lpt_nod_buf;
  1852. void *lpt_buf;
  1853. struct ubifs_nnode *nroot;
  1854. struct ubifs_cnode *lpt_cnext;
  1855. struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
  1856. struct ubifs_lpt_heap dirty_idx;
  1857. struct list_head uncat_list;
  1858. struct list_head empty_list;
  1859. struct list_head freeable_list;
  1860. struct list_head frdi_idx_list;
  1861. int freeable_cnt;
  1862. int in_a_category_cnt;
  1863. int ltab_lnum;
  1864. int ltab_offs;
  1865. struct ubifs_lpt_lprops *ltab;
  1866. struct ubifs_lpt_lprops *ltab_cmt;
  1867. int lsave_cnt;
  1868. int lsave_lnum;
  1869. int lsave_offs;
  1870. int *lsave;
  1871. int lscan_lnum;
  1872. long long rp_size;
  1873. long long report_rp_size;
  1874. kuid_t rp_uid;
  1875. kgid_t rp_gid;
  1876. /* The below fields are used only during mounting and re-mounting */
  1877. unsigned int empty:1;
  1878. unsigned int need_recovery:1;
  1879. unsigned int replaying:1;
  1880. unsigned int mounting:1;
  1881. unsigned int remounting_rw:1;
  1882. unsigned int probing:1;
  1883. struct list_head replay_list;
  1884. struct list_head replay_buds;
  1885. unsigned long long cs_sqnum;
  1886. unsigned long long replay_sqnum;
  1887. struct list_head unclean_leb_list;
  1888. struct ubifs_mst_node *rcvrd_mst_node;
  1889. struct rb_root size_tree;
  1890. struct ubifs_mount_opts mount_opts;
  1891. #ifndef __UBOOT__
  1892. struct ubifs_debug_info *dbg;
  1893. #endif
  1894. };
  1895. extern struct list_head ubifs_infos;
  1896. extern spinlock_t ubifs_infos_lock;
  1897. extern atomic_long_t ubifs_clean_zn_cnt;
  1898. extern struct kmem_cache *ubifs_inode_slab;
  1899. extern const struct super_operations ubifs_super_operations;
  1900. extern const struct xattr_handler *ubifs_xattr_handlers[];
  1901. extern const struct address_space_operations ubifs_file_address_operations;
  1902. extern const struct file_operations ubifs_file_operations;
  1903. extern const struct inode_operations ubifs_file_inode_operations;
  1904. extern const struct file_operations ubifs_dir_operations;
  1905. extern const struct inode_operations ubifs_dir_inode_operations;
  1906. extern const struct inode_operations ubifs_symlink_inode_operations;
  1907. extern struct backing_dev_info ubifs_backing_dev_info;
  1908. extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
  1909. /* io.c */
  1910. void ubifs_ro_mode(struct ubifs_info *c, int err);
  1911. int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
  1912. int len, int even_ebadmsg);
  1913. int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
  1914. int len);
  1915. int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
  1916. int ubifs_leb_unmap(struct ubifs_info *c, int lnum);
  1917. int ubifs_leb_map(struct ubifs_info *c, int lnum);
  1918. int ubifs_is_mapped(const struct ubifs_info *c, int lnum);
  1919. int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
  1920. int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs);
  1921. int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
  1922. int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
  1923. int lnum, int offs);
  1924. int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
  1925. int lnum, int offs);
  1926. int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
  1927. int offs);
  1928. int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
  1929. int offs, int quiet, int must_chk_crc);
  1930. void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
  1931. void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
  1932. int ubifs_io_init(struct ubifs_info *c);
  1933. void ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
  1934. int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
  1935. int ubifs_bg_wbufs_sync(struct ubifs_info *c);
  1936. void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
  1937. int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
  1938. /* scan.c */
  1939. struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
  1940. int offs, void *sbuf, int quiet);
  1941. void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
  1942. int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
  1943. int offs, int quiet);
  1944. struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
  1945. int offs, void *sbuf);
  1946. void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
  1947. int lnum, int offs);
  1948. int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
  1949. void *buf, int offs);
  1950. void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
  1951. void *buf);
  1952. /* log.c */
  1953. void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
  1954. void ubifs_create_buds_lists(struct ubifs_info *c);
  1955. int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
  1956. struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
  1957. struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
  1958. int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
  1959. int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
  1960. int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
  1961. int ubifs_consolidate_log(struct ubifs_info *c);
  1962. /* journal.c */
  1963. int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
  1964. const struct qstr *nm, const struct inode *inode,
  1965. int deletion, int xent);
  1966. int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
  1967. const union ubifs_key *key, const void *buf, int len);
  1968. int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
  1969. int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
  1970. int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
  1971. const struct dentry *old_dentry,
  1972. const struct inode *new_dir,
  1973. const struct dentry *new_dentry, int sync);
  1974. int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
  1975. loff_t old_size, loff_t new_size);
  1976. int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
  1977. const struct inode *inode, const struct qstr *nm);
  1978. int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
  1979. const struct inode *inode2);
  1980. /* budget.c */
  1981. int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
  1982. void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
  1983. void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
  1984. struct ubifs_inode *ui);
  1985. int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
  1986. struct ubifs_budget_req *req);
  1987. void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
  1988. struct ubifs_budget_req *req);
  1989. void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
  1990. struct ubifs_budget_req *req);
  1991. long long ubifs_get_free_space(struct ubifs_info *c);
  1992. long long ubifs_get_free_space_nolock(struct ubifs_info *c);
  1993. int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
  1994. void ubifs_convert_page_budget(struct ubifs_info *c);
  1995. long long ubifs_reported_space(const struct ubifs_info *c, long long free);
  1996. long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
  1997. /* find.c */
  1998. int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
  1999. int squeeze);
  2000. int ubifs_find_free_leb_for_idx(struct ubifs_info *c);
  2001. int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
  2002. int min_space, int pick_free);
  2003. int ubifs_find_dirty_idx_leb(struct ubifs_info *c);
  2004. int ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
  2005. /* tnc.c */
  2006. int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
  2007. struct ubifs_znode **zn, int *n);
  2008. int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
  2009. void *node, const struct qstr *nm);
  2010. int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
  2011. void *node, int *lnum, int *offs);
  2012. int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
  2013. int offs, int len);
  2014. int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
  2015. int old_lnum, int old_offs, int lnum, int offs, int len);
  2016. int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
  2017. int lnum, int offs, int len, const struct qstr *nm);
  2018. int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
  2019. int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
  2020. const struct qstr *nm);
  2021. int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
  2022. union ubifs_key *to_key);
  2023. int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
  2024. struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
  2025. union ubifs_key *key,
  2026. const struct qstr *nm);
  2027. void ubifs_tnc_close(struct ubifs_info *c);
  2028. int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
  2029. int lnum, int offs, int is_idx);
  2030. int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
  2031. int lnum, int offs);
  2032. /* Shared by tnc.c for tnc_commit.c */
  2033. void destroy_old_idx(struct ubifs_info *c);
  2034. int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
  2035. int lnum, int offs);
  2036. int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
  2037. int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
  2038. int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
  2039. /* tnc_misc.c */
  2040. struct ubifs_znode *ubifs_tnc_levelorder_next(struct ubifs_znode *zr,
  2041. struct ubifs_znode *znode);
  2042. int ubifs_search_zbranch(const struct ubifs_info *c,
  2043. const struct ubifs_znode *znode,
  2044. const union ubifs_key *key, int *n);
  2045. struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
  2046. struct ubifs_znode *ubifs_tnc_postorder_next(struct ubifs_znode *znode);
  2047. long ubifs_destroy_tnc_subtree(struct ubifs_znode *zr);
  2048. struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
  2049. struct ubifs_zbranch *zbr,
  2050. struct ubifs_znode *parent, int iip);
  2051. int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
  2052. void *node);
  2053. /* tnc_commit.c */
  2054. int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
  2055. int ubifs_tnc_end_commit(struct ubifs_info *c);
  2056. #ifndef __UBOOT__
  2057. /* shrinker.c */
  2058. unsigned long ubifs_shrink_scan(struct shrinker *shrink,
  2059. struct shrink_control *sc);
  2060. unsigned long ubifs_shrink_count(struct shrinker *shrink,
  2061. struct shrink_control *sc);
  2062. #endif
  2063. /* commit.c */
  2064. int ubifs_bg_thread(void *info);
  2065. void ubifs_commit_required(struct ubifs_info *c);
  2066. void ubifs_request_bg_commit(struct ubifs_info *c);
  2067. int ubifs_run_commit(struct ubifs_info *c);
  2068. void ubifs_recovery_commit(struct ubifs_info *c);
  2069. int ubifs_gc_should_commit(struct ubifs_info *c);
  2070. void ubifs_wait_for_commit(struct ubifs_info *c);
  2071. /* master.c */
  2072. int ubifs_read_master(struct ubifs_info *c);
  2073. int ubifs_write_master(struct ubifs_info *c);
  2074. /* sb.c */
  2075. int ubifs_read_superblock(struct ubifs_info *c);
  2076. struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c);
  2077. int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
  2078. int ubifs_fixup_free_space(struct ubifs_info *c);
  2079. /* replay.c */
  2080. int ubifs_validate_entry(struct ubifs_info *c,
  2081. const struct ubifs_dent_node *dent);
  2082. int ubifs_replay_journal(struct ubifs_info *c);
  2083. /* gc.c */
  2084. int ubifs_garbage_collect(struct ubifs_info *c, int anyway);
  2085. int ubifs_gc_start_commit(struct ubifs_info *c);
  2086. int ubifs_gc_end_commit(struct ubifs_info *c);
  2087. void ubifs_destroy_idx_gc(struct ubifs_info *c);
  2088. int ubifs_get_idx_gc_leb(struct ubifs_info *c);
  2089. int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
  2090. /* orphan.c */
  2091. int ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
  2092. void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
  2093. int ubifs_orphan_start_commit(struct ubifs_info *c);
  2094. int ubifs_orphan_end_commit(struct ubifs_info *c);
  2095. int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
  2096. int ubifs_clear_orphans(struct ubifs_info *c);
  2097. /* lpt.c */
  2098. int ubifs_calc_lpt_geom(struct ubifs_info *c);
  2099. int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
  2100. int *lpt_lebs, int *big_lpt);
  2101. int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
  2102. struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
  2103. struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
  2104. int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
  2105. ubifs_lpt_scan_callback scan_cb, void *data);
  2106. /* Shared by lpt.c for lpt_commit.c */
  2107. void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
  2108. void ubifs_pack_ltab(struct ubifs_info *c, void *buf,
  2109. struct ubifs_lpt_lprops *ltab);
  2110. void ubifs_pack_pnode(struct ubifs_info *c, void *buf,
  2111. struct ubifs_pnode *pnode);
  2112. void ubifs_pack_nnode(struct ubifs_info *c, void *buf,
  2113. struct ubifs_nnode *nnode);
  2114. struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
  2115. struct ubifs_nnode *parent, int iip);
  2116. struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
  2117. struct ubifs_nnode *parent, int iip);
  2118. int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
  2119. void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
  2120. void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
  2121. uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits);
  2122. struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
  2123. /* Needed only in debugging code in lpt_commit.c */
  2124. int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
  2125. struct ubifs_nnode *nnode);
  2126. /* lpt_commit.c */
  2127. int ubifs_lpt_start_commit(struct ubifs_info *c);
  2128. int ubifs_lpt_end_commit(struct ubifs_info *c);
  2129. int ubifs_lpt_post_commit(struct ubifs_info *c);
  2130. void ubifs_lpt_free(struct ubifs_info *c, int wr_only);
  2131. /* lprops.c */
  2132. const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
  2133. const struct ubifs_lprops *lp,
  2134. int free, int dirty, int flags,
  2135. int idx_gc_cnt);
  2136. void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst);
  2137. void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
  2138. int cat);
  2139. void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
  2140. struct ubifs_lprops *new_lprops);
  2141. void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
  2142. int ubifs_categorize_lprops(const struct ubifs_info *c,
  2143. const struct ubifs_lprops *lprops);
  2144. int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
  2145. int flags_set, int flags_clean, int idx_gc_cnt);
  2146. int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
  2147. int flags_set, int flags_clean);
  2148. int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
  2149. const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
  2150. const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
  2151. const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
  2152. const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
  2153. int ubifs_calc_dark(const struct ubifs_info *c, int spc);
  2154. /* file.c */
  2155. int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
  2156. int ubifs_setattr(struct dentry *dentry, struct iattr *attr);
  2157. /* dir.c */
  2158. struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir,
  2159. umode_t mode);
  2160. int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  2161. struct kstat *stat);
  2162. /* xattr.c */
  2163. int ubifs_setxattr(struct dentry *dentry, const char *name,
  2164. const void *value, size_t size, int flags);
  2165. ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf,
  2166. size_t size);
  2167. ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  2168. int ubifs_removexattr(struct dentry *dentry, const char *name);
  2169. int ubifs_init_security(struct inode *dentry, struct inode *inode,
  2170. const struct qstr *qstr);
  2171. /* super.c */
  2172. struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
  2173. int ubifs_iput(struct inode *inode);
  2174. /* recovery.c */
  2175. int ubifs_recover_master_node(struct ubifs_info *c);
  2176. int ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
  2177. struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
  2178. int offs, void *sbuf, int jhead);
  2179. struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
  2180. int offs, void *sbuf);
  2181. int ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf);
  2182. int ubifs_clean_lebs(struct ubifs_info *c, void *sbuf);
  2183. int ubifs_rcvry_gc_commit(struct ubifs_info *c);
  2184. int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
  2185. int deletion, loff_t new_size);
  2186. int ubifs_recover_size(struct ubifs_info *c);
  2187. void ubifs_destroy_size_tree(struct ubifs_info *c);
  2188. /* ioctl.c */
  2189. long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  2190. void ubifs_set_inode_flags(struct inode *inode);
  2191. #ifdef CONFIG_COMPAT
  2192. long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  2193. #endif
  2194. /* compressor.c */
  2195. int __init ubifs_compressors_init(void);
  2196. void ubifs_compressors_exit(void);
  2197. void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
  2198. void *out_buf, int *out_len, int *compr_type);
  2199. int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
  2200. void *out, int *out_len, int compr_type);
  2201. #include "debug.h"
  2202. #include "misc.h"
  2203. #include "key.h"
  2204. #ifdef __UBOOT__
  2205. void ubifs_umount(struct ubifs_info *c);
  2206. #endif
  2207. #endif /* !__UBIFS_H__ */