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