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