^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) * linux/fs/ufs/super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Daniel Pirkl <daniel.pirkl@email.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Charles University, Faculty of Mathematics and Physics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /* Derived from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * linux/fs/ext2/super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright (C) 1992, 1993, 1994, 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Remy Card (card@masi.ibp.fr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Laboratoire MASI - Institut Blaise Pascal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Universite Pierre et Marie Curie (Paris VI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * linux/fs/minix/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Big-endian to little-endian byte-swapping/bitmaps by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * David S. Miller (davem@caip.rutgers.edu), 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Inspired by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * linux/fs/ufs/super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Copyright (C) 1996
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Laboratory for Computer Science Research Computing Facility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Rutgers, The State University of New Jersey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Kernel module support added on 96/04/26 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Stefan Reinauer <stepan@home.culture.mipt.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Module usage counts added on 96/04/29 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Gertjan van Wingerde <gwingerde@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Clean swab support on 19970406 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Francois-Rene Rideau <fare@tunes.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * 4.4BSD (FreeBSD) support added on February 1st 1998 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * NeXTstep support added on February 5th 1998 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * Niels Kristian Bech Jensen <nkbj@image.dk>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * HP/UX hfs filesystem support added by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * Martin K. Petersen <mkp@mkp.net>, August 1999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * UFS2 (of FreeBSD 5.x) support added by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Niraj Kumar <niraj17@iitbombay.org>, Jan 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * UFS2 write support added by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * Evgeniy Dushistov <dushistov@mail.ru>, 2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #include <linux/log2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #include "ufs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #include "ufs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #include "swab.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static struct inode *ufs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (ino < UFS_ROOTINO || ino > (u64)uspi->s_ncg * uspi->s_ipg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) inode = ufs_iget(sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return ERR_CAST(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (generation && inode->i_generation != generation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static struct dentry *ufs_fh_to_dentry(struct super_block *sb, struct fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return generic_fh_to_dentry(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct dentry *ufs_fh_to_parent(struct super_block *sb, struct fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return generic_fh_to_parent(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static struct dentry *ufs_get_parent(struct dentry *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct qstr dot_dot = QSTR_INIT("..", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ino_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ino = ufs_inode_by_name(d_inode(child), &dot_dot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return d_obtain_alias(ufs_iget(child->d_sb, ino));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static const struct export_operations ufs_export_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .fh_to_dentry = ufs_fh_to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .fh_to_parent = ufs_fh_to_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .get_parent = ufs_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #ifdef CONFIG_UFS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Print contents of ufs_super_block, useful for debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void ufs_print_super_stuff(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct ufs_super_block_first *usb1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct ufs_super_block_second *usb2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct ufs_super_block_third *usb3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) pr_debug("ufs_print_super_stuff\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) pr_debug(" magic: 0x%x\n", magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) pr_debug(" fs_size: %llu\n", (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pr_debug(" fs_dsize: %llu\n", (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) pr_debug(" bsize: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) fs32_to_cpu(sb, usb1->fs_bsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) pr_debug(" fsize: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) fs32_to_cpu(sb, usb1->fs_fsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) pr_debug(" fs_volname: %s\n", usb2->fs_un.fs_u2.fs_volname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) pr_debug(" fs_sblockloc: %llu\n", (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) fs64_to_cpu(sb, usb2->fs_un.fs_u2.fs_sblockloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) pr_debug(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) pr_debug(" cs_nbfree(No of free blocks): %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) pr_info(" cs_nifree(Num of free inodes): %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) pr_info(" cs_nffree(Num of free frags): %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pr_info(" fs_maxsymlinklen: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) pr_debug(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) pr_debug(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pr_debug(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) pr_debug(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pr_debug(" cgoffset: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) fs32_to_cpu(sb, usb1->fs_cgoffset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) pr_debug(" ~cgmask: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ~fs32_to_cpu(sb, usb1->fs_cgmask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) pr_debug(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) pr_debug(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) pr_debug(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) pr_debug(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) pr_debug(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) pr_debug(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) pr_debug(" fragshift: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) fs32_to_cpu(sb, usb1->fs_fragshift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) pr_debug(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) pr_debug(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) pr_debug(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) pr_debug(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) pr_debug(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) pr_debug(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) pr_debug(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pr_debug(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) pr_debug(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pr_debug(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) pr_debug(" fstodb: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) fs32_to_cpu(sb, usb1->fs_fsbtodb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) pr_debug(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pr_debug(" ndir %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) pr_debug(" nifree %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) pr_debug(" nbfree %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) pr_debug(" nffree %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) pr_debug("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * Print contents of ufs_cylinder_group, useful for debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static void ufs_print_cylinder_stuff(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct ufs_cylinder_group *cg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) pr_debug("\nufs_print_cylinder_stuff\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) pr_debug("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) pr_debug(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pr_debug(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) pr_debug(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) pr_debug(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) pr_debug(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) pr_debug(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) pr_debug(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) pr_debug(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) pr_debug(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) pr_debug(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) pr_debug(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) pr_debug(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) pr_debug(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) pr_debug(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pr_debug(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) pr_debug(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) pr_debug(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) pr_debug(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) pr_debug(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) pr_debug(" clustersumoff %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pr_debug(" clusteroff %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pr_debug(" nclusterblks %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) pr_debug("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) # define ufs_print_cylinder_stuff(sb, cg) /**/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #endif /* CONFIG_UFS_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static const struct super_operations ufs_super_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) void ufs_error (struct super_block * sb, const char * function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) const char * fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct ufs_sb_private_info * uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct ufs_super_block_first * usb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) uspi = UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) usb1 = ubh_get_usb_first(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) usb1->fs_clean = UFS_FSBAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ubh_mark_buffer_dirty(USPI_UBH(uspi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ufs_mark_sb_dirty(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) case UFS_MOUNT_ONERROR_PANIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) panic("panic (device %s): %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) case UFS_MOUNT_ONERROR_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) case UFS_MOUNT_ONERROR_UMOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) case UFS_MOUNT_ONERROR_REPAIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) pr_crit("error (device %s): %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) void ufs_panic (struct super_block * sb, const char * function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) const char * fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct ufs_sb_private_info * uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct ufs_super_block_first * usb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) uspi = UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) usb1 = ubh_get_usb_first(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) usb1->fs_clean = UFS_FSBAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) ubh_mark_buffer_dirty(USPI_UBH(uspi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ufs_mark_sb_dirty(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) pr_crit("panic (device %s): %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) void ufs_warning (struct super_block * sb, const char * function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) const char * fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) pr_warn("(device %s): %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) Opt_type_old = UFS_MOUNT_UFSTYPE_OLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) Opt_type_sunx86 = UFS_MOUNT_UFSTYPE_SUNx86,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) Opt_type_sun = UFS_MOUNT_UFSTYPE_SUN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) Opt_type_sunos = UFS_MOUNT_UFSTYPE_SUNOS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) Opt_type_44bsd = UFS_MOUNT_UFSTYPE_44BSD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) Opt_type_ufs2 = UFS_MOUNT_UFSTYPE_UFS2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) Opt_type_hp = UFS_MOUNT_UFSTYPE_HP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) Opt_type_nextstepcd = UFS_MOUNT_UFSTYPE_NEXTSTEP_CD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) Opt_type_nextstep = UFS_MOUNT_UFSTYPE_NEXTSTEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) Opt_type_openstep = UFS_MOUNT_UFSTYPE_OPENSTEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) Opt_onerror_panic = UFS_MOUNT_ONERROR_PANIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) Opt_onerror_lock = UFS_MOUNT_ONERROR_LOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) Opt_onerror_umount = UFS_MOUNT_ONERROR_UMOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) Opt_onerror_repair = UFS_MOUNT_ONERROR_REPAIR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) Opt_err
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {Opt_type_old, "ufstype=old"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {Opt_type_sunx86, "ufstype=sunx86"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {Opt_type_sun, "ufstype=sun"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {Opt_type_sunos, "ufstype=sunos"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {Opt_type_44bsd, "ufstype=44bsd"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {Opt_type_ufs2, "ufstype=ufs2"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {Opt_type_ufs2, "ufstype=5xbsd"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {Opt_type_hp, "ufstype=hp"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {Opt_type_nextstep, "ufstype=nextstep"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {Opt_type_openstep, "ufstype=openstep"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /*end of possible ufs types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {Opt_onerror_panic, "onerror=panic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {Opt_onerror_lock, "onerror=lock"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {Opt_onerror_umount, "onerror=umount"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {Opt_onerror_repair, "onerror=repair"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {Opt_err, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static int ufs_parse_options (char * options, unsigned * mount_options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) char * p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) UFSD("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) case Opt_type_old:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ufs_set_opt (*mount_options, UFSTYPE_OLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) case Opt_type_sunx86:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) case Opt_type_sun:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ufs_set_opt (*mount_options, UFSTYPE_SUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) case Opt_type_sunos:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ufs_clear_opt(*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ufs_set_opt(*mount_options, UFSTYPE_SUNOS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) case Opt_type_44bsd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ufs_set_opt (*mount_options, UFSTYPE_44BSD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case Opt_type_ufs2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) ufs_clear_opt(*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ufs_set_opt(*mount_options, UFSTYPE_UFS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) case Opt_type_hp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) ufs_set_opt (*mount_options, UFSTYPE_HP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) case Opt_type_nextstepcd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) case Opt_type_nextstep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) case Opt_type_openstep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ufs_clear_opt (*mount_options, UFSTYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) case Opt_onerror_panic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ufs_clear_opt (*mount_options, ONERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ufs_set_opt (*mount_options, ONERROR_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) case Opt_onerror_lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ufs_clear_opt (*mount_options, ONERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ufs_set_opt (*mount_options, ONERROR_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) case Opt_onerror_umount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) ufs_clear_opt (*mount_options, ONERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ufs_set_opt (*mount_options, ONERROR_UMOUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) case Opt_onerror_repair:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) pr_err("Unable to do repair on error, will lock lock instead\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) ufs_clear_opt (*mount_options, ONERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) ufs_set_opt (*mount_options, ONERROR_REPAIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) pr_err("Invalid option: \"%s\" or missing value\n", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * Different types of UFS hold fs_cstotal in different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * places, and use different data structure for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * To make things simpler we just copy fs_cstotal to ufs_sb_private_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static void ufs_setup_cstotal(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct ufs_sb_info *sbi = UFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct ufs_sb_private_info *uspi = sbi->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct ufs_super_block_first *usb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct ufs_super_block_second *usb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct ufs_super_block_third *usb3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) unsigned mtype = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) UFSD("ENTER, mtype=%u\n", mtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) usb1 = ubh_get_usb_first(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) usb2 = ubh_get_usb_second(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) usb3 = ubh_get_usb_third(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) (usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) mtype == UFS_MOUNT_UFSTYPE_UFS2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /*we have statistic in different place, then usual*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) uspi->cs_total.cs_nbfree = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) uspi->cs_total.cs_nifree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) uspi->cs_total.cs_nffree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) uspi->cs_total.cs_ndir = fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) uspi->cs_total.cs_nbfree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) uspi->cs_total.cs_nifree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) uspi->cs_total.cs_nffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) UFSD("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * Read on-disk structures associated with cylinder groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int ufs_read_cylinder_structures(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct ufs_sb_info *sbi = UFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct ufs_sb_private_info *uspi = sbi->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct ufs_buffer_head * ubh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) unsigned char * base, * space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) unsigned size, blks, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) UFSD("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * Read cs structures from (usually) first data block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * on the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) size = uspi->s_cssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) base = space = kmalloc(size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (!base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) sbi->s_csp = (struct ufs_csum *)space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) for (i = 0; i < blks; i += uspi->s_fpb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) size = uspi->s_bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (i + uspi->s_fpb > blks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) size = (blks - i) * uspi->s_fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) ubh_ubhcpymem (space, ubh, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) space += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ubh_brelse (ubh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) ubh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * Read cylinder group (we read only first fragment from block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * at this time) and prepare internal data structures for cg caching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) sbi->s_ucg = kmalloc_array(uspi->s_ncg, sizeof(struct buffer_head *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (!sbi->s_ucg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) for (i = 0; i < uspi->s_ncg; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) sbi->s_ucg[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) sbi->s_ucpi[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) sbi->s_cgno[i] = UFS_CGNO_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) for (i = 0; i < uspi->s_ncg; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) UFSD("read cg %u\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_NOFS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) sbi->s_cgno[i] = UFS_CGNO_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) sbi->s_cg_loaded = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) UFSD("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) kfree (base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (sbi->s_ucg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) for (i = 0; i < uspi->s_ncg; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (sbi->s_ucg[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) brelse (sbi->s_ucg[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) kfree (sbi->s_ucg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) kfree (sbi->s_ucpi[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) UFSD("EXIT (FAILED)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * Sync our internal copy of fs_cstotal with disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static void ufs_put_cstotal(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) unsigned mtype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct ufs_super_block_first *usb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) struct ufs_super_block_second *usb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct ufs_super_block_third *usb3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) UFSD("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) usb1 = ubh_get_usb_first(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) usb2 = ubh_get_usb_second(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) usb3 = ubh_get_usb_third(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (mtype == UFS_MOUNT_UFSTYPE_UFS2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /*we have statistic in different place, then usual*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) usb2->fs_un.fs_u2.cs_ndir =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) usb2->fs_un.fs_u2.cs_nbfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) usb3->fs_un1.fs_u2.cs_nifree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) usb3->fs_un1.fs_u2.cs_nffree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (mtype == UFS_MOUNT_UFSTYPE_44BSD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) (usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) /* store stats in both old and new places */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) usb2->fs_un.fs_u2.cs_ndir =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) usb2->fs_un.fs_u2.cs_nbfree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) usb3->fs_un1.fs_u2.cs_nifree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) usb3->fs_un1.fs_u2.cs_nffree =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) usb1->fs_cstotal.cs_ndir = cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) usb1->fs_cstotal.cs_nbfree = cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) usb1->fs_cstotal.cs_nifree = cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) usb1->fs_cstotal.cs_nffree = cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) ubh_mark_buffer_dirty(USPI_UBH(uspi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) ufs_print_super_stuff(sb, usb1, usb2, usb3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) UFSD("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * ufs_put_super_internal() - put on-disk intrenal structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * @sb: pointer to super_block structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * Put on-disk structures associated with cylinder groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * and write them back to disk, also update cs_total on disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static void ufs_put_super_internal(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct ufs_sb_info *sbi = UFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct ufs_sb_private_info *uspi = sbi->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct ufs_buffer_head * ubh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) unsigned char * base, * space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) unsigned blks, size, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) UFSD("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) ufs_put_cstotal(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) size = uspi->s_cssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) base = space = (char*) sbi->s_csp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) for (i = 0; i < blks; i += uspi->s_fpb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) size = uspi->s_bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (i + uspi->s_fpb > blks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) size = (blks - i) * uspi->s_fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) ubh_memcpyubh (ubh, space, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) space += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ubh_mark_buffer_uptodate (ubh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) ubh_mark_buffer_dirty (ubh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) ubh_brelse (ubh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) for (i = 0; i < sbi->s_cg_loaded; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) ufs_put_cylinder (sb, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) kfree (sbi->s_ucpi[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) for (; i < UFS_MAX_GROUP_LOADED; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) kfree (sbi->s_ucpi[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) for (i = 0; i < uspi->s_ncg; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) brelse (sbi->s_ucg[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) kfree (sbi->s_ucg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) kfree (base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) UFSD("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static int ufs_sync_fs(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) struct ufs_sb_private_info * uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) struct ufs_super_block_first * usb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) struct ufs_super_block_third * usb3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) unsigned flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) mutex_lock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) UFSD("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) flags = UFS_SB(sb)->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) uspi = UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) usb1 = ubh_get_usb_first(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) usb3 = ubh_get_usb_third(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) usb1->fs_time = ufs_get_seconds(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if ((flags & UFS_ST_MASK) == UFS_ST_SUN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) ufs_set_fs_state(sb, usb1, usb3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) ufs_put_cstotal(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) UFSD("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) static void delayed_sync_fs(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct ufs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) sbi = container_of(work, struct ufs_sb_info, sync_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) spin_lock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) sbi->work_queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) spin_unlock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) ufs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) void ufs_mark_sb_dirty(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) struct ufs_sb_info *sbi = UFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) spin_lock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (!sbi->work_queued) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) delay = msecs_to_jiffies(dirty_writeback_interval * 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) queue_delayed_work(system_long_wq, &sbi->sync_work, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) sbi->work_queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) spin_unlock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) static void ufs_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) struct ufs_sb_info * sbi = UFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) UFSD("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) ufs_put_super_internal(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) cancel_delayed_work_sync(&sbi->sync_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) ubh_brelse_uspi (sbi->s_uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) kfree (sbi->s_uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) kfree (sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) UFSD("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static u64 ufs_max_bytes(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) int bits = uspi->s_apbshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) u64 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (bits > 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) res = ~0ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) res = UFS_NDADDR + (1LL << bits) + (1LL << (2*bits)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) (1LL << (3*bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (res >= (MAX_LFS_FILESIZE >> uspi->s_bshift))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) return res << uspi->s_bshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) static int ufs_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) struct ufs_sb_info * sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) struct ufs_sb_private_info * uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) struct ufs_super_block_first * usb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) struct ufs_super_block_second * usb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) struct ufs_super_block_third * usb3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) struct ufs_buffer_head * ubh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) unsigned block_size, super_block_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) unsigned flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) unsigned super_block_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) unsigned maxsymlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) uspi = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) ubh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) UFSD("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) #ifndef CONFIG_UFS_FS_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) goto failed_nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) sbi->sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) UFSD("flag %u\n", (int)(sb_rdonly(sb)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) mutex_init(&sbi->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) spin_lock_init(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * Set default mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * Parse mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) sbi->s_mount_opt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) pr_err("wrong mount options\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) pr_err("You didn't specify the type of your ufs filesystem\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) "mount -t ufs -o ufstype="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) "default is ufstype=old\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) sbi->s_uspi = uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (!uspi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) uspi->s_dirblksize = UFS_SECTOR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) super_block_offset=UFS_SBLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) sb->s_maxbytes = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) sb->s_time_gran = NSEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) sb->s_time_min = S32_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) sb->s_time_max = S32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) case UFS_MOUNT_UFSTYPE_44BSD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) UFSD("ufstype=44bsd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) uspi->s_fsize = block_size = 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) uspi->s_fmask = ~(512 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) uspi->s_fshift = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) uspi->s_sbsize = super_block_size = 1536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) case UFS_MOUNT_UFSTYPE_UFS2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) UFSD("ufstype=ufs2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) super_block_offset=SBLOCK_UFS2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) uspi->s_fsize = block_size = 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) uspi->s_fmask = ~(512 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) uspi->s_fshift = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) uspi->s_sbsize = super_block_size = 1536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) sb->s_time_min = S64_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) sb->s_time_max = S64_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) case UFS_MOUNT_UFSTYPE_SUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) UFSD("ufstype=sun\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) uspi->s_fsize = block_size = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) uspi->s_fmask = ~(1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) uspi->s_fshift = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) uspi->s_sbsize = super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) uspi->s_maxsymlinklen = 0; /* Not supported on disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) case UFS_MOUNT_UFSTYPE_SUNOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) UFSD("ufstype=sunos\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) uspi->s_fsize = block_size = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) uspi->s_fmask = ~(1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) uspi->s_fshift = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) uspi->s_sbsize = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) uspi->s_maxsymlinklen = 0; /* Not supported on disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_SUNOS | UFS_CG_SUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) case UFS_MOUNT_UFSTYPE_SUNx86:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) UFSD("ufstype=sunx86\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) uspi->s_fsize = block_size = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) uspi->s_fmask = ~(1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) uspi->s_fshift = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) uspi->s_sbsize = super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) uspi->s_maxsymlinklen = 0; /* Not supported on disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) case UFS_MOUNT_UFSTYPE_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) UFSD("ufstype=old\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) uspi->s_fsize = block_size = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) uspi->s_fmask = ~(1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) uspi->s_fshift = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) uspi->s_sbsize = super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) pr_info("ufstype=old is supported read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) case UFS_MOUNT_UFSTYPE_NEXTSTEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) UFSD("ufstype=nextstep\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) uspi->s_fsize = block_size = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) uspi->s_fmask = ~(1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) uspi->s_fshift = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) uspi->s_sbsize = super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) uspi->s_dirblksize = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) pr_info("ufstype=nextstep is supported read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) UFSD("ufstype=nextstep-cd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) uspi->s_fsize = block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) uspi->s_fmask = ~(2048 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) uspi->s_fshift = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) uspi->s_sbsize = super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) uspi->s_dirblksize = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) pr_info("ufstype=nextstep-cd is supported read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) case UFS_MOUNT_UFSTYPE_OPENSTEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) UFSD("ufstype=openstep\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) uspi->s_fsize = block_size = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) uspi->s_fmask = ~(1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) uspi->s_fshift = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) uspi->s_sbsize = super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) uspi->s_dirblksize = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) pr_info("ufstype=openstep is supported read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) case UFS_MOUNT_UFSTYPE_HP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) UFSD("ufstype=hp\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) uspi->s_fsize = block_size = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) uspi->s_fmask = ~(1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) uspi->s_fshift = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) uspi->s_sbsize = super_block_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) uspi->s_sbbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) pr_info("ufstype=hp is supported read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) pr_err("unknown ufstype\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (!sb_set_blocksize(sb, block_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) pr_err("failed to set blocksize\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) goto failed;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) * read ufs super block from device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) usb1 = ubh_get_usb_first(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) usb2 = ubh_get_usb_second(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) usb3 = ubh_get_usb_third(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) /* Sort out mod used on SunOS 4.1.3 for fs_state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (((flags & UFS_ST_MASK) == UFS_ST_SUNOS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) (uspi->s_postblformat != UFS_42POSTBLFMT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) flags &= ~UFS_ST_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) flags |= UFS_ST_SUN;
^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) if ((flags & UFS_ST_MASK) == UFS_ST_44BSD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) uspi->s_postblformat == UFS_42POSTBLFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) pr_err("this is not a 44bsd filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * Check ufs magic number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) sbi->s_bytesex = BYTESEX_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) case UFS_MAGIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) case UFS_MAGIC_BW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) case UFS2_MAGIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) case UFS_MAGIC_LFN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) case UFS_MAGIC_FEA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) case UFS_MAGIC_4GB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) goto magic_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) sbi->s_bytesex = BYTESEX_BE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) case UFS_MAGIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) case UFS_MAGIC_BW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) case UFS2_MAGIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) case UFS_MAGIC_LFN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) case UFS_MAGIC_FEA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) case UFS_MAGIC_4GB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) goto magic_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) && uspi->s_sbbase < 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) ubh_brelse_uspi(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) ubh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) uspi->s_sbbase += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) pr_err("%s(): bad magic number\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) magic_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * Check block and fragment sizes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (!is_power_of_2(uspi->s_fsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) pr_err("%s(): fragment size %u is not a power of 2\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) __func__, uspi->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) if (uspi->s_fsize < 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) pr_err("%s(): fragment size %u is too small\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) __func__, uspi->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (uspi->s_fsize > 4096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) pr_err("%s(): fragment size %u is too large\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) __func__, uspi->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if (!is_power_of_2(uspi->s_bsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) pr_err("%s(): block size %u is not a power of 2\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) __func__, uspi->s_bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (uspi->s_bsize < 4096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) pr_err("%s(): block size %u is too small\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) __func__, uspi->s_bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) if (uspi->s_bsize / uspi->s_fsize > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) pr_err("%s(): too many fragments per block (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) __func__, uspi->s_bsize / uspi->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) ubh_brelse_uspi(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) ubh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) block_size = uspi->s_fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) super_block_size = uspi->s_sbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) UFSD("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) sbi->s_flags = flags;/*after that line some functions use s_flags*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) ufs_print_super_stuff(sb, usb1, usb2, usb3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) * Check, if file system was correctly unmounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) * If not, make it read only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) switch(usb1->fs_clean) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) case UFS_FSCLEAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) UFSD("fs is clean\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) case UFS_FSSTABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) UFSD("fs is stable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) case UFS_FSLOG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) UFSD("fs is logging fs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) case UFS_FSOSF1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) UFSD("fs is DEC OSF/1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) case UFS_FSACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) pr_err("%s(): fs is active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) case UFS_FSBAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) pr_err("%s(): fs is bad\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) pr_err("%s(): can't grok fs_clean 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) __func__, usb1->fs_clean);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) pr_err("%s(): fs needs fsck\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) * Read ufs_super_block into internal data structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) sb->s_op = &ufs_super_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) sb->s_export_op = &ufs_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) uspi->s_size = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) uspi->s_dsize = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) /* s_bsize already set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) /* s_fsize already set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) uspi->s_fshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) /* s_sbsize already set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (uspi->fs_magic == UFS2_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) uspi->s_csaddr = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_csaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_un.fs_u1.fs_cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_contigsumsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) uspi->s_root_blocks = mul_u64_u32_div(uspi->s_dsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) uspi->s_minfree, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (uspi->s_minfree <= 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) uspi->s_time_to_space = ~0ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) uspi->s_space_to_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) usb1->fs_optim = cpu_to_fs32(sb, UFS_OPTSPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) uspi->s_time_to_space = (uspi->s_root_blocks / 2) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) uspi->s_space_to_time = mul_u64_u32_div(uspi->s_dsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) uspi->s_minfree - 2, 100) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) * Compute another frequently used values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) uspi->s_fpbmask = uspi->s_fpb - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) uspi->s_apbshift = uspi->s_bshift - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) uspi->s_apbshift = uspi->s_bshift - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) uspi->s_2apbshift = uspi->s_apbshift * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) uspi->s_3apbshift = uspi->s_apbshift * 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) uspi->s_apb = 1 << uspi->s_apbshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) uspi->s_2apb = 1 << uspi->s_2apbshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) uspi->s_3apb = 1 << uspi->s_3apbshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) uspi->s_apbmask = uspi->s_apb - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) uspi->s_bpf = uspi->s_fsize << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) uspi->s_bpfshift = uspi->s_fshift + 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) uspi->s_bpfmask = uspi->s_bpf - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) uspi->s_maxsymlinklen =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (uspi->fs_magic == UFS2_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) maxsymlen = 2 * 4 * (UFS_NDADDR + UFS_NINDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) maxsymlen = 4 * (UFS_NDADDR + UFS_NINDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (uspi->s_maxsymlinklen > maxsymlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) ufs_warning(sb, __func__, "ufs_read_super: excessive maximum "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) "fast symlink size (%u)\n", uspi->s_maxsymlinklen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) uspi->s_maxsymlinklen = maxsymlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) sb->s_maxbytes = ufs_max_bytes(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) sb->s_max_links = UFS_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) inode = ufs_iget(sb, UFS_ROOTINO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) ret = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) sb->s_root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) if (!sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) ufs_setup_cstotal(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) * Read cylinder group structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (!ufs_read_cylinder_structures(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) UFSD("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) ubh_brelse_uspi (uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) kfree (uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) UFSD("EXIT (FAILED)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) failed_nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) UFSD("EXIT (NOMEM)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) struct ufs_sb_private_info * uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) struct ufs_super_block_first * usb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) struct ufs_super_block_third * usb3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) unsigned new_mount_opt, ufstype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) unsigned flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) mutex_lock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) uspi = UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) flags = UFS_SB(sb)->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) usb1 = ubh_get_usb_first(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) usb3 = ubh_get_usb_third(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) * Allow the "check" option to be passed as a remount option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) * It is not possible to change ufstype option during remount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) new_mount_opt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) ufs_set_opt (new_mount_opt, ONERROR_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) if (!ufs_parse_options (data, &new_mount_opt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) new_mount_opt |= ufstype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) pr_err("ufstype can't be changed during remount\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) return -EINVAL;
^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) if ((bool)(*mount_flags & SB_RDONLY) == sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) UFS_SB(sb)->s_mount_opt = new_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) * fs was mouted as rw, remounting ro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) if (*mount_flags & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) ufs_put_super_internal(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) usb1->fs_time = ufs_get_seconds(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if ((flags & UFS_ST_MASK) == UFS_ST_SUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) ufs_set_fs_state(sb, usb1, usb3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) ubh_mark_buffer_dirty (USPI_UBH(uspi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) * fs was mounted as ro, remounting rw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) #ifndef CONFIG_UFS_FS_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) ufstype != UFS_MOUNT_UFSTYPE_SUNOS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) pr_err("this ufstype is read-only supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) if (!ufs_read_cylinder_structures(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) pr_err("failed during remounting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) sb->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) UFS_SB(sb)->s_mount_opt = new_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) return 0;
^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) static int ufs_show_options(struct seq_file *seq, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) struct ufs_sb_info *sbi = UFS_SB(root->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) unsigned mval = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) const struct match_token *tp = tokens;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) while (tp->token != Opt_onerror_panic && tp->token != mval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) ++tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) BUG_ON(tp->token == Opt_onerror_panic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) seq_printf(seq, ",%s", tp->pattern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) mval = sbi->s_mount_opt & UFS_MOUNT_ONERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) while (tp->token != Opt_err && tp->token != mval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) ++tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) BUG_ON(tp->token == Opt_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) seq_printf(seq, ",%s", tp->pattern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) static int ufs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) struct ufs_sb_private_info *uspi= UFS_SB(sb)->s_uspi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) unsigned flags = UFS_SB(sb)->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) mutex_lock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) buf->f_type = UFS2_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) buf->f_type = UFS_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) buf->f_blocks = uspi->s_dsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) buf->f_bfree = ufs_freefrags(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) buf->f_ffree = uspi->cs_total.cs_nifree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) buf->f_bsize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) buf->f_bavail = (buf->f_bfree > uspi->s_root_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) ? (buf->f_bfree - uspi->s_root_blocks) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) buf->f_files = uspi->s_ncg * uspi->s_ipg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) buf->f_namelen = UFS_MAXNAMLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) buf->f_fsid = u64_to_fsid(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) mutex_unlock(&UFS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) static struct kmem_cache * ufs_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) static struct inode *ufs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) struct ufs_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) ei = kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (!ei)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) inode_set_iversion(&ei->vfs_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) seqlock_init(&ei->meta_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) mutex_init(&ei->truncate_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) return &ei->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) static void ufs_free_in_core_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) static int __init init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) ufs_inode_cachep = kmem_cache_create_usercopy("ufs_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) sizeof(struct ufs_inode_info), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) offsetof(struct ufs_inode_info, i_u1.i_symlink),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) sizeof_field(struct ufs_inode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) i_u1.i_symlink),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) if (ufs_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) static void destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) kmem_cache_destroy(ufs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) static const struct super_operations ufs_super_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) .alloc_inode = ufs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) .free_inode = ufs_free_in_core_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) .write_inode = ufs_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) .evict_inode = ufs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) .put_super = ufs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) .sync_fs = ufs_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) .statfs = ufs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) .remount_fs = ufs_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) .show_options = ufs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) static struct dentry *ufs_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) return mount_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) static struct file_system_type ufs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) .name = "ufs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) .mount = ufs_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) .kill_sb = kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) .fs_flags = FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) MODULE_ALIAS_FS("ufs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) static int __init init_ufs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) int err = init_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) err = register_filesystem(&ufs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) static void __exit exit_ufs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) unregister_filesystem(&ufs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) module_init(init_ufs_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) module_exit(exit_ufs_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);