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