^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * This file is part of UBIFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2006-2008 Nokia Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Authors: Artem Bityutskiy (Битюцкий Артём)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Adrian Hunter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This file implements UBIFS initialization and VFS superblock operations. Some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * initialization stuff which is rather large and complex is placed at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * corresponding subsystems, but most of it is here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "ubifs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int ubifs_default_version_set(const char *val, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int n = 0, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ret = kstrtoint(val, 10, &n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (ret != 0 || n < 4 || n > UBIFS_FORMAT_VERSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return param_set_int(val, kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static const struct kernel_param_ops ubifs_default_version_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .set = ubifs_default_version_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .get = param_get_int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int ubifs_default_version = UBIFS_FORMAT_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) module_param_cb(default_version, &ubifs_default_version_ops, &ubifs_default_version, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Maximum amount of memory we may 'kmalloc()' without worrying that we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * allocating too much.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define UBIFS_KMALLOC_OK (128*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* Slab cache for UBIFS inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static struct kmem_cache *ubifs_inode_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* UBIFS TNC shrinker description */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static struct shrinker ubifs_shrinker_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .scan_objects = ubifs_shrink_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .count_objects = ubifs_shrink_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .seeks = DEFAULT_SEEKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * validate_inode - validate inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @inode: the inode to validate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * This is a helper function for 'ubifs_iget()' which validates various fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * of a newly built inode to make sure they contain sane values and prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * possible vulnerabilities. Returns zero if the inode is all right and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * a non-zero error code if not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int validate_inode(struct ubifs_info *c, const struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) const struct ubifs_inode *ui = ubifs_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (inode->i_size > c->max_inode_sz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ubifs_err(c, "inode is too large (%lld)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) (long long)inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (ui->compr_type >= UBIFS_COMPR_TYPES_CNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ubifs_err(c, "unknown compression type %d", ui->compr_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ui->xattr_names + ui->xattr_cnt > XATTR_LIST_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (ui->data_len < 0 || ui->data_len > UBIFS_MAX_INO_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (ui->xattr && !S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (!ubifs_compr_present(c, ui->compr_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ubifs_warn(c, "inode %lu uses '%s' compression, but it was not compiled in",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) inode->i_ino, ubifs_compr_name(c, ui->compr_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) err = dbg_check_dir(c, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct inode *ubifs_iget(struct super_block *sb, unsigned long inum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) union ubifs_key key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct ubifs_ino_node *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct ubifs_info *c = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct ubifs_inode *ui;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) dbg_gen("inode %lu", inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) inode = iget_locked(sb, inum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (!(inode->i_state & I_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ui = ubifs_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (!ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ino_key_init(c, &key, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) err = ubifs_tnc_lookup(c, &key, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) goto out_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) inode->i_flags |= S_NOCMTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) inode->i_flags |= S_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) set_nlink(inode, le32_to_cpu(ino->nlink));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) i_uid_write(inode, le32_to_cpu(ino->uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) i_gid_write(inode, le32_to_cpu(ino->gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) inode->i_atime.tv_sec = (int64_t)le64_to_cpu(ino->atime_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) inode->i_atime.tv_nsec = le32_to_cpu(ino->atime_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) inode->i_mtime.tv_sec = (int64_t)le64_to_cpu(ino->mtime_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) inode->i_mtime.tv_nsec = le32_to_cpu(ino->mtime_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) inode->i_ctime.tv_sec = (int64_t)le64_to_cpu(ino->ctime_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) inode->i_ctime.tv_nsec = le32_to_cpu(ino->ctime_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) inode->i_mode = le32_to_cpu(ino->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) inode->i_size = le64_to_cpu(ino->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ui->data_len = le32_to_cpu(ino->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ui->flags = le32_to_cpu(ino->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ui->compr_type = le16_to_cpu(ino->compr_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ui->creat_sqnum = le64_to_cpu(ino->creat_sqnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ui->xattr_cnt = le32_to_cpu(ino->xattr_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ui->xattr_size = le32_to_cpu(ino->xattr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ui->xattr_names = le32_to_cpu(ino->xattr_names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ui->synced_i_size = ui->ui_size = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ui->xattr = (ui->flags & UBIFS_XATTR_FL) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) err = validate_inode(c, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) goto out_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) switch (inode->i_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) inode->i_mapping->a_ops = &ubifs_file_address_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) inode->i_op = &ubifs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) inode->i_fop = &ubifs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (ui->xattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ui->data = kmalloc(ui->data_len + 1, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (!ui->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) goto out_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) memcpy(ui->data, ino->data, ui->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ((char *)ui->data)[ui->data_len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) } else if (ui->data_len != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) err = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto out_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) inode->i_op = &ubifs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) inode->i_fop = &ubifs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (ui->data_len != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) err = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) goto out_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) case S_IFLNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) inode->i_op = &ubifs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ui->data_len <= 0 || ui->data_len > UBIFS_MAX_INO_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) err = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) goto out_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ui->data = kmalloc(ui->data_len + 1, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (!ui->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto out_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) memcpy(ui->data, ino->data, ui->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ((char *)ui->data)[ui->data_len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) case S_IFBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) case S_IFCHR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) dev_t rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) union ubifs_dev_desc *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ui->data = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!ui->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto out_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) dev = (union ubifs_dev_desc *)ino->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (ui->data_len == sizeof(dev->new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) rdev = new_decode_dev(le32_to_cpu(dev->new));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) else if (ui->data_len == sizeof(dev->huge))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) rdev = huge_decode_dev(le64_to_cpu(dev->huge));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) err = 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) goto out_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) memcpy(ui->data, ino->data, ui->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) inode->i_op = &ubifs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) init_special_inode(inode, inode->i_mode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case S_IFSOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) case S_IFIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) inode->i_op = &ubifs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) init_special_inode(inode, inode->i_mode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (ui->data_len != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) err = 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) goto out_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) err = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) goto out_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) kfree(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) ubifs_set_inode_flags(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) out_invalid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ubifs_err(c, "inode %lu validation failed, error %d", inode->i_ino, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) ubifs_dump_node(c, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ubifs_dump_inode(c, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) out_ino:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) kfree(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ubifs_err(c, "failed to read inode %lu, error %d", inode->i_ino, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct inode *ubifs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct ubifs_inode *ui;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ui = kmem_cache_alloc(ubifs_inode_slab, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!ui)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) memset((void *)ui + sizeof(struct inode), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) sizeof(struct ubifs_inode) - sizeof(struct inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) mutex_init(&ui->ui_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) init_rwsem(&ui->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) spin_lock_init(&ui->ui_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return &ui->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static void ubifs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct ubifs_inode *ui = ubifs_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) kfree(ui->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) fscrypt_free_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) kmem_cache_free(ubifs_inode_slab, ui);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Note, Linux write-back code calls this without 'i_mutex'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static int ubifs_write_inode(struct inode *inode, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct ubifs_info *c = inode->i_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct ubifs_inode *ui = ubifs_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ubifs_assert(c, !ui->xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (is_bad_inode(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) mutex_lock(&ui->ui_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * Due to races between write-back forced by budgeting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * (see 'sync_some_inodes()') and background write-back, the inode may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * have already been synchronized, do not do this again. This might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * also happen if it was synchronized in an VFS operation, e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * 'ubifs_link()'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (!ui->dirty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) mutex_unlock(&ui->ui_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * As an optimization, do not write orphan inodes to the media just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * because this is not needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) dbg_gen("inode %lu, mode %#x, nlink %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) inode->i_ino, (int)inode->i_mode, inode->i_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (inode->i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) err = ubifs_jnl_write_inode(c, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) ubifs_err(c, "can't write inode %lu, error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) inode->i_ino, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) err = dbg_check_inode_size(c, inode, ui->ui_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ui->dirty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) mutex_unlock(&ui->ui_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ubifs_release_dirty_inode_budget(c, ui);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static int ubifs_drop_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int drop = generic_drop_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (!drop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) drop = fscrypt_drop_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static void ubifs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct ubifs_info *c = inode->i_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct ubifs_inode *ui = ubifs_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (ui->xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * Extended attribute inode deletions are fully handled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * 'ubifs_removexattr()'. These inodes are special and have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * limited usage, so there is nothing to do here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) dbg_gen("inode %lu, mode %#x", inode->i_ino, (int)inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ubifs_assert(c, !atomic_read(&inode->i_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (inode->i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (is_bad_inode(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ui->ui_size = inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) err = ubifs_jnl_delete_inode(c, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * Worst case we have a lost orphan inode wasting space, so a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * simple error message is OK here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ubifs_err(c, "can't delete inode %lu, error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) inode->i_ino, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (ui->dirty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ubifs_release_dirty_inode_budget(c, ui);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /* We've deleted something - clean the "no space" flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) c->bi.nospace = c->bi.nospace_rp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) fscrypt_put_encryption_info(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static void ubifs_dirty_inode(struct inode *inode, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct ubifs_info *c = inode->i_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct ubifs_inode *ui = ubifs_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ubifs_assert(c, mutex_is_locked(&ui->ui_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!ui->dirty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ui->dirty = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) dbg_gen("inode %lu", inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int ubifs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct ubifs_info *c = dentry->d_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) unsigned long long free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) __le32 *uuid = (__le32 *)c->uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) free = ubifs_get_free_space(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dbg_gen("free space %lld bytes (%lld blocks)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) free, free >> UBIFS_BLOCK_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) buf->f_type = UBIFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) buf->f_bsize = UBIFS_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) buf->f_blocks = c->block_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) buf->f_bfree = free >> UBIFS_BLOCK_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (free > c->report_rp_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) buf->f_bavail = (free - c->report_rp_size) >> UBIFS_BLOCK_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) buf->f_bavail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) buf->f_files = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) buf->f_ffree = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) buf->f_namelen = UBIFS_MAX_NLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) buf->f_fsid.val[0] = le32_to_cpu(uuid[0]) ^ le32_to_cpu(uuid[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) buf->f_fsid.val[1] = le32_to_cpu(uuid[1]) ^ le32_to_cpu(uuid[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ubifs_assert(c, buf->f_bfree <= c->block_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int ubifs_show_options(struct seq_file *s, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct ubifs_info *c = root->d_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (c->mount_opts.unmount_mode == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) seq_puts(s, ",fast_unmount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) else if (c->mount_opts.unmount_mode == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) seq_puts(s, ",norm_unmount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (c->mount_opts.bulk_read == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) seq_puts(s, ",bulk_read");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) else if (c->mount_opts.bulk_read == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) seq_puts(s, ",no_bulk_read");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (c->mount_opts.chk_data_crc == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) seq_puts(s, ",chk_data_crc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) else if (c->mount_opts.chk_data_crc == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) seq_puts(s, ",no_chk_data_crc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (c->mount_opts.override_compr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) seq_printf(s, ",compr=%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) ubifs_compr_name(c, c->mount_opts.compr_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) seq_printf(s, ",assert=%s", ubifs_assert_action_name(c));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) seq_printf(s, ",ubi=%d,vol=%d", c->vi.ubi_num, c->vi.vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static int ubifs_sync_fs(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct ubifs_info *c = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * Zero @wait is just an advisory thing to help the file system shove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * lots of data into the queues, and there will be the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * '->sync_fs()' call, with non-zero @wait.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * Synchronize write buffers, because 'ubifs_run_commit()' does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * do this if it waits for an already running commit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) for (i = 0; i < c->jhead_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * Strictly speaking, it is not necessary to commit the journal here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * synchronizing write-buffers would be enough. But committing makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * UBIFS free space predictions much more accurate, so we want to let
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * the user be able to get more accurate results of 'statfs()' after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * they synchronize the file system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) err = ubifs_run_commit(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return ubi_sync(c->vi.ubi_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * init_constants_early - initialize UBIFS constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * This function initialize UBIFS constants which do not need the superblock to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * be read. It also checks that the UBI volume satisfies basic UBIFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * requirements. Returns zero in case of success and a negative error code in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static int init_constants_early(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (c->vi.corrupted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ubifs_warn(c, "UBI volume is corrupted - read-only mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) c->ro_media = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (c->di.ro_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ubifs_msg(c, "read-only UBI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) c->ro_media = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (c->vi.vol_type == UBI_STATIC_VOLUME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) ubifs_msg(c, "static UBI volume - read-only mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) c->ro_media = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) c->leb_cnt = c->vi.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) c->leb_size = c->vi.usable_leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) c->leb_start = c->di.leb_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) c->half_leb_size = c->leb_size / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) c->min_io_size = c->di.min_io_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) c->min_io_shift = fls(c->min_io_size) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) c->max_write_size = c->di.max_write_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) c->max_write_shift = fls(c->max_write_size) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (c->leb_size < UBIFS_MIN_LEB_SZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ubifs_errc(c, "too small LEBs (%d bytes), min. is %d bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) c->leb_size, UBIFS_MIN_LEB_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (c->leb_cnt < UBIFS_MIN_LEB_CNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) ubifs_errc(c, "too few LEBs (%d), min. is %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) c->leb_cnt, UBIFS_MIN_LEB_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (!is_power_of_2(c->min_io_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) ubifs_errc(c, "bad min. I/O size %d", c->min_io_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * Maximum write size has to be greater or equivalent to min. I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * size, and be multiple of min. I/O size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (c->max_write_size < c->min_io_size ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) c->max_write_size % c->min_io_size ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) !is_power_of_2(c->max_write_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) ubifs_errc(c, "bad write buffer size %d for %d min. I/O unit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) c->max_write_size, c->min_io_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * UBIFS aligns all node to 8-byte boundary, so to make function in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * io.c simpler, assume minimum I/O unit size to be 8 bytes if it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * less than 8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (c->min_io_size < 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) c->min_io_size = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) c->min_io_shift = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (c->max_write_size < c->min_io_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) c->max_write_size = c->min_io_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) c->max_write_shift = c->min_io_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) c->mst_node_alsz = ALIGN(UBIFS_MST_NODE_SZ, c->min_io_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * Initialize node length ranges which are mostly needed for node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * length validation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) c->ranges[UBIFS_PAD_NODE].len = UBIFS_PAD_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) c->ranges[UBIFS_SB_NODE].len = UBIFS_SB_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) c->ranges[UBIFS_MST_NODE].len = UBIFS_MST_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) c->ranges[UBIFS_REF_NODE].len = UBIFS_REF_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) c->ranges[UBIFS_TRUN_NODE].len = UBIFS_TRUN_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) c->ranges[UBIFS_CS_NODE].len = UBIFS_CS_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) c->ranges[UBIFS_AUTH_NODE].min_len = UBIFS_AUTH_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) c->ranges[UBIFS_AUTH_NODE].max_len = UBIFS_AUTH_NODE_SZ +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) UBIFS_MAX_HMAC_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) c->ranges[UBIFS_SIG_NODE].min_len = UBIFS_SIG_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) c->ranges[UBIFS_SIG_NODE].max_len = c->leb_size - UBIFS_SB_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) c->ranges[UBIFS_ORPH_NODE].min_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) UBIFS_ORPH_NODE_SZ + sizeof(__le64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) c->ranges[UBIFS_ORPH_NODE].max_len = c->leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) c->ranges[UBIFS_DENT_NODE].min_len = UBIFS_DENT_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) c->ranges[UBIFS_DENT_NODE].max_len = UBIFS_MAX_DENT_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) c->ranges[UBIFS_XENT_NODE].min_len = UBIFS_XENT_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) c->ranges[UBIFS_XENT_NODE].max_len = UBIFS_MAX_XENT_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) c->ranges[UBIFS_DATA_NODE].min_len = UBIFS_DATA_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) c->ranges[UBIFS_DATA_NODE].max_len = UBIFS_MAX_DATA_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) * Minimum indexing node size is amended later when superblock is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * read and the key length is known.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) c->ranges[UBIFS_IDX_NODE].min_len = UBIFS_IDX_NODE_SZ + UBIFS_BRANCH_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * Maximum indexing node size is amended later when superblock is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * read and the fanout is known.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * Initialize dead and dark LEB space watermarks. See gc.c for comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * about these values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) * Calculate how many bytes would be wasted at the end of LEB if it was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) * fully filled with data nodes of maximum size. This is used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * calculations when reporting free space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /* Buffer size for bulk-reads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) c->max_bu_buf_len = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (c->max_bu_buf_len > c->leb_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) c->max_bu_buf_len = c->leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) /* Log is ready, preserve one LEB for commits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) c->min_log_bytes = c->leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * bud_wbuf_callback - bud LEB write-buffer synchronization call-back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * @lnum: LEB the write-buffer was synchronized to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * @free: how many free bytes left in this LEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * @pad: how many bytes were padded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * This is a callback function which is called by the I/O unit when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * write-buffer is synchronized. We need this to correctly maintain space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * accounting in bud logical eraseblocks. This function returns zero in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * success and a negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) * This function actually belongs to the journal, but we keep it here because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) * we want to keep it static.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static int bud_wbuf_callback(struct ubifs_info *c, int lnum, int free, int pad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return ubifs_update_one_lp(c, lnum, free, pad, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * init_constants_sb - initialize UBIFS constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * This is a helper function which initializes various UBIFS constants after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * the superblock has been read. It also checks various UBIFS parameters and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * makes sure they are all right. Returns zero in case of success and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static int init_constants_sb(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) int tmp, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) long long tmp64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) c->main_bytes = (long long)c->main_lebs * c->leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) c->max_znode_sz = sizeof(struct ubifs_znode) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) c->fanout * sizeof(struct ubifs_zbranch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) tmp = ubifs_idx_node_sz(c, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) c->ranges[UBIFS_IDX_NODE].min_len = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) c->min_idx_node_sz = ALIGN(tmp, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) tmp = ubifs_idx_node_sz(c, c->fanout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) c->ranges[UBIFS_IDX_NODE].max_len = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) c->max_idx_node_sz = ALIGN(tmp, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /* Make sure LEB size is large enough to fit full commit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) tmp = ALIGN(tmp, c->min_io_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (tmp > c->leb_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ubifs_err(c, "too small LEB size %d, at least %d needed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) c->leb_size, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * Make sure that the log is large enough to fit reference nodes for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * all buds plus one reserved LEB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) tmp64 = c->max_bud_bytes + c->leb_size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) c->max_bud_cnt = div_u64(tmp64, c->leb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) tmp /= c->leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) tmp += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (c->log_lebs < tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) ubifs_err(c, "too small log %d LEBs, required min. %d LEBs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) c->log_lebs, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) * When budgeting we assume worst-case scenarios when the pages are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * be compressed and direntries are of the maximum size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * Note, data, which may be stored in inodes is budgeted separately, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * it is not included into 'c->bi.inode_budget'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) c->bi.page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) c->bi.inode_budget = UBIFS_INO_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) c->bi.dent_budget = UBIFS_MAX_DENT_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * When the amount of flash space used by buds becomes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * 'c->max_bud_bytes', UBIFS just blocks all writers and starts commit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) * The writers are unblocked when the commit is finished. To avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * writers to be blocked UBIFS initiates background commit in advance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * when number of bud bytes becomes above the limit defined below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) c->bg_bud_bytes = (c->max_bud_bytes * 13) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) * Ensure minimum journal size. All the bytes in the journal heads are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) * considered to be used, when calculating the current journal usage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * Consequently, if the journal is too small, UBIFS will treat it as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * always full.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (c->bg_bud_bytes < tmp64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) c->bg_bud_bytes = tmp64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if (c->max_bud_bytes < tmp64 + c->leb_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) c->max_bud_bytes = tmp64 + c->leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) err = ubifs_calc_lpt_geom(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* Initialize effective LEB size used in budgeting calculations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) c->idx_leb_size = c->leb_size - c->max_idx_node_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * init_constants_master - initialize UBIFS constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) * This is a helper function which initializes various UBIFS constants after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * the master node has been read. It also checks various UBIFS parameters and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) * makes sure they are all right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static void init_constants_master(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) long long tmp64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) c->report_rp_size = ubifs_reported_space(c, c->rp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * Calculate total amount of FS blocks. This number is not used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * internally because it does not make much sense for UBIFS, but it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * necessary to report something for the 'statfs()' call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * Subtract the LEB reserved for GC, the LEB which is reserved for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) * deletions, minimum LEBs for the index, and assume only one journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * head is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) tmp64 *= (long long)c->leb_size - c->leb_overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) tmp64 = ubifs_reported_space(c, tmp64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) * take_gc_lnum - reserve GC LEB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * This function ensures that the LEB reserved for garbage collection is marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) * as "taken" in lprops. We also have to set free space to LEB size and dirty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * space to zero, because lprops may contain out-of-date information if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * file-system was un-mounted before it has been committed. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * returns zero in case of success and a negative error code in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) static int take_gc_lnum(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (c->gc_lnum == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) ubifs_err(c, "no LEB for GC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) /* And we have to tell lprops that this LEB is taken */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) LPROPS_TAKEN, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * alloc_wbufs - allocate write-buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * This helper function allocates and initializes UBIFS write-buffers. Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * zero in case of success and %-ENOMEM in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) static int alloc_wbufs(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) c->jheads = kcalloc(c->jhead_cnt, sizeof(struct ubifs_jhead),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (!c->jheads)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /* Initialize journal heads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) for (i = 0; i < c->jhead_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) INIT_LIST_HEAD(&c->jheads[i].buds_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) err = ubifs_wbuf_init(c, &c->jheads[i].wbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) c->jheads[i].wbuf.jhead = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) c->jheads[i].grouped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) c->jheads[i].log_hash = ubifs_hash_get_desc(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (IS_ERR(c->jheads[i].log_hash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) err = PTR_ERR(c->jheads[i].log_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * Garbage Collector head does not need to be synchronized by timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * Also GC head nodes are not grouped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) c->jheads[GCHD].wbuf.no_timer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) c->jheads[GCHD].grouped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) kfree(c->jheads[i].log_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) * free_wbufs - free write-buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) static void free_wbufs(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (c->jheads) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) for (i = 0; i < c->jhead_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) kfree(c->jheads[i].wbuf.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) kfree(c->jheads[i].wbuf.inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) kfree(c->jheads[i].log_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) kfree(c->jheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) c->jheads = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) * free_orphans - free orphans.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) static void free_orphans(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) struct ubifs_orphan *orph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) while (c->orph_dnext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) orph = c->orph_dnext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) c->orph_dnext = orph->dnext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) list_del(&orph->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) kfree(orph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) while (!list_empty(&c->orph_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) orph = list_entry(c->orph_list.next, struct ubifs_orphan, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) list_del(&orph->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) kfree(orph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) ubifs_err(c, "orphan list not empty at unmount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) vfree(c->orph_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) c->orph_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * free_buds - free per-bud objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) static void free_buds(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) struct ubifs_bud *bud, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) kfree(bud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) * check_volume_empty - check if the UBI volume is empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) * This function checks if the UBIFS volume is empty by looking if its LEBs are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * mapped or not. The result of checking is stored in the @c->empty variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) * Returns zero in case of success and a negative error code in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) * failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) static int check_volume_empty(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) int lnum, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) c->empty = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) for (lnum = 0; lnum < c->leb_cnt; lnum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) err = ubifs_is_mapped(c, lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (unlikely(err < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) if (err == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) c->empty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) * UBIFS mount options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) * Opt_fast_unmount: do not run a journal commit before un-mounting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) * Opt_norm_unmount: run a journal commit before un-mounting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) * Opt_bulk_read: enable bulk-reads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) * Opt_no_bulk_read: disable bulk-reads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) * Opt_chk_data_crc: check CRCs when reading data nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) * Opt_no_chk_data_crc: do not check CRCs when reading data nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) * Opt_override_compr: override default compressor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) * Opt_assert: set ubifs_assert() action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) * Opt_auth_key: The key name used for authentication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) * Opt_auth_hash_name: The hash type used for authentication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) * Opt_err: just end of array marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) Opt_fast_unmount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) Opt_norm_unmount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) Opt_bulk_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) Opt_no_bulk_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) Opt_chk_data_crc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) Opt_no_chk_data_crc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) Opt_override_compr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) Opt_assert,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) Opt_auth_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) Opt_auth_hash_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) Opt_ignore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) Opt_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) {Opt_fast_unmount, "fast_unmount"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) {Opt_norm_unmount, "norm_unmount"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) {Opt_bulk_read, "bulk_read"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) {Opt_no_bulk_read, "no_bulk_read"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) {Opt_chk_data_crc, "chk_data_crc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) {Opt_no_chk_data_crc, "no_chk_data_crc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) {Opt_override_compr, "compr=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) {Opt_auth_key, "auth_key=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) {Opt_auth_hash_name, "auth_hash_name=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) {Opt_ignore, "ubi=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) {Opt_ignore, "vol=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) {Opt_assert, "assert=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) {Opt_err, NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * parse_standard_option - parse a standard mount option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) * @option: the option to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) * Normally, standard mount options like "sync" are passed to file-systems as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * flags. However, when a "rootflags=" kernel boot parameter is used, they may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) * be present in the options string. This function tries to deal with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * situation and parse standard options. Returns 0 if the option was not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * recognized, and the corresponding integer flag if it was.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) * UBIFS is only interested in the "sync" option, so do not check for anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) * else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) static int parse_standard_option(const char *option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) pr_notice("UBIFS: parse %s\n", option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (!strcmp(option, "sync"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) return SB_SYNCHRONOUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) * ubifs_parse_options - parse mount parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) * @options: parameters to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * @is_remount: non-zero if this is FS re-mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * This function parses UBIFS mount options and returns zero in case success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * and a negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) static int ubifs_parse_options(struct ubifs_info *c, char *options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) int is_remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) while ((p = strsep(&options, ","))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * %Opt_fast_unmount and %Opt_norm_unmount options are ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) * We accept them in order to be backward-compatible. But this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) * should be removed at some point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) case Opt_fast_unmount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) c->mount_opts.unmount_mode = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) case Opt_norm_unmount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) c->mount_opts.unmount_mode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) case Opt_bulk_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) c->mount_opts.bulk_read = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) c->bulk_read = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) case Opt_no_bulk_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) c->mount_opts.bulk_read = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) c->bulk_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) case Opt_chk_data_crc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) c->mount_opts.chk_data_crc = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) c->no_chk_data_crc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) case Opt_no_chk_data_crc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) c->mount_opts.chk_data_crc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) c->no_chk_data_crc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) case Opt_override_compr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) char *name = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) if (!strcmp(name, "none"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) c->mount_opts.compr_type = UBIFS_COMPR_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) else if (!strcmp(name, "lzo"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) c->mount_opts.compr_type = UBIFS_COMPR_LZO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) else if (!strcmp(name, "zlib"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) else if (!strcmp(name, "zstd"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) c->mount_opts.compr_type = UBIFS_COMPR_ZSTD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) c->mount_opts.override_compr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) c->default_compr = c->mount_opts.compr_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) case Opt_assert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) char *act = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (!act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (!strcmp(act, "report"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) c->assert_action = ASSACT_REPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) else if (!strcmp(act, "read-only"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) c->assert_action = ASSACT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) else if (!strcmp(act, "panic"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) c->assert_action = ASSACT_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) ubifs_err(c, "unknown assert action \"%s\"", act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) kfree(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) kfree(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) case Opt_auth_key:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (!is_remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) c->auth_key_name = kstrdup(args[0].from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) if (!c->auth_key_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) case Opt_auth_hash_name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (!is_remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) c->auth_hash_name = kstrdup(args[0].from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) if (!c->auth_hash_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) case Opt_ignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) unsigned long flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) struct super_block *sb = c->vfs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) flag = parse_standard_option(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (!flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) ubifs_err(c, "unrecognized mount option \"%s\" or missing value",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) sb->s_flags |= flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) * ubifs_release_options - release mount parameters which have been dumped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) static void ubifs_release_options(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) kfree(c->auth_key_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) c->auth_key_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) kfree(c->auth_hash_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) c->auth_hash_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) * destroy_journal - destroy journal data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) * This function destroys journal data structures including those that may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) * been created by recovery functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) static void destroy_journal(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) while (!list_empty(&c->unclean_leb_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) struct ubifs_unclean_leb *ucleb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) ucleb = list_entry(c->unclean_leb_list.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) struct ubifs_unclean_leb, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) list_del(&ucleb->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) kfree(ucleb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) while (!list_empty(&c->old_buds)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) struct ubifs_bud *bud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) bud = list_entry(c->old_buds.next, struct ubifs_bud, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) list_del(&bud->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) kfree(bud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) ubifs_destroy_idx_gc(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) ubifs_destroy_size_tree(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) ubifs_tnc_close(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) free_buds(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) * bu_init - initialize bulk-read information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) static void bu_init(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) ubifs_assert(c, c->bulk_read == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (c->bu.buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) return; /* Already initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) c->bu.buf = kmalloc(c->max_bu_buf_len, GFP_KERNEL | __GFP_NOWARN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (!c->bu.buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if (c->max_bu_buf_len > UBIFS_KMALLOC_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) c->max_bu_buf_len = UBIFS_KMALLOC_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) /* Just disable bulk-read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) ubifs_warn(c, "cannot allocate %d bytes of memory for bulk-read, disabling it",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) c->max_bu_buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) c->mount_opts.bulk_read = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) c->bulk_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * check_free_space - check if there is enough free space to mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) * This function makes sure UBIFS has enough free space to be mounted in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * read/write mode. UBIFS must always have some free space to allow deletions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) static int check_free_space(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) ubifs_assert(c, c->dark_wm > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) ubifs_err(c, "insufficient free space to mount in R/W mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) ubifs_dump_budg(c, &c->bi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) ubifs_dump_lprops(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) * mount_ubifs - mount UBIFS file-system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) * This function mounts UBIFS file system. Returns zero in case of success and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) * a negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) static int mount_ubifs(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) long long x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) size_t sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) c->ro_mount = !!sb_rdonly(c->vfs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) /* Suppress error messages while probing if SB_SILENT is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) c->probing = !!(c->vfs_sb->s_flags & SB_SILENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) err = init_constants_early(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) err = ubifs_debugging_init(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) err = check_volume_empty(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) if (c->empty && (c->ro_mount || c->ro_media)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) * This UBI volume is empty, and read-only, or the file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * is mounted read-only - we cannot format it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) ubifs_err(c, "can't format empty UBI volume: read-only %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) c->ro_media ? "UBI volume" : "mount");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) if (c->ro_media && !c->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) ubifs_err(c, "cannot mount read-write - read-only media");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) * The requirement for the buffer is that it should fit indexing B-tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) * height amount of integers. We assume the height if the TNC tree will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) * never exceed 64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) c->bottom_up_buf = kmalloc_array(BOTTOM_UP_HEIGHT, sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) if (!c->bottom_up_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) c->sbuf = vmalloc(c->leb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (!c->sbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if (!c->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) c->ileb_buf = vmalloc(c->leb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) if (!c->ileb_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (c->bulk_read == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) bu_init(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (!c->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) UBIFS_CIPHER_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) if (!c->write_reserve_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) c->mounting = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (c->auth_key_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) if (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) err = ubifs_init_authentication(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) ubifs_err(c, "auth_key_name, but UBIFS is built without"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) " authentication support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) err = ubifs_read_superblock(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) goto out_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) c->probing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * Make sure the compressor which is set as default in the superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) * or overridden by mount options is actually compiled in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) if (!ubifs_compr_present(c, c->default_compr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) ubifs_err(c, "'compressor \"%s\" is not compiled in",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) ubifs_compr_name(c, c->default_compr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) err = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) goto out_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) err = init_constants_sb(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) goto out_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) sz = ALIGN(c->max_idx_node_sz, c->min_io_size) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) c->cbuf = kmalloc(sz, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (!c->cbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) goto out_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) err = alloc_wbufs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) goto out_cbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) if (!c->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) /* Create background thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) if (IS_ERR(c->bgt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) err = PTR_ERR(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) c->bgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) ubifs_err(c, "cannot spawn \"%s\", error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) c->bgt_name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) goto out_wbufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) wake_up_process(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) err = ubifs_read_master(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) goto out_master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) init_constants_master(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) ubifs_msg(c, "recovery needed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) c->need_recovery = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (c->need_recovery && !c->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) err = ubifs_recover_inl_heads(c, c->sbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) goto out_master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) err = ubifs_lpt_init(c, 1, !c->ro_mount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) goto out_master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) if (!c->ro_mount && c->space_fixup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) err = ubifs_fixup_free_space(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) goto out_lpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) if (!c->ro_mount && !c->need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) * Set the "dirty" flag so that if we reboot uncleanly we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) * will notice this immediately on the next mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) err = ubifs_write_master(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) goto out_lpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) * Handle offline signed images: Now that the master node is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) * written and its validation no longer depends on the hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) * in the superblock, we can update the offline signed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) * superblock with a HMAC version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) if (ubifs_authenticated(c) && ubifs_hmac_zero(c, c->sup_node->hmac)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) err = ubifs_hmac_wkm(c, c->sup_node->hmac_wkm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) goto out_lpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) c->superblock_need_write = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (!c->ro_mount && c->superblock_need_write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) err = ubifs_write_sb_node(c, c->sup_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) goto out_lpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) c->superblock_need_write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) err = dbg_check_idx_size(c, c->bi.old_idx_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) goto out_lpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) err = ubifs_replay_journal(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) goto out_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) /* Calculate 'min_idx_lebs' after journal replay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) if (!c->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) int lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) err = check_free_space(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) /* Check for enough log space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) lnum = c->lhead_lnum + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) if (lnum >= UBIFS_LOG_LNUM + c->log_lebs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) lnum = UBIFS_LOG_LNUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) if (lnum == c->ltail_lnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) err = ubifs_consolidate_log(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) if (c->need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) if (!ubifs_authenticated(c)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) err = ubifs_recover_size(c, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) err = ubifs_rcvry_gc_commit(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) if (ubifs_authenticated(c)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) err = ubifs_recover_size(c, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) err = take_gc_lnum(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) * GC LEB may contain garbage if there was an unclean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) * reboot, and it should be un-mapped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) err = ubifs_leb_unmap(c, c->gc_lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) err = dbg_check_lprops(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) } else if (c->need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) err = ubifs_recover_size(c, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) * Even if we mount read-only, we have to set space in GC LEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) * to proper value because this affects UBIFS free space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) * reporting. We do not want to have a situation when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) * re-mounting from R/O to R/W changes amount of free space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) err = take_gc_lnum(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) goto out_orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) spin_lock(&ubifs_infos_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) list_add_tail(&c->infos_list, &ubifs_infos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) spin_unlock(&ubifs_infos_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) if (c->need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) if (c->ro_mount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) ubifs_msg(c, "recovery deferred");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) c->need_recovery = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) ubifs_msg(c, "recovery completed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) * GC LEB has to be empty and taken at this point. But
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) * the journal head LEBs may also be accounted as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) * "empty taken" if they are empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) ubifs_assert(c, c->lst.taken_empty_lebs > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) ubifs_assert(c, c->lst.taken_empty_lebs > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) err = dbg_check_filesystem(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) goto out_infos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) dbg_debugfs_init_fs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) c->mounting = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) ubifs_msg(c, "UBIFS: mounted UBI device %d, volume %d, name \"%s\"%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) c->vi.ubi_num, c->vi.vol_id, c->vi.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) c->ro_mount ? ", R/O mode" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) x = (long long)c->main_lebs * c->leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) y = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) ubifs_msg(c, "LEB size: %d bytes (%d KiB), min./max. I/O unit sizes: %d bytes/%d bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) c->leb_size, c->leb_size >> 10, c->min_io_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) c->max_write_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) ubifs_msg(c, "FS size: %lld bytes (%lld MiB, %d LEBs), journal size %lld bytes (%lld MiB, %d LEBs)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) x, x >> 20, c->main_lebs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) y, y >> 20, c->log_lebs + c->max_bud_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) ubifs_msg(c, "reserved for root: %llu bytes (%llu KiB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) c->report_rp_size, c->report_rp_size >> 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) ubifs_msg(c, "media format: w%d/r%d (latest is w%d/r%d), UUID %pUB%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) c->fmt_version, c->ro_compat_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION, c->uuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) c->big_lpt ? ", big LPT model" : ", small LPT model");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) dbg_gen("default compressor: %s", ubifs_compr_name(c, c->default_compr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) dbg_gen("data journal heads: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) c->jhead_cnt - NONDATA_JHEADS_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) dbg_gen("log LEBs: %d (%d - %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) c->log_lebs, UBIFS_LOG_LNUM, c->log_last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) dbg_gen("LPT area LEBs: %d (%d - %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) c->lpt_lebs, c->lpt_first, c->lpt_last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) dbg_gen("orphan area LEBs: %d (%d - %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) c->orph_lebs, c->orph_first, c->orph_last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) dbg_gen("main area LEBs: %d (%d - %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) c->main_lebs, c->main_first, c->leb_cnt - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) dbg_gen("index LEBs: %d", c->lst.idx_lebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) dbg_gen("total index bytes: %lld (%lld KiB, %lld MiB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) c->bi.old_idx_sz, c->bi.old_idx_sz >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) c->bi.old_idx_sz >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) dbg_gen("key hash type: %d", c->key_hash_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) dbg_gen("tree fanout: %d", c->fanout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) dbg_gen("reserved GC LEB: %d", c->gc_lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) dbg_gen("max. znode size %d", c->max_znode_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) dbg_gen("max. index node size %d", c->max_idx_node_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) dbg_gen("node sizes: data %zu, inode %zu, dentry %zu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) UBIFS_DATA_NODE_SZ, UBIFS_INO_NODE_SZ, UBIFS_DENT_NODE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) dbg_gen("node sizes: trun %zu, sb %zu, master %zu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) dbg_gen("node sizes: ref %zu, cmt. start %zu, orph %zu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) dbg_gen("max. node sizes: data %zu, inode %zu dentry %zu, idx %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) dbg_gen("dead watermark: %d", c->dead_wm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) dbg_gen("dark watermark: %d", c->dark_wm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) dbg_gen("LEB overhead: %d", c->leb_overhead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) x = (long long)c->main_lebs * c->dark_wm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) dbg_gen("max. dark space: %lld (%lld KiB, %lld MiB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) x, x >> 10, x >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) dbg_gen("maximum bud bytes: %lld (%lld KiB, %lld MiB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) c->max_bud_bytes, c->max_bud_bytes >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) c->max_bud_bytes >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) dbg_gen("BG commit bud bytes: %lld (%lld KiB, %lld MiB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) c->bg_bud_bytes, c->bg_bud_bytes >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) c->bg_bud_bytes >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) dbg_gen("current bud bytes %lld (%lld KiB, %lld MiB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) c->bud_bytes, c->bud_bytes >> 10, c->bud_bytes >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) dbg_gen("max. seq. number: %llu", c->max_sqnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) dbg_gen("commit number: %llu", c->cmt_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) dbg_gen("max. xattrs per inode: %d", ubifs_xattr_max_cnt(c));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) dbg_gen("max orphans: %d", c->max_orphans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) out_infos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) spin_lock(&ubifs_infos_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) list_del(&c->infos_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) spin_unlock(&ubifs_infos_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) out_orphans:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) free_orphans(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) out_journal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) destroy_journal(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) out_lpt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) ubifs_lpt_free(c, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) out_master:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) kfree(c->mst_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) kfree(c->rcvrd_mst_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) if (c->bgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) kthread_stop(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) out_wbufs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) free_wbufs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) out_cbuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) kfree(c->cbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) out_auth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) ubifs_exit_authentication(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) kfree(c->write_reserve_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) kfree(c->bu.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) vfree(c->ileb_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) vfree(c->sbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) kfree(c->bottom_up_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) kfree(c->sup_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) ubifs_debugging_exit(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) * ubifs_umount - un-mount UBIFS file-system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) * Note, this function is called to free allocated resourced when un-mounting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) * as well as free resources when an error occurred while we were half way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) * through mounting (error path cleanup function). So it has to make sure the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) * resource was actually allocated before freeing it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) static void ubifs_umount(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) dbg_gen("un-mounting UBI device %d, volume %d", c->vi.ubi_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) c->vi.vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) dbg_debugfs_exit_fs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) spin_lock(&ubifs_infos_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) list_del(&c->infos_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) spin_unlock(&ubifs_infos_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (c->bgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) kthread_stop(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) destroy_journal(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) free_wbufs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) free_orphans(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) ubifs_lpt_free(c, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) ubifs_exit_authentication(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) ubifs_release_options(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) kfree(c->cbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) kfree(c->rcvrd_mst_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) kfree(c->mst_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) kfree(c->write_reserve_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) kfree(c->bu.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) vfree(c->ileb_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) vfree(c->sbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) kfree(c->bottom_up_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) kfree(c->sup_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) ubifs_debugging_exit(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) * ubifs_remount_rw - re-mount in read-write mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) * UBIFS avoids allocating many unnecessary resources when mounted in read-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) * mode. This function allocates the needed resources and re-mounts UBIFS in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) * read-write mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) static int ubifs_remount_rw(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) int err, lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) if (c->rw_incompat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) ubifs_err(c, "the file-system is not R/W-compatible");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) ubifs_msg(c, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) c->fmt_version, c->ro_compat_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) mutex_lock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) dbg_save_space_info(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) c->remounting_rw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) c->ro_mount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) if (c->space_fixup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) err = ubifs_fixup_free_space(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) err = check_free_space(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) if (c->need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) ubifs_msg(c, "completing deferred recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) err = ubifs_write_rcvrd_mst_node(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) if (!ubifs_authenticated(c)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) err = ubifs_recover_size(c, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) err = ubifs_clean_lebs(c, c->sbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) err = ubifs_recover_inl_heads(c, c->sbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) /* A readonly mount is not allowed to have orphans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) ubifs_assert(c, c->tot_orphans == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) err = ubifs_clear_orphans(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) err = ubifs_write_master(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) if (c->superblock_need_write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) struct ubifs_sb_node *sup = c->sup_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) err = ubifs_write_sb_node(c, sup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) c->superblock_need_write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) c->ileb_buf = vmalloc(c->leb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) if (!c->ileb_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) UBIFS_CIPHER_BLOCK_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) if (!c->write_reserve_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) err = ubifs_lpt_init(c, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) /* Create background thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) if (IS_ERR(c->bgt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) err = PTR_ERR(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) c->bgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) ubifs_err(c, "cannot spawn \"%s\", error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) c->bgt_name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) wake_up_process(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) c->orph_buf = vmalloc(c->leb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) if (!c->orph_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) /* Check for enough log space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) lnum = c->lhead_lnum + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) if (lnum >= UBIFS_LOG_LNUM + c->log_lebs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) lnum = UBIFS_LOG_LNUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) if (lnum == c->ltail_lnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) err = ubifs_consolidate_log(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) if (c->need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) err = ubifs_rcvry_gc_commit(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) if (ubifs_authenticated(c)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) err = ubifs_recover_size(c, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) err = ubifs_leb_unmap(c, c->gc_lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) dbg_gen("re-mounted read-write");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) c->remounting_rw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) if (c->need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) c->need_recovery = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) ubifs_msg(c, "deferred recovery completed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) * Do not run the debugging space check if the were doing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) * recovery, because when we saved the information we had the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) * file-system in a state where the TNC and lprops has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) * modified in memory, but all the I/O operations (including a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) * commit) were deferred. So the file-system was in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) * "non-committed" state. Now the file-system is in committed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) * state, and of course the amount of free space will change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) * because, for example, the old index size was imprecise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) err = dbg_check_space_info(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) mutex_unlock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) c->ro_mount = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) vfree(c->orph_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) c->orph_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if (c->bgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) kthread_stop(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) c->bgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) kfree(c->write_reserve_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) c->write_reserve_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) vfree(c->ileb_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) c->ileb_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) ubifs_lpt_free(c, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) c->remounting_rw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) mutex_unlock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) * ubifs_remount_ro - re-mount in read-only mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) * We assume VFS has stopped writing. Possibly the background thread could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) * running a commit, however kthread_stop will wait in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) static void ubifs_remount_ro(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) ubifs_assert(c, !c->need_recovery);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) ubifs_assert(c, !c->ro_mount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) mutex_lock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) if (c->bgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) kthread_stop(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) c->bgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) dbg_save_space_info(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) for (i = 0; i < c->jhead_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) ubifs_ro_mode(c, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) err = ubifs_write_master(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) ubifs_ro_mode(c, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) vfree(c->orph_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) c->orph_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) kfree(c->write_reserve_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) c->write_reserve_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) vfree(c->ileb_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) c->ileb_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) ubifs_lpt_free(c, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) c->ro_mount = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) err = dbg_check_space_info(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) ubifs_ro_mode(c, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) mutex_unlock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) static void ubifs_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) struct ubifs_info *c = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) ubifs_msg(c, "un-mount UBI device %d", c->vi.ubi_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) * The following asserts are only valid if there has not been a failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) * of the media. For example, there will be dirty inodes if we failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) * to write them back because of I/O errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) if (!c->ro_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) ubifs_assert(c, c->bi.idx_growth == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) ubifs_assert(c, c->bi.dd_growth == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) ubifs_assert(c, c->bi.data_growth == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) * The 'c->umount_lock' prevents races between UBIFS memory shrinker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) * and file system un-mount. Namely, it prevents the shrinker from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) * picking this superblock for shrinking - it will be just skipped if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) * the mutex is locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) mutex_lock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) if (!c->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) * First of all kill the background thread to make sure it does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) * not interfere with un-mounting and freeing resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) if (c->bgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) kthread_stop(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) c->bgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) * On fatal errors c->ro_error is set to 1, in which case we do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) * not write the master node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) if (!c->ro_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) /* Synchronize write-buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) for (i = 0; i < c->jhead_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) ubifs_ro_mode(c, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) * We are being cleanly unmounted which means the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) * orphans were killed - indicate this in the master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) * node. Also save the reserved GC LEB number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) err = ubifs_write_master(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) * Recovery will attempt to fix the master area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) * next mount, so we just print a message and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) * continue to unmount normally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) ubifs_err(c, "failed to write master node, error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) for (i = 0; i < c->jhead_cnt; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) /* Make sure write-buffer timers are canceled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) hrtimer_cancel(&c->jheads[i].wbuf.timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) ubifs_umount(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) ubi_close_volume(c->ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) mutex_unlock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) struct ubifs_info *c = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) dbg_gen("old flags %#lx, new flags %#x", sb->s_flags, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) err = ubifs_parse_options(c, data, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) ubifs_err(c, "invalid or unknown remount parameter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (c->ro_mount && !(*flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) if (c->ro_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) ubifs_msg(c, "cannot re-mount R/W due to prior errors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) if (c->ro_media) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) ubifs_msg(c, "cannot re-mount R/W - UBI volume is R/O");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) err = ubifs_remount_rw(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) } else if (!c->ro_mount && (*flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) if (c->ro_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) ubifs_msg(c, "cannot re-mount R/O due to prior errors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) ubifs_remount_ro(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) if (c->bulk_read == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) bu_init(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) dbg_gen("disable bulk-read");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) mutex_lock(&c->bu_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) kfree(c->bu.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) c->bu.buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) mutex_unlock(&c->bu_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) if (!c->need_recovery)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) ubifs_assert(c, c->lst.taken_empty_lebs > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) const struct super_operations ubifs_super_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) .alloc_inode = ubifs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) .free_inode = ubifs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) .put_super = ubifs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) .write_inode = ubifs_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) .drop_inode = ubifs_drop_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) .evict_inode = ubifs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) .statfs = ubifs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) .dirty_inode = ubifs_dirty_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) .remount_fs = ubifs_remount_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) .show_options = ubifs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) .sync_fs = ubifs_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) * open_ubi - parse UBI device name string and open the UBI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) * @name: UBI volume name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) * @mode: UBI volume open mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) * The primary method of mounting UBIFS is by specifying the UBI volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) * character device node path. However, UBIFS may also be mounted withoug any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) * character device node using one of the following methods:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) * o ubiX_Y - mount UBI device number X, volume Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) * o ubiY - mount UBI device number 0, volume Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) * o ubiX:NAME - mount UBI device X, volume with name NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) * o ubi:NAME - mount UBI device 0, volume with name NAME.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) * Alternative '!' separator may be used instead of ':' (because some shells
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) * like busybox may interpret ':' as an NFS host name separator). This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) * returns UBI volume description object in case of success and a negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) * error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) static struct ubi_volume_desc *open_ubi(const char *name, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) struct ubi_volume_desc *ubi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) int dev, vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) char *endptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) if (!name || !*name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) /* First, try to open using the device node path method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) ubi = ubi_open_volume_path(name, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) if (!IS_ERR(ubi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) return ubi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) /* Try the "nodev" method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) /* ubi:NAME method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) if ((name[3] == ':' || name[3] == '!') && name[4] != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) return ubi_open_volume_nm(0, name + 4, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) if (!isdigit(name[3]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) dev = simple_strtoul(name + 3, &endptr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) /* ubiY method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) if (*endptr == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) return ubi_open_volume(0, dev, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) /* ubiX_Y method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) if (*endptr == '_' && isdigit(endptr[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) vol = simple_strtoul(endptr + 1, &endptr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) if (*endptr != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) return ubi_open_volume(dev, vol, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) /* ubiX:NAME method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) if ((*endptr == ':' || *endptr == '!') && endptr[1] != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) return ubi_open_volume_nm(dev, ++endptr, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) struct ubifs_info *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) if (c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) spin_lock_init(&c->cnt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) spin_lock_init(&c->cs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) spin_lock_init(&c->buds_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) spin_lock_init(&c->space_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) spin_lock_init(&c->orphan_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) init_rwsem(&c->commit_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) mutex_init(&c->lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) mutex_init(&c->tnc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) mutex_init(&c->log_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) mutex_init(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) mutex_init(&c->bu_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) mutex_init(&c->write_reserve_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) init_waitqueue_head(&c->cmt_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) c->buds = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) c->old_idx = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) c->size_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) c->orph_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) INIT_LIST_HEAD(&c->infos_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) INIT_LIST_HEAD(&c->idx_gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) INIT_LIST_HEAD(&c->replay_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) INIT_LIST_HEAD(&c->replay_buds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) INIT_LIST_HEAD(&c->uncat_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) INIT_LIST_HEAD(&c->empty_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) INIT_LIST_HEAD(&c->freeable_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) INIT_LIST_HEAD(&c->frdi_idx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) INIT_LIST_HEAD(&c->unclean_leb_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) INIT_LIST_HEAD(&c->old_buds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) INIT_LIST_HEAD(&c->orph_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) INIT_LIST_HEAD(&c->orph_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) c->no_chk_data_crc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) c->assert_action = ASSACT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) c->highest_inum = UBIFS_FIRST_INO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) ubi_get_volume_info(ubi, &c->vi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) ubi_get_device_info(c->vi.ubi_num, &c->di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) return c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) struct ubifs_info *c = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) struct inode *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) c->vfs_sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) /* Re-open the UBI device in read-write mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) if (IS_ERR(c->ubi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) err = PTR_ERR(c->ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) err = ubifs_parse_options(c, data, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) goto out_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) * UBIFS provides 'backing_dev_info' in order to disable read-ahead. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) * UBIFS, I/O is not deferred, it is done immediately in readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) * which means the user would have to wait not just for their own I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) * but the read-ahead I/O as well i.e. completely pointless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) * Read-ahead will be disabled because @sb->s_bdi->ra_pages is 0. Also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) * @sb->s_bdi->capabilities are initialized to 0 so there won't be any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) * writeback happening.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) err = super_setup_bdi_name(sb, "ubifs_%d_%d", c->vi.ubi_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) c->vi.vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) goto out_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) sb->s_bdi->ra_pages = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) sb->s_bdi->io_pages = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) sb->s_fs_info = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) sb->s_magic = UBIFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) sb->s_blocksize = UBIFS_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) sb->s_blocksize_bits = UBIFS_BLOCK_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) sb->s_maxbytes = c->max_inode_sz = key_max_inode_size(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) if (c->max_inode_sz > MAX_LFS_FILESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) sb->s_op = &ubifs_super_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) #ifdef CONFIG_UBIFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) sb->s_xattr = ubifs_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) fscrypt_set_ops(sb, &ubifs_crypt_operations);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) mutex_lock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) err = mount_ubifs(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) ubifs_assert(c, err < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) /* Read the root inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) root = ubifs_iget(sb, UBIFS_ROOT_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) if (IS_ERR(root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) err = PTR_ERR(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) goto out_umount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) sb->s_root = d_make_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) if (!sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) goto out_umount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) mutex_unlock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) out_umount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) ubifs_umount(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) mutex_unlock(&c->umount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) out_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) ubifs_release_options(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) ubi_close_volume(c->ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) static int sb_test(struct super_block *sb, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) struct ubifs_info *c1 = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) struct ubifs_info *c = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) return c->vi.cdev == c1->vi.cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) static int sb_set(struct super_block *sb, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) sb->s_fs_info = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) return set_anon_super(sb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) const char *name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) struct ubi_volume_desc *ubi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) struct ubifs_info *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) dbg_gen("name %s, flags %#x", name, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) * Get UBI device number and volume ID. Mount it read-only so far
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) * because this might be a new mount point, and UBI allows only one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) * read-write user at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) ubi = open_ubi(name, UBI_READONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) if (IS_ERR(ubi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) if (!(flags & SB_SILENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) pr_err("UBIFS error (pid: %d): cannot open \"%s\", error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) current->pid, name, (int)PTR_ERR(ubi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) return ERR_CAST(ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) c = alloc_ubifs_info(ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) if (!c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) goto out_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) sb = sget(fs_type, sb_test, sb_set, flags, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) if (IS_ERR(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) err = PTR_ERR(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) kfree(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) goto out_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) if (sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) struct ubifs_info *c1 = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) kfree(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) /* A new mount point for already mounted UBIFS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) dbg_gen("this ubi volume is already mounted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) if (!!(flags & SB_RDONLY) != c1->ro_mount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) goto out_deact;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) err = ubifs_fill_super(sb, data, flags & SB_SILENT ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) goto out_deact;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) /* We do not support atime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) sb->s_flags |= SB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) if (IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) ubifs_msg(c, "full atime support is enabled.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) sb->s_flags |= SB_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) /* 'fill_super()' opens ubi again so we must close it here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) ubi_close_volume(ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) return dget(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) out_deact:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) deactivate_locked_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) out_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) ubi_close_volume(ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) static void kill_ubifs_super(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) struct ubifs_info *c = s->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) kill_anon_super(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) kfree(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) static struct file_system_type ubifs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) .name = "ubifs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) .mount = ubifs_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) .kill_sb = kill_ubifs_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) MODULE_ALIAS_FS("ubifs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) * Inode slab cache constructor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) static void inode_slab_ctor(void *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) struct ubifs_inode *ui = obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) inode_init_once(&ui->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) static int __init ubifs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) BUILD_BUG_ON(sizeof(struct ubifs_ch) != 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) /* Make sure node sizes are 8-byte aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) BUILD_BUG_ON(UBIFS_CH_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) BUILD_BUG_ON(UBIFS_INO_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) BUILD_BUG_ON(UBIFS_DENT_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) BUILD_BUG_ON(UBIFS_XENT_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) BUILD_BUG_ON(UBIFS_DATA_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) BUILD_BUG_ON(UBIFS_SB_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) BUILD_BUG_ON(UBIFS_MST_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) BUILD_BUG_ON(UBIFS_REF_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) BUILD_BUG_ON(UBIFS_CS_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) BUILD_BUG_ON(UBIFS_ORPH_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) BUILD_BUG_ON(UBIFS_MAX_NODE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) BUILD_BUG_ON(MIN_WRITE_SZ & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) /* Check min. node size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) BUILD_BUG_ON(UBIFS_INO_NODE_SZ < MIN_WRITE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) BUILD_BUG_ON(UBIFS_DENT_NODE_SZ < MIN_WRITE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) BUILD_BUG_ON(UBIFS_XENT_NODE_SZ < MIN_WRITE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ < MIN_WRITE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ > UBIFS_MAX_NODE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ > UBIFS_MAX_NODE_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) /* Defined node sizes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) BUILD_BUG_ON(UBIFS_SB_NODE_SZ != 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) BUILD_BUG_ON(UBIFS_MST_NODE_SZ != 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) * We use 2 bit wide bit-fields to store compression type, which should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) * be amended if more compressors are added. The bit-fields are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) * @compr_type in 'struct ubifs_inode', @default_compr in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) * 'struct ubifs_info' and @compr_type in 'struct ubifs_mount_opts'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) BUILD_BUG_ON(UBIFS_COMPR_TYPES_CNT > 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) * We require that PAGE_SIZE is greater-than-or-equal-to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) * UBIFS_BLOCK_SIZE. It is assumed that both are powers of 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) if (PAGE_SIZE < UBIFS_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) pr_err("UBIFS error (pid %d): VFS page cache size is %u bytes, but UBIFS requires at least 4096 bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) current->pid, (unsigned int)PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) ubifs_inode_slab = kmem_cache_create("ubifs_inode_slab",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) sizeof(struct ubifs_inode), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) SLAB_MEM_SPREAD | SLAB_RECLAIM_ACCOUNT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) SLAB_ACCOUNT, &inode_slab_ctor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) if (!ubifs_inode_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) err = register_shrinker(&ubifs_shrinker_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) goto out_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) err = ubifs_compressors_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) goto out_shrinker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) dbg_debugfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) err = register_filesystem(&ubifs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) pr_err("UBIFS error (pid %d): cannot register file system, error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) current->pid, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) goto out_dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) out_dbg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) dbg_debugfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) ubifs_compressors_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) out_shrinker:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) unregister_shrinker(&ubifs_shrinker_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) out_slab:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) kmem_cache_destroy(ubifs_inode_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) /* late_initcall to let compressors initialize first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) late_initcall(ubifs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) static void __exit ubifs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) WARN_ON(!list_empty(&ubifs_infos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) WARN_ON(atomic_long_read(&ubifs_clean_zn_cnt) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) dbg_debugfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) ubifs_compressors_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) unregister_shrinker(&ubifs_shrinker_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) kmem_cache_destroy(ubifs_inode_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) unregister_filesystem(&ubifs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) module_exit(ubifs_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) MODULE_VERSION(__stringify(UBIFS_VERSION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) MODULE_AUTHOR("Artem Bityutskiy, Adrian Hunter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) MODULE_DESCRIPTION("UBIFS - UBI File System");