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