ubifs.h 78 KB

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