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
67 #include <linux/config.h>
68 #include <linux/module.h>
69 #include <linux/bitops.h>
73 #include <asm/uaccess.h>
74 #include <asm/system.h>
76 #include <linux/errno.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>
93 #undef UFS_SUPER_DEBUG
94 #undef UFS_SUPER_DEBUG_MORE
97 #undef UFS_SUPER_DEBUG_MORE
98 #ifdef UFS_SUPER_DEBUG
99 #define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
104 #ifdef UFS_SUPER_DEBUG_MORE
106 * Print contents of ufs_super_block, useful for debugging
108 void ufs_print_super_stuff(struct super_block *sb,
109 struct ufs_super_block_first * usb1,
110 struct ufs_super_block_second * usb2,
111 struct ufs_super_block_third * usb3)
113 printk("ufs_print_super_stuff\n");
114 printk("size of usb: %u\n", sizeof(struct ufs_super_block));
115 printk(" magic: 0x%x\n", fs32_to_cpu(sb, usb3->fs_magic));
116 printk(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
117 printk(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
118 printk(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
119 printk(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
120 printk(" cgoffset: %u\n", fs32_to_cpu(sb, usb1->fs_cgoffset));
121 printk(" ~cgmask: 0x%x\n", ~fs32_to_cpu(sb, usb1->fs_cgmask));
122 printk(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
123 printk(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
124 printk(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
125 printk(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
126 printk(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
127 printk(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
128 printk(" fragshift: %u\n", fs32_to_cpu(sb, usb1->fs_fragshift));
129 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
130 printk(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
131 printk(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
132 printk(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
133 printk(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
134 printk(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
135 printk(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
136 printk(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
137 printk(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
138 printk(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
139 printk(" fstodb: %u\n", fs32_to_cpu(sb, usb1->fs_fsbtodb));
140 printk(" contigsumsize: %d\n", fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_contigsumsize));
141 printk(" postblformat: %u\n", fs32_to_cpu(sb, usb3->fs_postblformat));
142 printk(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
143 printk(" ndir %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
144 printk(" nifree %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
145 printk(" nbfree %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
146 printk(" nffree %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
151 * Print contents of ufs2 ufs_super_block, useful for debugging
153 void ufs2_print_super_stuff(
154 struct super_block *sb,
155 struct ufs_super_block *usb)
157 printk("ufs_print_super_stuff\n");
158 printk("size of usb: %u\n", sizeof(struct ufs_super_block));
159 printk(" magic: 0x%x\n", fs32_to_cpu(sb, usb->fs_magic));
160 printk(" fs_size: %u\n",fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_size));
161 printk(" fs_dsize: %u\n",fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_dsize));
162 printk(" bsize: %u\n", fs32_to_cpu(usb, usb->fs_bsize));
163 printk(" fsize: %u\n", fs32_to_cpu(usb, usb->fs_fsize));
164 printk(" fs_volname: %s\n", usb->fs_u11.fs_u2.fs_volname);
165 printk(" fs_fsmnt: %s\n", usb->fs_u11.fs_u2.fs_fsmnt);
166 printk(" fs_sblockloc: %u\n",fs64_to_cpu(sb,
167 usb->fs_u11.fs_u2.fs_sblockloc));
168 printk(" cs_ndir(No of dirs): %u\n",fs64_to_cpu(sb,
169 usb->fs_u11.fs_u2.fs_cstotal.cs_ndir));
170 printk(" cs_nbfree(No of free blocks): %u\n",fs64_to_cpu(sb,
171 usb->fs_u11.fs_u2.fs_cstotal.cs_nbfree));
176 * Print contents of ufs_cylinder_group, useful for debugging
178 void ufs_print_cylinder_stuff(struct super_block *sb, struct ufs_cylinder_group *cg)
180 printk("\nufs_print_cylinder_stuff\n");
181 printk("size of ucg: %u\n", sizeof(struct ufs_cylinder_group));
182 printk(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
183 printk(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
184 printk(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
185 printk(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
186 printk(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
187 printk(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
188 printk(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
189 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
190 printk(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
191 printk(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
192 printk(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
193 printk(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
194 printk(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
195 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
196 fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
197 fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
198 fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
199 fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
200 printk(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
201 printk(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
202 printk(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
203 printk(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
204 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
205 printk(" clustersumoff %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
206 printk(" clusteroff %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
207 printk(" nclusterblks %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
210 #endif /* UFS_SUPER_DEBUG_MORE */
212 static struct super_operations ufs_super_ops;
214 static char error_buf[1024];
216 void ufs_error (struct super_block * sb, const char * function,
217 const char * fmt, ...)
219 struct ufs_sb_private_info * uspi;
220 struct ufs_super_block_first * usb1;
223 uspi = UFS_SB(sb)->s_uspi;
224 usb1 = ubh_get_usb_first(uspi);
226 if (!(sb->s_flags & MS_RDONLY)) {
227 usb1->fs_clean = UFS_FSBAD;
228 ubh_mark_buffer_dirty(USPI_UBH);
230 sb->s_flags |= MS_RDONLY;
232 va_start (args, fmt);
233 vsprintf (error_buf, fmt, args);
235 switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
236 case UFS_MOUNT_ONERROR_PANIC:
237 panic ("UFS-fs panic (device %s): %s: %s\n",
238 sb->s_id, function, error_buf);
240 case UFS_MOUNT_ONERROR_LOCK:
241 case UFS_MOUNT_ONERROR_UMOUNT:
242 case UFS_MOUNT_ONERROR_REPAIR:
243 printk (KERN_CRIT "UFS-fs error (device %s): %s: %s\n",
244 sb->s_id, function, error_buf);
248 void ufs_panic (struct super_block * sb, const char * function,
249 const char * fmt, ...)
251 struct ufs_sb_private_info * uspi;
252 struct ufs_super_block_first * usb1;
255 uspi = UFS_SB(sb)->s_uspi;
256 usb1 = ubh_get_usb_first(uspi);
258 if (!(sb->s_flags & MS_RDONLY)) {
259 usb1->fs_clean = UFS_FSBAD;
260 ubh_mark_buffer_dirty(USPI_UBH);
263 va_start (args, fmt);
264 vsprintf (error_buf, fmt, args);
266 sb->s_flags |= MS_RDONLY;
267 printk (KERN_CRIT "UFS-fs panic (device %s): %s: %s\n",
268 sb->s_id, function, error_buf);
271 void ufs_warning (struct super_block * sb, const char * function,
272 const char * fmt, ...)
276 va_start (args, fmt);
277 vsprintf (error_buf, fmt, args);
279 printk (KERN_WARNING "UFS-fs warning (device %s): %s: %s\n",
280 sb->s_id, function, error_buf);
284 Opt_type_old, Opt_type_sunx86, Opt_type_sun, Opt_type_44bsd,
285 Opt_type_ufs2, Opt_type_hp, Opt_type_nextstepcd, Opt_type_nextstep,
286 Opt_type_openstep, Opt_onerror_panic, Opt_onerror_lock,
287 Opt_onerror_umount, Opt_onerror_repair, Opt_err
290 static match_table_t tokens = {
291 {Opt_type_old, "ufstype=old"},
292 {Opt_type_sunx86, "ufstype=sunx86"},
293 {Opt_type_sun, "ufstype=sun"},
294 {Opt_type_44bsd, "ufstype=44bsd"},
295 {Opt_type_ufs2, "ufstype=ufs2"},
296 {Opt_type_ufs2, "ufstype=5xbsd"},
297 {Opt_type_hp, "ufstype=hp"},
298 {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
299 {Opt_type_nextstep, "ufstype=nextstep"},
300 {Opt_type_openstep, "ufstype=openstep"},
301 {Opt_onerror_panic, "onerror=panic"},
302 {Opt_onerror_lock, "onerror=lock"},
303 {Opt_onerror_umount, "onerror=umount"},
304 {Opt_onerror_repair, "onerror=repair"},
308 static int ufs_parse_options (char * options, unsigned * mount_options)
317 while ((p = strsep(&options, ",")) != NULL) {
318 substring_t args[MAX_OPT_ARGS];
323 token = match_token(p, tokens, args);
326 ufs_clear_opt (*mount_options, UFSTYPE);
327 ufs_set_opt (*mount_options, UFSTYPE_OLD);
329 case Opt_type_sunx86:
330 ufs_clear_opt (*mount_options, UFSTYPE);
331 ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
334 ufs_clear_opt (*mount_options, UFSTYPE);
335 ufs_set_opt (*mount_options, UFSTYPE_SUN);
338 ufs_clear_opt (*mount_options, UFSTYPE);
339 ufs_set_opt (*mount_options, UFSTYPE_44BSD);
342 ufs_clear_opt(*mount_options, UFSTYPE);
343 ufs_set_opt(*mount_options, UFSTYPE_UFS2);
346 ufs_clear_opt (*mount_options, UFSTYPE);
347 ufs_set_opt (*mount_options, UFSTYPE_HP);
349 case Opt_type_nextstepcd:
350 ufs_clear_opt (*mount_options, UFSTYPE);
351 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
353 case Opt_type_nextstep:
354 ufs_clear_opt (*mount_options, UFSTYPE);
355 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
357 case Opt_type_openstep:
358 ufs_clear_opt (*mount_options, UFSTYPE);
359 ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
361 case Opt_onerror_panic:
362 ufs_clear_opt (*mount_options, ONERROR);
363 ufs_set_opt (*mount_options, ONERROR_PANIC);
365 case Opt_onerror_lock:
366 ufs_clear_opt (*mount_options, ONERROR);
367 ufs_set_opt (*mount_options, ONERROR_LOCK);
369 case Opt_onerror_umount:
370 ufs_clear_opt (*mount_options, ONERROR);
371 ufs_set_opt (*mount_options, ONERROR_UMOUNT);
373 case Opt_onerror_repair:
374 printk("UFS-fs: Unable to do repair on error, "
375 "will lock lock instead\n");
376 ufs_clear_opt (*mount_options, ONERROR);
377 ufs_set_opt (*mount_options, ONERROR_REPAIR);
380 printk("UFS-fs: Invalid option: \"%s\" "
381 "or missing value\n", p);
389 * Read on-disk structures associated with cylinder groups
391 static int ufs_read_cylinder_structures (struct super_block *sb)
393 struct ufs_sb_info * sbi = UFS_SB(sb);
394 struct ufs_sb_private_info * uspi;
395 struct ufs_super_block *usb;
396 struct ufs_buffer_head * ubh;
397 unsigned char * base, * space;
398 unsigned size, blks, i;
405 usb = (struct ufs_super_block *)
406 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data;
408 flags = UFS_SB(sb)->s_flags;
411 * Read cs structures from (usually) first data block
414 size = uspi->s_cssize;
415 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
416 base = space = kmalloc(size, GFP_KERNEL);
419 sbi->s_csp = (struct ufs_csum *)space;
420 for (i = 0; i < blks; i += uspi->s_fpb) {
421 size = uspi->s_bsize;
422 if (i + uspi->s_fpb > blks)
423 size = (blks - i) * uspi->s_fsize;
425 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
427 fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_csaddr) + i, size);
429 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
434 ubh_ubhcpymem (space, ubh, size);
442 * Read cylinder group (we read only first fragment from block
443 * at this time) and prepare internal data structures for cg caching.
445 if (!(sbi->s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_KERNEL)))
447 for (i = 0; i < uspi->s_ncg; i++)
448 sbi->s_ucg[i] = NULL;
449 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
450 sbi->s_ucpi[i] = NULL;
451 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
453 for (i = 0; i < uspi->s_ncg; i++) {
454 UFSD(("read cg %u\n", i))
455 if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
457 if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
459 #ifdef UFS_SUPER_DEBUG_MORE
460 ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
463 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
464 if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_KERNEL)))
466 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
468 sbi->s_cg_loaded = 0;
475 for (i = 0; i < uspi->s_ncg; i++)
477 brelse (sbi->s_ucg[i]);
479 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
480 kfree (sbi->s_ucpi[i]);
482 UFSD(("EXIT (FAILED)\n"))
487 * Put on-disk structures associated with cylinder groups and
488 * write them back to disk
490 static void ufs_put_cylinder_structures (struct super_block *sb)
492 struct ufs_sb_info * sbi = UFS_SB(sb);
493 struct ufs_sb_private_info * uspi;
494 struct ufs_buffer_head * ubh;
495 unsigned char * base, * space;
496 unsigned blks, size, i;
502 size = uspi->s_cssize;
503 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
504 base = space = (char*) sbi->s_csp;
505 for (i = 0; i < blks; i += uspi->s_fpb) {
506 size = uspi->s_bsize;
507 if (i + uspi->s_fpb > blks)
508 size = (blks - i) * uspi->s_fsize;
509 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
510 ubh_memcpyubh (ubh, space, size);
512 ubh_mark_buffer_uptodate (ubh, 1);
513 ubh_mark_buffer_dirty (ubh);
516 for (i = 0; i < sbi->s_cg_loaded; i++) {
517 ufs_put_cylinder (sb, i);
518 kfree (sbi->s_ucpi[i]);
520 for (; i < UFS_MAX_GROUP_LOADED; i++)
521 kfree (sbi->s_ucpi[i]);
522 for (i = 0; i < uspi->s_ncg; i++)
523 brelse (sbi->s_ucg[i]);
529 static int ufs_fill_super(struct super_block *sb, void *data, int silent)
531 struct ufs_sb_info * sbi;
532 struct ufs_sb_private_info * uspi;
533 struct ufs_super_block_first * usb1;
534 struct ufs_super_block_second * usb2;
535 struct ufs_super_block_third * usb3;
536 struct ufs_super_block *usb;
537 struct ufs_buffer_head * ubh;
539 unsigned block_size, super_block_size;
541 unsigned super_block_offset;
549 sbi = kmalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
553 memset(sbi, 0, sizeof(struct ufs_sb_info));
555 UFSD(("flag %u\n", (int)(sb->s_flags & MS_RDONLY)))
557 #ifndef CONFIG_UFS_FS_WRITE
558 if (!(sb->s_flags & MS_RDONLY)) {
559 printk("ufs was compiled with read-only support, "
560 "can't be mounted as read-write\n");
565 * Set default mount options
566 * Parse mount options
568 sbi->s_mount_opt = 0;
569 ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
570 if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
571 printk("wrong mount options\n");
574 if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
576 printk("You didn't specify the type of your ufs filesystem\n\n"
577 "mount -t ufs -o ufstype="
578 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|netxstep-cd|openstep ...\n\n"
579 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
580 "default is ufstype=old\n");
581 ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
585 kmalloc (sizeof(struct ufs_sb_private_info), GFP_KERNEL);
589 super_block_offset=UFS_SBLOCK;
591 /* Keep 2Gig file limit. Some UFS variants need to override
592 this but as I don't know which I'll let those in the know loosen
594 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
595 case UFS_MOUNT_UFSTYPE_44BSD:
596 UFSD(("ufstype=44bsd\n"))
597 uspi->s_fsize = block_size = 512;
598 uspi->s_fmask = ~(512 - 1);
600 uspi->s_sbsize = super_block_size = 1536;
602 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
604 case UFS_MOUNT_UFSTYPE_UFS2:
605 UFSD(("ufstype=ufs2\n"));
606 super_block_offset=SBLOCK_UFS2;
607 uspi->s_fsize = block_size = 512;
608 uspi->s_fmask = ~(512 - 1);
610 uspi->s_sbsize = super_block_size = 1536;
612 flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
613 if (!(sb->s_flags & MS_RDONLY)) {
614 printk(KERN_INFO "ufstype=ufs2 is supported read-only\n");
615 sb->s_flags |= MS_RDONLY;
619 case UFS_MOUNT_UFSTYPE_SUN:
620 UFSD(("ufstype=sun\n"))
621 uspi->s_fsize = block_size = 1024;
622 uspi->s_fmask = ~(1024 - 1);
624 uspi->s_sbsize = super_block_size = 2048;
626 uspi->s_maxsymlinklen = 56;
627 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
630 case UFS_MOUNT_UFSTYPE_SUNx86:
631 UFSD(("ufstype=sunx86\n"))
632 uspi->s_fsize = block_size = 1024;
633 uspi->s_fmask = ~(1024 - 1);
635 uspi->s_sbsize = super_block_size = 2048;
637 uspi->s_maxsymlinklen = 56;
638 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
641 case UFS_MOUNT_UFSTYPE_OLD:
642 UFSD(("ufstype=old\n"))
643 uspi->s_fsize = block_size = 1024;
644 uspi->s_fmask = ~(1024 - 1);
646 uspi->s_sbsize = super_block_size = 2048;
648 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
649 if (!(sb->s_flags & MS_RDONLY)) {
651 printk(KERN_INFO "ufstype=old is supported read-only\n");
652 sb->s_flags |= MS_RDONLY;
656 case UFS_MOUNT_UFSTYPE_NEXTSTEP:
657 UFSD(("ufstype=nextstep\n"))
658 uspi->s_fsize = block_size = 1024;
659 uspi->s_fmask = ~(1024 - 1);
661 uspi->s_sbsize = super_block_size = 2048;
663 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
664 if (!(sb->s_flags & MS_RDONLY)) {
666 printk(KERN_INFO "ufstype=nextstep is supported read-only\n");
667 sb->s_flags |= MS_RDONLY;
671 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
672 UFSD(("ufstype=nextstep-cd\n"))
673 uspi->s_fsize = block_size = 2048;
674 uspi->s_fmask = ~(2048 - 1);
676 uspi->s_sbsize = super_block_size = 2048;
678 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
679 if (!(sb->s_flags & MS_RDONLY)) {
681 printk(KERN_INFO "ufstype=nextstep-cd is supported read-only\n");
682 sb->s_flags |= MS_RDONLY;
686 case UFS_MOUNT_UFSTYPE_OPENSTEP:
687 UFSD(("ufstype=openstep\n"))
688 uspi->s_fsize = block_size = 1024;
689 uspi->s_fmask = ~(1024 - 1);
691 uspi->s_sbsize = super_block_size = 2048;
693 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
694 if (!(sb->s_flags & MS_RDONLY)) {
696 printk(KERN_INFO "ufstype=openstep is supported read-only\n");
697 sb->s_flags |= MS_RDONLY;
701 case UFS_MOUNT_UFSTYPE_HP:
702 UFSD(("ufstype=hp\n"))
703 uspi->s_fsize = block_size = 1024;
704 uspi->s_fmask = ~(1024 - 1);
706 uspi->s_sbsize = super_block_size = 2048;
708 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
709 if (!(sb->s_flags & MS_RDONLY)) {
711 printk(KERN_INFO "ufstype=hp is supported read-only\n");
712 sb->s_flags |= MS_RDONLY;
717 printk("unknown ufstype\n");
722 if (!sb_set_blocksize(sb, block_size)) {
723 printk(KERN_ERR "UFS: failed to set blocksize\n");
728 * read ufs super block from device
731 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
737 usb1 = ubh_get_usb_first(uspi);
738 usb2 = ubh_get_usb_second(uspi);
739 usb3 = ubh_get_usb_third(uspi);
740 usb = (struct ufs_super_block *)
741 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ;
744 * Check ufs magic number
746 sbi->s_bytesex = BYTESEX_LE;
747 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
755 sbi->s_bytesex = BYTESEX_BE;
756 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
765 if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
766 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
767 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
768 && uspi->s_sbbase < 256) {
769 ubh_brelse_uspi(uspi);
775 printk("ufs_read_super: bad magic number\n");
780 * Check block and fragment sizes
782 uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
783 uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
784 uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
785 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
786 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
788 if (uspi->s_fsize & (uspi->s_fsize - 1)) {
789 printk(KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n",
793 if (uspi->s_fsize < 512) {
794 printk(KERN_ERR "ufs_read_super: fragment size %u is too small\n",
798 if (uspi->s_fsize > 4096) {
799 printk(KERN_ERR "ufs_read_super: fragment size %u is too large\n",
803 if (uspi->s_bsize & (uspi->s_bsize - 1)) {
804 printk(KERN_ERR "ufs_read_super: block size %u is not a power of 2\n",
808 if (uspi->s_bsize < 4096) {
809 printk(KERN_ERR "ufs_read_super: block size %u is too small\n",
813 if (uspi->s_bsize / uspi->s_fsize > 8) {
814 printk(KERN_ERR "ufs_read_super: too many fragments per block (%u)\n",
815 uspi->s_bsize / uspi->s_fsize);
818 if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
819 ubh_brelse_uspi(uspi);
821 block_size = uspi->s_fsize;
822 super_block_size = uspi->s_sbsize;
823 UFSD(("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size))
827 #ifdef UFS_SUPER_DEBUG_MORE
828 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
829 ufs2_print_super_stuff(sb,usb);
831 ufs_print_super_stuff(sb, usb1, usb2, usb3);
835 * Check, if file system was correctly unmounted.
836 * If not, make it read only.
838 if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
839 ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
840 (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
841 (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
842 (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
843 switch(usb1->fs_clean) {
845 UFSD(("fs is clean\n"))
848 UFSD(("fs is stable\n"))
851 UFSD(("fs is DEC OSF/1\n"))
854 printk("ufs_read_super: fs is active\n");
855 sb->s_flags |= MS_RDONLY;
858 printk("ufs_read_super: fs is bad\n");
859 sb->s_flags |= MS_RDONLY;
862 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1->fs_clean);
863 sb->s_flags |= MS_RDONLY;
868 printk("ufs_read_super: fs needs fsck\n");
869 sb->s_flags |= MS_RDONLY;
873 * Read ufs_super_block into internal data structures
875 sb->s_op = &ufs_super_ops;
876 sb->dq_op = NULL; /***/
877 sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
879 uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
880 uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
881 uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
882 uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
883 uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
884 uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
886 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
887 uspi->s_u2_size = fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_size);
888 uspi->s_u2_dsize = fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_dsize);
891 uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
892 uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
895 uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
896 /* s_bsize already set */
897 /* s_fsize already set */
898 uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
899 uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
900 uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
901 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
902 uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
903 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
904 UFSD(("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
906 uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
907 uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
908 /* s_sbsize already set */
909 uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
910 uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
911 uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
912 uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
913 uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
914 uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
915 uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
916 uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
917 uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
918 uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
919 uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
920 uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
921 uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
922 uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
923 uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
924 uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
925 uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_cpc);
926 uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_contigsumsize);
927 uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
928 uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
929 uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
930 uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
931 uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
932 uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
935 * Compute another frequently used values
937 uspi->s_fpbmask = uspi->s_fpb - 1;
938 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
939 uspi->s_apbshift = uspi->s_bshift - 3;
942 uspi->s_apbshift = uspi->s_bshift - 2;
944 uspi->s_2apbshift = uspi->s_apbshift * 2;
945 uspi->s_3apbshift = uspi->s_apbshift * 3;
946 uspi->s_apb = 1 << uspi->s_apbshift;
947 uspi->s_2apb = 1 << uspi->s_2apbshift;
948 uspi->s_3apb = 1 << uspi->s_3apbshift;
949 uspi->s_apbmask = uspi->s_apb - 1;
950 uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
951 uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
952 uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
953 uspi->s_bpf = uspi->s_fsize << 3;
954 uspi->s_bpfshift = uspi->s_fshift + 3;
955 uspi->s_bpfmask = uspi->s_bpf - 1;
956 if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) ==
957 UFS_MOUNT_UFSTYPE_44BSD)
958 uspi->s_maxsymlinklen =
959 fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_maxsymlinklen);
961 sbi->s_flags = flags;
963 inode = iget(sb, UFS_ROOTINO);
964 if (!inode || is_bad_inode(inode))
966 sb->s_root = d_alloc_root(inode);
972 * Read cylinder group structures
974 if (!(sb->s_flags & MS_RDONLY))
975 if (!ufs_read_cylinder_structures(sb))
985 ubh_brelse_uspi (uspi);
988 sb->s_fs_info = NULL;
989 UFSD(("EXIT (FAILED)\n"))
993 UFSD(("EXIT (NOMEM)\n"))
997 static void ufs_write_super (struct super_block *sb) {
998 struct ufs_sb_private_info * uspi;
999 struct ufs_super_block_first * usb1;
1000 struct ufs_super_block_third * usb3;
1006 flags = UFS_SB(sb)->s_flags;
1007 uspi = UFS_SB(sb)->s_uspi;
1008 usb1 = ubh_get_usb_first(uspi);
1009 usb3 = ubh_get_usb_third(uspi);
1011 if (!(sb->s_flags & MS_RDONLY)) {
1012 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1013 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
1014 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1015 ufs_set_fs_state(sb, usb1, usb3,
1016 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
1017 ubh_mark_buffer_dirty (USPI_UBH);
1024 static void ufs_put_super (struct super_block *sb)
1026 struct ufs_sb_info * sbi = UFS_SB(sb);
1030 if (!(sb->s_flags & MS_RDONLY))
1031 ufs_put_cylinder_structures (sb);
1033 ubh_brelse_uspi (sbi->s_uspi);
1034 kfree (sbi->s_uspi);
1036 sb->s_fs_info = NULL;
1041 static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1043 struct ufs_sb_private_info * uspi;
1044 struct ufs_super_block_first * usb1;
1045 struct ufs_super_block_third * usb3;
1046 unsigned new_mount_opt, ufstype;
1049 uspi = UFS_SB(sb)->s_uspi;
1050 flags = UFS_SB(sb)->s_flags;
1051 usb1 = ubh_get_usb_first(uspi);
1052 usb3 = ubh_get_usb_third(uspi);
1055 * Allow the "check" option to be passed as a remount option.
1056 * It is not possible to change ufstype option during remount
1058 ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
1060 ufs_set_opt (new_mount_opt, ONERROR_LOCK);
1061 if (!ufs_parse_options (data, &new_mount_opt))
1063 if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
1064 new_mount_opt |= ufstype;
1066 else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
1067 printk("ufstype can't be changed during remount\n");
1071 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
1072 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1077 * fs was mouted as rw, remounting ro
1079 if (*mount_flags & MS_RDONLY) {
1080 ufs_put_cylinder_structures(sb);
1081 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1082 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
1083 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1084 ufs_set_fs_state(sb, usb1, usb3,
1085 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
1086 ubh_mark_buffer_dirty (USPI_UBH);
1088 sb->s_flags |= MS_RDONLY;
1091 * fs was mounted as ro, remounting rw
1094 #ifndef CONFIG_UFS_FS_WRITE
1095 printk("ufs was compiled with read-only support, "
1096 "can't be mounted as read-write\n");
1099 if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
1100 ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
1101 ufstype != UFS_MOUNT_UFSTYPE_SUNx86) {
1102 printk("this ufstype is read-only supported\n");
1105 if (!ufs_read_cylinder_structures (sb)) {
1106 printk("failed during remounting\n");
1109 sb->s_flags &= ~MS_RDONLY;
1112 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1116 static int ufs_statfs (struct super_block *sb, struct kstatfs *buf)
1118 struct ufs_sb_private_info * uspi;
1119 struct ufs_super_block_first * usb1;
1120 struct ufs_super_block * usb;
1125 uspi = UFS_SB(sb)->s_uspi;
1126 usb1 = ubh_get_usb_first (uspi);
1127 usb = (struct ufs_super_block *)
1128 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ;
1130 flags = UFS_SB(sb)->s_flags;
1131 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
1132 buf->f_type = UFS2_MAGIC;
1133 buf->f_blocks = fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_dsize);
1134 buf->f_bfree = ufs_blkstofrags(fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_cstotal.cs_nbfree)) +
1135 fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_cstotal.cs_nffree);
1136 buf->f_ffree = fs64_to_cpu(sb,
1137 usb->fs_u11.fs_u2.fs_cstotal.cs_nifree);
1140 buf->f_type = UFS_MAGIC;
1141 buf->f_blocks = uspi->s_dsize;
1142 buf->f_bfree = ufs_blkstofrags(fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree)) +
1143 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
1144 buf->f_ffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
1146 buf->f_bsize = sb->s_blocksize;
1147 buf->f_bavail = (buf->f_bfree > (((long)buf->f_blocks / 100) * uspi->s_minfree))
1148 ? (buf->f_bfree - (((long)buf->f_blocks / 100) * uspi->s_minfree)) : 0;
1149 buf->f_files = uspi->s_ncg * uspi->s_ipg;
1150 buf->f_namelen = UFS_MAXNAMLEN;
1157 static kmem_cache_t * ufs_inode_cachep;
1159 static struct inode *ufs_alloc_inode(struct super_block *sb)
1161 struct ufs_inode_info *ei;
1162 ei = (struct ufs_inode_info *)kmem_cache_alloc(ufs_inode_cachep, SLAB_KERNEL);
1165 ei->vfs_inode.i_version = 1;
1166 return &ei->vfs_inode;
1169 static void ufs_destroy_inode(struct inode *inode)
1171 kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
1174 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1176 struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
1178 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1179 SLAB_CTOR_CONSTRUCTOR)
1180 inode_init_once(&ei->vfs_inode);
1183 static int init_inodecache(void)
1185 ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
1186 sizeof(struct ufs_inode_info),
1187 0, SLAB_RECLAIM_ACCOUNT,
1189 if (ufs_inode_cachep == NULL)
1194 static void destroy_inodecache(void)
1196 if (kmem_cache_destroy(ufs_inode_cachep))
1197 printk(KERN_INFO "ufs_inode_cache: not all structures were freed\n");
1201 static ssize_t ufs_quota_read(struct super_block *, int, char *,size_t, loff_t);
1202 static ssize_t ufs_quota_write(struct super_block *, int, const char *, size_t, loff_t);
1205 static struct super_operations ufs_super_ops = {
1206 .alloc_inode = ufs_alloc_inode,
1207 .destroy_inode = ufs_destroy_inode,
1208 .read_inode = ufs_read_inode,
1209 .write_inode = ufs_write_inode,
1210 .delete_inode = ufs_delete_inode,
1211 .put_super = ufs_put_super,
1212 .write_super = ufs_write_super,
1213 .statfs = ufs_statfs,
1214 .remount_fs = ufs_remount,
1216 .quota_read = ufs_quota_read,
1217 .quota_write = ufs_quota_write,
1223 /* Read data from quotafile - avoid pagecache and such because we cannot afford
1224 * acquiring the locks... As quota files are never truncated and quota code
1225 * itself serializes the operations (and noone else should touch the files)
1226 * we don't have to be afraid of races */
1227 static ssize_t ufs_quota_read(struct super_block *sb, int type, char *data,
1228 size_t len, loff_t off)
1230 struct inode *inode = sb_dqopt(sb)->files[type];
1231 sector_t blk = off >> sb->s_blocksize_bits;
1233 int offset = off & (sb->s_blocksize - 1);
1236 struct buffer_head *bh;
1237 loff_t i_size = i_size_read(inode);
1241 if (off+len > i_size)
1244 while (toread > 0) {
1245 tocopy = sb->s_blocksize - offset < toread ?
1246 sb->s_blocksize - offset : toread;
1248 bh = ufs_bread(inode, blk, 0, &err);
1251 if (!bh) /* A hole? */
1252 memset(data, 0, tocopy);
1254 memcpy(data, bh->b_data+offset, tocopy);
1265 /* Write to quotafile */
1266 static ssize_t ufs_quota_write(struct super_block *sb, int type,
1267 const char *data, size_t len, loff_t off)
1269 struct inode *inode = sb_dqopt(sb)->files[type];
1270 sector_t blk = off >> sb->s_blocksize_bits;
1272 int offset = off & (sb->s_blocksize - 1);
1274 size_t towrite = len;
1275 struct buffer_head *bh;
1277 mutex_lock(&inode->i_mutex);
1278 while (towrite > 0) {
1279 tocopy = sb->s_blocksize - offset < towrite ?
1280 sb->s_blocksize - offset : towrite;
1282 bh = ufs_bread(inode, blk, 1, &err);
1286 memcpy(bh->b_data+offset, data, tocopy);
1287 flush_dcache_page(bh->b_page);
1288 set_buffer_uptodate(bh);
1289 mark_buffer_dirty(bh);
1298 if (len == towrite) {
1299 mutex_unlock(&inode->i_mutex);
1302 if (inode->i_size < off+len-towrite)
1303 i_size_write(inode, off+len-towrite);
1305 inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
1306 mark_inode_dirty(inode);
1307 mutex_unlock(&inode->i_mutex);
1308 return len - towrite;
1313 static struct super_block *ufs_get_sb(struct file_system_type *fs_type,
1314 int flags, const char *dev_name, void *data)
1316 return get_sb_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
1319 static struct file_system_type ufs_fs_type = {
1320 .owner = THIS_MODULE,
1322 .get_sb = ufs_get_sb,
1323 .kill_sb = kill_block_super,
1324 .fs_flags = FS_REQUIRES_DEV,
1327 static int __init init_ufs_fs(void)
1329 int err = init_inodecache();
1332 err = register_filesystem(&ufs_fs_type);
1337 destroy_inodecache();
1342 static void __exit exit_ufs_fs(void)
1344 unregister_filesystem(&ufs_fs_type);
1345 destroy_inodecache();
1348 module_init(init_ufs_fs)
1349 module_exit(exit_ufs_fs)
1350 MODULE_LICENSE("GPL");