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