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