ubifs.h 70 KB

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