5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
11 * linux/fs/ext2/super.c
13 * Copyright (C) 1992, 1993, 1994, 1995
14 * Remy Card (card@masi.ibp.fr)
15 * Laboratoire MASI - Institut Blaise Pascal
16 * Universite Pierre et Marie Curie (Paris VI)
20 * linux/fs/minix/inode.c
22 * Copyright (C) 1991, 1992 Linus Torvalds
24 * Big-endian to little-endian byte-swapping/bitmaps by
25 * David S. Miller (davem@caip.rutgers.edu), 1995
31 * linux/fs/ufs/super.c
34 * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
35 * Laboratory for Computer Science Research Computing Facility
36 * Rutgers, The State University of New Jersey
38 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
40 * Kernel module support added on 96/04/26 by
41 * Stefan Reinauer <stepan@home.culture.mipt.ru>
43 * Module usage counts added on 96/04/29 by
44 * Gertjan van Wingerde <gertjan@cs.vu.nl>
46 * Clean swab support on 19970406 by
47 * Francois-Rene Rideau <fare@tunes.org>
49 * 4.4BSD (FreeBSD) support added on February 1st 1998 by
50 * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
51 * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
53 * NeXTstep support added on February 5th 1998 by
54 * Niels Kristian Bech Jensen <nkbj@image.dk>.
56 * write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
58 * HP/UX hfs filesystem support added by
59 * Martin K. Petersen <mkp@mkp.net>, August 1999
61 * UFS2 (of FreeBSD 5.x) support added by
62 * Niraj Kumar <niraj17@iitbombay.org>, Jan 2004
64 * UFS2 write support added by
65 * Evgeniy Dushistov <dushistov@mail.ru>, 2007
69 #include <linux/module.h>
70 #include <linux/bitops.h>
74 #include <asm/uaccess.h>
75 #include <asm/system.h>
77 #include <linux/errno.h>
79 #include <linux/quotaops.h>
80 #include <linux/slab.h>
81 #include <linux/time.h>
82 #include <linux/stat.h>
83 #include <linux/string.h>
84 #include <linux/blkdev.h>
85 #include <linux/init.h>
86 #include <linux/parser.h>
87 #include <linux/smp_lock.h>
88 #include <linux/buffer_head.h>
89 #include <linux/vfs.h>
90 #include <linux/log2.h>
91 #include <linux/mount.h>
92 #include <linux/seq_file.h>
99 #ifdef CONFIG_UFS_DEBUG
101 * Print contents of ufs_super_block, useful for debugging
103 static void ufs_print_super_stuff(struct super_block
*sb
,
104 struct ufs_super_block_first
*usb1
,
105 struct ufs_super_block_second
*usb2
,
106 struct ufs_super_block_third
*usb3
)
108 u32 magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
110 printk("ufs_print_super_stuff\n");
111 printk(" magic: 0x%x\n", magic
);
112 if (fs32_to_cpu(sb
, usb3
->fs_magic
) == UFS2_MAGIC
) {
113 printk(" fs_size: %llu\n", (unsigned long long)
114 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
));
115 printk(" fs_dsize: %llu\n", (unsigned long long)
116 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
));
117 printk(" bsize: %u\n",
118 fs32_to_cpu(sb
, usb1
->fs_bsize
));
119 printk(" fsize: %u\n",
120 fs32_to_cpu(sb
, usb1
->fs_fsize
));
121 printk(" fs_volname: %s\n", usb2
->fs_un
.fs_u2
.fs_volname
);
122 printk(" fs_sblockloc: %llu\n", (unsigned long long)
123 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.fs_sblockloc
));
124 printk(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
125 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
));
126 printk(" cs_nbfree(No of free blocks): %llu\n",
128 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
));
129 printk(KERN_INFO
" cs_nifree(Num of free inodes): %llu\n",
131 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
));
132 printk(KERN_INFO
" cs_nffree(Num of free frags): %llu\n",
134 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
));
135 printk(KERN_INFO
" fs_maxsymlinklen: %u\n",
136 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
));
138 printk(" sblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_sblkno
));
139 printk(" cblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_cblkno
));
140 printk(" iblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_iblkno
));
141 printk(" dblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_dblkno
));
142 printk(" cgoffset: %u\n",
143 fs32_to_cpu(sb
, usb1
->fs_cgoffset
));
144 printk(" ~cgmask: 0x%x\n",
145 ~fs32_to_cpu(sb
, usb1
->fs_cgmask
));
146 printk(" size: %u\n", fs32_to_cpu(sb
, usb1
->fs_size
));
147 printk(" dsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_dsize
));
148 printk(" ncg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ncg
));
149 printk(" bsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_bsize
));
150 printk(" fsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_fsize
));
151 printk(" frag: %u\n", fs32_to_cpu(sb
, usb1
->fs_frag
));
152 printk(" fragshift: %u\n",
153 fs32_to_cpu(sb
, usb1
->fs_fragshift
));
154 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb
, usb1
->fs_fmask
));
155 printk(" fshift: %u\n", fs32_to_cpu(sb
, usb1
->fs_fshift
));
156 printk(" sbsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_sbsize
));
157 printk(" spc: %u\n", fs32_to_cpu(sb
, usb1
->fs_spc
));
158 printk(" cpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_cpg
));
159 printk(" ipg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ipg
));
160 printk(" fpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_fpg
));
161 printk(" csaddr: %u\n", fs32_to_cpu(sb
, usb1
->fs_csaddr
));
162 printk(" cssize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cssize
));
163 printk(" cgsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cgsize
));
164 printk(" fstodb: %u\n",
165 fs32_to_cpu(sb
, usb1
->fs_fsbtodb
));
166 printk(" nrpos: %u\n", fs32_to_cpu(sb
, usb3
->fs_nrpos
));
168 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
));
169 printk(" nifree %u\n",
170 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
));
171 printk(" nbfree %u\n",
172 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
));
173 printk(" nffree %u\n",
174 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
));
180 * Print contents of ufs_cylinder_group, useful for debugging
182 static void ufs_print_cylinder_stuff(struct super_block
*sb
,
183 struct ufs_cylinder_group
*cg
)
185 printk("\nufs_print_cylinder_stuff\n");
186 printk("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group
));
187 printk(" magic: %x\n", fs32_to_cpu(sb
, cg
->cg_magic
));
188 printk(" time: %u\n", fs32_to_cpu(sb
, cg
->cg_time
));
189 printk(" cgx: %u\n", fs32_to_cpu(sb
, cg
->cg_cgx
));
190 printk(" ncyl: %u\n", fs16_to_cpu(sb
, cg
->cg_ncyl
));
191 printk(" niblk: %u\n", fs16_to_cpu(sb
, cg
->cg_niblk
));
192 printk(" ndblk: %u\n", fs32_to_cpu(sb
, cg
->cg_ndblk
));
193 printk(" cs_ndir: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_ndir
));
194 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nbfree
));
195 printk(" cs_nifree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nifree
));
196 printk(" cs_nffree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nffree
));
197 printk(" rotor: %u\n", fs32_to_cpu(sb
, cg
->cg_rotor
));
198 printk(" frotor: %u\n", fs32_to_cpu(sb
, cg
->cg_frotor
));
199 printk(" irotor: %u\n", fs32_to_cpu(sb
, cg
->cg_irotor
));
200 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
201 fs32_to_cpu(sb
, cg
->cg_frsum
[0]), fs32_to_cpu(sb
, cg
->cg_frsum
[1]),
202 fs32_to_cpu(sb
, cg
->cg_frsum
[2]), fs32_to_cpu(sb
, cg
->cg_frsum
[3]),
203 fs32_to_cpu(sb
, cg
->cg_frsum
[4]), fs32_to_cpu(sb
, cg
->cg_frsum
[5]),
204 fs32_to_cpu(sb
, cg
->cg_frsum
[6]), fs32_to_cpu(sb
, cg
->cg_frsum
[7]));
205 printk(" btotoff: %u\n", fs32_to_cpu(sb
, cg
->cg_btotoff
));
206 printk(" boff: %u\n", fs32_to_cpu(sb
, cg
->cg_boff
));
207 printk(" iuseoff: %u\n", fs32_to_cpu(sb
, cg
->cg_iusedoff
));
208 printk(" freeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_freeoff
));
209 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_nextfreeoff
));
210 printk(" clustersumoff %u\n",
211 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clustersumoff
));
212 printk(" clusteroff %u\n",
213 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clusteroff
));
214 printk(" nclusterblks %u\n",
215 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_nclusterblks
));
219 # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
220 # define ufs_print_cylinder_stuff(sb, cg) /**/
221 #endif /* CONFIG_UFS_DEBUG */
223 static const struct super_operations ufs_super_ops
;
225 static char error_buf
[1024];
227 void ufs_error (struct super_block
* sb
, const char * function
,
228 const char * fmt
, ...)
230 struct ufs_sb_private_info
* uspi
;
231 struct ufs_super_block_first
* usb1
;
234 uspi
= UFS_SB(sb
)->s_uspi
;
235 usb1
= ubh_get_usb_first(uspi
);
237 if (!(sb
->s_flags
& MS_RDONLY
)) {
238 usb1
->fs_clean
= UFS_FSBAD
;
239 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
241 sb
->s_flags
|= MS_RDONLY
;
243 va_start (args
, fmt
);
244 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
246 switch (UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_ONERROR
) {
247 case UFS_MOUNT_ONERROR_PANIC
:
248 panic ("UFS-fs panic (device %s): %s: %s\n",
249 sb
->s_id
, function
, error_buf
);
251 case UFS_MOUNT_ONERROR_LOCK
:
252 case UFS_MOUNT_ONERROR_UMOUNT
:
253 case UFS_MOUNT_ONERROR_REPAIR
:
254 printk (KERN_CRIT
"UFS-fs error (device %s): %s: %s\n",
255 sb
->s_id
, function
, error_buf
);
259 void ufs_panic (struct super_block
* sb
, const char * function
,
260 const char * fmt
, ...)
262 struct ufs_sb_private_info
* uspi
;
263 struct ufs_super_block_first
* usb1
;
266 uspi
= UFS_SB(sb
)->s_uspi
;
267 usb1
= ubh_get_usb_first(uspi
);
269 if (!(sb
->s_flags
& MS_RDONLY
)) {
270 usb1
->fs_clean
= UFS_FSBAD
;
271 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
274 va_start (args
, fmt
);
275 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
277 sb
->s_flags
|= MS_RDONLY
;
278 printk (KERN_CRIT
"UFS-fs panic (device %s): %s: %s\n",
279 sb
->s_id
, function
, error_buf
);
282 void ufs_warning (struct super_block
* sb
, const char * function
,
283 const char * fmt
, ...)
287 va_start (args
, fmt
);
288 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
290 printk (KERN_WARNING
"UFS-fs warning (device %s): %s: %s\n",
291 sb
->s_id
, function
, error_buf
);
295 Opt_type_old
= UFS_MOUNT_UFSTYPE_OLD
,
296 Opt_type_sunx86
= UFS_MOUNT_UFSTYPE_SUNx86
,
297 Opt_type_sun
= UFS_MOUNT_UFSTYPE_SUN
,
298 Opt_type_sunos
= UFS_MOUNT_UFSTYPE_SUNOS
,
299 Opt_type_44bsd
= UFS_MOUNT_UFSTYPE_44BSD
,
300 Opt_type_ufs2
= UFS_MOUNT_UFSTYPE_UFS2
,
301 Opt_type_hp
= UFS_MOUNT_UFSTYPE_HP
,
302 Opt_type_nextstepcd
= UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
,
303 Opt_type_nextstep
= UFS_MOUNT_UFSTYPE_NEXTSTEP
,
304 Opt_type_openstep
= UFS_MOUNT_UFSTYPE_OPENSTEP
,
305 Opt_onerror_panic
= UFS_MOUNT_ONERROR_PANIC
,
306 Opt_onerror_lock
= UFS_MOUNT_ONERROR_LOCK
,
307 Opt_onerror_umount
= UFS_MOUNT_ONERROR_UMOUNT
,
308 Opt_onerror_repair
= UFS_MOUNT_ONERROR_REPAIR
,
312 static const match_table_t tokens
= {
313 {Opt_type_old
, "ufstype=old"},
314 {Opt_type_sunx86
, "ufstype=sunx86"},
315 {Opt_type_sun
, "ufstype=sun"},
316 {Opt_type_sunos
, "ufstype=sunos"},
317 {Opt_type_44bsd
, "ufstype=44bsd"},
318 {Opt_type_ufs2
, "ufstype=ufs2"},
319 {Opt_type_ufs2
, "ufstype=5xbsd"},
320 {Opt_type_hp
, "ufstype=hp"},
321 {Opt_type_nextstepcd
, "ufstype=nextstep-cd"},
322 {Opt_type_nextstep
, "ufstype=nextstep"},
323 {Opt_type_openstep
, "ufstype=openstep"},
324 /*end of possible ufs types */
325 {Opt_onerror_panic
, "onerror=panic"},
326 {Opt_onerror_lock
, "onerror=lock"},
327 {Opt_onerror_umount
, "onerror=umount"},
328 {Opt_onerror_repair
, "onerror=repair"},
332 static int ufs_parse_options (char * options
, unsigned * mount_options
)
341 while ((p
= strsep(&options
, ",")) != NULL
) {
342 substring_t args
[MAX_OPT_ARGS
];
347 token
= match_token(p
, tokens
, args
);
350 ufs_clear_opt (*mount_options
, UFSTYPE
);
351 ufs_set_opt (*mount_options
, UFSTYPE_OLD
);
353 case Opt_type_sunx86
:
354 ufs_clear_opt (*mount_options
, UFSTYPE
);
355 ufs_set_opt (*mount_options
, UFSTYPE_SUNx86
);
358 ufs_clear_opt (*mount_options
, UFSTYPE
);
359 ufs_set_opt (*mount_options
, UFSTYPE_SUN
);
362 ufs_clear_opt(*mount_options
, UFSTYPE
);
363 ufs_set_opt(*mount_options
, UFSTYPE_SUNOS
);
366 ufs_clear_opt (*mount_options
, UFSTYPE
);
367 ufs_set_opt (*mount_options
, UFSTYPE_44BSD
);
370 ufs_clear_opt(*mount_options
, UFSTYPE
);
371 ufs_set_opt(*mount_options
, UFSTYPE_UFS2
);
374 ufs_clear_opt (*mount_options
, UFSTYPE
);
375 ufs_set_opt (*mount_options
, UFSTYPE_HP
);
377 case Opt_type_nextstepcd
:
378 ufs_clear_opt (*mount_options
, UFSTYPE
);
379 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP_CD
);
381 case Opt_type_nextstep
:
382 ufs_clear_opt (*mount_options
, UFSTYPE
);
383 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP
);
385 case Opt_type_openstep
:
386 ufs_clear_opt (*mount_options
, UFSTYPE
);
387 ufs_set_opt (*mount_options
, UFSTYPE_OPENSTEP
);
389 case Opt_onerror_panic
:
390 ufs_clear_opt (*mount_options
, ONERROR
);
391 ufs_set_opt (*mount_options
, ONERROR_PANIC
);
393 case Opt_onerror_lock
:
394 ufs_clear_opt (*mount_options
, ONERROR
);
395 ufs_set_opt (*mount_options
, ONERROR_LOCK
);
397 case Opt_onerror_umount
:
398 ufs_clear_opt (*mount_options
, ONERROR
);
399 ufs_set_opt (*mount_options
, ONERROR_UMOUNT
);
401 case Opt_onerror_repair
:
402 printk("UFS-fs: Unable to do repair on error, "
403 "will lock lock instead\n");
404 ufs_clear_opt (*mount_options
, ONERROR
);
405 ufs_set_opt (*mount_options
, ONERROR_REPAIR
);
408 printk("UFS-fs: Invalid option: \"%s\" "
409 "or missing value\n", p
);
417 * Diffrent types of UFS hold fs_cstotal in different
418 * places, and use diffrent data structure for it.
419 * To make things simplier we just copy fs_cstotal to ufs_sb_private_info
421 static void ufs_setup_cstotal(struct super_block
*sb
)
423 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
424 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
425 struct ufs_super_block_first
*usb1
;
426 struct ufs_super_block_second
*usb2
;
427 struct ufs_super_block_third
*usb3
;
428 unsigned mtype
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
430 UFSD("ENTER, mtype=%u\n", mtype
);
431 usb1
= ubh_get_usb_first(uspi
);
432 usb2
= ubh_get_usb_second(uspi
);
433 usb3
= ubh_get_usb_third(uspi
);
435 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
436 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
437 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
438 /*we have statistic in different place, then usual*/
439 uspi
->cs_total
.cs_ndir
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
);
440 uspi
->cs_total
.cs_nbfree
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
);
441 uspi
->cs_total
.cs_nifree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
);
442 uspi
->cs_total
.cs_nffree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
);
444 uspi
->cs_total
.cs_ndir
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
);
445 uspi
->cs_total
.cs_nbfree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
);
446 uspi
->cs_total
.cs_nifree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
);
447 uspi
->cs_total
.cs_nffree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
);
453 * Read on-disk structures associated with cylinder groups
455 static int ufs_read_cylinder_structures(struct super_block
*sb
)
457 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
458 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
459 struct ufs_buffer_head
* ubh
;
460 unsigned char * base
, * space
;
461 unsigned size
, blks
, i
;
462 struct ufs_super_block_third
*usb3
;
466 usb3
= ubh_get_usb_third(uspi
);
468 * Read cs structures from (usually) first data block
471 size
= uspi
->s_cssize
;
472 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
473 base
= space
= kmalloc(size
, GFP_KERNEL
);
476 sbi
->s_csp
= (struct ufs_csum
*)space
;
477 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
478 size
= uspi
->s_bsize
;
479 if (i
+ uspi
->s_fpb
> blks
)
480 size
= (blks
- i
) * uspi
->s_fsize
;
482 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
487 ubh_ubhcpymem (space
, ubh
, size
);
495 * Read cylinder group (we read only first fragment from block
496 * at this time) and prepare internal data structures for cg caching.
498 if (!(sbi
->s_ucg
= kmalloc (sizeof(struct buffer_head
*) * uspi
->s_ncg
, GFP_KERNEL
)))
500 for (i
= 0; i
< uspi
->s_ncg
; i
++)
501 sbi
->s_ucg
[i
] = NULL
;
502 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
503 sbi
->s_ucpi
[i
] = NULL
;
504 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
506 for (i
= 0; i
< uspi
->s_ncg
; i
++) {
507 UFSD("read cg %u\n", i
);
508 if (!(sbi
->s_ucg
[i
] = sb_bread(sb
, ufs_cgcmin(i
))))
510 if (!ufs_cg_chkmagic (sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
))
513 ufs_print_cylinder_stuff(sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
);
515 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
516 if (!(sbi
->s_ucpi
[i
] = kmalloc (sizeof(struct ufs_cg_private_info
), GFP_KERNEL
)))
518 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
520 sbi
->s_cg_loaded
= 0;
527 for (i
= 0; i
< uspi
->s_ncg
; i
++)
529 brelse (sbi
->s_ucg
[i
]);
531 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++)
532 kfree (sbi
->s_ucpi
[i
]);
534 UFSD("EXIT (FAILED)\n");
539 * Sync our internal copy of fs_cstotal with disk
541 static void ufs_put_cstotal(struct super_block
*sb
)
543 unsigned mtype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
544 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
545 struct ufs_super_block_first
*usb1
;
546 struct ufs_super_block_second
*usb2
;
547 struct ufs_super_block_third
*usb3
;
550 usb1
= ubh_get_usb_first(uspi
);
551 usb2
= ubh_get_usb_second(uspi
);
552 usb3
= ubh_get_usb_third(uspi
);
554 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
555 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
556 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
557 /*we have statistic in different place, then usual*/
558 usb2
->fs_un
.fs_u2
.cs_ndir
=
559 cpu_to_fs64(sb
, uspi
->cs_total
.cs_ndir
);
560 usb2
->fs_un
.fs_u2
.cs_nbfree
=
561 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nbfree
);
562 usb3
->fs_un1
.fs_u2
.cs_nifree
=
563 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nifree
);
564 usb3
->fs_un1
.fs_u2
.cs_nffree
=
565 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nffree
);
567 usb1
->fs_cstotal
.cs_ndir
=
568 cpu_to_fs32(sb
, uspi
->cs_total
.cs_ndir
);
569 usb1
->fs_cstotal
.cs_nbfree
=
570 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nbfree
);
571 usb1
->fs_cstotal
.cs_nifree
=
572 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nifree
);
573 usb1
->fs_cstotal
.cs_nffree
=
574 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nffree
);
576 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
577 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
582 * ufs_put_super_internal() - put on-disk intrenal structures
583 * @sb: pointer to super_block structure
584 * Put on-disk structures associated with cylinder groups
585 * and write them back to disk, also update cs_total on disk
587 static void ufs_put_super_internal(struct super_block
*sb
)
589 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
590 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
591 struct ufs_buffer_head
* ubh
;
592 unsigned char * base
, * space
;
593 unsigned blks
, size
, i
;
598 size
= uspi
->s_cssize
;
599 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
600 base
= space
= (char*) sbi
->s_csp
;
601 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
602 size
= uspi
->s_bsize
;
603 if (i
+ uspi
->s_fpb
> blks
)
604 size
= (blks
- i
) * uspi
->s_fsize
;
606 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
608 ubh_memcpyubh (ubh
, space
, size
);
610 ubh_mark_buffer_uptodate (ubh
, 1);
611 ubh_mark_buffer_dirty (ubh
);
614 for (i
= 0; i
< sbi
->s_cg_loaded
; i
++) {
615 ufs_put_cylinder (sb
, i
);
616 kfree (sbi
->s_ucpi
[i
]);
618 for (; i
< UFS_MAX_GROUP_LOADED
; i
++)
619 kfree (sbi
->s_ucpi
[i
]);
620 for (i
= 0; i
< uspi
->s_ncg
; i
++)
621 brelse (sbi
->s_ucg
[i
]);
627 static int ufs_fill_super(struct super_block
*sb
, void *data
, int silent
)
629 struct ufs_sb_info
* sbi
;
630 struct ufs_sb_private_info
* uspi
;
631 struct ufs_super_block_first
* usb1
;
632 struct ufs_super_block_second
* usb2
;
633 struct ufs_super_block_third
* usb3
;
634 struct ufs_buffer_head
* ubh
;
636 unsigned block_size
, super_block_size
;
638 unsigned super_block_offset
;
647 sbi
= kzalloc(sizeof(struct ufs_sb_info
), GFP_KERNEL
);
652 UFSD("flag %u\n", (int)(sb
->s_flags
& MS_RDONLY
));
654 #ifndef CONFIG_UFS_FS_WRITE
655 if (!(sb
->s_flags
& MS_RDONLY
)) {
656 printk("ufs was compiled with read-only support, "
657 "can't be mounted as read-write\n");
662 * Set default mount options
663 * Parse mount options
665 sbi
->s_mount_opt
= 0;
666 ufs_set_opt (sbi
->s_mount_opt
, ONERROR_LOCK
);
667 if (!ufs_parse_options ((char *) data
, &sbi
->s_mount_opt
)) {
668 printk("wrong mount options\n");
671 if (!(sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
673 printk("You didn't specify the type of your ufs filesystem\n\n"
674 "mount -t ufs -o ufstype="
675 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
676 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
677 "default is ufstype=old\n");
678 ufs_set_opt (sbi
->s_mount_opt
, UFSTYPE_OLD
);
681 uspi
= kzalloc(sizeof(struct ufs_sb_private_info
), GFP_KERNEL
);
685 uspi
->s_dirblksize
= UFS_SECTOR_SIZE
;
686 super_block_offset
=UFS_SBLOCK
;
688 /* Keep 2Gig file limit. Some UFS variants need to override
689 this but as I don't know which I'll let those in the know loosen
691 switch (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) {
692 case UFS_MOUNT_UFSTYPE_44BSD
:
693 UFSD("ufstype=44bsd\n");
694 uspi
->s_fsize
= block_size
= 512;
695 uspi
->s_fmask
= ~(512 - 1);
697 uspi
->s_sbsize
= super_block_size
= 1536;
699 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
701 case UFS_MOUNT_UFSTYPE_UFS2
:
702 UFSD("ufstype=ufs2\n");
703 super_block_offset
=SBLOCK_UFS2
;
704 uspi
->s_fsize
= block_size
= 512;
705 uspi
->s_fmask
= ~(512 - 1);
707 uspi
->s_sbsize
= super_block_size
= 1536;
709 flags
|= UFS_TYPE_UFS2
| UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
712 case UFS_MOUNT_UFSTYPE_SUN
:
713 UFSD("ufstype=sun\n");
714 uspi
->s_fsize
= block_size
= 1024;
715 uspi
->s_fmask
= ~(1024 - 1);
717 uspi
->s_sbsize
= super_block_size
= 2048;
719 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
720 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUN
| UFS_CG_SUN
;
723 case UFS_MOUNT_UFSTYPE_SUNOS
:
724 UFSD(("ufstype=sunos\n"))
725 uspi
->s_fsize
= block_size
= 1024;
726 uspi
->s_fmask
= ~(1024 - 1);
728 uspi
->s_sbsize
= 2048;
729 super_block_size
= 2048;
731 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
732 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_SUNOS
| UFS_CG_SUN
;
735 case UFS_MOUNT_UFSTYPE_SUNx86
:
736 UFSD("ufstype=sunx86\n");
737 uspi
->s_fsize
= block_size
= 1024;
738 uspi
->s_fmask
= ~(1024 - 1);
740 uspi
->s_sbsize
= super_block_size
= 2048;
742 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
743 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUNx86
| UFS_CG_SUN
;
746 case UFS_MOUNT_UFSTYPE_OLD
:
747 UFSD("ufstype=old\n");
748 uspi
->s_fsize
= block_size
= 1024;
749 uspi
->s_fmask
= ~(1024 - 1);
751 uspi
->s_sbsize
= super_block_size
= 2048;
753 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
754 if (!(sb
->s_flags
& MS_RDONLY
)) {
756 printk(KERN_INFO
"ufstype=old is supported read-only\n");
757 sb
->s_flags
|= MS_RDONLY
;
761 case UFS_MOUNT_UFSTYPE_NEXTSTEP
:
762 UFSD("ufstype=nextstep\n");
763 uspi
->s_fsize
= block_size
= 1024;
764 uspi
->s_fmask
= ~(1024 - 1);
766 uspi
->s_sbsize
= super_block_size
= 2048;
768 uspi
->s_dirblksize
= 1024;
769 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
770 if (!(sb
->s_flags
& MS_RDONLY
)) {
772 printk(KERN_INFO
"ufstype=nextstep is supported read-only\n");
773 sb
->s_flags
|= MS_RDONLY
;
777 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
:
778 UFSD("ufstype=nextstep-cd\n");
779 uspi
->s_fsize
= block_size
= 2048;
780 uspi
->s_fmask
= ~(2048 - 1);
782 uspi
->s_sbsize
= super_block_size
= 2048;
784 uspi
->s_dirblksize
= 1024;
785 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
786 if (!(sb
->s_flags
& MS_RDONLY
)) {
788 printk(KERN_INFO
"ufstype=nextstep-cd is supported read-only\n");
789 sb
->s_flags
|= MS_RDONLY
;
793 case UFS_MOUNT_UFSTYPE_OPENSTEP
:
794 UFSD("ufstype=openstep\n");
795 uspi
->s_fsize
= block_size
= 1024;
796 uspi
->s_fmask
= ~(1024 - 1);
798 uspi
->s_sbsize
= super_block_size
= 2048;
800 uspi
->s_dirblksize
= 1024;
801 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
802 if (!(sb
->s_flags
& MS_RDONLY
)) {
804 printk(KERN_INFO
"ufstype=openstep is supported read-only\n");
805 sb
->s_flags
|= MS_RDONLY
;
809 case UFS_MOUNT_UFSTYPE_HP
:
810 UFSD("ufstype=hp\n");
811 uspi
->s_fsize
= block_size
= 1024;
812 uspi
->s_fmask
= ~(1024 - 1);
814 uspi
->s_sbsize
= super_block_size
= 2048;
816 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
817 if (!(sb
->s_flags
& MS_RDONLY
)) {
819 printk(KERN_INFO
"ufstype=hp is supported read-only\n");
820 sb
->s_flags
|= MS_RDONLY
;
825 printk("unknown ufstype\n");
830 if (!sb_set_blocksize(sb
, block_size
)) {
831 printk(KERN_ERR
"UFS: failed to set blocksize\n");
836 * read ufs super block from device
839 ubh
= ubh_bread_uspi(uspi
, sb
, uspi
->s_sbbase
+ super_block_offset
/block_size
, super_block_size
);
844 usb1
= ubh_get_usb_first(uspi
);
845 usb2
= ubh_get_usb_second(uspi
);
846 usb3
= ubh_get_usb_third(uspi
);
848 /* Sort out mod used on SunOS 4.1.3 for fs_state */
849 uspi
->s_postblformat
= fs32_to_cpu(sb
, usb3
->fs_postblformat
);
850 if (((flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
) &&
851 (uspi
->s_postblformat
!= UFS_42POSTBLFMT
)) {
852 flags
&= ~UFS_ST_MASK
;
857 * Check ufs magic number
859 sbi
->s_bytesex
= BYTESEX_LE
;
860 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
868 sbi
->s_bytesex
= BYTESEX_BE
;
869 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
878 if ((((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP
)
879 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
)
880 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_OPENSTEP
))
881 && uspi
->s_sbbase
< 256) {
882 ubh_brelse_uspi(uspi
);
888 printk("ufs_read_super: bad magic number\n");
893 * Check block and fragment sizes
895 uspi
->s_bsize
= fs32_to_cpu(sb
, usb1
->fs_bsize
);
896 uspi
->s_fsize
= fs32_to_cpu(sb
, usb1
->fs_fsize
);
897 uspi
->s_sbsize
= fs32_to_cpu(sb
, usb1
->fs_sbsize
);
898 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
899 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
901 if (!is_power_of_2(uspi
->s_fsize
)) {
902 printk(KERN_ERR
"ufs_read_super: fragment size %u is not a power of 2\n",
906 if (uspi
->s_fsize
< 512) {
907 printk(KERN_ERR
"ufs_read_super: fragment size %u is too small\n",
911 if (uspi
->s_fsize
> 4096) {
912 printk(KERN_ERR
"ufs_read_super: fragment size %u is too large\n",
916 if (!is_power_of_2(uspi
->s_bsize
)) {
917 printk(KERN_ERR
"ufs_read_super: block size %u is not a power of 2\n",
921 if (uspi
->s_bsize
< 4096) {
922 printk(KERN_ERR
"ufs_read_super: block size %u is too small\n",
926 if (uspi
->s_bsize
/ uspi
->s_fsize
> 8) {
927 printk(KERN_ERR
"ufs_read_super: too many fragments per block (%u)\n",
928 uspi
->s_bsize
/ uspi
->s_fsize
);
931 if (uspi
->s_fsize
!= block_size
|| uspi
->s_sbsize
!= super_block_size
) {
932 ubh_brelse_uspi(uspi
);
934 block_size
= uspi
->s_fsize
;
935 super_block_size
= uspi
->s_sbsize
;
936 UFSD("another value of block_size or super_block_size %u, %u\n", block_size
, super_block_size
);
940 sbi
->s_flags
= flags
;/*after that line some functions use s_flags*/
941 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
944 * Check, if file system was correctly unmounted.
945 * If not, make it read only.
947 if (((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
) ||
948 ((flags
& UFS_ST_MASK
) == UFS_ST_OLD
) ||
949 (((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
950 (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
||
951 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
) &&
952 (ufs_get_fs_state(sb
, usb1
, usb3
) == (UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
))))) {
953 switch(usb1
->fs_clean
) {
955 UFSD("fs is clean\n");
958 UFSD("fs is stable\n");
961 UFSD("fs is DEC OSF/1\n");
964 printk("ufs_read_super: fs is active\n");
965 sb
->s_flags
|= MS_RDONLY
;
968 printk("ufs_read_super: fs is bad\n");
969 sb
->s_flags
|= MS_RDONLY
;
972 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1
->fs_clean
);
973 sb
->s_flags
|= MS_RDONLY
;
977 printk("ufs_read_super: fs needs fsck\n");
978 sb
->s_flags
|= MS_RDONLY
;
982 * Read ufs_super_block into internal data structures
984 sb
->s_op
= &ufs_super_ops
;
985 sb
->dq_op
= NULL
; /***/
986 sb
->s_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
988 uspi
->s_sblkno
= fs32_to_cpu(sb
, usb1
->fs_sblkno
);
989 uspi
->s_cblkno
= fs32_to_cpu(sb
, usb1
->fs_cblkno
);
990 uspi
->s_iblkno
= fs32_to_cpu(sb
, usb1
->fs_iblkno
);
991 uspi
->s_dblkno
= fs32_to_cpu(sb
, usb1
->fs_dblkno
);
992 uspi
->s_cgoffset
= fs32_to_cpu(sb
, usb1
->fs_cgoffset
);
993 uspi
->s_cgmask
= fs32_to_cpu(sb
, usb1
->fs_cgmask
);
995 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
996 uspi
->s_u2_size
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
);
997 uspi
->s_u2_dsize
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
999 uspi
->s_size
= fs32_to_cpu(sb
, usb1
->fs_size
);
1000 uspi
->s_dsize
= fs32_to_cpu(sb
, usb1
->fs_dsize
);
1003 uspi
->s_ncg
= fs32_to_cpu(sb
, usb1
->fs_ncg
);
1004 /* s_bsize already set */
1005 /* s_fsize already set */
1006 uspi
->s_fpb
= fs32_to_cpu(sb
, usb1
->fs_frag
);
1007 uspi
->s_minfree
= fs32_to_cpu(sb
, usb1
->fs_minfree
);
1008 uspi
->s_bmask
= fs32_to_cpu(sb
, usb1
->fs_bmask
);
1009 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
1010 uspi
->s_bshift
= fs32_to_cpu(sb
, usb1
->fs_bshift
);
1011 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
1012 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi
->s_bshift
,
1014 uspi
->s_fpbshift
= fs32_to_cpu(sb
, usb1
->fs_fragshift
);
1015 uspi
->s_fsbtodb
= fs32_to_cpu(sb
, usb1
->fs_fsbtodb
);
1016 /* s_sbsize already set */
1017 uspi
->s_csmask
= fs32_to_cpu(sb
, usb1
->fs_csmask
);
1018 uspi
->s_csshift
= fs32_to_cpu(sb
, usb1
->fs_csshift
);
1019 uspi
->s_nindir
= fs32_to_cpu(sb
, usb1
->fs_nindir
);
1020 uspi
->s_inopb
= fs32_to_cpu(sb
, usb1
->fs_inopb
);
1021 uspi
->s_nspf
= fs32_to_cpu(sb
, usb1
->fs_nspf
);
1022 uspi
->s_npsect
= ufs_get_fs_npsect(sb
, usb1
, usb3
);
1023 uspi
->s_interleave
= fs32_to_cpu(sb
, usb1
->fs_interleave
);
1024 uspi
->s_trackskew
= fs32_to_cpu(sb
, usb1
->fs_trackskew
);
1026 if (uspi
->fs_magic
== UFS2_MAGIC
)
1027 uspi
->s_csaddr
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_csaddr
);
1029 uspi
->s_csaddr
= fs32_to_cpu(sb
, usb1
->fs_csaddr
);
1031 uspi
->s_cssize
= fs32_to_cpu(sb
, usb1
->fs_cssize
);
1032 uspi
->s_cgsize
= fs32_to_cpu(sb
, usb1
->fs_cgsize
);
1033 uspi
->s_ntrak
= fs32_to_cpu(sb
, usb1
->fs_ntrak
);
1034 uspi
->s_nsect
= fs32_to_cpu(sb
, usb1
->fs_nsect
);
1035 uspi
->s_spc
= fs32_to_cpu(sb
, usb1
->fs_spc
);
1036 uspi
->s_ipg
= fs32_to_cpu(sb
, usb1
->fs_ipg
);
1037 uspi
->s_fpg
= fs32_to_cpu(sb
, usb1
->fs_fpg
);
1038 uspi
->s_cpc
= fs32_to_cpu(sb
, usb2
->fs_un
.fs_u1
.fs_cpc
);
1039 uspi
->s_contigsumsize
= fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_contigsumsize
);
1040 uspi
->s_qbmask
= ufs_get_fs_qbmask(sb
, usb3
);
1041 uspi
->s_qfmask
= ufs_get_fs_qfmask(sb
, usb3
);
1042 uspi
->s_nrpos
= fs32_to_cpu(sb
, usb3
->fs_nrpos
);
1043 uspi
->s_postbloff
= fs32_to_cpu(sb
, usb3
->fs_postbloff
);
1044 uspi
->s_rotbloff
= fs32_to_cpu(sb
, usb3
->fs_rotbloff
);
1047 * Compute another frequently used values
1049 uspi
->s_fpbmask
= uspi
->s_fpb
- 1;
1050 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
1051 uspi
->s_apbshift
= uspi
->s_bshift
- 3;
1053 uspi
->s_apbshift
= uspi
->s_bshift
- 2;
1055 uspi
->s_2apbshift
= uspi
->s_apbshift
* 2;
1056 uspi
->s_3apbshift
= uspi
->s_apbshift
* 3;
1057 uspi
->s_apb
= 1 << uspi
->s_apbshift
;
1058 uspi
->s_2apb
= 1 << uspi
->s_2apbshift
;
1059 uspi
->s_3apb
= 1 << uspi
->s_3apbshift
;
1060 uspi
->s_apbmask
= uspi
->s_apb
- 1;
1061 uspi
->s_nspfshift
= uspi
->s_fshift
- UFS_SECTOR_BITS
;
1062 uspi
->s_nspb
= uspi
->s_nspf
<< uspi
->s_fpbshift
;
1063 uspi
->s_inopf
= uspi
->s_inopb
>> uspi
->s_fpbshift
;
1064 uspi
->s_bpf
= uspi
->s_fsize
<< 3;
1065 uspi
->s_bpfshift
= uspi
->s_fshift
+ 3;
1066 uspi
->s_bpfmask
= uspi
->s_bpf
- 1;
1067 if ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_44BSD
||
1068 (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_UFS2
)
1069 uspi
->s_maxsymlinklen
=
1070 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
);
1072 inode
= ufs_iget(sb
, UFS_ROOTINO
);
1073 if (IS_ERR(inode
)) {
1074 ret
= PTR_ERR(inode
);
1077 sb
->s_root
= d_alloc_root(inode
);
1083 ufs_setup_cstotal(sb
);
1085 * Read cylinder group structures
1087 if (!(sb
->s_flags
& MS_RDONLY
))
1088 if (!ufs_read_cylinder_structures(sb
))
1098 ubh_brelse_uspi (uspi
);
1101 sb
->s_fs_info
= NULL
;
1102 UFSD("EXIT (FAILED)\n");
1106 UFSD("EXIT (NOMEM)\n");
1110 static void ufs_write_super(struct super_block
*sb
)
1112 struct ufs_sb_private_info
* uspi
;
1113 struct ufs_super_block_first
* usb1
;
1114 struct ufs_super_block_third
* usb3
;
1119 flags
= UFS_SB(sb
)->s_flags
;
1120 uspi
= UFS_SB(sb
)->s_uspi
;
1121 usb1
= ubh_get_usb_first(uspi
);
1122 usb3
= ubh_get_usb_third(uspi
);
1124 if (!(sb
->s_flags
& MS_RDONLY
)) {
1125 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1126 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1127 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
1128 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1129 ufs_set_fs_state(sb
, usb1
, usb3
,
1130 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1131 ufs_put_cstotal(sb
);
1138 static void ufs_put_super(struct super_block
*sb
)
1140 struct ufs_sb_info
* sbi
= UFS_SB(sb
);
1144 if (!(sb
->s_flags
& MS_RDONLY
))
1145 ufs_put_super_internal(sb
);
1147 ubh_brelse_uspi (sbi
->s_uspi
);
1148 kfree (sbi
->s_uspi
);
1150 sb
->s_fs_info
= NULL
;
1156 static int ufs_remount (struct super_block
*sb
, int *mount_flags
, char *data
)
1158 struct ufs_sb_private_info
* uspi
;
1159 struct ufs_super_block_first
* usb1
;
1160 struct ufs_super_block_third
* usb3
;
1161 unsigned new_mount_opt
, ufstype
;
1164 uspi
= UFS_SB(sb
)->s_uspi
;
1165 flags
= UFS_SB(sb
)->s_flags
;
1166 usb1
= ubh_get_usb_first(uspi
);
1167 usb3
= ubh_get_usb_third(uspi
);
1170 * Allow the "check" option to be passed as a remount option.
1171 * It is not possible to change ufstype option during remount
1173 ufstype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1175 ufs_set_opt (new_mount_opt
, ONERROR_LOCK
);
1176 if (!ufs_parse_options (data
, &new_mount_opt
))
1178 if (!(new_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
1179 new_mount_opt
|= ufstype
;
1180 } else if ((new_mount_opt
& UFS_MOUNT_UFSTYPE
) != ufstype
) {
1181 printk("ufstype can't be changed during remount\n");
1185 if ((*mount_flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
)) {
1186 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1191 * fs was mouted as rw, remounting ro
1193 if (*mount_flags
& MS_RDONLY
) {
1194 ufs_put_super_internal(sb
);
1195 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1196 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1197 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
1198 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1199 ufs_set_fs_state(sb
, usb1
, usb3
,
1200 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1201 ubh_mark_buffer_dirty (USPI_UBH(uspi
));
1203 sb
->s_flags
|= MS_RDONLY
;
1206 * fs was mounted as ro, remounting rw
1208 #ifndef CONFIG_UFS_FS_WRITE
1209 printk("ufs was compiled with read-only support, "
1210 "can't be mounted as read-write\n");
1213 if (ufstype
!= UFS_MOUNT_UFSTYPE_SUN
&&
1214 ufstype
!= UFS_MOUNT_UFSTYPE_SUNOS
&&
1215 ufstype
!= UFS_MOUNT_UFSTYPE_44BSD
&&
1216 ufstype
!= UFS_MOUNT_UFSTYPE_SUNx86
&&
1217 ufstype
!= UFS_MOUNT_UFSTYPE_UFS2
) {
1218 printk("this ufstype is read-only supported\n");
1221 if (!ufs_read_cylinder_structures(sb
)) {
1222 printk("failed during remounting\n");
1225 sb
->s_flags
&= ~MS_RDONLY
;
1228 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1232 static int ufs_show_options(struct seq_file
*seq
, struct vfsmount
*vfs
)
1234 struct ufs_sb_info
*sbi
= UFS_SB(vfs
->mnt_sb
);
1235 unsigned mval
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1236 const struct match_token
*tp
= tokens
;
1238 while (tp
->token
!= Opt_onerror_panic
&& tp
->token
!= mval
)
1240 BUG_ON(tp
->token
== Opt_onerror_panic
);
1241 seq_printf(seq
, ",%s", tp
->pattern
);
1243 mval
= sbi
->s_mount_opt
& UFS_MOUNT_ONERROR
;
1244 while (tp
->token
!= Opt_err
&& tp
->token
!= mval
)
1246 BUG_ON(tp
->token
== Opt_err
);
1247 seq_printf(seq
, ",%s", tp
->pattern
);
1252 static int ufs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1254 struct super_block
*sb
= dentry
->d_sb
;
1255 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
1256 unsigned flags
= UFS_SB(sb
)->s_flags
;
1257 struct ufs_super_block_first
*usb1
;
1258 struct ufs_super_block_second
*usb2
;
1259 struct ufs_super_block_third
*usb3
;
1263 usb1
= ubh_get_usb_first(uspi
);
1264 usb2
= ubh_get_usb_second(uspi
);
1265 usb3
= ubh_get_usb_third(uspi
);
1267 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1268 buf
->f_type
= UFS2_MAGIC
;
1269 buf
->f_blocks
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1271 buf
->f_type
= UFS_MAGIC
;
1272 buf
->f_blocks
= uspi
->s_dsize
;
1274 buf
->f_bfree
= ufs_blkstofrags(uspi
->cs_total
.cs_nbfree
) +
1275 uspi
->cs_total
.cs_nffree
;
1276 buf
->f_ffree
= uspi
->cs_total
.cs_nifree
;
1277 buf
->f_bsize
= sb
->s_blocksize
;
1278 buf
->f_bavail
= (buf
->f_bfree
> (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
))
1279 ? (buf
->f_bfree
- (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
)) : 0;
1280 buf
->f_files
= uspi
->s_ncg
* uspi
->s_ipg
;
1281 buf
->f_namelen
= UFS_MAXNAMLEN
;
1288 static struct kmem_cache
* ufs_inode_cachep
;
1290 static struct inode
*ufs_alloc_inode(struct super_block
*sb
)
1292 struct ufs_inode_info
*ei
;
1293 ei
= (struct ufs_inode_info
*)kmem_cache_alloc(ufs_inode_cachep
, GFP_KERNEL
);
1296 ei
->vfs_inode
.i_version
= 1;
1297 return &ei
->vfs_inode
;
1300 static void ufs_destroy_inode(struct inode
*inode
)
1302 kmem_cache_free(ufs_inode_cachep
, UFS_I(inode
));
1305 static void init_once(void *foo
)
1307 struct ufs_inode_info
*ei
= (struct ufs_inode_info
*) foo
;
1309 inode_init_once(&ei
->vfs_inode
);
1312 static int init_inodecache(void)
1314 ufs_inode_cachep
= kmem_cache_create("ufs_inode_cache",
1315 sizeof(struct ufs_inode_info
),
1316 0, (SLAB_RECLAIM_ACCOUNT
|
1319 if (ufs_inode_cachep
== NULL
)
1324 static void destroy_inodecache(void)
1326 kmem_cache_destroy(ufs_inode_cachep
);
1330 static ssize_t
ufs_quota_read(struct super_block
*, int, char *,size_t, loff_t
);
1331 static ssize_t
ufs_quota_write(struct super_block
*, int, const char *, size_t, loff_t
);
1334 static const struct super_operations ufs_super_ops
= {
1335 .alloc_inode
= ufs_alloc_inode
,
1336 .destroy_inode
= ufs_destroy_inode
,
1337 .write_inode
= ufs_write_inode
,
1338 .delete_inode
= ufs_delete_inode
,
1339 .put_super
= ufs_put_super
,
1340 .write_super
= ufs_write_super
,
1341 .statfs
= ufs_statfs
,
1342 .remount_fs
= ufs_remount
,
1343 .show_options
= ufs_show_options
,
1345 .quota_read
= ufs_quota_read
,
1346 .quota_write
= ufs_quota_write
,
1352 /* Read data from quotafile - avoid pagecache and such because we cannot afford
1353 * acquiring the locks... As quota files are never truncated and quota code
1354 * itself serializes the operations (and noone else should touch the files)
1355 * we don't have to be afraid of races */
1356 static ssize_t
ufs_quota_read(struct super_block
*sb
, int type
, char *data
,
1357 size_t len
, loff_t off
)
1359 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1360 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1362 int offset
= off
& (sb
->s_blocksize
- 1);
1365 struct buffer_head
*bh
;
1366 loff_t i_size
= i_size_read(inode
);
1370 if (off
+len
> i_size
)
1373 while (toread
> 0) {
1374 tocopy
= sb
->s_blocksize
- offset
< toread
?
1375 sb
->s_blocksize
- offset
: toread
;
1377 bh
= ufs_bread(inode
, blk
, 0, &err
);
1380 if (!bh
) /* A hole? */
1381 memset(data
, 0, tocopy
);
1383 memcpy(data
, bh
->b_data
+offset
, tocopy
);
1394 /* Write to quotafile */
1395 static ssize_t
ufs_quota_write(struct super_block
*sb
, int type
,
1396 const char *data
, size_t len
, loff_t off
)
1398 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1399 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1401 int offset
= off
& (sb
->s_blocksize
- 1);
1403 size_t towrite
= len
;
1404 struct buffer_head
*bh
;
1406 mutex_lock_nested(&inode
->i_mutex
, I_MUTEX_QUOTA
);
1407 while (towrite
> 0) {
1408 tocopy
= sb
->s_blocksize
- offset
< towrite
?
1409 sb
->s_blocksize
- offset
: towrite
;
1411 bh
= ufs_bread(inode
, blk
, 1, &err
);
1415 memcpy(bh
->b_data
+offset
, data
, tocopy
);
1416 flush_dcache_page(bh
->b_page
);
1417 set_buffer_uptodate(bh
);
1418 mark_buffer_dirty(bh
);
1427 if (len
== towrite
) {
1428 mutex_unlock(&inode
->i_mutex
);
1431 if (inode
->i_size
< off
+len
-towrite
)
1432 i_size_write(inode
, off
+len
-towrite
);
1434 inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME_SEC
;
1435 mark_inode_dirty(inode
);
1436 mutex_unlock(&inode
->i_mutex
);
1437 return len
- towrite
;
1442 static int ufs_get_sb(struct file_system_type
*fs_type
,
1443 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
1445 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, ufs_fill_super
, mnt
);
1448 static struct file_system_type ufs_fs_type
= {
1449 .owner
= THIS_MODULE
,
1451 .get_sb
= ufs_get_sb
,
1452 .kill_sb
= kill_block_super
,
1453 .fs_flags
= FS_REQUIRES_DEV
,
1456 static int __init
init_ufs_fs(void)
1458 int err
= init_inodecache();
1461 err
= register_filesystem(&ufs_fs_type
);
1466 destroy_inodecache();
1471 static void __exit
exit_ufs_fs(void)
1473 unregister_filesystem(&ufs_fs_type
);
1474 destroy_inodecache();
1477 module_init(init_ufs_fs
)
1478 module_exit(exit_ufs_fs
)
1479 MODULE_LICENSE("GPL");