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