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 vsnprintf (error_buf
, sizeof(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 vsnprintf (error_buf
, sizeof(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 vsnprintf (error_buf
, sizeof(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
= kzalloc(sizeof(struct ufs_sb_info
), GFP_KERNEL
);
619 UFSD("flag %u\n", (int)(sb
->s_flags
& MS_RDONLY
));
621 #ifndef CONFIG_UFS_FS_WRITE
622 if (!(sb
->s_flags
& MS_RDONLY
)) {
623 printk("ufs was compiled with read-only support, "
624 "can't be mounted as read-write\n");
629 * Set default mount options
630 * Parse mount options
632 sbi
->s_mount_opt
= 0;
633 ufs_set_opt (sbi
->s_mount_opt
, ONERROR_LOCK
);
634 if (!ufs_parse_options ((char *) data
, &sbi
->s_mount_opt
)) {
635 printk("wrong mount options\n");
638 if (!(sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
640 printk("You didn't specify the type of your ufs filesystem\n\n"
641 "mount -t ufs -o ufstype="
642 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
643 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
644 "default is ufstype=old\n");
645 ufs_set_opt (sbi
->s_mount_opt
, UFSTYPE_OLD
);
649 kmalloc (sizeof(struct ufs_sb_private_info
), GFP_KERNEL
);
653 super_block_offset
=UFS_SBLOCK
;
655 /* Keep 2Gig file limit. Some UFS variants need to override
656 this but as I don't know which I'll let those in the know loosen
658 switch (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) {
659 case UFS_MOUNT_UFSTYPE_44BSD
:
660 UFSD("ufstype=44bsd\n");
661 uspi
->s_fsize
= block_size
= 512;
662 uspi
->s_fmask
= ~(512 - 1);
664 uspi
->s_sbsize
= super_block_size
= 1536;
666 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
668 case UFS_MOUNT_UFSTYPE_UFS2
:
669 UFSD("ufstype=ufs2\n");
670 super_block_offset
=SBLOCK_UFS2
;
671 uspi
->s_fsize
= block_size
= 512;
672 uspi
->s_fmask
= ~(512 - 1);
674 uspi
->s_sbsize
= super_block_size
= 1536;
676 flags
|= UFS_TYPE_UFS2
| UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
677 if (!(sb
->s_flags
& MS_RDONLY
)) {
678 printk(KERN_INFO
"ufstype=ufs2 is supported read-only\n");
679 sb
->s_flags
|= MS_RDONLY
;
683 case UFS_MOUNT_UFSTYPE_SUN
:
684 UFSD("ufstype=sun\n");
685 uspi
->s_fsize
= block_size
= 1024;
686 uspi
->s_fmask
= ~(1024 - 1);
688 uspi
->s_sbsize
= super_block_size
= 2048;
690 uspi
->s_maxsymlinklen
= 56;
691 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUN
| UFS_CG_SUN
;
694 case UFS_MOUNT_UFSTYPE_SUNx86
:
695 UFSD("ufstype=sunx86\n");
696 uspi
->s_fsize
= block_size
= 1024;
697 uspi
->s_fmask
= ~(1024 - 1);
699 uspi
->s_sbsize
= super_block_size
= 2048;
701 uspi
->s_maxsymlinklen
= 56;
702 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUNx86
| UFS_CG_SUN
;
705 case UFS_MOUNT_UFSTYPE_OLD
:
706 UFSD("ufstype=old\n");
707 uspi
->s_fsize
= block_size
= 1024;
708 uspi
->s_fmask
= ~(1024 - 1);
710 uspi
->s_sbsize
= super_block_size
= 2048;
712 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
713 if (!(sb
->s_flags
& MS_RDONLY
)) {
715 printk(KERN_INFO
"ufstype=old is supported read-only\n");
716 sb
->s_flags
|= MS_RDONLY
;
720 case UFS_MOUNT_UFSTYPE_NEXTSTEP
:
721 UFSD("ufstype=nextstep\n");
722 uspi
->s_fsize
= block_size
= 1024;
723 uspi
->s_fmask
= ~(1024 - 1);
725 uspi
->s_sbsize
= super_block_size
= 2048;
727 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
728 if (!(sb
->s_flags
& MS_RDONLY
)) {
730 printk(KERN_INFO
"ufstype=nextstep is supported read-only\n");
731 sb
->s_flags
|= MS_RDONLY
;
735 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
:
736 UFSD("ufstype=nextstep-cd\n");
737 uspi
->s_fsize
= block_size
= 2048;
738 uspi
->s_fmask
= ~(2048 - 1);
740 uspi
->s_sbsize
= super_block_size
= 2048;
742 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
743 if (!(sb
->s_flags
& MS_RDONLY
)) {
745 printk(KERN_INFO
"ufstype=nextstep-cd is supported read-only\n");
746 sb
->s_flags
|= MS_RDONLY
;
750 case UFS_MOUNT_UFSTYPE_OPENSTEP
:
751 UFSD("ufstype=openstep\n");
752 uspi
->s_fsize
= block_size
= 1024;
753 uspi
->s_fmask
= ~(1024 - 1);
755 uspi
->s_sbsize
= super_block_size
= 2048;
757 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
758 if (!(sb
->s_flags
& MS_RDONLY
)) {
760 printk(KERN_INFO
"ufstype=openstep is supported read-only\n");
761 sb
->s_flags
|= MS_RDONLY
;
765 case UFS_MOUNT_UFSTYPE_HP
:
766 UFSD("ufstype=hp\n");
767 uspi
->s_fsize
= block_size
= 1024;
768 uspi
->s_fmask
= ~(1024 - 1);
770 uspi
->s_sbsize
= super_block_size
= 2048;
772 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
773 if (!(sb
->s_flags
& MS_RDONLY
)) {
775 printk(KERN_INFO
"ufstype=hp is supported read-only\n");
776 sb
->s_flags
|= MS_RDONLY
;
781 printk("unknown ufstype\n");
786 if (!sb_set_blocksize(sb
, block_size
)) {
787 printk(KERN_ERR
"UFS: failed to set blocksize\n");
792 * read ufs super block from device
795 ubh
= ubh_bread_uspi(uspi
, sb
, uspi
->s_sbbase
+ super_block_offset
/block_size
, super_block_size
);
801 usb1
= ubh_get_usb_first(uspi
);
802 usb2
= ubh_get_usb_second(uspi
);
803 usb3
= ubh_get_usb_third(uspi
);
806 * Check ufs magic number
808 sbi
->s_bytesex
= BYTESEX_LE
;
809 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
817 sbi
->s_bytesex
= BYTESEX_BE
;
818 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
827 if ((((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP
)
828 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
)
829 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_OPENSTEP
))
830 && uspi
->s_sbbase
< 256) {
831 ubh_brelse_uspi(uspi
);
837 printk("ufs_read_super: bad magic number\n");
842 * Check block and fragment sizes
844 uspi
->s_bsize
= fs32_to_cpu(sb
, usb1
->fs_bsize
);
845 uspi
->s_fsize
= fs32_to_cpu(sb
, usb1
->fs_fsize
);
846 uspi
->s_sbsize
= fs32_to_cpu(sb
, usb1
->fs_sbsize
);
847 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
848 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
850 if (uspi
->s_fsize
& (uspi
->s_fsize
- 1)) {
851 printk(KERN_ERR
"ufs_read_super: fragment size %u is not a power of 2\n",
855 if (uspi
->s_fsize
< 512) {
856 printk(KERN_ERR
"ufs_read_super: fragment size %u is too small\n",
860 if (uspi
->s_fsize
> 4096) {
861 printk(KERN_ERR
"ufs_read_super: fragment size %u is too large\n",
865 if (uspi
->s_bsize
& (uspi
->s_bsize
- 1)) {
866 printk(KERN_ERR
"ufs_read_super: block size %u is not a power of 2\n",
870 if (uspi
->s_bsize
< 4096) {
871 printk(KERN_ERR
"ufs_read_super: block size %u is too small\n",
875 if (uspi
->s_bsize
/ uspi
->s_fsize
> 8) {
876 printk(KERN_ERR
"ufs_read_super: too many fragments per block (%u)\n",
877 uspi
->s_bsize
/ uspi
->s_fsize
);
880 if (uspi
->s_fsize
!= block_size
|| uspi
->s_sbsize
!= super_block_size
) {
881 ubh_brelse_uspi(uspi
);
883 block_size
= uspi
->s_fsize
;
884 super_block_size
= uspi
->s_sbsize
;
885 UFSD("another value of block_size or super_block_size %u, %u\n", block_size
, super_block_size
);
890 ufs_print_super_stuff(sb
, flags
, usb1
, usb2
, usb3
);
893 * Check, if file system was correctly unmounted.
894 * If not, make it read only.
896 if (((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
) ||
897 ((flags
& UFS_ST_MASK
) == UFS_ST_OLD
) ||
898 (((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
899 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
) &&
900 (ufs_get_fs_state(sb
, usb1
, usb3
) == (UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
))))) {
901 switch(usb1
->fs_clean
) {
903 UFSD("fs is clean\n");
906 UFSD("fs is stable\n");
909 UFSD("fs is DEC OSF/1\n");
912 printk("ufs_read_super: fs is active\n");
913 sb
->s_flags
|= MS_RDONLY
;
916 printk("ufs_read_super: fs is bad\n");
917 sb
->s_flags
|= MS_RDONLY
;
920 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1
->fs_clean
);
921 sb
->s_flags
|= MS_RDONLY
;
925 printk("ufs_read_super: fs needs fsck\n");
926 sb
->s_flags
|= MS_RDONLY
;
930 * Read ufs_super_block into internal data structures
932 sb
->s_op
= &ufs_super_ops
;
933 sb
->dq_op
= NULL
; /***/
934 sb
->s_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
936 uspi
->s_sblkno
= fs32_to_cpu(sb
, usb1
->fs_sblkno
);
937 uspi
->s_cblkno
= fs32_to_cpu(sb
, usb1
->fs_cblkno
);
938 uspi
->s_iblkno
= fs32_to_cpu(sb
, usb1
->fs_iblkno
);
939 uspi
->s_dblkno
= fs32_to_cpu(sb
, usb1
->fs_dblkno
);
940 uspi
->s_cgoffset
= fs32_to_cpu(sb
, usb1
->fs_cgoffset
);
941 uspi
->s_cgmask
= fs32_to_cpu(sb
, usb1
->fs_cgmask
);
943 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
944 uspi
->s_u2_size
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
);
945 uspi
->s_u2_dsize
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
947 uspi
->s_size
= fs32_to_cpu(sb
, usb1
->fs_size
);
948 uspi
->s_dsize
= fs32_to_cpu(sb
, usb1
->fs_dsize
);
951 uspi
->s_ncg
= fs32_to_cpu(sb
, usb1
->fs_ncg
);
952 /* s_bsize already set */
953 /* s_fsize already set */
954 uspi
->s_fpb
= fs32_to_cpu(sb
, usb1
->fs_frag
);
955 uspi
->s_minfree
= fs32_to_cpu(sb
, usb1
->fs_minfree
);
956 uspi
->s_bmask
= fs32_to_cpu(sb
, usb1
->fs_bmask
);
957 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
958 uspi
->s_bshift
= fs32_to_cpu(sb
, usb1
->fs_bshift
);
959 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
960 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi
->s_bshift
,
962 uspi
->s_fpbshift
= fs32_to_cpu(sb
, usb1
->fs_fragshift
);
963 uspi
->s_fsbtodb
= fs32_to_cpu(sb
, usb1
->fs_fsbtodb
);
964 /* s_sbsize already set */
965 uspi
->s_csmask
= fs32_to_cpu(sb
, usb1
->fs_csmask
);
966 uspi
->s_csshift
= fs32_to_cpu(sb
, usb1
->fs_csshift
);
967 uspi
->s_nindir
= fs32_to_cpu(sb
, usb1
->fs_nindir
);
968 uspi
->s_inopb
= fs32_to_cpu(sb
, usb1
->fs_inopb
);
969 uspi
->s_nspf
= fs32_to_cpu(sb
, usb1
->fs_nspf
);
970 uspi
->s_npsect
= ufs_get_fs_npsect(sb
, usb1
, usb3
);
971 uspi
->s_interleave
= fs32_to_cpu(sb
, usb1
->fs_interleave
);
972 uspi
->s_trackskew
= fs32_to_cpu(sb
, usb1
->fs_trackskew
);
973 uspi
->s_csaddr
= fs32_to_cpu(sb
, usb1
->fs_csaddr
);
974 uspi
->s_cssize
= fs32_to_cpu(sb
, usb1
->fs_cssize
);
975 uspi
->s_cgsize
= fs32_to_cpu(sb
, usb1
->fs_cgsize
);
976 uspi
->s_ntrak
= fs32_to_cpu(sb
, usb1
->fs_ntrak
);
977 uspi
->s_nsect
= fs32_to_cpu(sb
, usb1
->fs_nsect
);
978 uspi
->s_spc
= fs32_to_cpu(sb
, usb1
->fs_spc
);
979 uspi
->s_ipg
= fs32_to_cpu(sb
, usb1
->fs_ipg
);
980 uspi
->s_fpg
= fs32_to_cpu(sb
, usb1
->fs_fpg
);
981 uspi
->s_cpc
= fs32_to_cpu(sb
, usb2
->fs_un
.fs_u1
.fs_cpc
);
982 uspi
->s_contigsumsize
= fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_contigsumsize
);
983 uspi
->s_qbmask
= ufs_get_fs_qbmask(sb
, usb3
);
984 uspi
->s_qfmask
= ufs_get_fs_qfmask(sb
, usb3
);
985 uspi
->s_postblformat
= fs32_to_cpu(sb
, usb3
->fs_postblformat
);
986 uspi
->s_nrpos
= fs32_to_cpu(sb
, usb3
->fs_nrpos
);
987 uspi
->s_postbloff
= fs32_to_cpu(sb
, usb3
->fs_postbloff
);
988 uspi
->s_rotbloff
= fs32_to_cpu(sb
, usb3
->fs_rotbloff
);
991 * Compute another frequently used values
993 uspi
->s_fpbmask
= uspi
->s_fpb
- 1;
994 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
995 uspi
->s_apbshift
= uspi
->s_bshift
- 3;
997 uspi
->s_apbshift
= uspi
->s_bshift
- 2;
999 uspi
->s_2apbshift
= uspi
->s_apbshift
* 2;
1000 uspi
->s_3apbshift
= uspi
->s_apbshift
* 3;
1001 uspi
->s_apb
= 1 << uspi
->s_apbshift
;
1002 uspi
->s_2apb
= 1 << uspi
->s_2apbshift
;
1003 uspi
->s_3apb
= 1 << uspi
->s_3apbshift
;
1004 uspi
->s_apbmask
= uspi
->s_apb
- 1;
1005 uspi
->s_nspfshift
= uspi
->s_fshift
- UFS_SECTOR_BITS
;
1006 uspi
->s_nspb
= uspi
->s_nspf
<< uspi
->s_fpbshift
;
1007 uspi
->s_inopf
= uspi
->s_inopb
>> uspi
->s_fpbshift
;
1008 uspi
->s_bpf
= uspi
->s_fsize
<< 3;
1009 uspi
->s_bpfshift
= uspi
->s_fshift
+ 3;
1010 uspi
->s_bpfmask
= uspi
->s_bpf
- 1;
1011 if ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) ==
1012 UFS_MOUNT_UFSTYPE_44BSD
)
1013 uspi
->s_maxsymlinklen
=
1014 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
);
1016 sbi
->s_flags
= flags
;
1018 inode
= iget(sb
, UFS_ROOTINO
);
1019 if (!inode
|| is_bad_inode(inode
))
1021 sb
->s_root
= d_alloc_root(inode
);
1025 ufs_setup_cstotal(sb
);
1027 * Read cylinder group structures
1029 if (!(sb
->s_flags
& MS_RDONLY
))
1030 if (!ufs_read_cylinder_structures(sb
))
1040 ubh_brelse_uspi (uspi
);
1043 sb
->s_fs_info
= NULL
;
1044 UFSD("EXIT (FAILED)\n");
1048 UFSD("EXIT (NOMEM)\n");
1052 static void ufs_write_super(struct super_block
*sb
)
1054 struct ufs_sb_private_info
* uspi
;
1055 struct ufs_super_block_first
* usb1
;
1056 struct ufs_super_block_third
* usb3
;
1062 flags
= UFS_SB(sb
)->s_flags
;
1063 uspi
= UFS_SB(sb
)->s_uspi
;
1064 usb1
= ubh_get_usb_first(uspi
);
1065 usb3
= ubh_get_usb_third(uspi
);
1067 if (!(sb
->s_flags
& MS_RDONLY
)) {
1068 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1069 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1070 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1071 ufs_set_fs_state(sb
, usb1
, usb3
,
1072 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1073 ufs_put_cstotal(sb
);
1080 static void ufs_put_super(struct super_block
*sb
)
1082 struct ufs_sb_info
* sbi
= UFS_SB(sb
);
1086 if (!(sb
->s_flags
& MS_RDONLY
))
1087 ufs_put_super_internal(sb
);
1089 ubh_brelse_uspi (sbi
->s_uspi
);
1090 kfree (sbi
->s_uspi
);
1092 sb
->s_fs_info
= NULL
;
1098 static int ufs_remount (struct super_block
*sb
, int *mount_flags
, char *data
)
1100 struct ufs_sb_private_info
* uspi
;
1101 struct ufs_super_block_first
* usb1
;
1102 struct ufs_super_block_third
* usb3
;
1103 unsigned new_mount_opt
, ufstype
;
1106 uspi
= UFS_SB(sb
)->s_uspi
;
1107 flags
= UFS_SB(sb
)->s_flags
;
1108 usb1
= ubh_get_usb_first(uspi
);
1109 usb3
= ubh_get_usb_third(uspi
);
1112 * Allow the "check" option to be passed as a remount option.
1113 * It is not possible to change ufstype option during remount
1115 ufstype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1117 ufs_set_opt (new_mount_opt
, ONERROR_LOCK
);
1118 if (!ufs_parse_options (data
, &new_mount_opt
))
1120 if (!(new_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
1121 new_mount_opt
|= ufstype
;
1122 } else if ((new_mount_opt
& UFS_MOUNT_UFSTYPE
) != ufstype
) {
1123 printk("ufstype can't be changed during remount\n");
1127 if ((*mount_flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
)) {
1128 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1133 * fs was mouted as rw, remounting ro
1135 if (*mount_flags
& MS_RDONLY
) {
1136 ufs_put_super_internal(sb
);
1137 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1138 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1139 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1140 ufs_set_fs_state(sb
, usb1
, usb3
,
1141 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1142 ubh_mark_buffer_dirty (USPI_UBH(uspi
));
1144 sb
->s_flags
|= MS_RDONLY
;
1147 * fs was mounted as ro, remounting rw
1149 #ifndef CONFIG_UFS_FS_WRITE
1150 printk("ufs was compiled with read-only support, "
1151 "can't be mounted as read-write\n");
1154 if (ufstype
!= UFS_MOUNT_UFSTYPE_SUN
&&
1155 ufstype
!= UFS_MOUNT_UFSTYPE_44BSD
&&
1156 ufstype
!= UFS_MOUNT_UFSTYPE_SUNx86
) {
1157 printk("this ufstype is read-only supported\n");
1160 if (!ufs_read_cylinder_structures(sb
)) {
1161 printk("failed during remounting\n");
1164 sb
->s_flags
&= ~MS_RDONLY
;
1167 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1171 static int ufs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1173 struct super_block
*sb
= dentry
->d_sb
;
1174 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
1175 unsigned flags
= UFS_SB(sb
)->s_flags
;
1176 struct ufs_super_block_first
*usb1
;
1177 struct ufs_super_block_second
*usb2
;
1178 struct ufs_super_block_third
*usb3
;
1182 usb1
= ubh_get_usb_first(uspi
);
1183 usb2
= ubh_get_usb_second(uspi
);
1184 usb3
= ubh_get_usb_third(uspi
);
1186 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1187 buf
->f_type
= UFS2_MAGIC
;
1188 buf
->f_blocks
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1190 buf
->f_type
= UFS_MAGIC
;
1191 buf
->f_blocks
= uspi
->s_dsize
;
1193 buf
->f_bfree
= ufs_blkstofrags(uspi
->cs_total
.cs_nbfree
) +
1194 uspi
->cs_total
.cs_nffree
;
1195 buf
->f_ffree
= uspi
->cs_total
.cs_nifree
;
1196 buf
->f_bsize
= sb
->s_blocksize
;
1197 buf
->f_bavail
= (buf
->f_bfree
> (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
))
1198 ? (buf
->f_bfree
- (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
)) : 0;
1199 buf
->f_files
= uspi
->s_ncg
* uspi
->s_ipg
;
1200 buf
->f_namelen
= UFS_MAXNAMLEN
;
1207 static struct kmem_cache
* ufs_inode_cachep
;
1209 static struct inode
*ufs_alloc_inode(struct super_block
*sb
)
1211 struct ufs_inode_info
*ei
;
1212 ei
= (struct ufs_inode_info
*)kmem_cache_alloc(ufs_inode_cachep
, GFP_KERNEL
);
1215 ei
->vfs_inode
.i_version
= 1;
1216 return &ei
->vfs_inode
;
1219 static void ufs_destroy_inode(struct inode
*inode
)
1221 kmem_cache_free(ufs_inode_cachep
, UFS_I(inode
));
1224 static void init_once(void * foo
, struct kmem_cache
* cachep
, unsigned long flags
)
1226 struct ufs_inode_info
*ei
= (struct ufs_inode_info
*) foo
;
1228 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
1229 SLAB_CTOR_CONSTRUCTOR
)
1230 inode_init_once(&ei
->vfs_inode
);
1233 static int init_inodecache(void)
1235 ufs_inode_cachep
= kmem_cache_create("ufs_inode_cache",
1236 sizeof(struct ufs_inode_info
),
1237 0, (SLAB_RECLAIM_ACCOUNT
|
1240 if (ufs_inode_cachep
== NULL
)
1245 static void destroy_inodecache(void)
1247 kmem_cache_destroy(ufs_inode_cachep
);
1251 static ssize_t
ufs_quota_read(struct super_block
*, int, char *,size_t, loff_t
);
1252 static ssize_t
ufs_quota_write(struct super_block
*, int, const char *, size_t, loff_t
);
1255 static struct super_operations ufs_super_ops
= {
1256 .alloc_inode
= ufs_alloc_inode
,
1257 .destroy_inode
= ufs_destroy_inode
,
1258 .read_inode
= ufs_read_inode
,
1259 .write_inode
= ufs_write_inode
,
1260 .delete_inode
= ufs_delete_inode
,
1261 .put_super
= ufs_put_super
,
1262 .write_super
= ufs_write_super
,
1263 .statfs
= ufs_statfs
,
1264 .remount_fs
= ufs_remount
,
1266 .quota_read
= ufs_quota_read
,
1267 .quota_write
= ufs_quota_write
,
1273 /* Read data from quotafile - avoid pagecache and such because we cannot afford
1274 * acquiring the locks... As quota files are never truncated and quota code
1275 * itself serializes the operations (and noone else should touch the files)
1276 * we don't have to be afraid of races */
1277 static ssize_t
ufs_quota_read(struct super_block
*sb
, int type
, char *data
,
1278 size_t len
, loff_t off
)
1280 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1281 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1283 int offset
= off
& (sb
->s_blocksize
- 1);
1286 struct buffer_head
*bh
;
1287 loff_t i_size
= i_size_read(inode
);
1291 if (off
+len
> i_size
)
1294 while (toread
> 0) {
1295 tocopy
= sb
->s_blocksize
- offset
< toread
?
1296 sb
->s_blocksize
- offset
: toread
;
1298 bh
= ufs_bread(inode
, blk
, 0, &err
);
1301 if (!bh
) /* A hole? */
1302 memset(data
, 0, tocopy
);
1304 memcpy(data
, bh
->b_data
+offset
, tocopy
);
1315 /* Write to quotafile */
1316 static ssize_t
ufs_quota_write(struct super_block
*sb
, int type
,
1317 const char *data
, size_t len
, loff_t off
)
1319 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1320 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1322 int offset
= off
& (sb
->s_blocksize
- 1);
1324 size_t towrite
= len
;
1325 struct buffer_head
*bh
;
1327 mutex_lock_nested(&inode
->i_mutex
, I_MUTEX_QUOTA
);
1328 while (towrite
> 0) {
1329 tocopy
= sb
->s_blocksize
- offset
< towrite
?
1330 sb
->s_blocksize
- offset
: towrite
;
1332 bh
= ufs_bread(inode
, blk
, 1, &err
);
1336 memcpy(bh
->b_data
+offset
, data
, tocopy
);
1337 flush_dcache_page(bh
->b_page
);
1338 set_buffer_uptodate(bh
);
1339 mark_buffer_dirty(bh
);
1348 if (len
== towrite
) {
1349 mutex_unlock(&inode
->i_mutex
);
1352 if (inode
->i_size
< off
+len
-towrite
)
1353 i_size_write(inode
, off
+len
-towrite
);
1355 inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME_SEC
;
1356 mark_inode_dirty(inode
);
1357 mutex_unlock(&inode
->i_mutex
);
1358 return len
- towrite
;
1363 static int ufs_get_sb(struct file_system_type
*fs_type
,
1364 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
1366 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, ufs_fill_super
, mnt
);
1369 static struct file_system_type ufs_fs_type
= {
1370 .owner
= THIS_MODULE
,
1372 .get_sb
= ufs_get_sb
,
1373 .kill_sb
= kill_block_super
,
1374 .fs_flags
= FS_REQUIRES_DEV
,
1377 static int __init
init_ufs_fs(void)
1379 int err
= init_inodecache();
1382 err
= register_filesystem(&ufs_fs_type
);
1387 destroy_inodecache();
1392 static void __exit
exit_ufs_fs(void)
1394 unregister_filesystem(&ufs_fs_type
);
1395 destroy_inodecache();
1398 module_init(init_ufs_fs
)
1399 module_exit(exit_ufs_fs
)
1400 MODULE_LICENSE("GPL");