[PATCH] DVB: Documentation and Kconfig updazes
[linux-2.6/history.git] / fs / ufs / super.c
blob8d5f1c21bc63a085bb81261baa8bd2e432b2557d
1 /*
2 * linux/fs/ufs/super.c
4 * Copyright (C) 1998
5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
7 */
9 /* Derived from
11 * linux/fs/ext2/super.c
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)
18 * from
20 * linux/fs/minix/inode.c
22 * Copyright (C) 1991, 1992 Linus Torvalds
24 * Big-endian to little-endian byte-swapping/bitmaps by
25 * David S. Miller (davem@caip.rutgers.edu), 1995
29 * Inspired by
31 * linux/fs/ufs/super.c
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
38 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
40 * Kernel module support added on 96/04/26 by
41 * Stefan Reinauer <stepan@home.culture.mipt.ru>
43 * Module usage counts added on 96/04/29 by
44 * Gertjan van Wingerde <gertjan@cs.vu.nl>
46 * Clean swab support on 19970406 by
47 * Francois-Rene Rideau <fare@tunes.org>
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>.
53 * NeXTstep support added on February 5th 1998 by
54 * Niels Kristian Bech Jensen <nkbj@image.dk>.
56 * write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
58 * HP/UX hfs filesystem support added by
59 * Martin K. Petersen <mkp@mkp.net>, August 1999
61 * UFS2 (of FreeBSD 5.x) support added by
62 * Niraj Kumar <niraj17@iitbombay.org>, Jan 2004
67 #include <linux/config.h>
68 #include <linux/module.h>
70 #include <stdarg.h>
72 #include <asm/bitops.h>
73 #include <asm/uaccess.h>
74 #include <asm/system.h>
76 #include <linux/errno.h>
77 #include <linux/fs.h>
78 #include <linux/ufs_fs.h>
79 #include <linux/slab.h>
80 #include <linux/time.h>
81 #include <linux/stat.h>
82 #include <linux/string.h>
83 #include <linux/blkdev.h>
84 #include <linux/init.h>
85 #include <linux/parser.h>
86 #include <linux/smp_lock.h>
87 #include <linux/buffer_head.h>
88 #include <linux/vfs.h>
90 #include "swab.h"
91 #include "util.h"
93 #undef UFS_SUPER_DEBUG
94 #undef UFS_SUPER_DEBUG_MORE
96 #ifdef UFS_SUPER_DEBUG
97 #define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
98 #else
99 #define UFSD(x)
100 #endif
102 #ifdef UFS_SUPER_DEBUG_MORE
104 * Print contents of ufs_super_block, useful for debugging
106 void ufs_print_super_stuff(struct super_block *sb,
107 struct ufs_super_block_first * usb1,
108 struct ufs_super_block_second * usb2,
109 struct ufs_super_block_third * usb3)
111 printk("ufs_print_super_stuff\n");
112 printk("size of usb: %u\n", sizeof(struct ufs_super_block));
113 printk(" magic: 0x%x\n", fs32_to_cpu(sb, usb3->fs_magic));
114 printk(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
115 printk(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
116 printk(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
117 printk(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
118 printk(" cgoffset: %u\n", fs32_to_cpu(sb, usb1->fs_cgoffset));
119 printk(" ~cgmask: 0x%x\n", ~fs32_to_cpu(sb, usb1->fs_cgmask));
120 printk(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
121 printk(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
122 printk(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
123 printk(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
124 printk(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
125 printk(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
126 printk(" fragshift: %u\n", fs32_to_cpu(sb, usb1->fs_fragshift));
127 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
128 printk(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
129 printk(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
130 printk(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
131 printk(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
132 printk(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
133 printk(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
134 printk(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
135 printk(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
136 printk(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
137 printk(" fstodb: %u\n", fs32_to_cpu(sb, usb1->fs_fsbtodb));
138 printk(" contigsumsize: %d\n", fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_contigsumsize));
139 printk(" postblformat: %u\n", fs32_to_cpu(sb, usb3->fs_postblformat));
140 printk(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
141 printk(" ndir %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
142 printk(" nifree %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
143 printk(" nbfree %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
144 printk(" nffree %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
145 printk("\n");
149 * Print contents of ufs2 ufs_super_block, useful for debugging
151 void ufs2_print_super_stuff(
152 struct super_block *sb,
153 struct ufs_super_block *usb)
155 printk("ufs_print_super_stuff\n");
156 printk("size of usb: %u\n", sizeof(struct ufs_super_block));
157 printk(" magic: 0x%x\n", fs32_to_cpu(sb, usb->fs_magic));
158 printk(" fs_size: %u\n",fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_size));
159 printk(" fs_dsize: %u\n",fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_dsize));
160 printk(" fs_volname: %s\n", usb->fs_u11.fs_u2.fs_volname);
161 printk(" fs_fsmnt: %s\n", usb->fs_u11.fs_u2.fs_fsmnt);
162 printk(" fs_sblockloc: %u\n",fs64_to_cpu(sb,
163 usb->fs_u11.fs_u2.fs_sblockloc));
164 printk(" cs_ndir(No of dirs): %u\n",fs64_to_cpu(sb,
165 usb->fs_u11.fs_u2.fs_cstotal.cs_ndir));
166 printk(" cs_nbfree(No of free blocks): %u\n",fs64_to_cpu(sb,
167 usb->fs_u11.fs_u2.fs_cstotal.cs_nbfree));
168 printk("\n");
172 * Print contents of ufs_cylinder_group, useful for debugging
174 void ufs_print_cylinder_stuff(struct super_block *sb, struct ufs_cylinder_group *cg)
176 printk("\nufs_print_cylinder_stuff\n");
177 printk("size of ucg: %u\n", sizeof(struct ufs_cylinder_group));
178 printk(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
179 printk(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
180 printk(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
181 printk(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
182 printk(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
183 printk(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
184 printk(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
185 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
186 printk(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
187 printk(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
188 printk(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
189 printk(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
190 printk(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
191 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
192 fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
193 fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
194 fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
195 fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
196 printk(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
197 printk(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
198 printk(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
199 printk(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
200 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
201 printk(" clustersumoff %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
202 printk(" clusteroff %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
203 printk(" nclusterblks %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
204 printk("\n");
206 #endif /* UFS_SUPER_DEBUG_MORE */
208 static struct super_operations ufs_super_ops;
210 static char error_buf[1024];
212 void ufs_error (struct super_block * sb, const char * function,
213 const char * fmt, ...)
215 struct ufs_sb_private_info * uspi;
216 struct ufs_super_block_first * usb1;
217 va_list args;
219 uspi = UFS_SB(sb)->s_uspi;
220 usb1 = ubh_get_usb_first(USPI_UBH);
222 if (!(sb->s_flags & MS_RDONLY)) {
223 usb1->fs_clean = UFS_FSBAD;
224 ubh_mark_buffer_dirty(USPI_UBH);
225 sb->s_dirt = 1;
226 sb->s_flags |= MS_RDONLY;
228 va_start (args, fmt);
229 vsprintf (error_buf, fmt, args);
230 va_end (args);
231 switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
232 case UFS_MOUNT_ONERROR_PANIC:
233 panic ("UFS-fs panic (device %s): %s: %s\n",
234 sb->s_id, function, error_buf);
236 case UFS_MOUNT_ONERROR_LOCK:
237 case UFS_MOUNT_ONERROR_UMOUNT:
238 case UFS_MOUNT_ONERROR_REPAIR:
239 printk (KERN_CRIT "UFS-fs error (device %s): %s: %s\n",
240 sb->s_id, function, error_buf);
244 void ufs_panic (struct super_block * sb, const char * function,
245 const char * fmt, ...)
247 struct ufs_sb_private_info * uspi;
248 struct ufs_super_block_first * usb1;
249 va_list args;
251 uspi = UFS_SB(sb)->s_uspi;
252 usb1 = ubh_get_usb_first(USPI_UBH);
254 if (!(sb->s_flags & MS_RDONLY)) {
255 usb1->fs_clean = UFS_FSBAD;
256 ubh_mark_buffer_dirty(USPI_UBH);
257 sb->s_dirt = 1;
259 va_start (args, fmt);
260 vsprintf (error_buf, fmt, args);
261 va_end (args);
262 sb->s_flags |= MS_RDONLY;
263 printk (KERN_CRIT "UFS-fs panic (device %s): %s: %s\n",
264 sb->s_id, function, error_buf);
267 void ufs_warning (struct super_block * sb, const char * function,
268 const char * fmt, ...)
270 va_list args;
272 va_start (args, fmt);
273 vsprintf (error_buf, fmt, args);
274 va_end (args);
275 printk (KERN_WARNING "UFS-fs warning (device %s): %s: %s\n",
276 sb->s_id, function, error_buf);
279 enum {
280 Opt_type_old, Opt_type_sunx86, Opt_type_sun, Opt_type_44bsd,
281 Opt_type_ufs2, Opt_type_hp, Opt_type_nextstepcd, Opt_type_nextstep,
282 Opt_type_openstep, Opt_onerror_panic, Opt_onerror_lock,
283 Opt_onerror_umount, Opt_onerror_repair, Opt_err
286 static match_table_t tokens = {
287 {Opt_type_old, "ufstype=old"},
288 {Opt_type_sunx86, "ufstype=sunx86"},
289 {Opt_type_sun, "ufstype=sun"},
290 {Opt_type_44bsd, "ufstype=44bsd"},
291 {Opt_type_ufs2, "ufstype=ufs2"},
292 {Opt_type_ufs2, "ufstype=5xbsd"},
293 {Opt_type_hp, "ufstype=hp"},
294 {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
295 {Opt_type_nextstep, "ufstype=nextstep"},
296 {Opt_type_openstep, "ufstype=openstep"},
297 {Opt_onerror_panic, "onerror=panic"},
298 {Opt_onerror_lock, "onerror=lock"},
299 {Opt_onerror_umount, "onerror=umount"},
300 {Opt_onerror_repair, "onerror=repair"},
301 {Opt_err, NULL}
304 static int ufs_parse_options (char * options, unsigned * mount_options)
306 char * p;
308 UFSD(("ENTER\n"))
310 if (!options)
311 return 1;
313 while ((p = strsep(&options, ",")) != NULL) {
314 substring_t args[MAX_OPT_ARGS];
315 int token;
316 if (!*p)
317 continue;
319 token = match_token(p, tokens, args);
320 switch (token) {
321 case Opt_type_old:
322 ufs_clear_opt (*mount_options, UFSTYPE);
323 ufs_set_opt (*mount_options, UFSTYPE_OLD);
324 break;
325 case Opt_type_sunx86:
326 ufs_clear_opt (*mount_options, UFSTYPE);
327 ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
328 break;
329 case Opt_type_sun:
330 ufs_clear_opt (*mount_options, UFSTYPE);
331 ufs_set_opt (*mount_options, UFSTYPE_SUN);
332 break;
333 case Opt_type_44bsd:
334 ufs_clear_opt (*mount_options, UFSTYPE);
335 ufs_set_opt (*mount_options, UFSTYPE_44BSD);
336 break;
337 case Opt_type_ufs2:
338 ufs_clear_opt(*mount_options, UFSTYPE);
339 ufs_set_opt(*mount_options, UFSTYPE_UFS2);
340 break;
341 case Opt_type_hp:
342 ufs_clear_opt (*mount_options, UFSTYPE);
343 ufs_set_opt (*mount_options, UFSTYPE_HP);
344 break;
345 case Opt_type_nextstepcd:
346 ufs_clear_opt (*mount_options, UFSTYPE);
347 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
348 break;
349 case Opt_type_nextstep:
350 ufs_clear_opt (*mount_options, UFSTYPE);
351 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
352 break;
353 case Opt_type_openstep:
354 ufs_clear_opt (*mount_options, UFSTYPE);
355 ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
356 break;
357 case Opt_onerror_panic:
358 ufs_clear_opt (*mount_options, ONERROR);
359 ufs_set_opt (*mount_options, ONERROR_PANIC);
360 break;
361 case Opt_onerror_lock:
362 ufs_clear_opt (*mount_options, ONERROR);
363 ufs_set_opt (*mount_options, ONERROR_LOCK);
364 break;
365 case Opt_onerror_umount:
366 ufs_clear_opt (*mount_options, ONERROR);
367 ufs_set_opt (*mount_options, ONERROR_UMOUNT);
368 break;
369 case Opt_onerror_repair:
370 printk("UFS-fs: Unable to do repair on error, "
371 "will lock lock instead\n");
372 ufs_clear_opt (*mount_options, ONERROR);
373 ufs_set_opt (*mount_options, ONERROR_REPAIR);
374 break;
375 default:
376 printk("UFS-fs: Invalid option: \"%s\" "
377 "or missing value\n", p);
378 return 0;
381 return 1;
385 * Read on-disk structures associated with cylinder groups
387 int ufs_read_cylinder_structures (struct super_block * sb) {
388 struct ufs_sb_info * sbi = UFS_SB(sb);
389 struct ufs_sb_private_info * uspi;
390 struct ufs_super_block *usb;
391 struct ufs_buffer_head * ubh;
392 unsigned char * base, * space;
393 unsigned size, blks, i;
394 unsigned flags = 0;
396 UFSD(("ENTER\n"))
398 uspi = sbi->s_uspi;
400 usb = (struct ufs_super_block *)
401 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data;
403 flags = UFS_SB(sb)->s_flags;
406 * Read cs structures from (usually) first data block
407 * on the device.
409 size = uspi->s_cssize;
410 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
411 base = space = kmalloc(size, GFP_KERNEL);
412 if (!base)
413 goto failed;
414 for (i = 0; i < blks; i += uspi->s_fpb) {
415 size = uspi->s_bsize;
416 if (i + uspi->s_fpb > blks)
417 size = (blks - i) * uspi->s_fsize;
419 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
420 ubh = ubh_bread(sb,
421 fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_csaddr) + i, size);
422 if (!ubh)
423 goto failed;
424 ubh_ubhcpymem (space, ubh, size);
425 sbi->s_csp[ufs_fragstoblks(i)]=(struct ufs_csum *)space;
427 else {
428 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
429 if (!ubh)
430 goto failed;
431 ubh_ubhcpymem(space, ubh, size);
432 sbi->s_csp[ufs_fragstoblks(i)]=(struct ufs_csum *)space;
434 space += size;
435 ubh_brelse (ubh);
436 ubh = NULL;
440 * Read cylinder group (we read only first fragment from block
441 * at this time) and prepare internal data structures for cg caching.
443 if (!(sbi->s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_KERNEL)))
444 goto failed;
445 for (i = 0; i < uspi->s_ncg; i++)
446 sbi->s_ucg[i] = NULL;
447 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
448 sbi->s_ucpi[i] = NULL;
449 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
451 for (i = 0; i < uspi->s_ncg; i++) {
452 UFSD(("read cg %u\n", i))
453 if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
454 goto failed;
455 if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
456 goto failed;
457 #ifdef UFS_SUPER_DEBUG_MORE
458 ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
459 #endif
461 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
462 if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_KERNEL)))
463 goto failed;
464 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
466 sbi->s_cg_loaded = 0;
467 UFSD(("EXIT\n"))
468 return 1;
470 failed:
471 if (base) kfree (base);
472 if (sbi->s_ucg) {
473 for (i = 0; i < uspi->s_ncg; i++)
474 if (sbi->s_ucg[i]) brelse (sbi->s_ucg[i]);
475 kfree (sbi->s_ucg);
476 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
477 if (sbi->s_ucpi[i]) kfree (sbi->s_ucpi[i]);
479 UFSD(("EXIT (FAILED)\n"))
480 return 0;
484 * Put on-disk structures associated with cylinder groups and
485 * write them back to disk
487 void ufs_put_cylinder_structures (struct super_block * sb) {
488 struct ufs_sb_info * sbi = UFS_SB(sb);
489 struct ufs_sb_private_info * uspi;
490 struct ufs_buffer_head * ubh;
491 unsigned char * base, * space;
492 unsigned blks, size, i;
494 UFSD(("ENTER\n"))
496 uspi = sbi->s_uspi;
498 size = uspi->s_cssize;
499 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
500 base = space = (char*) sbi->s_csp[0];
501 for (i = 0; i < blks; i += uspi->s_fpb) {
502 size = uspi->s_bsize;
503 if (i + uspi->s_fpb > blks)
504 size = (blks - i) * uspi->s_fsize;
505 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
506 ubh_memcpyubh (ubh, space, size);
507 space += size;
508 ubh_mark_buffer_uptodate (ubh, 1);
509 ubh_mark_buffer_dirty (ubh);
510 ubh_brelse (ubh);
512 for (i = 0; i < sbi->s_cg_loaded; i++) {
513 ufs_put_cylinder (sb, i);
514 kfree (sbi->s_ucpi[i]);
516 for (; i < UFS_MAX_GROUP_LOADED; i++)
517 kfree (sbi->s_ucpi[i]);
518 for (i = 0; i < uspi->s_ncg; i++)
519 brelse (sbi->s_ucg[i]);
520 kfree (sbi->s_ucg);
521 kfree (base);
522 UFSD(("EXIT\n"))
525 static int ufs_fill_super(struct super_block *sb, void *data, int silent)
527 struct ufs_sb_info * sbi;
528 struct ufs_sb_private_info * uspi;
529 struct ufs_super_block_first * usb1;
530 struct ufs_super_block_second * usb2;
531 struct ufs_super_block_third * usb3;
532 struct ufs_super_block *usb;
533 struct ufs_buffer_head * ubh;
534 struct inode *inode;
535 unsigned block_size, super_block_size;
536 unsigned flags;
538 uspi = NULL;
539 ubh = NULL;
540 flags = 0;
542 UFSD(("ENTER\n"))
544 sbi = kmalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
545 if (!sbi)
546 goto failed_nomem;
547 sb->s_fs_info = sbi;
548 memset(sbi, 0, sizeof(struct ufs_sb_info));
550 UFSD(("flag %u\n", (int)(sb->s_flags & MS_RDONLY)))
552 #ifndef CONFIG_UFS_FS_WRITE
553 if (!(sb->s_flags & MS_RDONLY)) {
554 printk("ufs was compiled with read-only support, "
555 "can't be mounted as read-write\n");
556 goto failed;
558 #endif
560 * Set default mount options
561 * Parse mount options
563 sbi->s_mount_opt = 0;
564 ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
565 if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
566 printk("wrong mount options\n");
567 goto failed;
569 if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
570 if (!silent)
571 printk("You didn't specify the type of your ufs filesystem\n\n"
572 "mount -t ufs -o ufstype="
573 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|netxstep-cd|openstep ...\n\n"
574 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
575 "default is ufstype=old\n");
576 ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
579 sbi->s_uspi = uspi =
580 kmalloc (sizeof(struct ufs_sb_private_info), GFP_KERNEL);
581 if (!uspi)
582 goto failed;
584 /* Keep 2Gig file limit. Some UFS variants need to override
585 this but as I don't know which I'll let those in the know loosen
586 the rules */
588 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
589 case UFS_MOUNT_UFSTYPE_44BSD:
590 UFSD(("ufstype=44bsd\n"))
591 uspi->s_fsize = block_size = 512;
592 uspi->s_fmask = ~(512 - 1);
593 uspi->s_fshift = 9;
594 uspi->s_sbsize = super_block_size = 1536;
595 uspi->s_sbbase = 0;
596 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
597 break;
598 case UFS_MOUNT_UFSTYPE_UFS2:
599 UFSD(("ufstype=ufs2\n"))
600 uspi->s_fsize = block_size = 512;
601 uspi->s_fmask = ~(512 - 1);
602 uspi->s_fshift = 9;
603 uspi->s_sbsize = super_block_size = 1536;
604 uspi->s_sbbase = 0;
605 flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
606 if (!(sb->s_flags & MS_RDONLY)) {
607 printk(KERN_INFO "ufstype=ufs2 is supported read-only\n");
608 sb->s_flags |= MS_RDONLY;
610 break;
612 case UFS_MOUNT_UFSTYPE_SUN:
613 UFSD(("ufstype=sun\n"))
614 uspi->s_fsize = block_size = 1024;
615 uspi->s_fmask = ~(1024 - 1);
616 uspi->s_fshift = 10;
617 uspi->s_sbsize = super_block_size = 2048;
618 uspi->s_sbbase = 0;
619 uspi->s_maxsymlinklen = 56;
620 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
621 break;
623 case UFS_MOUNT_UFSTYPE_SUNx86:
624 UFSD(("ufstype=sunx86\n"))
625 uspi->s_fsize = block_size = 1024;
626 uspi->s_fmask = ~(1024 - 1);
627 uspi->s_fshift = 10;
628 uspi->s_sbsize = super_block_size = 2048;
629 uspi->s_sbbase = 0;
630 uspi->s_maxsymlinklen = 56;
631 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
632 break;
634 case UFS_MOUNT_UFSTYPE_OLD:
635 UFSD(("ufstype=old\n"))
636 uspi->s_fsize = block_size = 1024;
637 uspi->s_fmask = ~(1024 - 1);
638 uspi->s_fshift = 10;
639 uspi->s_sbsize = super_block_size = 2048;
640 uspi->s_sbbase = 0;
641 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
642 if (!(sb->s_flags & MS_RDONLY)) {
643 if (!silent)
644 printk(KERN_INFO "ufstype=old is supported read-only\n");
645 sb->s_flags |= MS_RDONLY;
647 break;
649 case UFS_MOUNT_UFSTYPE_NEXTSTEP:
650 UFSD(("ufstype=nextstep\n"))
651 uspi->s_fsize = block_size = 1024;
652 uspi->s_fmask = ~(1024 - 1);
653 uspi->s_fshift = 10;
654 uspi->s_sbsize = super_block_size = 2048;
655 uspi->s_sbbase = 0;
656 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
657 if (!(sb->s_flags & MS_RDONLY)) {
658 if (!silent)
659 printk(KERN_INFO "ufstype=nextstep is supported read-only\n");
660 sb->s_flags |= MS_RDONLY;
662 break;
664 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
665 UFSD(("ufstype=nextstep-cd\n"))
666 uspi->s_fsize = block_size = 2048;
667 uspi->s_fmask = ~(2048 - 1);
668 uspi->s_fshift = 11;
669 uspi->s_sbsize = super_block_size = 2048;
670 uspi->s_sbbase = 0;
671 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
672 if (!(sb->s_flags & MS_RDONLY)) {
673 if (!silent)
674 printk(KERN_INFO "ufstype=nextstep-cd is supported read-only\n");
675 sb->s_flags |= MS_RDONLY;
677 break;
679 case UFS_MOUNT_UFSTYPE_OPENSTEP:
680 UFSD(("ufstype=openstep\n"))
681 uspi->s_fsize = block_size = 1024;
682 uspi->s_fmask = ~(1024 - 1);
683 uspi->s_fshift = 10;
684 uspi->s_sbsize = super_block_size = 2048;
685 uspi->s_sbbase = 0;
686 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
687 if (!(sb->s_flags & MS_RDONLY)) {
688 if (!silent)
689 printk(KERN_INFO "ufstype=openstep is supported read-only\n");
690 sb->s_flags |= MS_RDONLY;
692 break;
694 case UFS_MOUNT_UFSTYPE_HP:
695 UFSD(("ufstype=hp\n"))
696 uspi->s_fsize = block_size = 1024;
697 uspi->s_fmask = ~(1024 - 1);
698 uspi->s_fshift = 10;
699 uspi->s_sbsize = super_block_size = 2048;
700 uspi->s_sbbase = 0;
701 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
702 if (!(sb->s_flags & MS_RDONLY)) {
703 if (!silent)
704 printk(KERN_INFO "ufstype=hp is supported read-only\n");
705 sb->s_flags |= MS_RDONLY;
707 break;
708 default:
709 if (!silent)
710 printk("unknown ufstype\n");
711 goto failed;
714 again:
715 if (!sb_set_blocksize(sb, block_size)) {
716 printk(KERN_ERR "UFS: failed to set blocksize\n");
717 goto failed;
721 * read ufs super block from device
723 if ( (flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
724 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + SBLOCK_UFS2/block_size, super_block_size);
726 else {
727 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + UFS_SBLOCK/block_size, super_block_size);
729 if (!ubh)
730 goto failed;
733 usb1 = ubh_get_usb_first(USPI_UBH);
734 usb2 = ubh_get_usb_second(USPI_UBH);
735 usb3 = ubh_get_usb_third(USPI_UBH);
736 usb = (struct ufs_super_block *)
737 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ;
740 * Check ufs magic number
742 switch ((uspi->fs_magic = __constant_le32_to_cpu(usb3->fs_magic))) {
743 case UFS_MAGIC:
744 case UFS2_MAGIC:
745 case UFS_MAGIC_LFN:
746 case UFS_MAGIC_FEA:
747 case UFS_MAGIC_4GB:
748 sbi->s_bytesex = BYTESEX_LE;
749 goto magic_found;
751 switch ((uspi->fs_magic = __constant_be32_to_cpu(usb3->fs_magic))) {
752 case UFS_MAGIC:
753 case UFS2_MAGIC:
754 case UFS_MAGIC_LFN:
755 case UFS_MAGIC_FEA:
756 case UFS_MAGIC_4GB:
757 sbi->s_bytesex = BYTESEX_BE;
758 goto magic_found;
761 if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
762 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
763 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
764 && uspi->s_sbbase < 256) {
765 ubh_brelse_uspi(uspi);
766 ubh = NULL;
767 uspi->s_sbbase += 8;
768 goto again;
770 if (!silent)
771 printk("ufs_read_super: bad magic number\n");
772 goto failed;
774 magic_found:
776 * Check block and fragment sizes
778 uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
779 uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
780 uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
781 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
782 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
784 if (uspi->s_fsize & (uspi->s_fsize - 1)) {
785 printk(KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n",
786 uspi->s_fsize);
787 goto failed;
789 if (uspi->s_fsize < 512) {
790 printk(KERN_ERR "ufs_read_super: fragment size %u is too small\n",
791 uspi->s_fsize);
792 goto failed;
794 if (uspi->s_fsize > 4096) {
795 printk(KERN_ERR "ufs_read_super: fragment size %u is too large\n",
796 uspi->s_fsize);
797 goto failed;
799 if (uspi->s_bsize & (uspi->s_bsize - 1)) {
800 printk(KERN_ERR "ufs_read_super: block size %u is not a power of 2\n",
801 uspi->s_bsize);
802 goto failed;
804 if (uspi->s_bsize < 4096) {
805 printk(KERN_ERR "ufs_read_super: block size %u is too small\n",
806 uspi->s_bsize);
807 goto failed;
809 if (uspi->s_bsize / uspi->s_fsize > 8) {
810 printk(KERN_ERR "ufs_read_super: too many fragments per block (%u)\n",
811 uspi->s_bsize / uspi->s_fsize);
812 goto failed;
814 if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
815 ubh_brelse_uspi(uspi);
816 ubh = NULL;
817 block_size = uspi->s_fsize;
818 super_block_size = uspi->s_sbsize;
819 UFSD(("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size))
820 goto again;
823 #ifdef UFS_SUPER_DEBUG_MORE
824 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
825 ufs2_print_super_stuff(sb,usb);
826 else
827 ufs_print_super_stuff(sb, usb1, usb2, usb3);
828 #endif
831 * Check, if file system was correctly unmounted.
832 * If not, make it read only.
834 if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
835 ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
836 (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
837 (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
838 (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
839 switch(usb1->fs_clean) {
840 case UFS_FSCLEAN:
841 UFSD(("fs is clean\n"))
842 break;
843 case UFS_FSSTABLE:
844 UFSD(("fs is stable\n"))
845 break;
846 case UFS_FSOSF1:
847 UFSD(("fs is DEC OSF/1\n"))
848 break;
849 case UFS_FSACTIVE:
850 printk("ufs_read_super: fs is active\n");
851 sb->s_flags |= MS_RDONLY;
852 break;
853 case UFS_FSBAD:
854 printk("ufs_read_super: fs is bad\n");
855 sb->s_flags |= MS_RDONLY;
856 break;
857 default:
858 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1->fs_clean);
859 sb->s_flags |= MS_RDONLY;
860 break;
863 else {
864 printk("ufs_read_super: fs needs fsck\n");
865 sb->s_flags |= MS_RDONLY;
869 * Read ufs_super_block into internal data structures
871 sb->s_op = &ufs_super_ops;
872 sb->dq_op = NULL; /***/
873 sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
875 uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
876 uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
877 uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
878 uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
879 uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
880 uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
882 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
883 uspi->s_u2_size = fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_size);
884 uspi->s_u2_dsize = fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_dsize);
886 else {
887 uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
888 uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
891 uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
892 /* s_bsize already set */
893 /* s_fsize already set */
894 uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
895 uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
896 uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
897 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
898 uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
899 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
900 uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
901 uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
902 /* s_sbsize already set */
903 uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
904 uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
905 uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
906 uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
907 uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
908 uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
909 uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
910 uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
911 uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
912 uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
913 uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
914 uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
915 uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
916 uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
917 uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
918 uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
919 uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_cpc);
920 uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_contigsumsize);
921 uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
922 uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
923 uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
924 uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
925 uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
926 uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
929 * Compute another frequently used values
931 uspi->s_fpbmask = uspi->s_fpb - 1;
932 uspi->s_apbshift = uspi->s_bshift - 2;
933 uspi->s_2apbshift = uspi->s_apbshift * 2;
934 uspi->s_3apbshift = uspi->s_apbshift * 3;
935 uspi->s_apb = 1 << uspi->s_apbshift;
936 uspi->s_2apb = 1 << uspi->s_2apbshift;
937 uspi->s_3apb = 1 << uspi->s_3apbshift;
938 uspi->s_apbmask = uspi->s_apb - 1;
939 uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
940 uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
941 uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
942 uspi->s_bpf = uspi->s_fsize << 3;
943 uspi->s_bpfshift = uspi->s_fshift + 3;
944 uspi->s_bpfmask = uspi->s_bpf - 1;
945 if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) ==
946 UFS_MOUNT_UFSTYPE_44BSD)
947 uspi->s_maxsymlinklen =
948 fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_maxsymlinklen);
950 sbi->s_flags = flags;
952 inode = iget(sb, UFS_ROOTINO);
953 if (!inode || is_bad_inode(inode))
954 goto failed;
955 sb->s_root = d_alloc_root(inode);
956 if (!sb->s_root)
957 goto dalloc_failed;
961 * Read cylinder group structures
963 if (!(sb->s_flags & MS_RDONLY))
964 if (!ufs_read_cylinder_structures(sb))
965 goto failed;
967 UFSD(("EXIT\n"))
968 return 0;
970 dalloc_failed:
971 iput(inode);
972 failed:
973 if (ubh) ubh_brelse_uspi (uspi);
974 if (uspi) kfree (uspi);
975 if (sbi) kfree(sbi);
976 sb->s_fs_info = NULL;
977 UFSD(("EXIT (FAILED)\n"))
978 return -EINVAL;
980 failed_nomem:
981 UFSD(("EXIT (NOMEM)\n"))
982 return -ENOMEM;
985 void ufs_write_super (struct super_block * sb) {
986 struct ufs_sb_private_info * uspi;
987 struct ufs_super_block_first * usb1;
988 struct ufs_super_block_third * usb3;
989 unsigned flags;
991 lock_kernel();
993 UFSD(("ENTER\n"))
994 flags = UFS_SB(sb)->s_flags;
995 uspi = UFS_SB(sb)->s_uspi;
996 usb1 = ubh_get_usb_first(USPI_UBH);
997 usb3 = ubh_get_usb_third(USPI_UBH);
999 if (!(sb->s_flags & MS_RDONLY)) {
1000 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1001 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
1002 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1003 ufs_set_fs_state(sb, usb1, usb3,
1004 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
1005 ubh_mark_buffer_dirty (USPI_UBH);
1007 sb->s_dirt = 0;
1008 UFSD(("EXIT\n"))
1009 unlock_kernel();
1012 void ufs_put_super (struct super_block * sb)
1014 struct ufs_sb_info * sbi = UFS_SB(sb);
1016 UFSD(("ENTER\n"))
1018 if (!(sb->s_flags & MS_RDONLY))
1019 ufs_put_cylinder_structures (sb);
1021 ubh_brelse_uspi (sbi->s_uspi);
1022 kfree (sbi->s_uspi);
1023 kfree (sbi);
1024 sb->s_fs_info = NULL;
1025 return;
1029 int ufs_remount (struct super_block * sb, int * mount_flags, char * data)
1031 struct ufs_sb_private_info * uspi;
1032 struct ufs_super_block_first * usb1;
1033 struct ufs_super_block_third * usb3;
1034 unsigned new_mount_opt, ufstype;
1035 unsigned flags;
1037 uspi = UFS_SB(sb)->s_uspi;
1038 flags = UFS_SB(sb)->s_flags;
1039 usb1 = ubh_get_usb_first(USPI_UBH);
1040 usb3 = ubh_get_usb_third(USPI_UBH);
1043 * Allow the "check" option to be passed as a remount option.
1044 * It is not possible to change ufstype option during remount
1046 ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
1047 new_mount_opt = 0;
1048 ufs_set_opt (new_mount_opt, ONERROR_LOCK);
1049 if (!ufs_parse_options (data, &new_mount_opt))
1050 return -EINVAL;
1051 if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
1052 new_mount_opt |= ufstype;
1054 else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
1055 printk("ufstype can't be changed during remount\n");
1056 return -EINVAL;
1059 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
1060 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1061 return 0;
1065 * fs was mouted as rw, remounting ro
1067 if (*mount_flags & MS_RDONLY) {
1068 ufs_put_cylinder_structures(sb);
1069 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1070 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
1071 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1072 ufs_set_fs_state(sb, usb1, usb3,
1073 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
1074 ubh_mark_buffer_dirty (USPI_UBH);
1075 sb->s_dirt = 0;
1076 sb->s_flags |= MS_RDONLY;
1079 * fs was mounted as ro, remounting rw
1081 else {
1082 #ifndef CONFIG_UFS_FS_WRITE
1083 printk("ufs was compiled with read-only support, "
1084 "can't be mounted as read-write\n");
1085 return -EINVAL;
1086 #else
1087 if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
1088 ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
1089 ufstype != UFS_MOUNT_UFSTYPE_SUNx86) {
1090 printk("this ufstype is read-only supported\n");
1091 return -EINVAL;
1093 if (!ufs_read_cylinder_structures (sb)) {
1094 printk("failed during remounting\n");
1095 return -EPERM;
1097 sb->s_flags &= ~MS_RDONLY;
1098 #endif
1100 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1101 return 0;
1104 int ufs_statfs (struct super_block * sb, struct kstatfs * buf)
1106 struct ufs_sb_private_info * uspi;
1107 struct ufs_super_block_first * usb1;
1108 struct ufs_super_block * usb;
1109 unsigned flags = 0;
1111 lock_kernel();
1113 uspi = UFS_SB(sb)->s_uspi;
1114 usb1 = ubh_get_usb_first (USPI_UBH);
1115 usb = (struct ufs_super_block *)
1116 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ;
1118 flags = UFS_SB(sb)->s_flags;
1119 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
1120 buf->f_type = UFS2_MAGIC;
1121 buf->f_blocks = usb->fs_u11.fs_u2.fs_dsize;
1122 buf->f_bfree = ufs_blkstofrags(fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_cstotal.cs_nbfree)) +
1123 fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_cstotal.cs_nffree);
1124 buf->f_ffree = fs64_to_cpu(sb,
1125 usb->fs_u11.fs_u2.fs_cstotal.cs_nifree);
1127 else {
1128 buf->f_type = UFS_MAGIC;
1129 buf->f_blocks = uspi->s_dsize;
1130 buf->f_bfree = ufs_blkstofrags(fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree)) +
1131 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
1132 buf->f_ffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
1134 buf->f_bsize = sb->s_blocksize;
1135 buf->f_bavail = (buf->f_bfree > (((long)buf->f_blocks / 100) * uspi->s_minfree))
1136 ? (buf->f_bfree - (((long)buf->f_blocks / 100) * uspi->s_minfree)) : 0;
1137 buf->f_files = uspi->s_ncg * uspi->s_ipg;
1138 buf->f_namelen = UFS_MAXNAMLEN;
1140 unlock_kernel();
1142 return 0;
1145 static kmem_cache_t * ufs_inode_cachep;
1147 static struct inode *ufs_alloc_inode(struct super_block *sb)
1149 struct ufs_inode_info *ei;
1150 ei = (struct ufs_inode_info *)kmem_cache_alloc(ufs_inode_cachep, SLAB_KERNEL);
1151 if (!ei)
1152 return NULL;
1153 ei->vfs_inode.i_version = 1;
1154 return &ei->vfs_inode;
1157 static void ufs_destroy_inode(struct inode *inode)
1159 kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
1162 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1164 struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
1166 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1167 SLAB_CTOR_CONSTRUCTOR)
1168 inode_init_once(&ei->vfs_inode);
1171 static int init_inodecache(void)
1173 ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
1174 sizeof(struct ufs_inode_info),
1175 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1176 init_once, NULL);
1177 if (ufs_inode_cachep == NULL)
1178 return -ENOMEM;
1179 return 0;
1182 static void destroy_inodecache(void)
1184 if (kmem_cache_destroy(ufs_inode_cachep))
1185 printk(KERN_INFO "ufs_inode_cache: not all structures were freed\n");
1188 static struct super_operations ufs_super_ops = {
1189 .alloc_inode = ufs_alloc_inode,
1190 .destroy_inode = ufs_destroy_inode,
1191 .read_inode = ufs_read_inode,
1192 .write_inode = ufs_write_inode,
1193 .delete_inode = ufs_delete_inode,
1194 .put_super = ufs_put_super,
1195 .write_super = ufs_write_super,
1196 .statfs = ufs_statfs,
1197 .remount_fs = ufs_remount,
1200 static struct super_block *ufs_get_sb(struct file_system_type *fs_type,
1201 int flags, const char *dev_name, void *data)
1203 return get_sb_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
1206 static struct file_system_type ufs_fs_type = {
1207 .owner = THIS_MODULE,
1208 .name = "ufs",
1209 .get_sb = ufs_get_sb,
1210 .kill_sb = kill_block_super,
1211 .fs_flags = FS_REQUIRES_DEV,
1214 static int __init init_ufs_fs(void)
1216 int err = init_inodecache();
1217 if (err)
1218 goto out1;
1219 err = register_filesystem(&ufs_fs_type);
1220 if (err)
1221 goto out;
1222 return 0;
1223 out:
1224 destroy_inodecache();
1225 out1:
1226 return err;
1229 static void __exit exit_ufs_fs(void)
1231 unregister_filesystem(&ufs_fs_type);
1232 destroy_inodecache();
1235 module_init(init_ufs_fs)
1236 module_exit(exit_ufs_fs)
1237 MODULE_LICENSE("GPL");