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