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