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