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