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