5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
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)
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
31 * linux/fs/ufs/super.c
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
64 * UFS2 write support added by
65 * Evgeniy Dushistov <dushistov@mail.ru>, 2007
69 #include <linux/module.h>
70 #include <linux/bitops.h>
74 #include <asm/uaccess.h>
75 #include <asm/system.h>
77 #include <linux/errno.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>
89 #include <linux/log2.h>
90 #include <linux/mount.h>
91 #include <linux/seq_file.h>
98 #ifdef CONFIG_UFS_DEBUG
100 * Print contents of ufs_super_block, useful for debugging
102 static void ufs_print_super_stuff(struct super_block *sb,
103 struct ufs_super_block_first *usb1,
104 struct ufs_super_block_second *usb2,
105 struct ufs_super_block_third *usb3)
107 u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
109 printk("ufs_print_super_stuff\n");
110 printk(" magic: 0x%x\n", magic);
111 if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
112 printk(" fs_size: %llu\n", (unsigned long long)
113 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size));
114 printk(" fs_dsize: %llu\n", (unsigned long long)
115 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize));
116 printk(" bsize: %u\n",
117 fs32_to_cpu(sb, usb1->fs_bsize));
118 printk(" fsize: %u\n",
119 fs32_to_cpu(sb, usb1->fs_fsize));
120 printk(" fs_volname: %s\n", usb2->fs_un.fs_u2.fs_volname);
121 printk(" fs_sblockloc: %llu\n", (unsigned long long)
122 fs64_to_cpu(sb, usb2->fs_un.fs_u2.fs_sblockloc));
123 printk(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
124 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir));
125 printk(" cs_nbfree(No of free blocks): %llu\n",
127 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree));
128 printk(KERN_INFO" cs_nifree(Num of free inodes): %llu\n",
130 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree));
131 printk(KERN_INFO" cs_nffree(Num of free frags): %llu\n",
133 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
134 printk(KERN_INFO" fs_maxsymlinklen: %u\n",
135 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
137 printk(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
138 printk(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
139 printk(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
140 printk(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
141 printk(" cgoffset: %u\n",
142 fs32_to_cpu(sb, usb1->fs_cgoffset));
143 printk(" ~cgmask: 0x%x\n",
144 ~fs32_to_cpu(sb, usb1->fs_cgmask));
145 printk(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
146 printk(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
147 printk(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
148 printk(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
149 printk(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
150 printk(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
151 printk(" fragshift: %u\n",
152 fs32_to_cpu(sb, usb1->fs_fragshift));
153 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
154 printk(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
155 printk(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
156 printk(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
157 printk(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
158 printk(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
159 printk(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
160 printk(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
161 printk(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
162 printk(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
163 printk(" fstodb: %u\n",
164 fs32_to_cpu(sb, usb1->fs_fsbtodb));
165 printk(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
167 fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
168 printk(" nifree %u\n",
169 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
170 printk(" nbfree %u\n",
171 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
172 printk(" nffree %u\n",
173 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
179 * Print contents of ufs_cylinder_group, useful for debugging
181 static void ufs_print_cylinder_stuff(struct super_block *sb,
182 struct ufs_cylinder_group *cg)
184 printk("\nufs_print_cylinder_stuff\n");
185 printk("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group));
186 printk(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
187 printk(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
188 printk(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
189 printk(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
190 printk(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
191 printk(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
192 printk(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
193 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
194 printk(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
195 printk(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
196 printk(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
197 printk(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
198 printk(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
199 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
200 fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
201 fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
202 fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
203 fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
204 printk(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
205 printk(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
206 printk(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
207 printk(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
208 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
209 printk(" clustersumoff %u\n",
210 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
211 printk(" clusteroff %u\n",
212 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
213 printk(" nclusterblks %u\n",
214 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
218 # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
219 # define ufs_print_cylinder_stuff(sb, cg) /**/
220 #endif /* CONFIG_UFS_DEBUG */
222 static const struct super_operations ufs_super_ops;
224 static char error_buf[1024];
226 void ufs_error (struct super_block * sb, const char * function,
227 const char * fmt, ...)
229 struct ufs_sb_private_info * uspi;
230 struct ufs_super_block_first * usb1;
233 uspi = UFS_SB(sb)->s_uspi;
234 usb1 = ubh_get_usb_first(uspi);
236 if (!(sb->s_flags & MS_RDONLY)) {
237 usb1->fs_clean = UFS_FSBAD;
238 ubh_mark_buffer_dirty(USPI_UBH(uspi));
240 sb->s_flags |= MS_RDONLY;
242 va_start (args, fmt);
243 vsnprintf (error_buf, sizeof(error_buf), fmt, args);
245 switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
246 case UFS_MOUNT_ONERROR_PANIC:
247 panic ("UFS-fs panic (device %s): %s: %s\n",
248 sb->s_id, function, error_buf);
250 case UFS_MOUNT_ONERROR_LOCK:
251 case UFS_MOUNT_ONERROR_UMOUNT:
252 case UFS_MOUNT_ONERROR_REPAIR:
253 printk (KERN_CRIT "UFS-fs error (device %s): %s: %s\n",
254 sb->s_id, function, error_buf);
258 void ufs_panic (struct super_block * sb, const char * function,
259 const char * fmt, ...)
261 struct ufs_sb_private_info * uspi;
262 struct ufs_super_block_first * usb1;
265 uspi = UFS_SB(sb)->s_uspi;
266 usb1 = ubh_get_usb_first(uspi);
268 if (!(sb->s_flags & MS_RDONLY)) {
269 usb1->fs_clean = UFS_FSBAD;
270 ubh_mark_buffer_dirty(USPI_UBH(uspi));
273 va_start (args, fmt);
274 vsnprintf (error_buf, sizeof(error_buf), fmt, args);
276 sb->s_flags |= MS_RDONLY;
277 printk (KERN_CRIT "UFS-fs panic (device %s): %s: %s\n",
278 sb->s_id, function, error_buf);
281 void ufs_warning (struct super_block * sb, const char * function,
282 const char * fmt, ...)
286 va_start (args, fmt);
287 vsnprintf (error_buf, sizeof(error_buf), fmt, args);
289 printk (KERN_WARNING "UFS-fs warning (device %s): %s: %s\n",
290 sb->s_id, function, error_buf);
294 Opt_type_old = UFS_MOUNT_UFSTYPE_OLD,
295 Opt_type_sunx86 = UFS_MOUNT_UFSTYPE_SUNx86,
296 Opt_type_sun = UFS_MOUNT_UFSTYPE_SUN,
297 Opt_type_sunos = UFS_MOUNT_UFSTYPE_SUNOS,
298 Opt_type_44bsd = UFS_MOUNT_UFSTYPE_44BSD,
299 Opt_type_ufs2 = UFS_MOUNT_UFSTYPE_UFS2,
300 Opt_type_hp = UFS_MOUNT_UFSTYPE_HP,
301 Opt_type_nextstepcd = UFS_MOUNT_UFSTYPE_NEXTSTEP_CD,
302 Opt_type_nextstep = UFS_MOUNT_UFSTYPE_NEXTSTEP,
303 Opt_type_openstep = UFS_MOUNT_UFSTYPE_OPENSTEP,
304 Opt_onerror_panic = UFS_MOUNT_ONERROR_PANIC,
305 Opt_onerror_lock = UFS_MOUNT_ONERROR_LOCK,
306 Opt_onerror_umount = UFS_MOUNT_ONERROR_UMOUNT,
307 Opt_onerror_repair = UFS_MOUNT_ONERROR_REPAIR,
311 static match_table_t tokens = {
312 {Opt_type_old, "ufstype=old"},
313 {Opt_type_sunx86, "ufstype=sunx86"},
314 {Opt_type_sun, "ufstype=sun"},
315 {Opt_type_sunos, "ufstype=sunos"},
316 {Opt_type_44bsd, "ufstype=44bsd"},
317 {Opt_type_ufs2, "ufstype=ufs2"},
318 {Opt_type_ufs2, "ufstype=5xbsd"},
319 {Opt_type_hp, "ufstype=hp"},
320 {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
321 {Opt_type_nextstep, "ufstype=nextstep"},
322 {Opt_type_openstep, "ufstype=openstep"},
323 /*end of possible ufs types */
324 {Opt_onerror_panic, "onerror=panic"},
325 {Opt_onerror_lock, "onerror=lock"},
326 {Opt_onerror_umount, "onerror=umount"},
327 {Opt_onerror_repair, "onerror=repair"},
331 static int ufs_parse_options (char * options, unsigned * mount_options)
340 while ((p = strsep(&options, ",")) != NULL) {
341 substring_t args[MAX_OPT_ARGS];
346 token = match_token(p, tokens, args);
349 ufs_clear_opt (*mount_options, UFSTYPE);
350 ufs_set_opt (*mount_options, UFSTYPE_OLD);
352 case Opt_type_sunx86:
353 ufs_clear_opt (*mount_options, UFSTYPE);
354 ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
357 ufs_clear_opt (*mount_options, UFSTYPE);
358 ufs_set_opt (*mount_options, UFSTYPE_SUN);
361 ufs_clear_opt(*mount_options, UFSTYPE);
362 ufs_set_opt(*mount_options, UFSTYPE_SUNOS);
365 ufs_clear_opt (*mount_options, UFSTYPE);
366 ufs_set_opt (*mount_options, UFSTYPE_44BSD);
369 ufs_clear_opt(*mount_options, UFSTYPE);
370 ufs_set_opt(*mount_options, UFSTYPE_UFS2);
373 ufs_clear_opt (*mount_options, UFSTYPE);
374 ufs_set_opt (*mount_options, UFSTYPE_HP);
376 case Opt_type_nextstepcd:
377 ufs_clear_opt (*mount_options, UFSTYPE);
378 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
380 case Opt_type_nextstep:
381 ufs_clear_opt (*mount_options, UFSTYPE);
382 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
384 case Opt_type_openstep:
385 ufs_clear_opt (*mount_options, UFSTYPE);
386 ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
388 case Opt_onerror_panic:
389 ufs_clear_opt (*mount_options, ONERROR);
390 ufs_set_opt (*mount_options, ONERROR_PANIC);
392 case Opt_onerror_lock:
393 ufs_clear_opt (*mount_options, ONERROR);
394 ufs_set_opt (*mount_options, ONERROR_LOCK);
396 case Opt_onerror_umount:
397 ufs_clear_opt (*mount_options, ONERROR);
398 ufs_set_opt (*mount_options, ONERROR_UMOUNT);
400 case Opt_onerror_repair:
401 printk("UFS-fs: Unable to do repair on error, "
402 "will lock lock instead\n");
403 ufs_clear_opt (*mount_options, ONERROR);
404 ufs_set_opt (*mount_options, ONERROR_REPAIR);
407 printk("UFS-fs: Invalid option: \"%s\" "
408 "or missing value\n", p);
416 * Diffrent types of UFS hold fs_cstotal in different
417 * places, and use diffrent data structure for it.
418 * To make things simplier we just copy fs_cstotal to ufs_sb_private_info
420 static void ufs_setup_cstotal(struct super_block *sb)
422 struct ufs_sb_info *sbi = UFS_SB(sb);
423 struct ufs_sb_private_info *uspi = sbi->s_uspi;
424 struct ufs_super_block_first *usb1;
425 struct ufs_super_block_second *usb2;
426 struct ufs_super_block_third *usb3;
427 unsigned mtype = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
429 UFSD("ENTER, mtype=%u\n", mtype);
430 usb1 = ubh_get_usb_first(uspi);
431 usb2 = ubh_get_usb_second(uspi);
432 usb3 = ubh_get_usb_third(uspi);
434 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
435 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
436 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
437 /*we have statistic in different place, then usual*/
438 uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
439 uspi->cs_total.cs_nbfree = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree);
440 uspi->cs_total.cs_nifree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree);
441 uspi->cs_total.cs_nffree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree);
443 uspi->cs_total.cs_ndir = fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir);
444 uspi->cs_total.cs_nbfree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree);
445 uspi->cs_total.cs_nifree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
446 uspi->cs_total.cs_nffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
452 * Read on-disk structures associated with cylinder groups
454 static int ufs_read_cylinder_structures(struct super_block *sb)
456 struct ufs_sb_info *sbi = UFS_SB(sb);
457 struct ufs_sb_private_info *uspi = sbi->s_uspi;
458 struct ufs_buffer_head * ubh;
459 unsigned char * base, * space;
460 unsigned size, blks, i;
461 struct ufs_super_block_third *usb3;
465 usb3 = ubh_get_usb_third(uspi);
467 * Read cs structures from (usually) first data block
470 size = uspi->s_cssize;
471 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
472 base = space = kmalloc(size, GFP_KERNEL);
475 sbi->s_csp = (struct ufs_csum *)space;
476 for (i = 0; i < blks; i += uspi->s_fpb) {
477 size = uspi->s_bsize;
478 if (i + uspi->s_fpb > blks)
479 size = (blks - i) * uspi->s_fsize;
481 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
486 ubh_ubhcpymem (space, ubh, size);
494 * Read cylinder group (we read only first fragment from block
495 * at this time) and prepare internal data structures for cg caching.
497 if (!(sbi->s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_KERNEL)))
499 for (i = 0; i < uspi->s_ncg; i++)
500 sbi->s_ucg[i] = NULL;
501 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
502 sbi->s_ucpi[i] = NULL;
503 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
505 for (i = 0; i < uspi->s_ncg; i++) {
506 UFSD("read cg %u\n", i);
507 if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
509 if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
512 ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
514 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
515 if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_KERNEL)))
517 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
519 sbi->s_cg_loaded = 0;
526 for (i = 0; i < uspi->s_ncg; i++)
528 brelse (sbi->s_ucg[i]);
530 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
531 kfree (sbi->s_ucpi[i]);
533 UFSD("EXIT (FAILED)\n");
538 * Sync our internal copy of fs_cstotal with disk
540 static void ufs_put_cstotal(struct super_block *sb)
542 unsigned mtype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
543 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
544 struct ufs_super_block_first *usb1;
545 struct ufs_super_block_second *usb2;
546 struct ufs_super_block_third *usb3;
549 usb1 = ubh_get_usb_first(uspi);
550 usb2 = ubh_get_usb_second(uspi);
551 usb3 = ubh_get_usb_third(uspi);
553 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
554 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
555 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
556 /*we have statistic in different place, then usual*/
557 usb2->fs_un.fs_u2.cs_ndir =
558 cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
559 usb2->fs_un.fs_u2.cs_nbfree =
560 cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
561 usb3->fs_un1.fs_u2.cs_nifree =
562 cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
563 usb3->fs_un1.fs_u2.cs_nffree =
564 cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
566 usb1->fs_cstotal.cs_ndir =
567 cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
568 usb1->fs_cstotal.cs_nbfree =
569 cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
570 usb1->fs_cstotal.cs_nifree =
571 cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
572 usb1->fs_cstotal.cs_nffree =
573 cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
575 ubh_mark_buffer_dirty(USPI_UBH(uspi));
576 ufs_print_super_stuff(sb, usb1, usb2, usb3);
581 * ufs_put_super_internal() - put on-disk intrenal structures
582 * @sb: pointer to super_block structure
583 * Put on-disk structures associated with cylinder groups
584 * and write them back to disk, also update cs_total on disk
586 static void ufs_put_super_internal(struct super_block *sb)
588 struct ufs_sb_info *sbi = UFS_SB(sb);
589 struct ufs_sb_private_info *uspi = sbi->s_uspi;
590 struct ufs_buffer_head * ubh;
591 unsigned char * base, * space;
592 unsigned blks, size, i;
597 size = uspi->s_cssize;
598 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
599 base = space = (char*) sbi->s_csp;
600 for (i = 0; i < blks; i += uspi->s_fpb) {
601 size = uspi->s_bsize;
602 if (i + uspi->s_fpb > blks)
603 size = (blks - i) * uspi->s_fsize;
605 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
607 ubh_memcpyubh (ubh, space, size);
609 ubh_mark_buffer_uptodate (ubh, 1);
610 ubh_mark_buffer_dirty (ubh);
613 for (i = 0; i < sbi->s_cg_loaded; i++) {
614 ufs_put_cylinder (sb, i);
615 kfree (sbi->s_ucpi[i]);
617 for (; i < UFS_MAX_GROUP_LOADED; i++)
618 kfree (sbi->s_ucpi[i]);
619 for (i = 0; i < uspi->s_ncg; i++)
620 brelse (sbi->s_ucg[i]);
626 static int ufs_fill_super(struct super_block *sb, void *data, int silent)
628 struct ufs_sb_info * sbi;
629 struct ufs_sb_private_info * uspi;
630 struct ufs_super_block_first * usb1;
631 struct ufs_super_block_second * usb2;
632 struct ufs_super_block_third * usb3;
633 struct ufs_buffer_head * ubh;
635 unsigned block_size, super_block_size;
637 unsigned super_block_offset;
646 sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
651 UFSD("flag %u\n", (int)(sb->s_flags & MS_RDONLY));
653 #ifndef CONFIG_UFS_FS_WRITE
654 if (!(sb->s_flags & MS_RDONLY)) {
655 printk("ufs was compiled with read-only support, "
656 "can't be mounted as read-write\n");
661 * Set default mount options
662 * Parse mount options
664 sbi->s_mount_opt = 0;
665 ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
666 if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
667 printk("wrong mount options\n");
670 if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
672 printk("You didn't specify the type of your ufs filesystem\n\n"
673 "mount -t ufs -o ufstype="
674 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
675 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
676 "default is ufstype=old\n");
677 ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
680 uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
684 uspi->s_dirblksize = UFS_SECTOR_SIZE;
685 super_block_offset=UFS_SBLOCK;
687 /* Keep 2Gig file limit. Some UFS variants need to override
688 this but as I don't know which I'll let those in the know loosen
690 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
691 case UFS_MOUNT_UFSTYPE_44BSD:
692 UFSD("ufstype=44bsd\n");
693 uspi->s_fsize = block_size = 512;
694 uspi->s_fmask = ~(512 - 1);
696 uspi->s_sbsize = super_block_size = 1536;
698 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
700 case UFS_MOUNT_UFSTYPE_UFS2:
701 UFSD("ufstype=ufs2\n");
702 super_block_offset=SBLOCK_UFS2;
703 uspi->s_fsize = block_size = 512;
704 uspi->s_fmask = ~(512 - 1);
706 uspi->s_sbsize = super_block_size = 1536;
708 flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
711 case UFS_MOUNT_UFSTYPE_SUN:
712 UFSD("ufstype=sun\n");
713 uspi->s_fsize = block_size = 1024;
714 uspi->s_fmask = ~(1024 - 1);
716 uspi->s_sbsize = super_block_size = 2048;
718 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
719 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
722 case UFS_MOUNT_UFSTYPE_SUNOS:
723 UFSD(("ufstype=sunos\n"))
724 uspi->s_fsize = block_size = 1024;
725 uspi->s_fmask = ~(1024 - 1);
727 uspi->s_sbsize = 2048;
728 super_block_size = 2048;
730 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
731 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_SUNOS | UFS_CG_SUN;
734 case UFS_MOUNT_UFSTYPE_SUNx86:
735 UFSD("ufstype=sunx86\n");
736 uspi->s_fsize = block_size = 1024;
737 uspi->s_fmask = ~(1024 - 1);
739 uspi->s_sbsize = super_block_size = 2048;
741 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
742 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
745 case UFS_MOUNT_UFSTYPE_OLD:
746 UFSD("ufstype=old\n");
747 uspi->s_fsize = block_size = 1024;
748 uspi->s_fmask = ~(1024 - 1);
750 uspi->s_sbsize = super_block_size = 2048;
752 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
753 if (!(sb->s_flags & MS_RDONLY)) {
755 printk(KERN_INFO "ufstype=old is supported read-only\n");
756 sb->s_flags |= MS_RDONLY;
760 case UFS_MOUNT_UFSTYPE_NEXTSTEP:
761 UFSD("ufstype=nextstep\n");
762 uspi->s_fsize = block_size = 1024;
763 uspi->s_fmask = ~(1024 - 1);
765 uspi->s_sbsize = super_block_size = 2048;
767 uspi->s_dirblksize = 1024;
768 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
769 if (!(sb->s_flags & MS_RDONLY)) {
771 printk(KERN_INFO "ufstype=nextstep is supported read-only\n");
772 sb->s_flags |= MS_RDONLY;
776 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
777 UFSD("ufstype=nextstep-cd\n");
778 uspi->s_fsize = block_size = 2048;
779 uspi->s_fmask = ~(2048 - 1);
781 uspi->s_sbsize = super_block_size = 2048;
783 uspi->s_dirblksize = 1024;
784 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
785 if (!(sb->s_flags & MS_RDONLY)) {
787 printk(KERN_INFO "ufstype=nextstep-cd is supported read-only\n");
788 sb->s_flags |= MS_RDONLY;
792 case UFS_MOUNT_UFSTYPE_OPENSTEP:
793 UFSD("ufstype=openstep\n");
794 uspi->s_fsize = block_size = 1024;
795 uspi->s_fmask = ~(1024 - 1);
797 uspi->s_sbsize = super_block_size = 2048;
799 uspi->s_dirblksize = 1024;
800 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
801 if (!(sb->s_flags & MS_RDONLY)) {
803 printk(KERN_INFO "ufstype=openstep is supported read-only\n");
804 sb->s_flags |= MS_RDONLY;
808 case UFS_MOUNT_UFSTYPE_HP:
809 UFSD("ufstype=hp\n");
810 uspi->s_fsize = block_size = 1024;
811 uspi->s_fmask = ~(1024 - 1);
813 uspi->s_sbsize = super_block_size = 2048;
815 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
816 if (!(sb->s_flags & MS_RDONLY)) {
818 printk(KERN_INFO "ufstype=hp is supported read-only\n");
819 sb->s_flags |= MS_RDONLY;
824 printk("unknown ufstype\n");
829 if (!sb_set_blocksize(sb, block_size)) {
830 printk(KERN_ERR "UFS: failed to set blocksize\n");
835 * read ufs super block from device
838 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
843 usb1 = ubh_get_usb_first(uspi);
844 usb2 = ubh_get_usb_second(uspi);
845 usb3 = ubh_get_usb_third(uspi);
847 /* Sort out mod used on SunOS 4.1.3 for fs_state */
848 uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
849 if (((flags & UFS_ST_MASK) == UFS_ST_SUNOS) &&
850 (uspi->s_postblformat != UFS_42POSTBLFMT)) {
851 flags &= ~UFS_ST_MASK;
856 * Check ufs magic number
858 sbi->s_bytesex = BYTESEX_LE;
859 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
867 sbi->s_bytesex = BYTESEX_BE;
868 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
877 if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
878 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
879 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
880 && uspi->s_sbbase < 256) {
881 ubh_brelse_uspi(uspi);
887 printk("ufs_read_super: bad magic number\n");
892 * Check block and fragment sizes
894 uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
895 uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
896 uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
897 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
898 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
900 if (!is_power_of_2(uspi->s_fsize)) {
901 printk(KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n",
905 if (uspi->s_fsize < 512) {
906 printk(KERN_ERR "ufs_read_super: fragment size %u is too small\n",
910 if (uspi->s_fsize > 4096) {
911 printk(KERN_ERR "ufs_read_super: fragment size %u is too large\n",
915 if (!is_power_of_2(uspi->s_bsize)) {
916 printk(KERN_ERR "ufs_read_super: block size %u is not a power of 2\n",
920 if (uspi->s_bsize < 4096) {
921 printk(KERN_ERR "ufs_read_super: block size %u is too small\n",
925 if (uspi->s_bsize / uspi->s_fsize > 8) {
926 printk(KERN_ERR "ufs_read_super: too many fragments per block (%u)\n",
927 uspi->s_bsize / uspi->s_fsize);
930 if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
931 ubh_brelse_uspi(uspi);
933 block_size = uspi->s_fsize;
934 super_block_size = uspi->s_sbsize;
935 UFSD("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size);
939 sbi->s_flags = flags;/*after that line some functions use s_flags*/
940 ufs_print_super_stuff(sb, usb1, usb2, usb3);
943 * Check, if file system was correctly unmounted.
944 * If not, make it read only.
946 if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
947 ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
948 (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
949 (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
950 (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
951 (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
952 switch(usb1->fs_clean) {
954 UFSD("fs is clean\n");
957 UFSD("fs is stable\n");
960 UFSD("fs is DEC OSF/1\n");
963 printk("ufs_read_super: fs is active\n");
964 sb->s_flags |= MS_RDONLY;
967 printk("ufs_read_super: fs is bad\n");
968 sb->s_flags |= MS_RDONLY;
971 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1->fs_clean);
972 sb->s_flags |= MS_RDONLY;
976 printk("ufs_read_super: fs needs fsck\n");
977 sb->s_flags |= MS_RDONLY;
981 * Read ufs_super_block into internal data structures
983 sb->s_op = &ufs_super_ops;
984 sb->dq_op = NULL; /***/
985 sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
987 uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
988 uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
989 uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
990 uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
991 uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
992 uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
994 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
995 uspi->s_u2_size = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size);
996 uspi->s_u2_dsize = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
998 uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
999 uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
1002 uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
1003 /* s_bsize already set */
1004 /* s_fsize already set */
1005 uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
1006 uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
1007 uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
1008 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
1009 uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
1010 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
1011 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
1013 uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
1014 uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
1015 /* s_sbsize already set */
1016 uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
1017 uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
1018 uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
1019 uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
1020 uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
1021 uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
1022 uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
1023 uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
1025 if (uspi->fs_magic == UFS2_MAGIC)
1026 uspi->s_csaddr = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_csaddr);
1028 uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
1030 uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
1031 uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
1032 uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
1033 uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
1034 uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
1035 uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
1036 uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
1037 uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_un.fs_u1.fs_cpc);
1038 uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_contigsumsize);
1039 uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
1040 uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
1041 uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
1042 uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
1043 uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
1046 * Compute another frequently used values
1048 uspi->s_fpbmask = uspi->s_fpb - 1;
1049 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
1050 uspi->s_apbshift = uspi->s_bshift - 3;
1052 uspi->s_apbshift = uspi->s_bshift - 2;
1054 uspi->s_2apbshift = uspi->s_apbshift * 2;
1055 uspi->s_3apbshift = uspi->s_apbshift * 3;
1056 uspi->s_apb = 1 << uspi->s_apbshift;
1057 uspi->s_2apb = 1 << uspi->s_2apbshift;
1058 uspi->s_3apb = 1 << uspi->s_3apbshift;
1059 uspi->s_apbmask = uspi->s_apb - 1;
1060 uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
1061 uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
1062 uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
1063 uspi->s_bpf = uspi->s_fsize << 3;
1064 uspi->s_bpfshift = uspi->s_fshift + 3;
1065 uspi->s_bpfmask = uspi->s_bpf - 1;
1066 if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
1067 (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
1068 uspi->s_maxsymlinklen =
1069 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
1071 inode = ufs_iget(sb, UFS_ROOTINO);
1072 if (IS_ERR(inode)) {
1073 ret = PTR_ERR(inode);
1076 sb->s_root = d_alloc_root(inode);
1082 ufs_setup_cstotal(sb);
1084 * Read cylinder group structures
1086 if (!(sb->s_flags & MS_RDONLY))
1087 if (!ufs_read_cylinder_structures(sb))
1097 ubh_brelse_uspi (uspi);
1100 sb->s_fs_info = NULL;
1101 UFSD("EXIT (FAILED)\n");
1105 UFSD("EXIT (NOMEM)\n");
1109 static void ufs_write_super(struct super_block *sb)
1111 struct ufs_sb_private_info * uspi;
1112 struct ufs_super_block_first * usb1;
1113 struct ufs_super_block_third * usb3;
1118 flags = UFS_SB(sb)->s_flags;
1119 uspi = UFS_SB(sb)->s_uspi;
1120 usb1 = ubh_get_usb_first(uspi);
1121 usb3 = ubh_get_usb_third(uspi);
1123 if (!(sb->s_flags & MS_RDONLY)) {
1124 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1125 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
1126 || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
1127 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1128 ufs_set_fs_state(sb, usb1, usb3,
1129 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
1130 ufs_put_cstotal(sb);
1137 static void ufs_put_super(struct super_block *sb)
1139 struct ufs_sb_info * sbi = UFS_SB(sb);
1143 if (!(sb->s_flags & MS_RDONLY))
1144 ufs_put_super_internal(sb);
1146 ubh_brelse_uspi (sbi->s_uspi);
1147 kfree (sbi->s_uspi);
1149 sb->s_fs_info = NULL;
1155 static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1157 struct ufs_sb_private_info * uspi;
1158 struct ufs_super_block_first * usb1;
1159 struct ufs_super_block_third * usb3;
1160 unsigned new_mount_opt, ufstype;
1163 uspi = UFS_SB(sb)->s_uspi;
1164 flags = UFS_SB(sb)->s_flags;
1165 usb1 = ubh_get_usb_first(uspi);
1166 usb3 = ubh_get_usb_third(uspi);
1169 * Allow the "check" option to be passed as a remount option.
1170 * It is not possible to change ufstype option during remount
1172 ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
1174 ufs_set_opt (new_mount_opt, ONERROR_LOCK);
1175 if (!ufs_parse_options (data, &new_mount_opt))
1177 if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
1178 new_mount_opt |= ufstype;
1179 } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
1180 printk("ufstype can't be changed during remount\n");
1184 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
1185 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1190 * fs was mouted as rw, remounting ro
1192 if (*mount_flags & MS_RDONLY) {
1193 ufs_put_super_internal(sb);
1194 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1195 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
1196 || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
1197 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1198 ufs_set_fs_state(sb, usb1, usb3,
1199 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
1200 ubh_mark_buffer_dirty (USPI_UBH(uspi));
1202 sb->s_flags |= MS_RDONLY;
1205 * fs was mounted as ro, remounting rw
1207 #ifndef CONFIG_UFS_FS_WRITE
1208 printk("ufs was compiled with read-only support, "
1209 "can't be mounted as read-write\n");
1212 if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
1213 ufstype != UFS_MOUNT_UFSTYPE_SUNOS &&
1214 ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
1215 ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
1216 ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
1217 printk("this ufstype is read-only supported\n");
1220 if (!ufs_read_cylinder_structures(sb)) {
1221 printk("failed during remounting\n");
1224 sb->s_flags &= ~MS_RDONLY;
1227 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1231 static int ufs_show_options(struct seq_file *seq, struct vfsmount *vfs)
1233 struct ufs_sb_info *sbi = UFS_SB(vfs->mnt_sb);
1234 unsigned mval = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
1235 struct match_token *tp = tokens;
1237 while (tp->token != Opt_onerror_panic && tp->token != mval)
1239 BUG_ON(tp->token == Opt_onerror_panic);
1240 seq_printf(seq, ",%s", tp->pattern);
1242 mval = sbi->s_mount_opt & UFS_MOUNT_ONERROR;
1243 while (tp->token != Opt_err && tp->token != mval)
1245 BUG_ON(tp->token == Opt_err);
1246 seq_printf(seq, ",%s", tp->pattern);
1251 static int ufs_statfs(struct dentry *dentry, struct kstatfs *buf)
1253 struct super_block *sb = dentry->d_sb;
1254 struct ufs_sb_private_info *uspi= UFS_SB(sb)->s_uspi;
1255 unsigned flags = UFS_SB(sb)->s_flags;
1256 struct ufs_super_block_first *usb1;
1257 struct ufs_super_block_second *usb2;
1258 struct ufs_super_block_third *usb3;
1262 usb1 = ubh_get_usb_first(uspi);
1263 usb2 = ubh_get_usb_second(uspi);
1264 usb3 = ubh_get_usb_third(uspi);
1266 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
1267 buf->f_type = UFS2_MAGIC;
1268 buf->f_blocks = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
1270 buf->f_type = UFS_MAGIC;
1271 buf->f_blocks = uspi->s_dsize;
1273 buf->f_bfree = ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
1274 uspi->cs_total.cs_nffree;
1275 buf->f_ffree = uspi->cs_total.cs_nifree;
1276 buf->f_bsize = sb->s_blocksize;
1277 buf->f_bavail = (buf->f_bfree > (((long)buf->f_blocks / 100) * uspi->s_minfree))
1278 ? (buf->f_bfree - (((long)buf->f_blocks / 100) * uspi->s_minfree)) : 0;
1279 buf->f_files = uspi->s_ncg * uspi->s_ipg;
1280 buf->f_namelen = UFS_MAXNAMLEN;
1287 static struct kmem_cache * ufs_inode_cachep;
1289 static struct inode *ufs_alloc_inode(struct super_block *sb)
1291 struct ufs_inode_info *ei;
1292 ei = (struct ufs_inode_info *)kmem_cache_alloc(ufs_inode_cachep, GFP_KERNEL);
1295 ei->vfs_inode.i_version = 1;
1296 return &ei->vfs_inode;
1299 static void ufs_destroy_inode(struct inode *inode)
1301 kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
1304 static void init_once(struct kmem_cache * cachep, void *foo)
1306 struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
1308 inode_init_once(&ei->vfs_inode);
1311 static int init_inodecache(void)
1313 ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
1314 sizeof(struct ufs_inode_info),
1315 0, (SLAB_RECLAIM_ACCOUNT|
1318 if (ufs_inode_cachep == NULL)
1323 static void destroy_inodecache(void)
1325 kmem_cache_destroy(ufs_inode_cachep);
1329 static ssize_t ufs_quota_read(struct super_block *, int, char *,size_t, loff_t);
1330 static ssize_t ufs_quota_write(struct super_block *, int, const char *, size_t, loff_t);
1333 static const struct super_operations ufs_super_ops = {
1334 .alloc_inode = ufs_alloc_inode,
1335 .destroy_inode = ufs_destroy_inode,
1336 .write_inode = ufs_write_inode,
1337 .delete_inode = ufs_delete_inode,
1338 .put_super = ufs_put_super,
1339 .write_super = ufs_write_super,
1340 .statfs = ufs_statfs,
1341 .remount_fs = ufs_remount,
1342 .show_options = ufs_show_options,
1344 .quota_read = ufs_quota_read,
1345 .quota_write = ufs_quota_write,
1351 /* Read data from quotafile - avoid pagecache and such because we cannot afford
1352 * acquiring the locks... As quota files are never truncated and quota code
1353 * itself serializes the operations (and noone else should touch the files)
1354 * we don't have to be afraid of races */
1355 static ssize_t ufs_quota_read(struct super_block *sb, int type, char *data,
1356 size_t len, loff_t off)
1358 struct inode *inode = sb_dqopt(sb)->files[type];
1359 sector_t blk = off >> sb->s_blocksize_bits;
1361 int offset = off & (sb->s_blocksize - 1);
1364 struct buffer_head *bh;
1365 loff_t i_size = i_size_read(inode);
1369 if (off+len > i_size)
1372 while (toread > 0) {
1373 tocopy = sb->s_blocksize - offset < toread ?
1374 sb->s_blocksize - offset : toread;
1376 bh = ufs_bread(inode, blk, 0, &err);
1379 if (!bh) /* A hole? */
1380 memset(data, 0, tocopy);
1382 memcpy(data, bh->b_data+offset, tocopy);
1393 /* Write to quotafile */
1394 static ssize_t ufs_quota_write(struct super_block *sb, int type,
1395 const char *data, size_t len, loff_t off)
1397 struct inode *inode = sb_dqopt(sb)->files[type];
1398 sector_t blk = off >> sb->s_blocksize_bits;
1400 int offset = off & (sb->s_blocksize - 1);
1402 size_t towrite = len;
1403 struct buffer_head *bh;
1405 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
1406 while (towrite > 0) {
1407 tocopy = sb->s_blocksize - offset < towrite ?
1408 sb->s_blocksize - offset : towrite;
1410 bh = ufs_bread(inode, blk, 1, &err);
1414 memcpy(bh->b_data+offset, data, tocopy);
1415 flush_dcache_page(bh->b_page);
1416 set_buffer_uptodate(bh);
1417 mark_buffer_dirty(bh);
1426 if (len == towrite) {
1427 mutex_unlock(&inode->i_mutex);
1430 if (inode->i_size < off+len-towrite)
1431 i_size_write(inode, off+len-towrite);
1433 inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
1434 mark_inode_dirty(inode);
1435 mutex_unlock(&inode->i_mutex);
1436 return len - towrite;
1441 static int ufs_get_sb(struct file_system_type *fs_type,
1442 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1444 return get_sb_bdev(fs_type, flags, dev_name, data, ufs_fill_super, mnt);
1447 static struct file_system_type ufs_fs_type = {
1448 .owner = THIS_MODULE,
1450 .get_sb = ufs_get_sb,
1451 .kill_sb = kill_block_super,
1452 .fs_flags = FS_REQUIRES_DEV,
1455 static int __init init_ufs_fs(void)
1457 int err = init_inodecache();
1460 err = register_filesystem(&ufs_fs_type);
1465 destroy_inodecache();
1470 static void __exit exit_ufs_fs(void)
1472 unregister_filesystem(&ufs_fs_type);
1473 destroy_inodecache();
1476 module_init(init_ufs_fs)
1477 module_exit(exit_ufs_fs)
1478 MODULE_LICENSE("GPL");