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