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