blob: 60c989b7012febad007b07bd9f5bb33150297570 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Wingerdef762dd62009-03-21 23:18:57 +010044 * Gertjan van Wingerde <gwingerde@gmail.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 *
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 Dushistovcbcae392007-02-12 00:54:30 -080064 * UFS2 write support added by
65 * Evgeniy Dushistov <dushistov@mail.ru>, 2007
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
67
68
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -080069#include <linux/exportfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#include <linux/module.h>
71#include <linux/bitops.h>
72
73#include <stdarg.h>
74
75#include <asm/uaccess.h>
76#include <asm/system.h>
77
78#include <linux/errno.h>
79#include <linux/fs.h>
Jan Kara74abb982008-07-25 01:46:51 -070080#include <linux/quotaops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#include <linux/slab.h>
82#include <linux/time.h>
83#include <linux/stat.h>
84#include <linux/string.h>
85#include <linux/blkdev.h>
86#include <linux/init.h>
87#include <linux/parser.h>
88#include <linux/smp_lock.h>
89#include <linux/buffer_head.h>
90#include <linux/vfs.h>
vignesh babu9e8c4272007-07-15 23:41:36 -070091#include <linux/log2.h>
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -070092#include <linux/mount.h>
93#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Mike Frysingere5420592008-02-08 04:21:31 -080095#include "ufs_fs.h"
Christoph Hellwigbcd6d4e2007-10-16 23:26:51 -070096#include "ufs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#include "swab.h"
98#include "util.h"
99
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -0800100static struct inode *ufs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation)
101{
102 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
103 struct inode *inode;
104
105 if (ino < UFS_ROOTINO || ino > uspi->s_ncg * uspi->s_ipg)
106 return ERR_PTR(-ESTALE);
107
108 inode = ufs_iget(sb, ino);
109 if (IS_ERR(inode))
110 return ERR_CAST(inode);
111 if (generation && inode->i_generation != generation) {
112 iput(inode);
113 return ERR_PTR(-ESTALE);
114 }
115 return inode;
116}
117
118static struct dentry *ufs_fh_to_dentry(struct super_block *sb, struct fid *fid,
119 int fh_len, int fh_type)
120{
121 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
122}
123
124static struct dentry *ufs_fh_to_parent(struct super_block *sb, struct fid *fid,
125 int fh_len, int fh_type)
126{
127 return generic_fh_to_parent(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
128}
129
130static struct dentry *ufs_get_parent(struct dentry *child)
131{
132 struct qstr dot_dot = {
133 .name = "..",
134 .len = 2,
135 };
136 ino_t ino;
137
138 ino = ufs_inode_by_name(child->d_inode, &dot_dot);
139 if (!ino)
140 return ERR_PTR(-ENOENT);
141 return d_obtain_alias(ufs_iget(child->d_inode->i_sb, ino));
142}
143
144static const struct export_operations ufs_export_ops = {
145 .fh_to_dentry = ufs_fh_to_dentry,
146 .fh_to_parent = ufs_fh_to_parent,
147 .get_parent = ufs_get_parent,
148};
149
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700150#ifdef CONFIG_UFS_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151/*
152 * Print contents of ufs_super_block, useful for debugging
153 */
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800154static void ufs_print_super_stuff(struct super_block *sb,
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700155 struct ufs_super_block_first *usb1,
156 struct ufs_super_block_second *usb2,
157 struct ufs_super_block_third *usb3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800159 u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 printk("ufs_print_super_stuff\n");
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800162 printk(" magic: 0x%x\n", magic);
163 if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700164 printk(" fs_size: %llu\n", (unsigned long long)
165 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size));
166 printk(" fs_dsize: %llu\n", (unsigned long long)
167 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize));
168 printk(" bsize: %u\n",
169 fs32_to_cpu(sb, usb1->fs_bsize));
170 printk(" fsize: %u\n",
171 fs32_to_cpu(sb, usb1->fs_fsize));
172 printk(" fs_volname: %s\n", usb2->fs_un.fs_u2.fs_volname);
173 printk(" fs_sblockloc: %llu\n", (unsigned long long)
174 fs64_to_cpu(sb, usb2->fs_un.fs_u2.fs_sblockloc));
175 printk(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
176 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir));
177 printk(" cs_nbfree(No of free blocks): %llu\n",
178 (unsigned long long)
179 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree));
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800180 printk(KERN_INFO" cs_nifree(Num of free inodes): %llu\n",
181 (unsigned long long)
182 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree));
183 printk(KERN_INFO" cs_nffree(Num of free frags): %llu\n",
184 (unsigned long long)
185 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
Evgeniy Dushistov90b315a2008-02-08 04:20:16 -0800186 printk(KERN_INFO" fs_maxsymlinklen: %u\n",
187 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700188 } else {
189 printk(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
190 printk(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
191 printk(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
192 printk(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
193 printk(" cgoffset: %u\n",
194 fs32_to_cpu(sb, usb1->fs_cgoffset));
195 printk(" ~cgmask: 0x%x\n",
196 ~fs32_to_cpu(sb, usb1->fs_cgmask));
197 printk(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
198 printk(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
199 printk(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
200 printk(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
201 printk(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
202 printk(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
203 printk(" fragshift: %u\n",
204 fs32_to_cpu(sb, usb1->fs_fragshift));
205 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
206 printk(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
207 printk(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
208 printk(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
209 printk(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
210 printk(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
211 printk(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
212 printk(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
213 printk(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
214 printk(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
215 printk(" fstodb: %u\n",
216 fs32_to_cpu(sb, usb1->fs_fsbtodb));
217 printk(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
218 printk(" ndir %u\n",
219 fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
220 printk(" nifree %u\n",
221 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
222 printk(" nbfree %u\n",
223 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
224 printk(" nffree %u\n",
225 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 printk("\n");
228}
229
230/*
231 * Print contents of ufs_cylinder_group, useful for debugging
232 */
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700233static void ufs_print_cylinder_stuff(struct super_block *sb,
234 struct ufs_cylinder_group *cg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 printk("\nufs_print_cylinder_stuff\n");
Andrew Morton96710b22006-06-25 05:47:28 -0700237 printk("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 printk(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
239 printk(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
240 printk(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
241 printk(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
242 printk(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
243 printk(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
244 printk(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
245 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
246 printk(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
247 printk(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
248 printk(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
249 printk(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
250 printk(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
251 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
252 fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
253 fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
254 fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
255 fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
256 printk(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
257 printk(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
258 printk(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
259 printk(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
260 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700261 printk(" clustersumoff %u\n",
262 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
263 printk(" clusteroff %u\n",
264 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
265 printk(" nclusterblks %u\n",
266 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 printk("\n");
268}
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700269#else
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800270# define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700271# define ufs_print_cylinder_stuff(sb, cg) /**/
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700272#endif /* CONFIG_UFS_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800274static const struct super_operations ufs_super_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276static char error_buf[1024];
277
278void ufs_error (struct super_block * sb, const char * function,
279 const char * fmt, ...)
280{
281 struct ufs_sb_private_info * uspi;
282 struct ufs_super_block_first * usb1;
283 va_list args;
284
285 uspi = UFS_SB(sb)->s_uspi;
Evgeniy7b4ee732006-01-14 11:42:06 +0300286 usb1 = ubh_get_usb_first(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 if (!(sb->s_flags & MS_RDONLY)) {
289 usb1->fs_clean = UFS_FSBAD;
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700290 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 sb->s_dirt = 1;
292 sb->s_flags |= MS_RDONLY;
293 }
294 va_start (args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -0800295 vsnprintf (error_buf, sizeof(error_buf), fmt, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 va_end (args);
297 switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
298 case UFS_MOUNT_ONERROR_PANIC:
299 panic ("UFS-fs panic (device %s): %s: %s\n",
300 sb->s_id, function, error_buf);
301
302 case UFS_MOUNT_ONERROR_LOCK:
303 case UFS_MOUNT_ONERROR_UMOUNT:
304 case UFS_MOUNT_ONERROR_REPAIR:
305 printk (KERN_CRIT "UFS-fs error (device %s): %s: %s\n",
306 sb->s_id, function, error_buf);
307 }
308}
309
310void ufs_panic (struct super_block * sb, const char * function,
311 const char * fmt, ...)
312{
313 struct ufs_sb_private_info * uspi;
314 struct ufs_super_block_first * usb1;
315 va_list args;
316
Alessio Igor Bogani337eb002009-05-12 15:10:54 +0200317 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 uspi = UFS_SB(sb)->s_uspi;
Evgeniy7b4ee732006-01-14 11:42:06 +0300319 usb1 = ubh_get_usb_first(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 if (!(sb->s_flags & MS_RDONLY)) {
322 usb1->fs_clean = UFS_FSBAD;
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700323 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 sb->s_dirt = 1;
325 }
326 va_start (args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -0800327 vsnprintf (error_buf, sizeof(error_buf), fmt, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 va_end (args);
329 sb->s_flags |= MS_RDONLY;
330 printk (KERN_CRIT "UFS-fs panic (device %s): %s: %s\n",
331 sb->s_id, function, error_buf);
332}
333
334void ufs_warning (struct super_block * sb, const char * function,
335 const char * fmt, ...)
336{
337 va_list args;
338
339 va_start (args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -0800340 vsnprintf (error_buf, sizeof(error_buf), fmt, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 va_end (args);
342 printk (KERN_WARNING "UFS-fs warning (device %s): %s: %s\n",
343 sb->s_id, function, error_buf);
344}
345
346enum {
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -0700347 Opt_type_old = UFS_MOUNT_UFSTYPE_OLD,
348 Opt_type_sunx86 = UFS_MOUNT_UFSTYPE_SUNx86,
349 Opt_type_sun = UFS_MOUNT_UFSTYPE_SUN,
350 Opt_type_sunos = UFS_MOUNT_UFSTYPE_SUNOS,
351 Opt_type_44bsd = UFS_MOUNT_UFSTYPE_44BSD,
352 Opt_type_ufs2 = UFS_MOUNT_UFSTYPE_UFS2,
353 Opt_type_hp = UFS_MOUNT_UFSTYPE_HP,
354 Opt_type_nextstepcd = UFS_MOUNT_UFSTYPE_NEXTSTEP_CD,
355 Opt_type_nextstep = UFS_MOUNT_UFSTYPE_NEXTSTEP,
356 Opt_type_openstep = UFS_MOUNT_UFSTYPE_OPENSTEP,
357 Opt_onerror_panic = UFS_MOUNT_ONERROR_PANIC,
358 Opt_onerror_lock = UFS_MOUNT_ONERROR_LOCK,
359 Opt_onerror_umount = UFS_MOUNT_ONERROR_UMOUNT,
360 Opt_onerror_repair = UFS_MOUNT_ONERROR_REPAIR,
361 Opt_err
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362};
363
Steven Whitehousea447c092008-10-13 10:46:57 +0100364static const match_table_t tokens = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 {Opt_type_old, "ufstype=old"},
366 {Opt_type_sunx86, "ufstype=sunx86"},
367 {Opt_type_sun, "ufstype=sun"},
Mark Fortescue252e2112007-10-16 23:26:31 -0700368 {Opt_type_sunos, "ufstype=sunos"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 {Opt_type_44bsd, "ufstype=44bsd"},
370 {Opt_type_ufs2, "ufstype=ufs2"},
371 {Opt_type_ufs2, "ufstype=5xbsd"},
372 {Opt_type_hp, "ufstype=hp"},
373 {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
374 {Opt_type_nextstep, "ufstype=nextstep"},
375 {Opt_type_openstep, "ufstype=openstep"},
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -0700376/*end of possible ufs types */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 {Opt_onerror_panic, "onerror=panic"},
378 {Opt_onerror_lock, "onerror=lock"},
379 {Opt_onerror_umount, "onerror=umount"},
380 {Opt_onerror_repair, "onerror=repair"},
381 {Opt_err, NULL}
382};
383
384static int ufs_parse_options (char * options, unsigned * mount_options)
385{
386 char * p;
387
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700388 UFSD("ENTER\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 if (!options)
391 return 1;
392
393 while ((p = strsep(&options, ",")) != NULL) {
394 substring_t args[MAX_OPT_ARGS];
395 int token;
396 if (!*p)
397 continue;
398
399 token = match_token(p, tokens, args);
400 switch (token) {
401 case Opt_type_old:
402 ufs_clear_opt (*mount_options, UFSTYPE);
403 ufs_set_opt (*mount_options, UFSTYPE_OLD);
404 break;
405 case Opt_type_sunx86:
406 ufs_clear_opt (*mount_options, UFSTYPE);
407 ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
408 break;
409 case Opt_type_sun:
410 ufs_clear_opt (*mount_options, UFSTYPE);
411 ufs_set_opt (*mount_options, UFSTYPE_SUN);
412 break;
Mark Fortescue252e2112007-10-16 23:26:31 -0700413 case Opt_type_sunos:
414 ufs_clear_opt(*mount_options, UFSTYPE);
415 ufs_set_opt(*mount_options, UFSTYPE_SUNOS);
416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 case Opt_type_44bsd:
418 ufs_clear_opt (*mount_options, UFSTYPE);
419 ufs_set_opt (*mount_options, UFSTYPE_44BSD);
420 break;
421 case Opt_type_ufs2:
422 ufs_clear_opt(*mount_options, UFSTYPE);
423 ufs_set_opt(*mount_options, UFSTYPE_UFS2);
424 break;
425 case Opt_type_hp:
426 ufs_clear_opt (*mount_options, UFSTYPE);
427 ufs_set_opt (*mount_options, UFSTYPE_HP);
428 break;
429 case Opt_type_nextstepcd:
430 ufs_clear_opt (*mount_options, UFSTYPE);
431 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
432 break;
433 case Opt_type_nextstep:
434 ufs_clear_opt (*mount_options, UFSTYPE);
435 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
436 break;
437 case Opt_type_openstep:
438 ufs_clear_opt (*mount_options, UFSTYPE);
439 ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
440 break;
441 case Opt_onerror_panic:
442 ufs_clear_opt (*mount_options, ONERROR);
443 ufs_set_opt (*mount_options, ONERROR_PANIC);
444 break;
445 case Opt_onerror_lock:
446 ufs_clear_opt (*mount_options, ONERROR);
447 ufs_set_opt (*mount_options, ONERROR_LOCK);
448 break;
449 case Opt_onerror_umount:
450 ufs_clear_opt (*mount_options, ONERROR);
451 ufs_set_opt (*mount_options, ONERROR_UMOUNT);
452 break;
453 case Opt_onerror_repair:
454 printk("UFS-fs: Unable to do repair on error, "
455 "will lock lock instead\n");
456 ufs_clear_opt (*mount_options, ONERROR);
457 ufs_set_opt (*mount_options, ONERROR_REPAIR);
458 break;
459 default:
460 printk("UFS-fs: Invalid option: \"%s\" "
461 "or missing value\n", p);
462 return 0;
463 }
464 }
465 return 1;
466}
467
468/*
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700469 * Diffrent types of UFS hold fs_cstotal in different
470 * places, and use diffrent data structure for it.
471 * To make things simplier we just copy fs_cstotal to ufs_sb_private_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 */
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700473static void ufs_setup_cstotal(struct super_block *sb)
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800474{
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700475 struct ufs_sb_info *sbi = UFS_SB(sb);
476 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700477 struct ufs_super_block_first *usb1;
478 struct ufs_super_block_second *usb2;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700479 struct ufs_super_block_third *usb3;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700480 unsigned mtype = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
481
482 UFSD("ENTER, mtype=%u\n", mtype);
483 usb1 = ubh_get_usb_first(uspi);
484 usb2 = ubh_get_usb_second(uspi);
485 usb3 = ubh_get_usb_third(uspi);
486
487 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
488 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
489 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
490 /*we have statistic in different place, then usual*/
491 uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
492 uspi->cs_total.cs_nbfree = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree);
493 uspi->cs_total.cs_nifree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree);
494 uspi->cs_total.cs_nffree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree);
495 } else {
496 uspi->cs_total.cs_ndir = fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir);
497 uspi->cs_total.cs_nbfree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree);
498 uspi->cs_total.cs_nifree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
499 uspi->cs_total.cs_nffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
500 }
501 UFSD("EXIT\n");
502}
503
504/*
505 * Read on-disk structures associated with cylinder groups
506 */
507static int ufs_read_cylinder_structures(struct super_block *sb)
508{
509 struct ufs_sb_info *sbi = UFS_SB(sb);
510 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 struct ufs_buffer_head * ubh;
512 unsigned char * base, * space;
513 unsigned size, blks, i;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700514 struct ufs_super_block_third *usb3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700516 UFSD("ENTER\n");
517
518 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 /*
520 * Read cs structures from (usually) first data block
521 * on the device.
522 */
523 size = uspi->s_cssize;
524 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
525 base = space = kmalloc(size, GFP_KERNEL);
526 if (!base)
527 goto failed;
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800528 sbi->s_csp = (struct ufs_csum *)space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 for (i = 0; i < blks; i += uspi->s_fpb) {
530 size = uspi->s_bsize;
531 if (i + uspi->s_fpb > blks)
532 size = (blks - i) * uspi->s_fsize;
533
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800534 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
Evgeniy7b4ee732006-01-14 11:42:06 +0300535
536 if (!ubh)
537 goto failed;
538
539 ubh_ubhcpymem (space, ubh, size);
Evgeniy7b4ee732006-01-14 11:42:06 +0300540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 space += size;
542 ubh_brelse (ubh);
543 ubh = NULL;
544 }
545
546 /*
547 * Read cylinder group (we read only first fragment from block
548 * at this time) and prepare internal data structures for cg caching.
549 */
550 if (!(sbi->s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_KERNEL)))
551 goto failed;
552 for (i = 0; i < uspi->s_ncg; i++)
553 sbi->s_ucg[i] = NULL;
554 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
555 sbi->s_ucpi[i] = NULL;
556 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
557 }
558 for (i = 0; i < uspi->s_ncg; i++) {
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700559 UFSD("read cg %u\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
561 goto failed;
562 if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
563 goto failed;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 }
567 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
568 if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_KERNEL)))
569 goto failed;
570 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
571 }
572 sbi->s_cg_loaded = 0;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700573 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return 1;
575
576failed:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800577 kfree (base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 if (sbi->s_ucg) {
579 for (i = 0; i < uspi->s_ncg; i++)
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800580 if (sbi->s_ucg[i])
581 brelse (sbi->s_ucg[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 kfree (sbi->s_ucg);
583 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800584 kfree (sbi->s_ucpi[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700586 UFSD("EXIT (FAILED)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 return 0;
588}
589
590/*
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700591 * Sync our internal copy of fs_cstotal with disk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 */
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700593static void ufs_put_cstotal(struct super_block *sb)
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800594{
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700595 unsigned mtype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
596 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
597 struct ufs_super_block_first *usb1;
598 struct ufs_super_block_second *usb2;
599 struct ufs_super_block_third *usb3;
600
601 UFSD("ENTER\n");
602 usb1 = ubh_get_usb_first(uspi);
603 usb2 = ubh_get_usb_second(uspi);
604 usb3 = ubh_get_usb_third(uspi);
605
606 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
607 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
608 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
609 /*we have statistic in different place, then usual*/
610 usb2->fs_un.fs_u2.cs_ndir =
611 cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
612 usb2->fs_un.fs_u2.cs_nbfree =
613 cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
614 usb3->fs_un1.fs_u2.cs_nifree =
615 cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
616 usb3->fs_un1.fs_u2.cs_nffree =
617 cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
618 } else {
619 usb1->fs_cstotal.cs_ndir =
620 cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
621 usb1->fs_cstotal.cs_nbfree =
622 cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
623 usb1->fs_cstotal.cs_nifree =
624 cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
625 usb1->fs_cstotal.cs_nffree =
626 cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
627 }
628 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800629 ufs_print_super_stuff(sb, usb1, usb2, usb3);
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700630 UFSD("EXIT\n");
631}
632
633/**
634 * ufs_put_super_internal() - put on-disk intrenal structures
635 * @sb: pointer to super_block structure
636 * Put on-disk structures associated with cylinder groups
637 * and write them back to disk, also update cs_total on disk
638 */
639static void ufs_put_super_internal(struct super_block *sb)
640{
641 struct ufs_sb_info *sbi = UFS_SB(sb);
642 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 struct ufs_buffer_head * ubh;
644 unsigned char * base, * space;
645 unsigned blks, size, i;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700648 UFSD("ENTER\n");
Christoph Hellwig6cfd0142009-05-05 15:40:36 +0200649
650 lock_kernel();
651
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700652 ufs_put_cstotal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 size = uspi->s_cssize;
654 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800655 base = space = (char*) sbi->s_csp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 for (i = 0; i < blks; i += uspi->s_fpb) {
657 size = uspi->s_bsize;
658 if (i + uspi->s_fpb > blks)
659 size = (blks - i) * uspi->s_fsize;
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 ubh_memcpyubh (ubh, space, size);
664 space += size;
665 ubh_mark_buffer_uptodate (ubh, 1);
666 ubh_mark_buffer_dirty (ubh);
667 ubh_brelse (ubh);
668 }
669 for (i = 0; i < sbi->s_cg_loaded; i++) {
670 ufs_put_cylinder (sb, i);
671 kfree (sbi->s_ucpi[i]);
672 }
673 for (; i < UFS_MAX_GROUP_LOADED; i++)
674 kfree (sbi->s_ucpi[i]);
675 for (i = 0; i < uspi->s_ncg; i++)
676 brelse (sbi->s_ucg[i]);
677 kfree (sbi->s_ucg);
678 kfree (base);
Christoph Hellwig6cfd0142009-05-05 15:40:36 +0200679
680 unlock_kernel();
681
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700682 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685static int ufs_fill_super(struct super_block *sb, void *data, int silent)
686{
687 struct ufs_sb_info * sbi;
688 struct ufs_sb_private_info * uspi;
689 struct ufs_super_block_first * usb1;
690 struct ufs_super_block_second * usb2;
691 struct ufs_super_block_third * usb3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 struct ufs_buffer_head * ubh;
693 struct inode *inode;
694 unsigned block_size, super_block_size;
695 unsigned flags;
Evgeniy7b4ee732006-01-14 11:42:06 +0300696 unsigned super_block_offset;
Duane Griffin9e6766c2009-01-08 22:43:48 +0000697 unsigned maxsymlen;
David Howellsb55c4602008-02-07 00:15:48 -0800698 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 uspi = NULL;
701 ubh = NULL;
702 flags = 0;
703
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700704 UFSD("ENTER\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Panagiotis Issarisf8314dc2006-09-27 01:49:37 -0700706 sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 if (!sbi)
708 goto failed_nomem;
709 sb->s_fs_info = sbi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700711 UFSD("flag %u\n", (int)(sb->s_flags & MS_RDONLY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713#ifndef CONFIG_UFS_FS_WRITE
714 if (!(sb->s_flags & MS_RDONLY)) {
715 printk("ufs was compiled with read-only support, "
716 "can't be mounted as read-write\n");
717 goto failed;
718 }
719#endif
720 /*
721 * Set default mount options
722 * Parse mount options
723 */
724 sbi->s_mount_opt = 0;
725 ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
726 if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
727 printk("wrong mount options\n");
728 goto failed;
729 }
730 if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
731 if (!silent)
732 printk("You didn't specify the type of your ufs filesystem\n\n"
733 "mount -t ufs -o ufstype="
Michael Owenc690a722006-03-24 18:21:44 +0100734 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
736 "default is ufstype=old\n");
737 ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
738 }
739
Mark Fortescue252e2112007-10-16 23:26:31 -0700740 uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
741 sbi->s_uspi = uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 if (!uspi)
743 goto failed;
Evgeniy Dushistovf3369532007-02-08 14:20:25 -0800744 uspi->s_dirblksize = UFS_SECTOR_SIZE;
Evgeniy7b4ee732006-01-14 11:42:06 +0300745 super_block_offset=UFS_SBLOCK;
746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 /* Keep 2Gig file limit. Some UFS variants need to override
748 this but as I don't know which I'll let those in the know loosen
749 the rules */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
751 case UFS_MOUNT_UFSTYPE_44BSD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700752 UFSD("ufstype=44bsd\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 uspi->s_fsize = block_size = 512;
754 uspi->s_fmask = ~(512 - 1);
755 uspi->s_fshift = 9;
756 uspi->s_sbsize = super_block_size = 1536;
757 uspi->s_sbbase = 0;
758 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
759 break;
760 case UFS_MOUNT_UFSTYPE_UFS2:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700761 UFSD("ufstype=ufs2\n");
Evgeniy7b4ee732006-01-14 11:42:06 +0300762 super_block_offset=SBLOCK_UFS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 uspi->s_fsize = block_size = 512;
764 uspi->s_fmask = ~(512 - 1);
765 uspi->s_fshift = 9;
766 uspi->s_sbsize = super_block_size = 1536;
767 uspi->s_sbbase = 0;
768 flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 break;
770
771 case UFS_MOUNT_UFSTYPE_SUN:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700772 UFSD("ufstype=sun\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 uspi->s_fsize = block_size = 1024;
774 uspi->s_fmask = ~(1024 - 1);
775 uspi->s_fshift = 10;
776 uspi->s_sbsize = super_block_size = 2048;
777 uspi->s_sbbase = 0;
Mark Fortescue252e2112007-10-16 23:26:31 -0700778 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
780 break;
781
Mark Fortescue252e2112007-10-16 23:26:31 -0700782 case UFS_MOUNT_UFSTYPE_SUNOS:
783 UFSD(("ufstype=sunos\n"))
784 uspi->s_fsize = block_size = 1024;
785 uspi->s_fmask = ~(1024 - 1);
786 uspi->s_fshift = 10;
787 uspi->s_sbsize = 2048;
788 super_block_size = 2048;
789 uspi->s_sbbase = 0;
790 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
791 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_SUNOS | UFS_CG_SUN;
792 break;
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 case UFS_MOUNT_UFSTYPE_SUNx86:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700795 UFSD("ufstype=sunx86\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 uspi->s_fsize = block_size = 1024;
797 uspi->s_fmask = ~(1024 - 1);
798 uspi->s_fshift = 10;
799 uspi->s_sbsize = super_block_size = 2048;
800 uspi->s_sbbase = 0;
Mark Fortescue252e2112007-10-16 23:26:31 -0700801 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
803 break;
804
805 case UFS_MOUNT_UFSTYPE_OLD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700806 UFSD("ufstype=old\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 uspi->s_fsize = block_size = 1024;
808 uspi->s_fmask = ~(1024 - 1);
809 uspi->s_fshift = 10;
810 uspi->s_sbsize = super_block_size = 2048;
811 uspi->s_sbbase = 0;
812 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
813 if (!(sb->s_flags & MS_RDONLY)) {
814 if (!silent)
815 printk(KERN_INFO "ufstype=old is supported read-only\n");
816 sb->s_flags |= MS_RDONLY;
817 }
818 break;
819
820 case UFS_MOUNT_UFSTYPE_NEXTSTEP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700821 UFSD("ufstype=nextstep\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 uspi->s_fsize = block_size = 1024;
823 uspi->s_fmask = ~(1024 - 1);
824 uspi->s_fshift = 10;
825 uspi->s_sbsize = super_block_size = 2048;
826 uspi->s_sbbase = 0;
Evgeniy Dushistov0c664f92007-12-04 23:45:06 -0800827 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
829 if (!(sb->s_flags & MS_RDONLY)) {
830 if (!silent)
831 printk(KERN_INFO "ufstype=nextstep is supported read-only\n");
832 sb->s_flags |= MS_RDONLY;
833 }
834 break;
835
836 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700837 UFSD("ufstype=nextstep-cd\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 uspi->s_fsize = block_size = 2048;
839 uspi->s_fmask = ~(2048 - 1);
840 uspi->s_fshift = 11;
841 uspi->s_sbsize = super_block_size = 2048;
842 uspi->s_sbbase = 0;
Evgeniy Dushistov0c664f92007-12-04 23:45:06 -0800843 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
845 if (!(sb->s_flags & MS_RDONLY)) {
846 if (!silent)
847 printk(KERN_INFO "ufstype=nextstep-cd is supported read-only\n");
848 sb->s_flags |= MS_RDONLY;
849 }
850 break;
851
852 case UFS_MOUNT_UFSTYPE_OPENSTEP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700853 UFSD("ufstype=openstep\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 uspi->s_fsize = block_size = 1024;
855 uspi->s_fmask = ~(1024 - 1);
856 uspi->s_fshift = 10;
857 uspi->s_sbsize = super_block_size = 2048;
858 uspi->s_sbbase = 0;
Evgeniy Dushistovf3369532007-02-08 14:20:25 -0800859 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
861 if (!(sb->s_flags & MS_RDONLY)) {
862 if (!silent)
863 printk(KERN_INFO "ufstype=openstep is supported read-only\n");
864 sb->s_flags |= MS_RDONLY;
865 }
866 break;
867
868 case UFS_MOUNT_UFSTYPE_HP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700869 UFSD("ufstype=hp\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 uspi->s_fsize = block_size = 1024;
871 uspi->s_fmask = ~(1024 - 1);
872 uspi->s_fshift = 10;
873 uspi->s_sbsize = super_block_size = 2048;
874 uspi->s_sbbase = 0;
875 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
876 if (!(sb->s_flags & MS_RDONLY)) {
877 if (!silent)
878 printk(KERN_INFO "ufstype=hp is supported read-only\n");
879 sb->s_flags |= MS_RDONLY;
880 }
881 break;
882 default:
883 if (!silent)
884 printk("unknown ufstype\n");
885 goto failed;
886 }
887
888again:
889 if (!sb_set_blocksize(sb, block_size)) {
890 printk(KERN_ERR "UFS: failed to set blocksize\n");
891 goto failed;
892 }
893
894 /*
895 * read ufs super block from device
896 */
Evgeniy7b4ee732006-01-14 11:42:06 +0300897
898 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 if (!ubh)
901 goto failed;
902
Evgeniy7b4ee732006-01-14 11:42:06 +0300903 usb1 = ubh_get_usb_first(uspi);
904 usb2 = ubh_get_usb_second(uspi);
905 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Mark Fortescue252e2112007-10-16 23:26:31 -0700907 /* Sort out mod used on SunOS 4.1.3 for fs_state */
908 uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
909 if (((flags & UFS_ST_MASK) == UFS_ST_SUNOS) &&
910 (uspi->s_postblformat != UFS_42POSTBLFMT)) {
911 flags &= ~UFS_ST_MASK;
912 flags |= UFS_ST_SUN;
913 }
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 /*
916 * Check ufs magic number
917 */
918 sbi->s_bytesex = BYTESEX_LE;
919 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
920 case UFS_MAGIC:
921 case UFS2_MAGIC:
922 case UFS_MAGIC_LFN:
923 case UFS_MAGIC_FEA:
924 case UFS_MAGIC_4GB:
925 goto magic_found;
926 }
927 sbi->s_bytesex = BYTESEX_BE;
928 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
929 case UFS_MAGIC:
930 case UFS2_MAGIC:
931 case UFS_MAGIC_LFN:
932 case UFS_MAGIC_FEA:
933 case UFS_MAGIC_4GB:
934 goto magic_found;
935 }
936
937 if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
938 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
939 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
940 && uspi->s_sbbase < 256) {
941 ubh_brelse_uspi(uspi);
942 ubh = NULL;
943 uspi->s_sbbase += 8;
944 goto again;
945 }
946 if (!silent)
947 printk("ufs_read_super: bad magic number\n");
948 goto failed;
949
950magic_found:
951 /*
952 * Check block and fragment sizes
953 */
954 uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
955 uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
956 uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
957 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
958 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
959
vignesh babu9e8c4272007-07-15 23:41:36 -0700960 if (!is_power_of_2(uspi->s_fsize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 printk(KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n",
962 uspi->s_fsize);
963 goto failed;
964 }
965 if (uspi->s_fsize < 512) {
966 printk(KERN_ERR "ufs_read_super: fragment size %u is too small\n",
967 uspi->s_fsize);
968 goto failed;
969 }
970 if (uspi->s_fsize > 4096) {
971 printk(KERN_ERR "ufs_read_super: fragment size %u is too large\n",
972 uspi->s_fsize);
973 goto failed;
974 }
vignesh babu9e8c4272007-07-15 23:41:36 -0700975 if (!is_power_of_2(uspi->s_bsize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 printk(KERN_ERR "ufs_read_super: block size %u is not a power of 2\n",
977 uspi->s_bsize);
978 goto failed;
979 }
980 if (uspi->s_bsize < 4096) {
981 printk(KERN_ERR "ufs_read_super: block size %u is too small\n",
982 uspi->s_bsize);
983 goto failed;
984 }
985 if (uspi->s_bsize / uspi->s_fsize > 8) {
986 printk(KERN_ERR "ufs_read_super: too many fragments per block (%u)\n",
987 uspi->s_bsize / uspi->s_fsize);
988 goto failed;
989 }
990 if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
991 ubh_brelse_uspi(uspi);
992 ubh = NULL;
993 block_size = uspi->s_fsize;
994 super_block_size = uspi->s_sbsize;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700995 UFSD("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 goto again;
997 }
998
Andrew Mortonf664f1f2007-10-29 14:37:21 -0700999 sbi->s_flags = flags;/*after that line some functions use s_flags*/
Evgeniy Dushistov3313e292007-02-12 00:54:31 -08001000 ufs_print_super_stuff(sb, usb1, usb2, usb3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 /*
1003 * Check, if file system was correctly unmounted.
1004 * If not, make it read only.
1005 */
Andrew Mortonf664f1f2007-10-29 14:37:21 -07001006 if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
1007 ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
1008 (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
1009 (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
1010 (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
1011 (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 switch(usb1->fs_clean) {
1013 case UFS_FSCLEAN:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001014 UFSD("fs is clean\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 break;
1016 case UFS_FSSTABLE:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001017 UFSD("fs is stable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 break;
Alex Viskovatoffb3a0fd42010-03-10 15:21:53 -08001019 case UFS_FSLOG:
1020 UFSD("fs is logging fs\n");
1021 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 case UFS_FSOSF1:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001023 UFSD("fs is DEC OSF/1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 break;
1025 case UFS_FSACTIVE:
1026 printk("ufs_read_super: fs is active\n");
1027 sb->s_flags |= MS_RDONLY;
1028 break;
1029 case UFS_FSBAD:
1030 printk("ufs_read_super: fs is bad\n");
1031 sb->s_flags |= MS_RDONLY;
1032 break;
1033 default:
1034 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1->fs_clean);
1035 sb->s_flags |= MS_RDONLY;
1036 break;
1037 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001038 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 printk("ufs_read_super: fs needs fsck\n");
1040 sb->s_flags |= MS_RDONLY;
1041 }
1042
1043 /*
1044 * Read ufs_super_block into internal data structures
1045 */
1046 sb->s_op = &ufs_super_ops;
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -08001047 sb->s_export_op = &ufs_export_ops;
Christoph Hellwig123e9ca2010-05-19 07:16:44 -04001048#ifdef CONFIG_QUOTA
1049 sb->s_qcop = &vfs_quotactl_ops;
1050 sb->dq_op = NULL; /* &dquot_operations */
1051#endif
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
1054
1055 uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
1056 uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
1057 uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
1058 uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
1059 uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
1060 uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
1061
1062 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001063 uspi->s_u2_size = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size);
1064 uspi->s_u2_dsize = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
1065 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
1067 uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
1068 }
1069
1070 uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
1071 /* s_bsize already set */
1072 /* s_fsize already set */
1073 uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
1074 uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
1075 uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
1076 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
1077 uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
1078 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001079 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
1080 uspi->s_fshift);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
1082 uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
1083 /* s_sbsize already set */
1084 uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
1085 uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
1086 uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
1087 uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
1088 uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
1089 uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
1090 uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
1091 uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -08001092
1093 if (uspi->fs_magic == UFS2_MAGIC)
1094 uspi->s_csaddr = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_csaddr);
1095 else
1096 uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
1097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
1099 uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
1100 uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
1101 uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
1102 uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
1103 uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
1104 uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001105 uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_un.fs_u1.fs_cpc);
1106 uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_contigsumsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
1108 uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
1110 uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
1111 uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
1112
1113 /*
1114 * Compute another frequently used values
1115 */
1116 uspi->s_fpbmask = uspi->s_fpb - 1;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001117 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 uspi->s_apbshift = uspi->s_bshift - 3;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001119 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 uspi->s_apbshift = uspi->s_bshift - 2;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 uspi->s_2apbshift = uspi->s_apbshift * 2;
1123 uspi->s_3apbshift = uspi->s_apbshift * 3;
1124 uspi->s_apb = 1 << uspi->s_apbshift;
1125 uspi->s_2apb = 1 << uspi->s_2apbshift;
1126 uspi->s_3apb = 1 << uspi->s_3apbshift;
1127 uspi->s_apbmask = uspi->s_apb - 1;
1128 uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
1129 uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
1130 uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
1131 uspi->s_bpf = uspi->s_fsize << 3;
1132 uspi->s_bpfshift = uspi->s_fshift + 3;
1133 uspi->s_bpfmask = uspi->s_bpf - 1;
Evgeniy Dushistov90b315a2008-02-08 04:20:16 -08001134 if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
1135 (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 uspi->s_maxsymlinklen =
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001137 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Duane Griffin9e6766c2009-01-08 22:43:48 +00001139 if (uspi->fs_magic == UFS2_MAGIC)
1140 maxsymlen = 2 * 4 * (UFS_NDADDR + UFS_NINDIR);
1141 else
1142 maxsymlen = 4 * (UFS_NDADDR + UFS_NINDIR);
1143 if (uspi->s_maxsymlinklen > maxsymlen) {
1144 ufs_warning(sb, __func__, "ufs_read_super: excessive maximum "
1145 "fast symlink size (%u)\n", uspi->s_maxsymlinklen);
1146 uspi->s_maxsymlinklen = maxsymlen;
1147 }
1148
David Howellsb55c4602008-02-07 00:15:48 -08001149 inode = ufs_iget(sb, UFS_ROOTINO);
1150 if (IS_ERR(inode)) {
1151 ret = PTR_ERR(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 goto failed;
David Howellsb55c4602008-02-07 00:15:48 -08001153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 sb->s_root = d_alloc_root(inode);
David Howellsb55c4602008-02-07 00:15:48 -08001155 if (!sb->s_root) {
1156 ret = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 goto dalloc_failed;
David Howellsb55c4602008-02-07 00:15:48 -08001158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001160 ufs_setup_cstotal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 /*
1162 * Read cylinder group structures
1163 */
1164 if (!(sb->s_flags & MS_RDONLY))
1165 if (!ufs_read_cylinder_structures(sb))
1166 goto failed;
1167
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001168 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 return 0;
1170
1171dalloc_failed:
1172 iput(inode);
1173failed:
Jesper Juhlf99d49a2005-11-07 01:01:34 -08001174 if (ubh)
1175 ubh_brelse_uspi (uspi);
1176 kfree (uspi);
1177 kfree(sbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 sb->s_fs_info = NULL;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001179 UFSD("EXIT (FAILED)\n");
David Howellsb55c4602008-02-07 00:15:48 -08001180 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
1182failed_nomem:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001183 UFSD("EXIT (NOMEM)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 return -ENOMEM;
1185}
1186
Christoph Hellwig8c800652009-06-08 10:08:05 +02001187static int ufs_sync_fs(struct super_block *sb, int wait)
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001188{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 struct ufs_sb_private_info * uspi;
1190 struct ufs_super_block_first * usb1;
1191 struct ufs_super_block_third * usb3;
1192 unsigned flags;
1193
Christoph Hellwigebc1ac12009-05-11 23:35:03 +02001194 lock_super(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 lock_kernel();
Christoph Hellwig8c800652009-06-08 10:08:05 +02001196
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001197 UFSD("ENTER\n");
Christoph Hellwig8c800652009-06-08 10:08:05 +02001198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 flags = UFS_SB(sb)->s_flags;
1200 uspi = UFS_SB(sb)->s_uspi;
Evgeniy7b4ee732006-01-14 11:42:06 +03001201 usb1 = ubh_get_usb_first(uspi);
1202 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Christoph Hellwig8c800652009-06-08 10:08:05 +02001204 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1205 if ((flags & UFS_ST_MASK) == UFS_ST_SUN ||
1206 (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
1207 (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1208 ufs_set_fs_state(sb, usb1, usb3,
1209 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
1210 ufs_put_cstotal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 sb->s_dirt = 0;
Christoph Hellwig8c800652009-06-08 10:08:05 +02001212
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001213 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 unlock_kernel();
Christoph Hellwigebc1ac12009-05-11 23:35:03 +02001215 unlock_super(sb);
Christoph Hellwig8c800652009-06-08 10:08:05 +02001216
1217 return 0;
1218}
1219
1220static void ufs_write_super(struct super_block *sb)
1221{
1222 if (!(sb->s_flags & MS_RDONLY))
1223 ufs_sync_fs(sb, 1);
1224 else
1225 sb->s_dirt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226}
1227
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001228static void ufs_put_super(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
1230 struct ufs_sb_info * sbi = UFS_SB(sb);
1231
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001232 UFSD("ENTER\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Christoph Hellwige0ccfd92010-05-19 07:16:42 -04001234 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
1235
Christoph Hellwig8c85e122009-04-28 18:00:26 +02001236 if (sb->s_dirt)
1237 ufs_write_super(sb);
1238
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 if (!(sb->s_flags & MS_RDONLY))
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001240 ufs_put_super_internal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
1242 ubh_brelse_uspi (sbi->s_uspi);
1243 kfree (sbi->s_uspi);
1244 kfree (sbi);
1245 sb->s_fs_info = NULL;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001246 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 return;
1248}
1249
1250
1251static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1252{
1253 struct ufs_sb_private_info * uspi;
1254 struct ufs_super_block_first * usb1;
1255 struct ufs_super_block_third * usb3;
1256 unsigned new_mount_opt, ufstype;
Christoph Hellwigc79d9672010-05-19 07:16:40 -04001257 int enable_quota = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 unsigned flags;
Christoph Hellwigc79d9672010-05-19 07:16:40 -04001259 int err;
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001260
1261 lock_kernel();
Al Virobbd68512009-05-06 10:43:07 -04001262 lock_super(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 uspi = UFS_SB(sb)->s_uspi;
1264 flags = UFS_SB(sb)->s_flags;
Evgeniy7b4ee732006-01-14 11:42:06 +03001265 usb1 = ubh_get_usb_first(uspi);
1266 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 /*
1269 * Allow the "check" option to be passed as a remount option.
1270 * It is not possible to change ufstype option during remount
1271 */
1272 ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
1273 new_mount_opt = 0;
1274 ufs_set_opt (new_mount_opt, ONERROR_LOCK);
Al Virobbd68512009-05-06 10:43:07 -04001275 if (!ufs_parse_options (data, &new_mount_opt)) {
1276 unlock_super(sb);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001277 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 return -EINVAL;
Al Virobbd68512009-05-06 10:43:07 -04001279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
1281 new_mount_opt |= ufstype;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001282 } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 printk("ufstype can't be changed during remount\n");
Al Virobbd68512009-05-06 10:43:07 -04001284 unlock_super(sb);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001285 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 return -EINVAL;
1287 }
1288
1289 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
1290 UFS_SB(sb)->s_mount_opt = new_mount_opt;
Al Virobbd68512009-05-06 10:43:07 -04001291 unlock_super(sb);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001292 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 return 0;
1294 }
1295
1296 /*
1297 * fs was mouted as rw, remounting ro
1298 */
1299 if (*mount_flags & MS_RDONLY) {
Christoph Hellwig0f0dd622010-05-19 07:16:41 -04001300 err = dquot_suspend(sb, -1);
1301 if (err < 0) {
Christoph Hellwigc79d9672010-05-19 07:16:40 -04001302 unlock_super(sb);
1303 unlock_kernel();
Christoph Hellwig0f0dd622010-05-19 07:16:41 -04001304 return err;
Christoph Hellwigc79d9672010-05-19 07:16:40 -04001305 }
1306
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001307 ufs_put_super_internal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1309 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
Mark Fortescue252e2112007-10-16 23:26:31 -07001310 || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1312 ufs_set_fs_state(sb, usb1, usb3,
1313 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -07001314 ubh_mark_buffer_dirty (USPI_UBH(uspi));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 sb->s_dirt = 0;
1316 sb->s_flags |= MS_RDONLY;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001317 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 /*
1319 * fs was mounted as ro, remounting rw
1320 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321#ifndef CONFIG_UFS_FS_WRITE
1322 printk("ufs was compiled with read-only support, "
1323 "can't be mounted as read-write\n");
Al Virobbd68512009-05-06 10:43:07 -04001324 unlock_super(sb);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001325 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 return -EINVAL;
1327#else
1328 if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
Mark Fortescue252e2112007-10-16 23:26:31 -07001329 ufstype != UFS_MOUNT_UFSTYPE_SUNOS &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
Evgeniy Dushistovcbcae392007-02-12 00:54:30 -08001331 ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
1332 ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 printk("this ufstype is read-only supported\n");
Al Virobbd68512009-05-06 10:43:07 -04001334 unlock_super(sb);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001335 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 return -EINVAL;
1337 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001338 if (!ufs_read_cylinder_structures(sb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 printk("failed during remounting\n");
Al Virobbd68512009-05-06 10:43:07 -04001340 unlock_super(sb);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001341 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 return -EPERM;
1343 }
1344 sb->s_flags &= ~MS_RDONLY;
Christoph Hellwigc79d9672010-05-19 07:16:40 -04001345 enable_quota = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346#endif
1347 }
1348 UFS_SB(sb)->s_mount_opt = new_mount_opt;
Al Virobbd68512009-05-06 10:43:07 -04001349 unlock_super(sb);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001350 unlock_kernel();
Christoph Hellwigc79d9672010-05-19 07:16:40 -04001351 if (enable_quota)
Christoph Hellwig0f0dd622010-05-19 07:16:41 -04001352 dquot_resume(sb, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 return 0;
1354}
1355
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001356static int ufs_show_options(struct seq_file *seq, struct vfsmount *vfs)
1357{
1358 struct ufs_sb_info *sbi = UFS_SB(vfs->mnt_sb);
1359 unsigned mval = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
Steven Whitehousea447c092008-10-13 10:46:57 +01001360 const struct match_token *tp = tokens;
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001361
1362 while (tp->token != Opt_onerror_panic && tp->token != mval)
1363 ++tp;
1364 BUG_ON(tp->token == Opt_onerror_panic);
1365 seq_printf(seq, ",%s", tp->pattern);
1366
1367 mval = sbi->s_mount_opt & UFS_MOUNT_ONERROR;
1368 while (tp->token != Opt_err && tp->token != mval)
1369 ++tp;
1370 BUG_ON(tp->token == Opt_err);
1371 seq_printf(seq, ",%s", tp->pattern);
1372
1373 return 0;
1374}
1375
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001376static int ufs_statfs(struct dentry *dentry, struct kstatfs *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
David Howells726c3342006-06-23 02:02:58 -07001378 struct super_block *sb = dentry->d_sb;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001379 struct ufs_sb_private_info *uspi= UFS_SB(sb)->s_uspi;
1380 unsigned flags = UFS_SB(sb)->s_flags;
1381 struct ufs_super_block_first *usb1;
1382 struct ufs_super_block_second *usb2;
1383 struct ufs_super_block_third *usb3;
Coly Li41d577a2009-04-02 16:59:44 -07001384 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 lock_kernel();
1387
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001388 usb1 = ubh_get_usb_first(uspi);
1389 usb2 = ubh_get_usb_second(uspi);
1390 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
1393 buf->f_type = UFS2_MAGIC;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001394 buf->f_blocks = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001395 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 buf->f_type = UFS_MAGIC;
1397 buf->f_blocks = uspi->s_dsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001399 buf->f_bfree = ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
1400 uspi->cs_total.cs_nffree;
1401 buf->f_ffree = uspi->cs_total.cs_nifree;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 buf->f_bsize = sb->s_blocksize;
1403 buf->f_bavail = (buf->f_bfree > (((long)buf->f_blocks / 100) * uspi->s_minfree))
1404 ? (buf->f_bfree - (((long)buf->f_blocks / 100) * uspi->s_minfree)) : 0;
1405 buf->f_files = uspi->s_ncg * uspi->s_ipg;
1406 buf->f_namelen = UFS_MAXNAMLEN;
Coly Li41d577a2009-04-02 16:59:44 -07001407 buf->f_fsid.val[0] = (u32)id;
1408 buf->f_fsid.val[1] = (u32)(id >> 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 unlock_kernel();
1411
1412 return 0;
1413}
1414
Christoph Lametere18b8902006-12-06 20:33:20 -08001415static struct kmem_cache * ufs_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
1417static struct inode *ufs_alloc_inode(struct super_block *sb)
1418{
1419 struct ufs_inode_info *ei;
Christoph Lametere94b1762006-12-06 20:33:17 -08001420 ei = (struct ufs_inode_info *)kmem_cache_alloc(ufs_inode_cachep, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 if (!ei)
1422 return NULL;
1423 ei->vfs_inode.i_version = 1;
1424 return &ei->vfs_inode;
1425}
1426
1427static void ufs_destroy_inode(struct inode *inode)
1428{
1429 kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
1430}
1431
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001432static void init_once(void *foo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
1434 struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
1435
Christoph Lametera35afb82007-05-16 22:10:57 -07001436 inode_init_once(&ei->vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
Paul Mundt20c2df82007-07-20 10:11:58 +09001438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439static int init_inodecache(void)
1440{
1441 ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
1442 sizeof(struct ufs_inode_info),
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001443 0, (SLAB_RECLAIM_ACCOUNT|
1444 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001445 init_once);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 if (ufs_inode_cachep == NULL)
1447 return -ENOMEM;
1448 return 0;
1449}
1450
1451static void destroy_inodecache(void)
1452{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001453 kmem_cache_destroy(ufs_inode_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
Christoph Hellwig257ba152010-03-03 09:05:04 -05001456static void ufs_clear_inode(struct inode *inode)
1457{
Christoph Hellwig9f754752010-03-03 09:05:05 -05001458 dquot_drop(inode);
Christoph Hellwig257ba152010-03-03 09:05:04 -05001459}
1460
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461#ifdef CONFIG_QUOTA
1462static ssize_t ufs_quota_read(struct super_block *, int, char *,size_t, loff_t);
1463static ssize_t ufs_quota_write(struct super_block *, int, const char *, size_t, loff_t);
1464#endif
1465
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -08001466static const struct super_operations ufs_super_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 .alloc_inode = ufs_alloc_inode,
1468 .destroy_inode = ufs_destroy_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 .write_inode = ufs_write_inode,
1470 .delete_inode = ufs_delete_inode,
Christoph Hellwig257ba152010-03-03 09:05:04 -05001471 .clear_inode = ufs_clear_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 .put_super = ufs_put_super,
1473 .write_super = ufs_write_super,
Christoph Hellwig8c800652009-06-08 10:08:05 +02001474 .sync_fs = ufs_sync_fs,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 .statfs = ufs_statfs,
1476 .remount_fs = ufs_remount,
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001477 .show_options = ufs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478#ifdef CONFIG_QUOTA
1479 .quota_read = ufs_quota_read,
1480 .quota_write = ufs_quota_write,
1481#endif
1482};
1483
1484#ifdef CONFIG_QUOTA
1485
1486/* Read data from quotafile - avoid pagecache and such because we cannot afford
1487 * acquiring the locks... As quota files are never truncated and quota code
1488 * itself serializes the operations (and noone else should touch the files)
1489 * we don't have to be afraid of races */
1490static ssize_t ufs_quota_read(struct super_block *sb, int type, char *data,
1491 size_t len, loff_t off)
1492{
1493 struct inode *inode = sb_dqopt(sb)->files[type];
1494 sector_t blk = off >> sb->s_blocksize_bits;
1495 int err = 0;
1496 int offset = off & (sb->s_blocksize - 1);
1497 int tocopy;
1498 size_t toread;
1499 struct buffer_head *bh;
1500 loff_t i_size = i_size_read(inode);
1501
1502 if (off > i_size)
1503 return 0;
1504 if (off+len > i_size)
1505 len = i_size-off;
1506 toread = len;
1507 while (toread > 0) {
1508 tocopy = sb->s_blocksize - offset < toread ?
1509 sb->s_blocksize - offset : toread;
1510
1511 bh = ufs_bread(inode, blk, 0, &err);
1512 if (err)
1513 return err;
1514 if (!bh) /* A hole? */
1515 memset(data, 0, tocopy);
1516 else {
1517 memcpy(data, bh->b_data+offset, tocopy);
1518 brelse(bh);
1519 }
1520 offset = 0;
1521 toread -= tocopy;
1522 data += tocopy;
1523 blk++;
1524 }
1525 return len;
1526}
1527
1528/* Write to quotafile */
1529static ssize_t ufs_quota_write(struct super_block *sb, int type,
1530 const char *data, size_t len, loff_t off)
1531{
1532 struct inode *inode = sb_dqopt(sb)->files[type];
1533 sector_t blk = off >> sb->s_blocksize_bits;
1534 int err = 0;
1535 int offset = off & (sb->s_blocksize - 1);
1536 int tocopy;
1537 size_t towrite = len;
1538 struct buffer_head *bh;
1539
Arjan van de Ven5c81a412006-07-03 00:25:20 -07001540 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 while (towrite > 0) {
1542 tocopy = sb->s_blocksize - offset < towrite ?
1543 sb->s_blocksize - offset : towrite;
1544
1545 bh = ufs_bread(inode, blk, 1, &err);
1546 if (!bh)
1547 goto out;
1548 lock_buffer(bh);
1549 memcpy(bh->b_data+offset, data, tocopy);
1550 flush_dcache_page(bh->b_page);
1551 set_buffer_uptodate(bh);
1552 mark_buffer_dirty(bh);
1553 unlock_buffer(bh);
1554 brelse(bh);
1555 offset = 0;
1556 towrite -= tocopy;
1557 data += tocopy;
1558 blk++;
1559 }
1560out:
Evgeniy Polyakov15b2fe32006-01-08 01:04:51 -08001561 if (len == towrite) {
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001562 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 return err;
Evgeniy Polyakov15b2fe32006-01-08 01:04:51 -08001564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 if (inode->i_size < off+len-towrite)
1566 i_size_write(inode, off+len-towrite);
1567 inode->i_version++;
1568 inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
1569 mark_inode_dirty(inode);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001570 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 return len - towrite;
1572}
1573
1574#endif
1575
David Howells454e2392006-06-23 02:02:57 -07001576static int ufs_get_sb(struct file_system_type *fs_type,
1577 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578{
David Howells454e2392006-06-23 02:02:57 -07001579 return get_sb_bdev(fs_type, flags, dev_name, data, ufs_fill_super, mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
1582static struct file_system_type ufs_fs_type = {
1583 .owner = THIS_MODULE,
1584 .name = "ufs",
1585 .get_sb = ufs_get_sb,
1586 .kill_sb = kill_block_super,
1587 .fs_flags = FS_REQUIRES_DEV,
1588};
1589
1590static int __init init_ufs_fs(void)
1591{
1592 int err = init_inodecache();
1593 if (err)
1594 goto out1;
1595 err = register_filesystem(&ufs_fs_type);
1596 if (err)
1597 goto out;
1598 return 0;
1599out:
1600 destroy_inodecache();
1601out1:
1602 return err;
1603}
1604
1605static void __exit exit_ufs_fs(void)
1606{
1607 unregister_filesystem(&ufs_fs_type);
1608 destroy_inodecache();
1609}
1610
1611module_init(init_ufs_fs)
1612module_exit(exit_ufs_fs)
1613MODULE_LICENSE("GPL");