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/module.h>
68 #include <linux/bitops.h>
72 #include <asm/uaccess.h>
73 #include <asm/system.h>
75 #include <linux/errno.h>
77 #include <linux/ufs_fs.h>
78 #include <linux/slab.h>
79 #include <linux/time.h>
80 #include <linux/stat.h>
81 #include <linux/string.h>
82 #include <linux/blkdev.h>
83 #include <linux/init.h>
84 #include <linux/parser.h>
85 #include <linux/smp_lock.h>
86 #include <linux/buffer_head.h>
87 #include <linux/vfs.h>
92 #ifdef CONFIG_UFS_DEBUG
94 * Print contents of ufs_super_block, useful for debugging
96 static void ufs_print_super_stuff(struct super_block
*sb
, unsigned flags
,
97 struct ufs_super_block_first
*usb1
,
98 struct ufs_super_block_second
*usb2
,
99 struct ufs_super_block_third
*usb3
)
101 printk("ufs_print_super_stuff\n");
102 printk(" magic: 0x%x\n", fs32_to_cpu(sb
, usb3
->fs_magic
));
103 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
104 printk(" fs_size: %llu\n", (unsigned long long)
105 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
));
106 printk(" fs_dsize: %llu\n", (unsigned long long)
107 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
));
108 printk(" bsize: %u\n",
109 fs32_to_cpu(sb
, usb1
->fs_bsize
));
110 printk(" fsize: %u\n",
111 fs32_to_cpu(sb
, usb1
->fs_fsize
));
112 printk(" fs_volname: %s\n", usb2
->fs_un
.fs_u2
.fs_volname
);
113 printk(" fs_sblockloc: %llu\n", (unsigned long long)
114 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.fs_sblockloc
));
115 printk(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
116 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
));
117 printk(" cs_nbfree(No of free blocks): %llu\n",
119 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
));
121 printk(" sblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_sblkno
));
122 printk(" cblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_cblkno
));
123 printk(" iblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_iblkno
));
124 printk(" dblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_dblkno
));
125 printk(" cgoffset: %u\n",
126 fs32_to_cpu(sb
, usb1
->fs_cgoffset
));
127 printk(" ~cgmask: 0x%x\n",
128 ~fs32_to_cpu(sb
, usb1
->fs_cgmask
));
129 printk(" size: %u\n", fs32_to_cpu(sb
, usb1
->fs_size
));
130 printk(" dsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_dsize
));
131 printk(" ncg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ncg
));
132 printk(" bsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_bsize
));
133 printk(" fsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_fsize
));
134 printk(" frag: %u\n", fs32_to_cpu(sb
, usb1
->fs_frag
));
135 printk(" fragshift: %u\n",
136 fs32_to_cpu(sb
, usb1
->fs_fragshift
));
137 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb
, usb1
->fs_fmask
));
138 printk(" fshift: %u\n", fs32_to_cpu(sb
, usb1
->fs_fshift
));
139 printk(" sbsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_sbsize
));
140 printk(" spc: %u\n", fs32_to_cpu(sb
, usb1
->fs_spc
));
141 printk(" cpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_cpg
));
142 printk(" ipg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ipg
));
143 printk(" fpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_fpg
));
144 printk(" csaddr: %u\n", fs32_to_cpu(sb
, usb1
->fs_csaddr
));
145 printk(" cssize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cssize
));
146 printk(" cgsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cgsize
));
147 printk(" fstodb: %u\n",
148 fs32_to_cpu(sb
, usb1
->fs_fsbtodb
));
149 printk(" nrpos: %u\n", fs32_to_cpu(sb
, usb3
->fs_nrpos
));
151 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
));
152 printk(" nifree %u\n",
153 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
));
154 printk(" nbfree %u\n",
155 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
));
156 printk(" nffree %u\n",
157 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
));
163 * Print contents of ufs_cylinder_group, useful for debugging
165 static void ufs_print_cylinder_stuff(struct super_block
*sb
,
166 struct ufs_cylinder_group
*cg
)
168 printk("\nufs_print_cylinder_stuff\n");
169 printk("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group
));
170 printk(" magic: %x\n", fs32_to_cpu(sb
, cg
->cg_magic
));
171 printk(" time: %u\n", fs32_to_cpu(sb
, cg
->cg_time
));
172 printk(" cgx: %u\n", fs32_to_cpu(sb
, cg
->cg_cgx
));
173 printk(" ncyl: %u\n", fs16_to_cpu(sb
, cg
->cg_ncyl
));
174 printk(" niblk: %u\n", fs16_to_cpu(sb
, cg
->cg_niblk
));
175 printk(" ndblk: %u\n", fs32_to_cpu(sb
, cg
->cg_ndblk
));
176 printk(" cs_ndir: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_ndir
));
177 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nbfree
));
178 printk(" cs_nifree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nifree
));
179 printk(" cs_nffree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nffree
));
180 printk(" rotor: %u\n", fs32_to_cpu(sb
, cg
->cg_rotor
));
181 printk(" frotor: %u\n", fs32_to_cpu(sb
, cg
->cg_frotor
));
182 printk(" irotor: %u\n", fs32_to_cpu(sb
, cg
->cg_irotor
));
183 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
184 fs32_to_cpu(sb
, cg
->cg_frsum
[0]), fs32_to_cpu(sb
, cg
->cg_frsum
[1]),
185 fs32_to_cpu(sb
, cg
->cg_frsum
[2]), fs32_to_cpu(sb
, cg
->cg_frsum
[3]),
186 fs32_to_cpu(sb
, cg
->cg_frsum
[4]), fs32_to_cpu(sb
, cg
->cg_frsum
[5]),
187 fs32_to_cpu(sb
, cg
->cg_frsum
[6]), fs32_to_cpu(sb
, cg
->cg_frsum
[7]));
188 printk(" btotoff: %u\n", fs32_to_cpu(sb
, cg
->cg_btotoff
));
189 printk(" boff: %u\n", fs32_to_cpu(sb
, cg
->cg_boff
));
190 printk(" iuseoff: %u\n", fs32_to_cpu(sb
, cg
->cg_iusedoff
));
191 printk(" freeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_freeoff
));
192 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_nextfreeoff
));
193 printk(" clustersumoff %u\n",
194 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clustersumoff
));
195 printk(" clusteroff %u\n",
196 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clusteroff
));
197 printk(" nclusterblks %u\n",
198 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_nclusterblks
));
202 # define ufs_print_super_stuff(sb, flags, usb1, usb2, usb3) /**/
203 # define ufs_print_cylinder_stuff(sb, cg) /**/
204 #endif /* CONFIG_UFS_DEBUG */
206 static struct super_operations ufs_super_ops
;
208 static char error_buf
[1024];
210 void ufs_error (struct super_block
* sb
, const char * function
,
211 const char * fmt
, ...)
213 struct ufs_sb_private_info
* uspi
;
214 struct ufs_super_block_first
* usb1
;
217 uspi
= UFS_SB(sb
)->s_uspi
;
218 usb1
= ubh_get_usb_first(uspi
);
220 if (!(sb
->s_flags
& MS_RDONLY
)) {
221 usb1
->fs_clean
= UFS_FSBAD
;
222 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
224 sb
->s_flags
|= MS_RDONLY
;
226 va_start (args
, fmt
);
227 vsprintf (error_buf
, fmt
, args
);
229 switch (UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_ONERROR
) {
230 case UFS_MOUNT_ONERROR_PANIC
:
231 panic ("UFS-fs panic (device %s): %s: %s\n",
232 sb
->s_id
, function
, error_buf
);
234 case UFS_MOUNT_ONERROR_LOCK
:
235 case UFS_MOUNT_ONERROR_UMOUNT
:
236 case UFS_MOUNT_ONERROR_REPAIR
:
237 printk (KERN_CRIT
"UFS-fs error (device %s): %s: %s\n",
238 sb
->s_id
, function
, error_buf
);
242 void ufs_panic (struct super_block
* sb
, const char * function
,
243 const char * fmt
, ...)
245 struct ufs_sb_private_info
* uspi
;
246 struct ufs_super_block_first
* usb1
;
249 uspi
= UFS_SB(sb
)->s_uspi
;
250 usb1
= ubh_get_usb_first(uspi
);
252 if (!(sb
->s_flags
& MS_RDONLY
)) {
253 usb1
->fs_clean
= UFS_FSBAD
;
254 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
257 va_start (args
, fmt
);
258 vsprintf (error_buf
, fmt
, args
);
260 sb
->s_flags
|= MS_RDONLY
;
261 printk (KERN_CRIT
"UFS-fs panic (device %s): %s: %s\n",
262 sb
->s_id
, function
, error_buf
);
265 void ufs_warning (struct super_block
* sb
, const char * function
,
266 const char * fmt
, ...)
270 va_start (args
, fmt
);
271 vsprintf (error_buf
, fmt
, args
);
273 printk (KERN_WARNING
"UFS-fs warning (device %s): %s: %s\n",
274 sb
->s_id
, function
, error_buf
);
278 Opt_type_old
, Opt_type_sunx86
, Opt_type_sun
, Opt_type_44bsd
,
279 Opt_type_ufs2
, Opt_type_hp
, Opt_type_nextstepcd
, Opt_type_nextstep
,
280 Opt_type_openstep
, Opt_onerror_panic
, Opt_onerror_lock
,
281 Opt_onerror_umount
, Opt_onerror_repair
, Opt_err
284 static match_table_t tokens
= {
285 {Opt_type_old
, "ufstype=old"},
286 {Opt_type_sunx86
, "ufstype=sunx86"},
287 {Opt_type_sun
, "ufstype=sun"},
288 {Opt_type_44bsd
, "ufstype=44bsd"},
289 {Opt_type_ufs2
, "ufstype=ufs2"},
290 {Opt_type_ufs2
, "ufstype=5xbsd"},
291 {Opt_type_hp
, "ufstype=hp"},
292 {Opt_type_nextstepcd
, "ufstype=nextstep-cd"},
293 {Opt_type_nextstep
, "ufstype=nextstep"},
294 {Opt_type_openstep
, "ufstype=openstep"},
295 {Opt_onerror_panic
, "onerror=panic"},
296 {Opt_onerror_lock
, "onerror=lock"},
297 {Opt_onerror_umount
, "onerror=umount"},
298 {Opt_onerror_repair
, "onerror=repair"},
302 static int ufs_parse_options (char * options
, unsigned * mount_options
)
311 while ((p
= strsep(&options
, ",")) != NULL
) {
312 substring_t args
[MAX_OPT_ARGS
];
317 token
= match_token(p
, tokens
, args
);
320 ufs_clear_opt (*mount_options
, UFSTYPE
);
321 ufs_set_opt (*mount_options
, UFSTYPE_OLD
);
323 case Opt_type_sunx86
:
324 ufs_clear_opt (*mount_options
, UFSTYPE
);
325 ufs_set_opt (*mount_options
, UFSTYPE_SUNx86
);
328 ufs_clear_opt (*mount_options
, UFSTYPE
);
329 ufs_set_opt (*mount_options
, UFSTYPE_SUN
);
332 ufs_clear_opt (*mount_options
, UFSTYPE
);
333 ufs_set_opt (*mount_options
, UFSTYPE_44BSD
);
336 ufs_clear_opt(*mount_options
, UFSTYPE
);
337 ufs_set_opt(*mount_options
, UFSTYPE_UFS2
);
340 ufs_clear_opt (*mount_options
, UFSTYPE
);
341 ufs_set_opt (*mount_options
, UFSTYPE_HP
);
343 case Opt_type_nextstepcd
:
344 ufs_clear_opt (*mount_options
, UFSTYPE
);
345 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP_CD
);
347 case Opt_type_nextstep
:
348 ufs_clear_opt (*mount_options
, UFSTYPE
);
349 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP
);
351 case Opt_type_openstep
:
352 ufs_clear_opt (*mount_options
, UFSTYPE
);
353 ufs_set_opt (*mount_options
, UFSTYPE_OPENSTEP
);
355 case Opt_onerror_panic
:
356 ufs_clear_opt (*mount_options
, ONERROR
);
357 ufs_set_opt (*mount_options
, ONERROR_PANIC
);
359 case Opt_onerror_lock
:
360 ufs_clear_opt (*mount_options
, ONERROR
);
361 ufs_set_opt (*mount_options
, ONERROR_LOCK
);
363 case Opt_onerror_umount
:
364 ufs_clear_opt (*mount_options
, ONERROR
);
365 ufs_set_opt (*mount_options
, ONERROR_UMOUNT
);
367 case Opt_onerror_repair
:
368 printk("UFS-fs: Unable to do repair on error, "
369 "will lock lock instead\n");
370 ufs_clear_opt (*mount_options
, ONERROR
);
371 ufs_set_opt (*mount_options
, ONERROR_REPAIR
);
374 printk("UFS-fs: Invalid option: \"%s\" "
375 "or missing value\n", p
);
383 * Diffrent types of UFS hold fs_cstotal in different
384 * places, and use diffrent data structure for it.
385 * To make things simplier we just copy fs_cstotal to ufs_sb_private_info
387 static void ufs_setup_cstotal(struct super_block
*sb
)
389 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
390 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
391 struct ufs_super_block_first
*usb1
;
392 struct ufs_super_block_second
*usb2
;
393 struct ufs_super_block_third
*usb3
;
394 unsigned mtype
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
396 UFSD("ENTER, mtype=%u\n", mtype
);
397 usb1
= ubh_get_usb_first(uspi
);
398 usb2
= ubh_get_usb_second(uspi
);
399 usb3
= ubh_get_usb_third(uspi
);
401 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
402 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
403 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
404 /*we have statistic in different place, then usual*/
405 uspi
->cs_total
.cs_ndir
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
);
406 uspi
->cs_total
.cs_nbfree
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
);
407 uspi
->cs_total
.cs_nifree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
);
408 uspi
->cs_total
.cs_nffree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
);
410 uspi
->cs_total
.cs_ndir
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
);
411 uspi
->cs_total
.cs_nbfree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
);
412 uspi
->cs_total
.cs_nifree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
);
413 uspi
->cs_total
.cs_nffree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
);
419 * Read on-disk structures associated with cylinder groups
421 static int ufs_read_cylinder_structures(struct super_block
*sb
)
423 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
424 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
425 unsigned flags
= sbi
->s_flags
;
426 struct ufs_buffer_head
* ubh
;
427 unsigned char * base
, * space
;
428 unsigned size
, blks
, i
;
429 struct ufs_super_block_third
*usb3
;
433 usb3
= ubh_get_usb_third(uspi
);
435 * Read cs structures from (usually) first data block
438 size
= uspi
->s_cssize
;
439 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
440 base
= space
= kmalloc(size
, GFP_KERNEL
);
443 sbi
->s_csp
= (struct ufs_csum
*)space
;
444 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
445 size
= uspi
->s_bsize
;
446 if (i
+ uspi
->s_fpb
> blks
)
447 size
= (blks
- i
) * uspi
->s_fsize
;
449 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
451 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_csaddr
) + i
, size
);
453 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
458 ubh_ubhcpymem (space
, ubh
, size
);
466 * Read cylinder group (we read only first fragment from block
467 * at this time) and prepare internal data structures for cg caching.
469 if (!(sbi
->s_ucg
= kmalloc (sizeof(struct buffer_head
*) * uspi
->s_ncg
, GFP_KERNEL
)))
471 for (i
= 0; i
< uspi
->s_ncg
; i
++)
472 sbi
->s_ucg
[i
] = NULL
;
473 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
474 sbi
->s_ucpi
[i
] = NULL
;
475 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
477 for (i
= 0; i
< uspi
->s_ncg
; i
++) {
478 UFSD("read cg %u\n", i
);
479 if (!(sbi
->s_ucg
[i
] = sb_bread(sb
, ufs_cgcmin(i
))))
481 if (!ufs_cg_chkmagic (sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
))
484 ufs_print_cylinder_stuff(sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
);
486 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
487 if (!(sbi
->s_ucpi
[i
] = kmalloc (sizeof(struct ufs_cg_private_info
), GFP_KERNEL
)))
489 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
491 sbi
->s_cg_loaded
= 0;
498 for (i
= 0; i
< uspi
->s_ncg
; i
++)
500 brelse (sbi
->s_ucg
[i
]);
502 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++)
503 kfree (sbi
->s_ucpi
[i
]);
505 UFSD("EXIT (FAILED)\n");
510 * Sync our internal copy of fs_cstotal with disk
512 static void ufs_put_cstotal(struct super_block
*sb
)
514 unsigned mtype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
515 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
516 struct ufs_super_block_first
*usb1
;
517 struct ufs_super_block_second
*usb2
;
518 struct ufs_super_block_third
*usb3
;
521 usb1
= ubh_get_usb_first(uspi
);
522 usb2
= ubh_get_usb_second(uspi
);
523 usb3
= ubh_get_usb_third(uspi
);
525 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
526 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
527 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
528 /*we have statistic in different place, then usual*/
529 usb2
->fs_un
.fs_u2
.cs_ndir
=
530 cpu_to_fs64(sb
, uspi
->cs_total
.cs_ndir
);
531 usb2
->fs_un
.fs_u2
.cs_nbfree
=
532 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nbfree
);
533 usb3
->fs_un1
.fs_u2
.cs_nifree
=
534 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nifree
);
535 usb3
->fs_un1
.fs_u2
.cs_nffree
=
536 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nffree
);
538 usb1
->fs_cstotal
.cs_ndir
=
539 cpu_to_fs32(sb
, uspi
->cs_total
.cs_ndir
);
540 usb1
->fs_cstotal
.cs_nbfree
=
541 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nbfree
);
542 usb1
->fs_cstotal
.cs_nifree
=
543 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nifree
);
544 usb1
->fs_cstotal
.cs_nffree
=
545 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nffree
);
547 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
552 * ufs_put_super_internal() - put on-disk intrenal structures
553 * @sb: pointer to super_block structure
554 * Put on-disk structures associated with cylinder groups
555 * and write them back to disk, also update cs_total on disk
557 static void ufs_put_super_internal(struct super_block
*sb
)
559 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
560 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
561 struct ufs_buffer_head
* ubh
;
562 unsigned char * base
, * space
;
563 unsigned blks
, size
, i
;
568 size
= uspi
->s_cssize
;
569 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
570 base
= space
= (char*) sbi
->s_csp
;
571 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
572 size
= uspi
->s_bsize
;
573 if (i
+ uspi
->s_fpb
> blks
)
574 size
= (blks
- i
) * uspi
->s_fsize
;
575 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
576 ubh_memcpyubh (ubh
, space
, size
);
578 ubh_mark_buffer_uptodate (ubh
, 1);
579 ubh_mark_buffer_dirty (ubh
);
582 for (i
= 0; i
< sbi
->s_cg_loaded
; i
++) {
583 ufs_put_cylinder (sb
, i
);
584 kfree (sbi
->s_ucpi
[i
]);
586 for (; i
< UFS_MAX_GROUP_LOADED
; i
++)
587 kfree (sbi
->s_ucpi
[i
]);
588 for (i
= 0; i
< uspi
->s_ncg
; i
++)
589 brelse (sbi
->s_ucg
[i
]);
595 static int ufs_fill_super(struct super_block
*sb
, void *data
, int silent
)
597 struct ufs_sb_info
* sbi
;
598 struct ufs_sb_private_info
* uspi
;
599 struct ufs_super_block_first
* usb1
;
600 struct ufs_super_block_second
* usb2
;
601 struct ufs_super_block_third
* usb3
;
602 struct ufs_buffer_head
* ubh
;
604 unsigned block_size
, super_block_size
;
606 unsigned super_block_offset
;
614 sbi
= kmalloc(sizeof(struct ufs_sb_info
), GFP_KERNEL
);
618 memset(sbi
, 0, sizeof(struct ufs_sb_info
));
620 UFSD("flag %u\n", (int)(sb
->s_flags
& MS_RDONLY
));
622 #ifndef CONFIG_UFS_FS_WRITE
623 if (!(sb
->s_flags
& MS_RDONLY
)) {
624 printk("ufs was compiled with read-only support, "
625 "can't be mounted as read-write\n");
630 * Set default mount options
631 * Parse mount options
633 sbi
->s_mount_opt
= 0;
634 ufs_set_opt (sbi
->s_mount_opt
, ONERROR_LOCK
);
635 if (!ufs_parse_options ((char *) data
, &sbi
->s_mount_opt
)) {
636 printk("wrong mount options\n");
639 if (!(sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
641 printk("You didn't specify the type of your ufs filesystem\n\n"
642 "mount -t ufs -o ufstype="
643 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
644 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
645 "default is ufstype=old\n");
646 ufs_set_opt (sbi
->s_mount_opt
, UFSTYPE_OLD
);
650 kmalloc (sizeof(struct ufs_sb_private_info
), GFP_KERNEL
);
654 super_block_offset
=UFS_SBLOCK
;
656 /* Keep 2Gig file limit. Some UFS variants need to override
657 this but as I don't know which I'll let those in the know loosen
659 switch (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) {
660 case UFS_MOUNT_UFSTYPE_44BSD
:
661 UFSD("ufstype=44bsd\n");
662 uspi
->s_fsize
= block_size
= 512;
663 uspi
->s_fmask
= ~(512 - 1);
665 uspi
->s_sbsize
= super_block_size
= 1536;
667 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
669 case UFS_MOUNT_UFSTYPE_UFS2
:
670 UFSD("ufstype=ufs2\n");
671 super_block_offset
=SBLOCK_UFS2
;
672 uspi
->s_fsize
= block_size
= 512;
673 uspi
->s_fmask
= ~(512 - 1);
675 uspi
->s_sbsize
= super_block_size
= 1536;
677 flags
|= UFS_TYPE_UFS2
| UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
678 if (!(sb
->s_flags
& MS_RDONLY
)) {
679 printk(KERN_INFO
"ufstype=ufs2 is supported read-only\n");
680 sb
->s_flags
|= MS_RDONLY
;
684 case UFS_MOUNT_UFSTYPE_SUN
:
685 UFSD("ufstype=sun\n");
686 uspi
->s_fsize
= block_size
= 1024;
687 uspi
->s_fmask
= ~(1024 - 1);
689 uspi
->s_sbsize
= super_block_size
= 2048;
691 uspi
->s_maxsymlinklen
= 56;
692 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUN
| UFS_CG_SUN
;
695 case UFS_MOUNT_UFSTYPE_SUNx86
:
696 UFSD("ufstype=sunx86\n");
697 uspi
->s_fsize
= block_size
= 1024;
698 uspi
->s_fmask
= ~(1024 - 1);
700 uspi
->s_sbsize
= super_block_size
= 2048;
702 uspi
->s_maxsymlinklen
= 56;
703 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUNx86
| UFS_CG_SUN
;
706 case UFS_MOUNT_UFSTYPE_OLD
:
707 UFSD("ufstype=old\n");
708 uspi
->s_fsize
= block_size
= 1024;
709 uspi
->s_fmask
= ~(1024 - 1);
711 uspi
->s_sbsize
= super_block_size
= 2048;
713 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
714 if (!(sb
->s_flags
& MS_RDONLY
)) {
716 printk(KERN_INFO
"ufstype=old is supported read-only\n");
717 sb
->s_flags
|= MS_RDONLY
;
721 case UFS_MOUNT_UFSTYPE_NEXTSTEP
:
722 UFSD("ufstype=nextstep\n");
723 uspi
->s_fsize
= block_size
= 1024;
724 uspi
->s_fmask
= ~(1024 - 1);
726 uspi
->s_sbsize
= super_block_size
= 2048;
728 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
729 if (!(sb
->s_flags
& MS_RDONLY
)) {
731 printk(KERN_INFO
"ufstype=nextstep is supported read-only\n");
732 sb
->s_flags
|= MS_RDONLY
;
736 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
:
737 UFSD("ufstype=nextstep-cd\n");
738 uspi
->s_fsize
= block_size
= 2048;
739 uspi
->s_fmask
= ~(2048 - 1);
741 uspi
->s_sbsize
= super_block_size
= 2048;
743 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
744 if (!(sb
->s_flags
& MS_RDONLY
)) {
746 printk(KERN_INFO
"ufstype=nextstep-cd is supported read-only\n");
747 sb
->s_flags
|= MS_RDONLY
;
751 case UFS_MOUNT_UFSTYPE_OPENSTEP
:
752 UFSD("ufstype=openstep\n");
753 uspi
->s_fsize
= block_size
= 1024;
754 uspi
->s_fmask
= ~(1024 - 1);
756 uspi
->s_sbsize
= super_block_size
= 2048;
758 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
759 if (!(sb
->s_flags
& MS_RDONLY
)) {
761 printk(KERN_INFO
"ufstype=openstep is supported read-only\n");
762 sb
->s_flags
|= MS_RDONLY
;
766 case UFS_MOUNT_UFSTYPE_HP
:
767 UFSD("ufstype=hp\n");
768 uspi
->s_fsize
= block_size
= 1024;
769 uspi
->s_fmask
= ~(1024 - 1);
771 uspi
->s_sbsize
= super_block_size
= 2048;
773 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
774 if (!(sb
->s_flags
& MS_RDONLY
)) {
776 printk(KERN_INFO
"ufstype=hp is supported read-only\n");
777 sb
->s_flags
|= MS_RDONLY
;
782 printk("unknown ufstype\n");
787 if (!sb_set_blocksize(sb
, block_size
)) {
788 printk(KERN_ERR
"UFS: failed to set blocksize\n");
793 * read ufs super block from device
796 ubh
= ubh_bread_uspi(uspi
, sb
, uspi
->s_sbbase
+ super_block_offset
/block_size
, super_block_size
);
802 usb1
= ubh_get_usb_first(uspi
);
803 usb2
= ubh_get_usb_second(uspi
);
804 usb3
= ubh_get_usb_third(uspi
);
807 * Check ufs magic number
809 sbi
->s_bytesex
= BYTESEX_LE
;
810 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
818 sbi
->s_bytesex
= BYTESEX_BE
;
819 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
828 if ((((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP
)
829 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
)
830 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_OPENSTEP
))
831 && uspi
->s_sbbase
< 256) {
832 ubh_brelse_uspi(uspi
);
838 printk("ufs_read_super: bad magic number\n");
843 * Check block and fragment sizes
845 uspi
->s_bsize
= fs32_to_cpu(sb
, usb1
->fs_bsize
);
846 uspi
->s_fsize
= fs32_to_cpu(sb
, usb1
->fs_fsize
);
847 uspi
->s_sbsize
= fs32_to_cpu(sb
, usb1
->fs_sbsize
);
848 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
849 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
851 if (uspi
->s_fsize
& (uspi
->s_fsize
- 1)) {
852 printk(KERN_ERR
"ufs_read_super: fragment size %u is not a power of 2\n",
856 if (uspi
->s_fsize
< 512) {
857 printk(KERN_ERR
"ufs_read_super: fragment size %u is too small\n",
861 if (uspi
->s_fsize
> 4096) {
862 printk(KERN_ERR
"ufs_read_super: fragment size %u is too large\n",
866 if (uspi
->s_bsize
& (uspi
->s_bsize
- 1)) {
867 printk(KERN_ERR
"ufs_read_super: block size %u is not a power of 2\n",
871 if (uspi
->s_bsize
< 4096) {
872 printk(KERN_ERR
"ufs_read_super: block size %u is too small\n",
876 if (uspi
->s_bsize
/ uspi
->s_fsize
> 8) {
877 printk(KERN_ERR
"ufs_read_super: too many fragments per block (%u)\n",
878 uspi
->s_bsize
/ uspi
->s_fsize
);
881 if (uspi
->s_fsize
!= block_size
|| uspi
->s_sbsize
!= super_block_size
) {
882 ubh_brelse_uspi(uspi
);
884 block_size
= uspi
->s_fsize
;
885 super_block_size
= uspi
->s_sbsize
;
886 UFSD("another value of block_size or super_block_size %u, %u\n", block_size
, super_block_size
);
891 ufs_print_super_stuff(sb
, flags
, usb1
, usb2
, usb3
);
894 * Check, if file system was correctly unmounted.
895 * If not, make it read only.
897 if (((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
) ||
898 ((flags
& UFS_ST_MASK
) == UFS_ST_OLD
) ||
899 (((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
900 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
) &&
901 (ufs_get_fs_state(sb
, usb1
, usb3
) == (UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
))))) {
902 switch(usb1
->fs_clean
) {
904 UFSD("fs is clean\n");
907 UFSD("fs is stable\n");
910 UFSD("fs is DEC OSF/1\n");
913 printk("ufs_read_super: fs is active\n");
914 sb
->s_flags
|= MS_RDONLY
;
917 printk("ufs_read_super: fs is bad\n");
918 sb
->s_flags
|= MS_RDONLY
;
921 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1
->fs_clean
);
922 sb
->s_flags
|= MS_RDONLY
;
926 printk("ufs_read_super: fs needs fsck\n");
927 sb
->s_flags
|= MS_RDONLY
;
931 * Read ufs_super_block into internal data structures
933 sb
->s_op
= &ufs_super_ops
;
934 sb
->dq_op
= NULL
; /***/
935 sb
->s_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
937 uspi
->s_sblkno
= fs32_to_cpu(sb
, usb1
->fs_sblkno
);
938 uspi
->s_cblkno
= fs32_to_cpu(sb
, usb1
->fs_cblkno
);
939 uspi
->s_iblkno
= fs32_to_cpu(sb
, usb1
->fs_iblkno
);
940 uspi
->s_dblkno
= fs32_to_cpu(sb
, usb1
->fs_dblkno
);
941 uspi
->s_cgoffset
= fs32_to_cpu(sb
, usb1
->fs_cgoffset
);
942 uspi
->s_cgmask
= fs32_to_cpu(sb
, usb1
->fs_cgmask
);
944 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
945 uspi
->s_u2_size
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
);
946 uspi
->s_u2_dsize
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
948 uspi
->s_size
= fs32_to_cpu(sb
, usb1
->fs_size
);
949 uspi
->s_dsize
= fs32_to_cpu(sb
, usb1
->fs_dsize
);
952 uspi
->s_ncg
= fs32_to_cpu(sb
, usb1
->fs_ncg
);
953 /* s_bsize already set */
954 /* s_fsize already set */
955 uspi
->s_fpb
= fs32_to_cpu(sb
, usb1
->fs_frag
);
956 uspi
->s_minfree
= fs32_to_cpu(sb
, usb1
->fs_minfree
);
957 uspi
->s_bmask
= fs32_to_cpu(sb
, usb1
->fs_bmask
);
958 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
959 uspi
->s_bshift
= fs32_to_cpu(sb
, usb1
->fs_bshift
);
960 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
961 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi
->s_bshift
,
963 uspi
->s_fpbshift
= fs32_to_cpu(sb
, usb1
->fs_fragshift
);
964 uspi
->s_fsbtodb
= fs32_to_cpu(sb
, usb1
->fs_fsbtodb
);
965 /* s_sbsize already set */
966 uspi
->s_csmask
= fs32_to_cpu(sb
, usb1
->fs_csmask
);
967 uspi
->s_csshift
= fs32_to_cpu(sb
, usb1
->fs_csshift
);
968 uspi
->s_nindir
= fs32_to_cpu(sb
, usb1
->fs_nindir
);
969 uspi
->s_inopb
= fs32_to_cpu(sb
, usb1
->fs_inopb
);
970 uspi
->s_nspf
= fs32_to_cpu(sb
, usb1
->fs_nspf
);
971 uspi
->s_npsect
= ufs_get_fs_npsect(sb
, usb1
, usb3
);
972 uspi
->s_interleave
= fs32_to_cpu(sb
, usb1
->fs_interleave
);
973 uspi
->s_trackskew
= fs32_to_cpu(sb
, usb1
->fs_trackskew
);
974 uspi
->s_csaddr
= fs32_to_cpu(sb
, usb1
->fs_csaddr
);
975 uspi
->s_cssize
= fs32_to_cpu(sb
, usb1
->fs_cssize
);
976 uspi
->s_cgsize
= fs32_to_cpu(sb
, usb1
->fs_cgsize
);
977 uspi
->s_ntrak
= fs32_to_cpu(sb
, usb1
->fs_ntrak
);
978 uspi
->s_nsect
= fs32_to_cpu(sb
, usb1
->fs_nsect
);
979 uspi
->s_spc
= fs32_to_cpu(sb
, usb1
->fs_spc
);
980 uspi
->s_ipg
= fs32_to_cpu(sb
, usb1
->fs_ipg
);
981 uspi
->s_fpg
= fs32_to_cpu(sb
, usb1
->fs_fpg
);
982 uspi
->s_cpc
= fs32_to_cpu(sb
, usb2
->fs_un
.fs_u1
.fs_cpc
);
983 uspi
->s_contigsumsize
= fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_contigsumsize
);
984 uspi
->s_qbmask
= ufs_get_fs_qbmask(sb
, usb3
);
985 uspi
->s_qfmask
= ufs_get_fs_qfmask(sb
, usb3
);
986 uspi
->s_postblformat
= fs32_to_cpu(sb
, usb3
->fs_postblformat
);
987 uspi
->s_nrpos
= fs32_to_cpu(sb
, usb3
->fs_nrpos
);
988 uspi
->s_postbloff
= fs32_to_cpu(sb
, usb3
->fs_postbloff
);
989 uspi
->s_rotbloff
= fs32_to_cpu(sb
, usb3
->fs_rotbloff
);
992 * Compute another frequently used values
994 uspi
->s_fpbmask
= uspi
->s_fpb
- 1;
995 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
996 uspi
->s_apbshift
= uspi
->s_bshift
- 3;
998 uspi
->s_apbshift
= uspi
->s_bshift
- 2;
1000 uspi
->s_2apbshift
= uspi
->s_apbshift
* 2;
1001 uspi
->s_3apbshift
= uspi
->s_apbshift
* 3;
1002 uspi
->s_apb
= 1 << uspi
->s_apbshift
;
1003 uspi
->s_2apb
= 1 << uspi
->s_2apbshift
;
1004 uspi
->s_3apb
= 1 << uspi
->s_3apbshift
;
1005 uspi
->s_apbmask
= uspi
->s_apb
- 1;
1006 uspi
->s_nspfshift
= uspi
->s_fshift
- UFS_SECTOR_BITS
;
1007 uspi
->s_nspb
= uspi
->s_nspf
<< uspi
->s_fpbshift
;
1008 uspi
->s_inopf
= uspi
->s_inopb
>> uspi
->s_fpbshift
;
1009 uspi
->s_bpf
= uspi
->s_fsize
<< 3;
1010 uspi
->s_bpfshift
= uspi
->s_fshift
+ 3;
1011 uspi
->s_bpfmask
= uspi
->s_bpf
- 1;
1012 if ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) ==
1013 UFS_MOUNT_UFSTYPE_44BSD
)
1014 uspi
->s_maxsymlinklen
=
1015 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
);
1017 sbi
->s_flags
= flags
;
1019 inode
= iget(sb
, UFS_ROOTINO
);
1020 if (!inode
|| is_bad_inode(inode
))
1022 sb
->s_root
= d_alloc_root(inode
);
1026 ufs_setup_cstotal(sb
);
1028 * Read cylinder group structures
1030 if (!(sb
->s_flags
& MS_RDONLY
))
1031 if (!ufs_read_cylinder_structures(sb
))
1041 ubh_brelse_uspi (uspi
);
1044 sb
->s_fs_info
= NULL
;
1045 UFSD("EXIT (FAILED)\n");
1049 UFSD("EXIT (NOMEM)\n");
1053 static void ufs_write_super(struct super_block
*sb
)
1055 struct ufs_sb_private_info
* uspi
;
1056 struct ufs_super_block_first
* usb1
;
1057 struct ufs_super_block_third
* usb3
;
1063 flags
= UFS_SB(sb
)->s_flags
;
1064 uspi
= UFS_SB(sb
)->s_uspi
;
1065 usb1
= ubh_get_usb_first(uspi
);
1066 usb3
= ubh_get_usb_third(uspi
);
1068 if (!(sb
->s_flags
& MS_RDONLY
)) {
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 ufs_put_cstotal(sb
);
1081 static void ufs_put_super(struct super_block
*sb
)
1083 struct ufs_sb_info
* sbi
= UFS_SB(sb
);
1087 if (!(sb
->s_flags
& MS_RDONLY
))
1088 ufs_put_super_internal(sb
);
1090 ubh_brelse_uspi (sbi
->s_uspi
);
1091 kfree (sbi
->s_uspi
);
1093 sb
->s_fs_info
= NULL
;
1099 static int ufs_remount (struct super_block
*sb
, int *mount_flags
, char *data
)
1101 struct ufs_sb_private_info
* uspi
;
1102 struct ufs_super_block_first
* usb1
;
1103 struct ufs_super_block_third
* usb3
;
1104 unsigned new_mount_opt
, ufstype
;
1107 uspi
= UFS_SB(sb
)->s_uspi
;
1108 flags
= UFS_SB(sb
)->s_flags
;
1109 usb1
= ubh_get_usb_first(uspi
);
1110 usb3
= ubh_get_usb_third(uspi
);
1113 * Allow the "check" option to be passed as a remount option.
1114 * It is not possible to change ufstype option during remount
1116 ufstype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1118 ufs_set_opt (new_mount_opt
, ONERROR_LOCK
);
1119 if (!ufs_parse_options (data
, &new_mount_opt
))
1121 if (!(new_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
1122 new_mount_opt
|= ufstype
;
1123 } else if ((new_mount_opt
& UFS_MOUNT_UFSTYPE
) != ufstype
) {
1124 printk("ufstype can't be changed during remount\n");
1128 if ((*mount_flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
)) {
1129 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1134 * fs was mouted as rw, remounting ro
1136 if (*mount_flags
& MS_RDONLY
) {
1137 ufs_put_super_internal(sb
);
1138 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1139 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1140 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1141 ufs_set_fs_state(sb
, usb1
, usb3
,
1142 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1143 ubh_mark_buffer_dirty (USPI_UBH(uspi
));
1145 sb
->s_flags
|= MS_RDONLY
;
1148 * fs was mounted as ro, remounting rw
1150 #ifndef CONFIG_UFS_FS_WRITE
1151 printk("ufs was compiled with read-only support, "
1152 "can't be mounted as read-write\n");
1155 if (ufstype
!= UFS_MOUNT_UFSTYPE_SUN
&&
1156 ufstype
!= UFS_MOUNT_UFSTYPE_44BSD
&&
1157 ufstype
!= UFS_MOUNT_UFSTYPE_SUNx86
) {
1158 printk("this ufstype is read-only supported\n");
1161 if (!ufs_read_cylinder_structures(sb
)) {
1162 printk("failed during remounting\n");
1165 sb
->s_flags
&= ~MS_RDONLY
;
1168 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1172 static int ufs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1174 struct super_block
*sb
= dentry
->d_sb
;
1175 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
1176 unsigned flags
= UFS_SB(sb
)->s_flags
;
1177 struct ufs_super_block_first
*usb1
;
1178 struct ufs_super_block_second
*usb2
;
1179 struct ufs_super_block_third
*usb3
;
1183 usb1
= ubh_get_usb_first(uspi
);
1184 usb2
= ubh_get_usb_second(uspi
);
1185 usb3
= ubh_get_usb_third(uspi
);
1187 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1188 buf
->f_type
= UFS2_MAGIC
;
1189 buf
->f_blocks
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1191 buf
->f_type
= UFS_MAGIC
;
1192 buf
->f_blocks
= uspi
->s_dsize
;
1194 buf
->f_bfree
= ufs_blkstofrags(uspi
->cs_total
.cs_nbfree
) +
1195 uspi
->cs_total
.cs_nffree
;
1196 buf
->f_ffree
= uspi
->cs_total
.cs_nifree
;
1197 buf
->f_bsize
= sb
->s_blocksize
;
1198 buf
->f_bavail
= (buf
->f_bfree
> (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
))
1199 ? (buf
->f_bfree
- (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
)) : 0;
1200 buf
->f_files
= uspi
->s_ncg
* uspi
->s_ipg
;
1201 buf
->f_namelen
= UFS_MAXNAMLEN
;
1208 static kmem_cache_t
* ufs_inode_cachep
;
1210 static struct inode
*ufs_alloc_inode(struct super_block
*sb
)
1212 struct ufs_inode_info
*ei
;
1213 ei
= (struct ufs_inode_info
*)kmem_cache_alloc(ufs_inode_cachep
, SLAB_KERNEL
);
1216 ei
->vfs_inode
.i_version
= 1;
1217 return &ei
->vfs_inode
;
1220 static void ufs_destroy_inode(struct inode
*inode
)
1222 kmem_cache_free(ufs_inode_cachep
, UFS_I(inode
));
1225 static void init_once(void * foo
, kmem_cache_t
* cachep
, unsigned long flags
)
1227 struct ufs_inode_info
*ei
= (struct ufs_inode_info
*) foo
;
1229 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
1230 SLAB_CTOR_CONSTRUCTOR
)
1231 inode_init_once(&ei
->vfs_inode
);
1234 static int init_inodecache(void)
1236 ufs_inode_cachep
= kmem_cache_create("ufs_inode_cache",
1237 sizeof(struct ufs_inode_info
),
1238 0, (SLAB_RECLAIM_ACCOUNT
|
1241 if (ufs_inode_cachep
== NULL
)
1246 static void destroy_inodecache(void)
1248 if (kmem_cache_destroy(ufs_inode_cachep
))
1249 printk(KERN_INFO
"ufs_inode_cache: not all structures were freed\n");
1253 static ssize_t
ufs_quota_read(struct super_block
*, int, char *,size_t, loff_t
);
1254 static ssize_t
ufs_quota_write(struct super_block
*, int, const char *, size_t, loff_t
);
1257 static struct super_operations ufs_super_ops
= {
1258 .alloc_inode
= ufs_alloc_inode
,
1259 .destroy_inode
= ufs_destroy_inode
,
1260 .read_inode
= ufs_read_inode
,
1261 .write_inode
= ufs_write_inode
,
1262 .delete_inode
= ufs_delete_inode
,
1263 .put_super
= ufs_put_super
,
1264 .write_super
= ufs_write_super
,
1265 .statfs
= ufs_statfs
,
1266 .remount_fs
= ufs_remount
,
1268 .quota_read
= ufs_quota_read
,
1269 .quota_write
= ufs_quota_write
,
1275 /* Read data from quotafile - avoid pagecache and such because we cannot afford
1276 * acquiring the locks... As quota files are never truncated and quota code
1277 * itself serializes the operations (and noone else should touch the files)
1278 * we don't have to be afraid of races */
1279 static ssize_t
ufs_quota_read(struct super_block
*sb
, int type
, char *data
,
1280 size_t len
, loff_t off
)
1282 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1283 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1285 int offset
= off
& (sb
->s_blocksize
- 1);
1288 struct buffer_head
*bh
;
1289 loff_t i_size
= i_size_read(inode
);
1293 if (off
+len
> i_size
)
1296 while (toread
> 0) {
1297 tocopy
= sb
->s_blocksize
- offset
< toread
?
1298 sb
->s_blocksize
- offset
: toread
;
1300 bh
= ufs_bread(inode
, blk
, 0, &err
);
1303 if (!bh
) /* A hole? */
1304 memset(data
, 0, tocopy
);
1306 memcpy(data
, bh
->b_data
+offset
, tocopy
);
1317 /* Write to quotafile */
1318 static ssize_t
ufs_quota_write(struct super_block
*sb
, int type
,
1319 const char *data
, size_t len
, loff_t off
)
1321 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1322 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1324 int offset
= off
& (sb
->s_blocksize
- 1);
1326 size_t towrite
= len
;
1327 struct buffer_head
*bh
;
1329 mutex_lock_nested(&inode
->i_mutex
, I_MUTEX_QUOTA
);
1330 while (towrite
> 0) {
1331 tocopy
= sb
->s_blocksize
- offset
< towrite
?
1332 sb
->s_blocksize
- offset
: towrite
;
1334 bh
= ufs_bread(inode
, blk
, 1, &err
);
1338 memcpy(bh
->b_data
+offset
, data
, tocopy
);
1339 flush_dcache_page(bh
->b_page
);
1340 set_buffer_uptodate(bh
);
1341 mark_buffer_dirty(bh
);
1350 if (len
== towrite
) {
1351 mutex_unlock(&inode
->i_mutex
);
1354 if (inode
->i_size
< off
+len
-towrite
)
1355 i_size_write(inode
, off
+len
-towrite
);
1357 inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME_SEC
;
1358 mark_inode_dirty(inode
);
1359 mutex_unlock(&inode
->i_mutex
);
1360 return len
- towrite
;
1365 static int ufs_get_sb(struct file_system_type
*fs_type
,
1366 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
1368 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, ufs_fill_super
, mnt
);
1371 static struct file_system_type ufs_fs_type
= {
1372 .owner
= THIS_MODULE
,
1374 .get_sb
= ufs_get_sb
,
1375 .kill_sb
= kill_block_super
,
1376 .fs_flags
= FS_REQUIRES_DEV
,
1379 static int __init
init_ufs_fs(void)
1381 int err
= init_inodecache();
1384 err
= register_filesystem(&ufs_fs_type
);
1389 destroy_inodecache();
1394 static void __exit
exit_ufs_fs(void)
1396 unregister_filesystem(&ufs_fs_type
);
1397 destroy_inodecache();
1400 module_init(init_ufs_fs
)
1401 module_exit(exit_ufs_fs
)
1402 MODULE_LICENSE("GPL");