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