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 <gwingerde@gmail.com>
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/exportfs.h>
70 #include <linux/module.h>
71 #include <linux/bitops.h>
75 #include <asm/uaccess.h>
77 #include <linux/errno.h>
79 #include <linux/slab.h>
80 #include <linux/time.h>
81 #include <linux/stat.h>
82 #include <linux/string.h>
83 #include <linux/blkdev.h>
84 #include <linux/init.h>
85 #include <linux/parser.h>
86 #include <linux/buffer_head.h>
87 #include <linux/vfs.h>
88 #include <linux/log2.h>
89 #include <linux/mount.h>
90 #include <linux/seq_file.h>
97 void lock_ufs(struct super_block
*sb
)
99 #if defined(CONFIG_SMP) || defined (CONFIG_PREEMPT)
100 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
102 mutex_lock(&sbi
->mutex
);
103 sbi
->mutex_owner
= current
;
107 void unlock_ufs(struct super_block
*sb
)
109 #if defined(CONFIG_SMP) || defined (CONFIG_PREEMPT)
110 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
112 sbi
->mutex_owner
= NULL
;
113 mutex_unlock(&sbi
->mutex
);
117 static struct inode
*ufs_nfs_get_inode(struct super_block
*sb
, u64 ino
, u32 generation
)
119 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
122 if (ino
< UFS_ROOTINO
|| ino
> uspi
->s_ncg
* uspi
->s_ipg
)
123 return ERR_PTR(-ESTALE
);
125 inode
= ufs_iget(sb
, ino
);
127 return ERR_CAST(inode
);
128 if (generation
&& inode
->i_generation
!= generation
) {
130 return ERR_PTR(-ESTALE
);
135 static struct dentry
*ufs_fh_to_dentry(struct super_block
*sb
, struct fid
*fid
,
136 int fh_len
, int fh_type
)
138 return generic_fh_to_dentry(sb
, fid
, fh_len
, fh_type
, ufs_nfs_get_inode
);
141 static struct dentry
*ufs_fh_to_parent(struct super_block
*sb
, struct fid
*fid
,
142 int fh_len
, int fh_type
)
144 return generic_fh_to_parent(sb
, fid
, fh_len
, fh_type
, ufs_nfs_get_inode
);
147 static struct dentry
*ufs_get_parent(struct dentry
*child
)
149 struct qstr dot_dot
= QSTR_INIT("..", 2);
152 ino
= ufs_inode_by_name(child
->d_inode
, &dot_dot
);
154 return ERR_PTR(-ENOENT
);
155 return d_obtain_alias(ufs_iget(child
->d_inode
->i_sb
, ino
));
158 static const struct export_operations ufs_export_ops
= {
159 .fh_to_dentry
= ufs_fh_to_dentry
,
160 .fh_to_parent
= ufs_fh_to_parent
,
161 .get_parent
= ufs_get_parent
,
164 #ifdef CONFIG_UFS_DEBUG
166 * Print contents of ufs_super_block, useful for debugging
168 static void ufs_print_super_stuff(struct super_block
*sb
,
169 struct ufs_super_block_first
*usb1
,
170 struct ufs_super_block_second
*usb2
,
171 struct ufs_super_block_third
*usb3
)
173 u32 magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
175 printk("ufs_print_super_stuff\n");
176 printk(" magic: 0x%x\n", magic
);
177 if (fs32_to_cpu(sb
, usb3
->fs_magic
) == UFS2_MAGIC
) {
178 printk(" fs_size: %llu\n", (unsigned long long)
179 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
));
180 printk(" fs_dsize: %llu\n", (unsigned long long)
181 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
));
182 printk(" bsize: %u\n",
183 fs32_to_cpu(sb
, usb1
->fs_bsize
));
184 printk(" fsize: %u\n",
185 fs32_to_cpu(sb
, usb1
->fs_fsize
));
186 printk(" fs_volname: %s\n", usb2
->fs_un
.fs_u2
.fs_volname
);
187 printk(" fs_sblockloc: %llu\n", (unsigned long long)
188 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.fs_sblockloc
));
189 printk(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
190 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
));
191 printk(" cs_nbfree(No of free blocks): %llu\n",
193 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
));
194 printk(KERN_INFO
" cs_nifree(Num of free inodes): %llu\n",
196 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
));
197 printk(KERN_INFO
" cs_nffree(Num of free frags): %llu\n",
199 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
));
200 printk(KERN_INFO
" fs_maxsymlinklen: %u\n",
201 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
));
203 printk(" sblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_sblkno
));
204 printk(" cblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_cblkno
));
205 printk(" iblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_iblkno
));
206 printk(" dblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_dblkno
));
207 printk(" cgoffset: %u\n",
208 fs32_to_cpu(sb
, usb1
->fs_cgoffset
));
209 printk(" ~cgmask: 0x%x\n",
210 ~fs32_to_cpu(sb
, usb1
->fs_cgmask
));
211 printk(" size: %u\n", fs32_to_cpu(sb
, usb1
->fs_size
));
212 printk(" dsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_dsize
));
213 printk(" ncg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ncg
));
214 printk(" bsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_bsize
));
215 printk(" fsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_fsize
));
216 printk(" frag: %u\n", fs32_to_cpu(sb
, usb1
->fs_frag
));
217 printk(" fragshift: %u\n",
218 fs32_to_cpu(sb
, usb1
->fs_fragshift
));
219 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb
, usb1
->fs_fmask
));
220 printk(" fshift: %u\n", fs32_to_cpu(sb
, usb1
->fs_fshift
));
221 printk(" sbsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_sbsize
));
222 printk(" spc: %u\n", fs32_to_cpu(sb
, usb1
->fs_spc
));
223 printk(" cpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_cpg
));
224 printk(" ipg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ipg
));
225 printk(" fpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_fpg
));
226 printk(" csaddr: %u\n", fs32_to_cpu(sb
, usb1
->fs_csaddr
));
227 printk(" cssize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cssize
));
228 printk(" cgsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cgsize
));
229 printk(" fstodb: %u\n",
230 fs32_to_cpu(sb
, usb1
->fs_fsbtodb
));
231 printk(" nrpos: %u\n", fs32_to_cpu(sb
, usb3
->fs_nrpos
));
233 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
));
234 printk(" nifree %u\n",
235 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
));
236 printk(" nbfree %u\n",
237 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
));
238 printk(" nffree %u\n",
239 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
));
245 * Print contents of ufs_cylinder_group, useful for debugging
247 static void ufs_print_cylinder_stuff(struct super_block
*sb
,
248 struct ufs_cylinder_group
*cg
)
250 printk("\nufs_print_cylinder_stuff\n");
251 printk("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group
));
252 printk(" magic: %x\n", fs32_to_cpu(sb
, cg
->cg_magic
));
253 printk(" time: %u\n", fs32_to_cpu(sb
, cg
->cg_time
));
254 printk(" cgx: %u\n", fs32_to_cpu(sb
, cg
->cg_cgx
));
255 printk(" ncyl: %u\n", fs16_to_cpu(sb
, cg
->cg_ncyl
));
256 printk(" niblk: %u\n", fs16_to_cpu(sb
, cg
->cg_niblk
));
257 printk(" ndblk: %u\n", fs32_to_cpu(sb
, cg
->cg_ndblk
));
258 printk(" cs_ndir: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_ndir
));
259 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nbfree
));
260 printk(" cs_nifree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nifree
));
261 printk(" cs_nffree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nffree
));
262 printk(" rotor: %u\n", fs32_to_cpu(sb
, cg
->cg_rotor
));
263 printk(" frotor: %u\n", fs32_to_cpu(sb
, cg
->cg_frotor
));
264 printk(" irotor: %u\n", fs32_to_cpu(sb
, cg
->cg_irotor
));
265 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
266 fs32_to_cpu(sb
, cg
->cg_frsum
[0]), fs32_to_cpu(sb
, cg
->cg_frsum
[1]),
267 fs32_to_cpu(sb
, cg
->cg_frsum
[2]), fs32_to_cpu(sb
, cg
->cg_frsum
[3]),
268 fs32_to_cpu(sb
, cg
->cg_frsum
[4]), fs32_to_cpu(sb
, cg
->cg_frsum
[5]),
269 fs32_to_cpu(sb
, cg
->cg_frsum
[6]), fs32_to_cpu(sb
, cg
->cg_frsum
[7]));
270 printk(" btotoff: %u\n", fs32_to_cpu(sb
, cg
->cg_btotoff
));
271 printk(" boff: %u\n", fs32_to_cpu(sb
, cg
->cg_boff
));
272 printk(" iuseoff: %u\n", fs32_to_cpu(sb
, cg
->cg_iusedoff
));
273 printk(" freeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_freeoff
));
274 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_nextfreeoff
));
275 printk(" clustersumoff %u\n",
276 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clustersumoff
));
277 printk(" clusteroff %u\n",
278 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clusteroff
));
279 printk(" nclusterblks %u\n",
280 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_nclusterblks
));
284 # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
285 # define ufs_print_cylinder_stuff(sb, cg) /**/
286 #endif /* CONFIG_UFS_DEBUG */
288 static const struct super_operations ufs_super_ops
;
290 static char error_buf
[1024];
292 void ufs_error (struct super_block
* sb
, const char * function
,
293 const char * fmt
, ...)
295 struct ufs_sb_private_info
* uspi
;
296 struct ufs_super_block_first
* usb1
;
299 uspi
= UFS_SB(sb
)->s_uspi
;
300 usb1
= ubh_get_usb_first(uspi
);
302 if (!(sb
->s_flags
& MS_RDONLY
)) {
303 usb1
->fs_clean
= UFS_FSBAD
;
304 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
305 ufs_mark_sb_dirty(sb
);
306 sb
->s_flags
|= MS_RDONLY
;
308 va_start (args
, fmt
);
309 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
311 switch (UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_ONERROR
) {
312 case UFS_MOUNT_ONERROR_PANIC
:
313 panic ("UFS-fs panic (device %s): %s: %s\n",
314 sb
->s_id
, function
, error_buf
);
316 case UFS_MOUNT_ONERROR_LOCK
:
317 case UFS_MOUNT_ONERROR_UMOUNT
:
318 case UFS_MOUNT_ONERROR_REPAIR
:
319 printk (KERN_CRIT
"UFS-fs error (device %s): %s: %s\n",
320 sb
->s_id
, function
, error_buf
);
324 void ufs_panic (struct super_block
* sb
, const char * function
,
325 const char * fmt
, ...)
327 struct ufs_sb_private_info
* uspi
;
328 struct ufs_super_block_first
* usb1
;
331 uspi
= UFS_SB(sb
)->s_uspi
;
332 usb1
= ubh_get_usb_first(uspi
);
334 if (!(sb
->s_flags
& MS_RDONLY
)) {
335 usb1
->fs_clean
= UFS_FSBAD
;
336 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
337 ufs_mark_sb_dirty(sb
);
339 va_start (args
, fmt
);
340 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
342 sb
->s_flags
|= MS_RDONLY
;
343 printk (KERN_CRIT
"UFS-fs panic (device %s): %s: %s\n",
344 sb
->s_id
, function
, error_buf
);
347 void ufs_warning (struct super_block
* sb
, const char * function
,
348 const char * fmt
, ...)
352 va_start (args
, fmt
);
353 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
355 printk (KERN_WARNING
"UFS-fs warning (device %s): %s: %s\n",
356 sb
->s_id
, function
, error_buf
);
360 Opt_type_old
= UFS_MOUNT_UFSTYPE_OLD
,
361 Opt_type_sunx86
= UFS_MOUNT_UFSTYPE_SUNx86
,
362 Opt_type_sun
= UFS_MOUNT_UFSTYPE_SUN
,
363 Opt_type_sunos
= UFS_MOUNT_UFSTYPE_SUNOS
,
364 Opt_type_44bsd
= UFS_MOUNT_UFSTYPE_44BSD
,
365 Opt_type_ufs2
= UFS_MOUNT_UFSTYPE_UFS2
,
366 Opt_type_hp
= UFS_MOUNT_UFSTYPE_HP
,
367 Opt_type_nextstepcd
= UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
,
368 Opt_type_nextstep
= UFS_MOUNT_UFSTYPE_NEXTSTEP
,
369 Opt_type_openstep
= UFS_MOUNT_UFSTYPE_OPENSTEP
,
370 Opt_onerror_panic
= UFS_MOUNT_ONERROR_PANIC
,
371 Opt_onerror_lock
= UFS_MOUNT_ONERROR_LOCK
,
372 Opt_onerror_umount
= UFS_MOUNT_ONERROR_UMOUNT
,
373 Opt_onerror_repair
= UFS_MOUNT_ONERROR_REPAIR
,
377 static const match_table_t tokens
= {
378 {Opt_type_old
, "ufstype=old"},
379 {Opt_type_sunx86
, "ufstype=sunx86"},
380 {Opt_type_sun
, "ufstype=sun"},
381 {Opt_type_sunos
, "ufstype=sunos"},
382 {Opt_type_44bsd
, "ufstype=44bsd"},
383 {Opt_type_ufs2
, "ufstype=ufs2"},
384 {Opt_type_ufs2
, "ufstype=5xbsd"},
385 {Opt_type_hp
, "ufstype=hp"},
386 {Opt_type_nextstepcd
, "ufstype=nextstep-cd"},
387 {Opt_type_nextstep
, "ufstype=nextstep"},
388 {Opt_type_openstep
, "ufstype=openstep"},
389 /*end of possible ufs types */
390 {Opt_onerror_panic
, "onerror=panic"},
391 {Opt_onerror_lock
, "onerror=lock"},
392 {Opt_onerror_umount
, "onerror=umount"},
393 {Opt_onerror_repair
, "onerror=repair"},
397 static int ufs_parse_options (char * options
, unsigned * mount_options
)
406 while ((p
= strsep(&options
, ",")) != NULL
) {
407 substring_t args
[MAX_OPT_ARGS
];
412 token
= match_token(p
, tokens
, args
);
415 ufs_clear_opt (*mount_options
, UFSTYPE
);
416 ufs_set_opt (*mount_options
, UFSTYPE_OLD
);
418 case Opt_type_sunx86
:
419 ufs_clear_opt (*mount_options
, UFSTYPE
);
420 ufs_set_opt (*mount_options
, UFSTYPE_SUNx86
);
423 ufs_clear_opt (*mount_options
, UFSTYPE
);
424 ufs_set_opt (*mount_options
, UFSTYPE_SUN
);
427 ufs_clear_opt(*mount_options
, UFSTYPE
);
428 ufs_set_opt(*mount_options
, UFSTYPE_SUNOS
);
431 ufs_clear_opt (*mount_options
, UFSTYPE
);
432 ufs_set_opt (*mount_options
, UFSTYPE_44BSD
);
435 ufs_clear_opt(*mount_options
, UFSTYPE
);
436 ufs_set_opt(*mount_options
, UFSTYPE_UFS2
);
439 ufs_clear_opt (*mount_options
, UFSTYPE
);
440 ufs_set_opt (*mount_options
, UFSTYPE_HP
);
442 case Opt_type_nextstepcd
:
443 ufs_clear_opt (*mount_options
, UFSTYPE
);
444 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP_CD
);
446 case Opt_type_nextstep
:
447 ufs_clear_opt (*mount_options
, UFSTYPE
);
448 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP
);
450 case Opt_type_openstep
:
451 ufs_clear_opt (*mount_options
, UFSTYPE
);
452 ufs_set_opt (*mount_options
, UFSTYPE_OPENSTEP
);
454 case Opt_onerror_panic
:
455 ufs_clear_opt (*mount_options
, ONERROR
);
456 ufs_set_opt (*mount_options
, ONERROR_PANIC
);
458 case Opt_onerror_lock
:
459 ufs_clear_opt (*mount_options
, ONERROR
);
460 ufs_set_opt (*mount_options
, ONERROR_LOCK
);
462 case Opt_onerror_umount
:
463 ufs_clear_opt (*mount_options
, ONERROR
);
464 ufs_set_opt (*mount_options
, ONERROR_UMOUNT
);
466 case Opt_onerror_repair
:
467 printk("UFS-fs: Unable to do repair on error, "
468 "will lock lock instead\n");
469 ufs_clear_opt (*mount_options
, ONERROR
);
470 ufs_set_opt (*mount_options
, ONERROR_REPAIR
);
473 printk("UFS-fs: Invalid option: \"%s\" "
474 "or missing value\n", p
);
482 * Different types of UFS hold fs_cstotal in different
483 * places, and use different data structure for it.
484 * To make things simpler we just copy fs_cstotal to ufs_sb_private_info
486 static void ufs_setup_cstotal(struct super_block
*sb
)
488 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
489 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
490 struct ufs_super_block_first
*usb1
;
491 struct ufs_super_block_second
*usb2
;
492 struct ufs_super_block_third
*usb3
;
493 unsigned mtype
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
495 UFSD("ENTER, mtype=%u\n", mtype
);
496 usb1
= ubh_get_usb_first(uspi
);
497 usb2
= ubh_get_usb_second(uspi
);
498 usb3
= ubh_get_usb_third(uspi
);
500 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
501 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
502 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
503 /*we have statistic in different place, then usual*/
504 uspi
->cs_total
.cs_ndir
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
);
505 uspi
->cs_total
.cs_nbfree
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
);
506 uspi
->cs_total
.cs_nifree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
);
507 uspi
->cs_total
.cs_nffree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
);
509 uspi
->cs_total
.cs_ndir
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
);
510 uspi
->cs_total
.cs_nbfree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
);
511 uspi
->cs_total
.cs_nifree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
);
512 uspi
->cs_total
.cs_nffree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
);
518 * Read on-disk structures associated with cylinder groups
520 static int ufs_read_cylinder_structures(struct super_block
*sb
)
522 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
523 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
524 struct ufs_buffer_head
* ubh
;
525 unsigned char * base
, * space
;
526 unsigned size
, blks
, i
;
527 struct ufs_super_block_third
*usb3
;
531 usb3
= ubh_get_usb_third(uspi
);
533 * Read cs structures from (usually) first data block
536 size
= uspi
->s_cssize
;
537 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
538 base
= space
= kmalloc(size
, GFP_NOFS
);
541 sbi
->s_csp
= (struct ufs_csum
*)space
;
542 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
543 size
= uspi
->s_bsize
;
544 if (i
+ uspi
->s_fpb
> blks
)
545 size
= (blks
- i
) * uspi
->s_fsize
;
547 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
552 ubh_ubhcpymem (space
, ubh
, size
);
560 * Read cylinder group (we read only first fragment from block
561 * at this time) and prepare internal data structures for cg caching.
563 if (!(sbi
->s_ucg
= kmalloc (sizeof(struct buffer_head
*) * uspi
->s_ncg
, GFP_NOFS
)))
565 for (i
= 0; i
< uspi
->s_ncg
; i
++)
566 sbi
->s_ucg
[i
] = NULL
;
567 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
568 sbi
->s_ucpi
[i
] = NULL
;
569 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
571 for (i
= 0; i
< uspi
->s_ncg
; i
++) {
572 UFSD("read cg %u\n", i
);
573 if (!(sbi
->s_ucg
[i
] = sb_bread(sb
, ufs_cgcmin(i
))))
575 if (!ufs_cg_chkmagic (sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
))
578 ufs_print_cylinder_stuff(sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
);
580 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
581 if (!(sbi
->s_ucpi
[i
] = kmalloc (sizeof(struct ufs_cg_private_info
), GFP_NOFS
)))
583 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
585 sbi
->s_cg_loaded
= 0;
592 for (i
= 0; i
< uspi
->s_ncg
; i
++)
594 brelse (sbi
->s_ucg
[i
]);
596 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++)
597 kfree (sbi
->s_ucpi
[i
]);
599 UFSD("EXIT (FAILED)\n");
604 * Sync our internal copy of fs_cstotal with disk
606 static void ufs_put_cstotal(struct super_block
*sb
)
608 unsigned mtype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
609 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
610 struct ufs_super_block_first
*usb1
;
611 struct ufs_super_block_second
*usb2
;
612 struct ufs_super_block_third
*usb3
;
615 usb1
= ubh_get_usb_first(uspi
);
616 usb2
= ubh_get_usb_second(uspi
);
617 usb3
= ubh_get_usb_third(uspi
);
619 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
620 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
621 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
622 /*we have statistic in different place, then usual*/
623 usb2
->fs_un
.fs_u2
.cs_ndir
=
624 cpu_to_fs64(sb
, uspi
->cs_total
.cs_ndir
);
625 usb2
->fs_un
.fs_u2
.cs_nbfree
=
626 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nbfree
);
627 usb3
->fs_un1
.fs_u2
.cs_nifree
=
628 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nifree
);
629 usb3
->fs_un1
.fs_u2
.cs_nffree
=
630 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nffree
);
632 usb1
->fs_cstotal
.cs_ndir
=
633 cpu_to_fs32(sb
, uspi
->cs_total
.cs_ndir
);
634 usb1
->fs_cstotal
.cs_nbfree
=
635 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nbfree
);
636 usb1
->fs_cstotal
.cs_nifree
=
637 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nifree
);
638 usb1
->fs_cstotal
.cs_nffree
=
639 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nffree
);
641 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
642 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
647 * ufs_put_super_internal() - put on-disk intrenal structures
648 * @sb: pointer to super_block structure
649 * Put on-disk structures associated with cylinder groups
650 * and write them back to disk, also update cs_total on disk
652 static void ufs_put_super_internal(struct super_block
*sb
)
654 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
655 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
656 struct ufs_buffer_head
* ubh
;
657 unsigned char * base
, * space
;
658 unsigned blks
, size
, i
;
664 size
= uspi
->s_cssize
;
665 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
666 base
= space
= (char*) sbi
->s_csp
;
667 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
668 size
= uspi
->s_bsize
;
669 if (i
+ uspi
->s_fpb
> blks
)
670 size
= (blks
- i
) * uspi
->s_fsize
;
672 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
674 ubh_memcpyubh (ubh
, space
, size
);
676 ubh_mark_buffer_uptodate (ubh
, 1);
677 ubh_mark_buffer_dirty (ubh
);
680 for (i
= 0; i
< sbi
->s_cg_loaded
; i
++) {
681 ufs_put_cylinder (sb
, i
);
682 kfree (sbi
->s_ucpi
[i
]);
684 for (; i
< UFS_MAX_GROUP_LOADED
; i
++)
685 kfree (sbi
->s_ucpi
[i
]);
686 for (i
= 0; i
< uspi
->s_ncg
; i
++)
687 brelse (sbi
->s_ucg
[i
]);
694 static int ufs_sync_fs(struct super_block
*sb
, int wait
)
696 struct ufs_sb_private_info
* uspi
;
697 struct ufs_super_block_first
* usb1
;
698 struct ufs_super_block_third
* usb3
;
706 flags
= UFS_SB(sb
)->s_flags
;
707 uspi
= UFS_SB(sb
)->s_uspi
;
708 usb1
= ubh_get_usb_first(uspi
);
709 usb3
= ubh_get_usb_third(uspi
);
711 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
712 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
713 (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
||
714 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
715 ufs_set_fs_state(sb
, usb1
, usb3
,
716 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
726 static void delayed_sync_fs(struct work_struct
*work
)
728 struct ufs_sb_info
*sbi
;
730 sbi
= container_of(work
, struct ufs_sb_info
, sync_work
.work
);
732 spin_lock(&sbi
->work_lock
);
733 sbi
->work_queued
= 0;
734 spin_unlock(&sbi
->work_lock
);
736 ufs_sync_fs(sbi
->sb
, 1);
739 void ufs_mark_sb_dirty(struct super_block
*sb
)
741 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
744 spin_lock(&sbi
->work_lock
);
745 if (!sbi
->work_queued
) {
746 delay
= msecs_to_jiffies(dirty_writeback_interval
* 10);
747 queue_delayed_work(system_long_wq
, &sbi
->sync_work
, delay
);
748 sbi
->work_queued
= 1;
750 spin_unlock(&sbi
->work_lock
);
753 static void ufs_put_super(struct super_block
*sb
)
755 struct ufs_sb_info
* sbi
= UFS_SB(sb
);
759 if (!(sb
->s_flags
& MS_RDONLY
))
760 ufs_put_super_internal(sb
);
761 cancel_delayed_work_sync(&sbi
->sync_work
);
763 ubh_brelse_uspi (sbi
->s_uspi
);
766 sb
->s_fs_info
= NULL
;
771 static int ufs_fill_super(struct super_block
*sb
, void *data
, int silent
)
773 struct ufs_sb_info
* sbi
;
774 struct ufs_sb_private_info
* uspi
;
775 struct ufs_super_block_first
* usb1
;
776 struct ufs_super_block_second
* usb2
;
777 struct ufs_super_block_third
* usb3
;
778 struct ufs_buffer_head
* ubh
;
780 unsigned block_size
, super_block_size
;
782 unsigned super_block_offset
;
792 sbi
= kzalloc(sizeof(struct ufs_sb_info
), GFP_KERNEL
);
798 UFSD("flag %u\n", (int)(sb
->s_flags
& MS_RDONLY
));
800 #ifndef CONFIG_UFS_FS_WRITE
801 if (!(sb
->s_flags
& MS_RDONLY
)) {
802 printk("ufs was compiled with read-only support, "
803 "can't be mounted as read-write\n");
807 mutex_init(&sbi
->mutex
);
808 spin_lock_init(&sbi
->work_lock
);
809 INIT_DELAYED_WORK(&sbi
->sync_work
, delayed_sync_fs
);
811 * Set default mount options
812 * Parse mount options
814 sbi
->s_mount_opt
= 0;
815 ufs_set_opt (sbi
->s_mount_opt
, ONERROR_LOCK
);
816 if (!ufs_parse_options ((char *) data
, &sbi
->s_mount_opt
)) {
817 printk("wrong mount options\n");
820 if (!(sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
822 printk("You didn't specify the type of your ufs filesystem\n\n"
823 "mount -t ufs -o ufstype="
824 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
825 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
826 "default is ufstype=old\n");
827 ufs_set_opt (sbi
->s_mount_opt
, UFSTYPE_OLD
);
830 uspi
= kzalloc(sizeof(struct ufs_sb_private_info
), GFP_KERNEL
);
834 uspi
->s_dirblksize
= UFS_SECTOR_SIZE
;
835 super_block_offset
=UFS_SBLOCK
;
837 /* Keep 2Gig file limit. Some UFS variants need to override
838 this but as I don't know which I'll let those in the know loosen
840 switch (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) {
841 case UFS_MOUNT_UFSTYPE_44BSD
:
842 UFSD("ufstype=44bsd\n");
843 uspi
->s_fsize
= block_size
= 512;
844 uspi
->s_fmask
= ~(512 - 1);
846 uspi
->s_sbsize
= super_block_size
= 1536;
848 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
850 case UFS_MOUNT_UFSTYPE_UFS2
:
851 UFSD("ufstype=ufs2\n");
852 super_block_offset
=SBLOCK_UFS2
;
853 uspi
->s_fsize
= block_size
= 512;
854 uspi
->s_fmask
= ~(512 - 1);
856 uspi
->s_sbsize
= super_block_size
= 1536;
858 flags
|= UFS_TYPE_UFS2
| UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
861 case UFS_MOUNT_UFSTYPE_SUN
:
862 UFSD("ufstype=sun\n");
863 uspi
->s_fsize
= block_size
= 1024;
864 uspi
->s_fmask
= ~(1024 - 1);
866 uspi
->s_sbsize
= super_block_size
= 2048;
868 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
869 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUN
| UFS_CG_SUN
;
872 case UFS_MOUNT_UFSTYPE_SUNOS
:
873 UFSD(("ufstype=sunos\n"))
874 uspi
->s_fsize
= block_size
= 1024;
875 uspi
->s_fmask
= ~(1024 - 1);
877 uspi
->s_sbsize
= 2048;
878 super_block_size
= 2048;
880 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
881 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_SUNOS
| UFS_CG_SUN
;
884 case UFS_MOUNT_UFSTYPE_SUNx86
:
885 UFSD("ufstype=sunx86\n");
886 uspi
->s_fsize
= block_size
= 1024;
887 uspi
->s_fmask
= ~(1024 - 1);
889 uspi
->s_sbsize
= super_block_size
= 2048;
891 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
892 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUNx86
| UFS_CG_SUN
;
895 case UFS_MOUNT_UFSTYPE_OLD
:
896 UFSD("ufstype=old\n");
897 uspi
->s_fsize
= block_size
= 1024;
898 uspi
->s_fmask
= ~(1024 - 1);
900 uspi
->s_sbsize
= super_block_size
= 2048;
902 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
903 if (!(sb
->s_flags
& MS_RDONLY
)) {
905 printk(KERN_INFO
"ufstype=old is supported read-only\n");
906 sb
->s_flags
|= MS_RDONLY
;
910 case UFS_MOUNT_UFSTYPE_NEXTSTEP
:
911 UFSD("ufstype=nextstep\n");
912 uspi
->s_fsize
= block_size
= 1024;
913 uspi
->s_fmask
= ~(1024 - 1);
915 uspi
->s_sbsize
= super_block_size
= 2048;
917 uspi
->s_dirblksize
= 1024;
918 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
919 if (!(sb
->s_flags
& MS_RDONLY
)) {
921 printk(KERN_INFO
"ufstype=nextstep is supported read-only\n");
922 sb
->s_flags
|= MS_RDONLY
;
926 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
:
927 UFSD("ufstype=nextstep-cd\n");
928 uspi
->s_fsize
= block_size
= 2048;
929 uspi
->s_fmask
= ~(2048 - 1);
931 uspi
->s_sbsize
= super_block_size
= 2048;
933 uspi
->s_dirblksize
= 1024;
934 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
935 if (!(sb
->s_flags
& MS_RDONLY
)) {
937 printk(KERN_INFO
"ufstype=nextstep-cd is supported read-only\n");
938 sb
->s_flags
|= MS_RDONLY
;
942 case UFS_MOUNT_UFSTYPE_OPENSTEP
:
943 UFSD("ufstype=openstep\n");
944 uspi
->s_fsize
= block_size
= 1024;
945 uspi
->s_fmask
= ~(1024 - 1);
947 uspi
->s_sbsize
= super_block_size
= 2048;
949 uspi
->s_dirblksize
= 1024;
950 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
951 if (!(sb
->s_flags
& MS_RDONLY
)) {
953 printk(KERN_INFO
"ufstype=openstep is supported read-only\n");
954 sb
->s_flags
|= MS_RDONLY
;
958 case UFS_MOUNT_UFSTYPE_HP
:
959 UFSD("ufstype=hp\n");
960 uspi
->s_fsize
= block_size
= 1024;
961 uspi
->s_fmask
= ~(1024 - 1);
963 uspi
->s_sbsize
= super_block_size
= 2048;
965 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
966 if (!(sb
->s_flags
& MS_RDONLY
)) {
968 printk(KERN_INFO
"ufstype=hp is supported read-only\n");
969 sb
->s_flags
|= MS_RDONLY
;
974 printk("unknown ufstype\n");
979 if (!sb_set_blocksize(sb
, block_size
)) {
980 printk(KERN_ERR
"UFS: failed to set blocksize\n");
985 * read ufs super block from device
988 ubh
= ubh_bread_uspi(uspi
, sb
, uspi
->s_sbbase
+ super_block_offset
/block_size
, super_block_size
);
993 usb1
= ubh_get_usb_first(uspi
);
994 usb2
= ubh_get_usb_second(uspi
);
995 usb3
= ubh_get_usb_third(uspi
);
997 /* Sort out mod used on SunOS 4.1.3 for fs_state */
998 uspi
->s_postblformat
= fs32_to_cpu(sb
, usb3
->fs_postblformat
);
999 if (((flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
) &&
1000 (uspi
->s_postblformat
!= UFS_42POSTBLFMT
)) {
1001 flags
&= ~UFS_ST_MASK
;
1002 flags
|= UFS_ST_SUN
;
1006 * Check ufs magic number
1008 sbi
->s_bytesex
= BYTESEX_LE
;
1009 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
1018 sbi
->s_bytesex
= BYTESEX_BE
;
1019 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
1029 if ((((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP
)
1030 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
)
1031 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_OPENSTEP
))
1032 && uspi
->s_sbbase
< 256) {
1033 ubh_brelse_uspi(uspi
);
1035 uspi
->s_sbbase
+= 8;
1039 printk("ufs_read_super: bad magic number\n");
1044 * Check block and fragment sizes
1046 uspi
->s_bsize
= fs32_to_cpu(sb
, usb1
->fs_bsize
);
1047 uspi
->s_fsize
= fs32_to_cpu(sb
, usb1
->fs_fsize
);
1048 uspi
->s_sbsize
= fs32_to_cpu(sb
, usb1
->fs_sbsize
);
1049 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
1050 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
1052 if (!is_power_of_2(uspi
->s_fsize
)) {
1053 printk(KERN_ERR
"ufs_read_super: fragment size %u is not a power of 2\n",
1057 if (uspi
->s_fsize
< 512) {
1058 printk(KERN_ERR
"ufs_read_super: fragment size %u is too small\n",
1062 if (uspi
->s_fsize
> 4096) {
1063 printk(KERN_ERR
"ufs_read_super: fragment size %u is too large\n",
1067 if (!is_power_of_2(uspi
->s_bsize
)) {
1068 printk(KERN_ERR
"ufs_read_super: block size %u is not a power of 2\n",
1072 if (uspi
->s_bsize
< 4096) {
1073 printk(KERN_ERR
"ufs_read_super: block size %u is too small\n",
1077 if (uspi
->s_bsize
/ uspi
->s_fsize
> 8) {
1078 printk(KERN_ERR
"ufs_read_super: too many fragments per block (%u)\n",
1079 uspi
->s_bsize
/ uspi
->s_fsize
);
1082 if (uspi
->s_fsize
!= block_size
|| uspi
->s_sbsize
!= super_block_size
) {
1083 ubh_brelse_uspi(uspi
);
1085 block_size
= uspi
->s_fsize
;
1086 super_block_size
= uspi
->s_sbsize
;
1087 UFSD("another value of block_size or super_block_size %u, %u\n", block_size
, super_block_size
);
1091 sbi
->s_flags
= flags
;/*after that line some functions use s_flags*/
1092 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
1095 * Check, if file system was correctly unmounted.
1096 * If not, make it read only.
1098 if (((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
) ||
1099 ((flags
& UFS_ST_MASK
) == UFS_ST_OLD
) ||
1100 (((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
1101 (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
||
1102 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
) &&
1103 (ufs_get_fs_state(sb
, usb1
, usb3
) == (UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
))))) {
1104 switch(usb1
->fs_clean
) {
1106 UFSD("fs is clean\n");
1109 UFSD("fs is stable\n");
1112 UFSD("fs is logging fs\n");
1115 UFSD("fs is DEC OSF/1\n");
1118 printk("ufs_read_super: fs is active\n");
1119 sb
->s_flags
|= MS_RDONLY
;
1122 printk("ufs_read_super: fs is bad\n");
1123 sb
->s_flags
|= MS_RDONLY
;
1126 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1
->fs_clean
);
1127 sb
->s_flags
|= MS_RDONLY
;
1131 printk("ufs_read_super: fs needs fsck\n");
1132 sb
->s_flags
|= MS_RDONLY
;
1136 * Read ufs_super_block into internal data structures
1138 sb
->s_op
= &ufs_super_ops
;
1139 sb
->s_export_op
= &ufs_export_ops
;
1141 sb
->s_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
1143 uspi
->s_sblkno
= fs32_to_cpu(sb
, usb1
->fs_sblkno
);
1144 uspi
->s_cblkno
= fs32_to_cpu(sb
, usb1
->fs_cblkno
);
1145 uspi
->s_iblkno
= fs32_to_cpu(sb
, usb1
->fs_iblkno
);
1146 uspi
->s_dblkno
= fs32_to_cpu(sb
, usb1
->fs_dblkno
);
1147 uspi
->s_cgoffset
= fs32_to_cpu(sb
, usb1
->fs_cgoffset
);
1148 uspi
->s_cgmask
= fs32_to_cpu(sb
, usb1
->fs_cgmask
);
1150 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1151 uspi
->s_u2_size
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
);
1152 uspi
->s_u2_dsize
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1154 uspi
->s_size
= fs32_to_cpu(sb
, usb1
->fs_size
);
1155 uspi
->s_dsize
= fs32_to_cpu(sb
, usb1
->fs_dsize
);
1158 uspi
->s_ncg
= fs32_to_cpu(sb
, usb1
->fs_ncg
);
1159 /* s_bsize already set */
1160 /* s_fsize already set */
1161 uspi
->s_fpb
= fs32_to_cpu(sb
, usb1
->fs_frag
);
1162 uspi
->s_minfree
= fs32_to_cpu(sb
, usb1
->fs_minfree
);
1163 uspi
->s_bmask
= fs32_to_cpu(sb
, usb1
->fs_bmask
);
1164 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
1165 uspi
->s_bshift
= fs32_to_cpu(sb
, usb1
->fs_bshift
);
1166 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
1167 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi
->s_bshift
,
1169 uspi
->s_fpbshift
= fs32_to_cpu(sb
, usb1
->fs_fragshift
);
1170 uspi
->s_fsbtodb
= fs32_to_cpu(sb
, usb1
->fs_fsbtodb
);
1171 /* s_sbsize already set */
1172 uspi
->s_csmask
= fs32_to_cpu(sb
, usb1
->fs_csmask
);
1173 uspi
->s_csshift
= fs32_to_cpu(sb
, usb1
->fs_csshift
);
1174 uspi
->s_nindir
= fs32_to_cpu(sb
, usb1
->fs_nindir
);
1175 uspi
->s_inopb
= fs32_to_cpu(sb
, usb1
->fs_inopb
);
1176 uspi
->s_nspf
= fs32_to_cpu(sb
, usb1
->fs_nspf
);
1177 uspi
->s_npsect
= ufs_get_fs_npsect(sb
, usb1
, usb3
);
1178 uspi
->s_interleave
= fs32_to_cpu(sb
, usb1
->fs_interleave
);
1179 uspi
->s_trackskew
= fs32_to_cpu(sb
, usb1
->fs_trackskew
);
1181 if (uspi
->fs_magic
== UFS2_MAGIC
)
1182 uspi
->s_csaddr
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_csaddr
);
1184 uspi
->s_csaddr
= fs32_to_cpu(sb
, usb1
->fs_csaddr
);
1186 uspi
->s_cssize
= fs32_to_cpu(sb
, usb1
->fs_cssize
);
1187 uspi
->s_cgsize
= fs32_to_cpu(sb
, usb1
->fs_cgsize
);
1188 uspi
->s_ntrak
= fs32_to_cpu(sb
, usb1
->fs_ntrak
);
1189 uspi
->s_nsect
= fs32_to_cpu(sb
, usb1
->fs_nsect
);
1190 uspi
->s_spc
= fs32_to_cpu(sb
, usb1
->fs_spc
);
1191 uspi
->s_ipg
= fs32_to_cpu(sb
, usb1
->fs_ipg
);
1192 uspi
->s_fpg
= fs32_to_cpu(sb
, usb1
->fs_fpg
);
1193 uspi
->s_cpc
= fs32_to_cpu(sb
, usb2
->fs_un
.fs_u1
.fs_cpc
);
1194 uspi
->s_contigsumsize
= fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_contigsumsize
);
1195 uspi
->s_qbmask
= ufs_get_fs_qbmask(sb
, usb3
);
1196 uspi
->s_qfmask
= ufs_get_fs_qfmask(sb
, usb3
);
1197 uspi
->s_nrpos
= fs32_to_cpu(sb
, usb3
->fs_nrpos
);
1198 uspi
->s_postbloff
= fs32_to_cpu(sb
, usb3
->fs_postbloff
);
1199 uspi
->s_rotbloff
= fs32_to_cpu(sb
, usb3
->fs_rotbloff
);
1202 * Compute another frequently used values
1204 uspi
->s_fpbmask
= uspi
->s_fpb
- 1;
1205 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
1206 uspi
->s_apbshift
= uspi
->s_bshift
- 3;
1208 uspi
->s_apbshift
= uspi
->s_bshift
- 2;
1210 uspi
->s_2apbshift
= uspi
->s_apbshift
* 2;
1211 uspi
->s_3apbshift
= uspi
->s_apbshift
* 3;
1212 uspi
->s_apb
= 1 << uspi
->s_apbshift
;
1213 uspi
->s_2apb
= 1 << uspi
->s_2apbshift
;
1214 uspi
->s_3apb
= 1 << uspi
->s_3apbshift
;
1215 uspi
->s_apbmask
= uspi
->s_apb
- 1;
1216 uspi
->s_nspfshift
= uspi
->s_fshift
- UFS_SECTOR_BITS
;
1217 uspi
->s_nspb
= uspi
->s_nspf
<< uspi
->s_fpbshift
;
1218 uspi
->s_inopf
= uspi
->s_inopb
>> uspi
->s_fpbshift
;
1219 uspi
->s_bpf
= uspi
->s_fsize
<< 3;
1220 uspi
->s_bpfshift
= uspi
->s_fshift
+ 3;
1221 uspi
->s_bpfmask
= uspi
->s_bpf
- 1;
1222 if ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_44BSD
||
1223 (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_UFS2
)
1224 uspi
->s_maxsymlinklen
=
1225 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
);
1227 if (uspi
->fs_magic
== UFS2_MAGIC
)
1228 maxsymlen
= 2 * 4 * (UFS_NDADDR
+ UFS_NINDIR
);
1230 maxsymlen
= 4 * (UFS_NDADDR
+ UFS_NINDIR
);
1231 if (uspi
->s_maxsymlinklen
> maxsymlen
) {
1232 ufs_warning(sb
, __func__
, "ufs_read_super: excessive maximum "
1233 "fast symlink size (%u)\n", uspi
->s_maxsymlinklen
);
1234 uspi
->s_maxsymlinklen
= maxsymlen
;
1236 sb
->s_max_links
= UFS_LINK_MAX
;
1238 inode
= ufs_iget(sb
, UFS_ROOTINO
);
1239 if (IS_ERR(inode
)) {
1240 ret
= PTR_ERR(inode
);
1243 sb
->s_root
= d_make_root(inode
);
1249 ufs_setup_cstotal(sb
);
1251 * Read cylinder group structures
1253 if (!(sb
->s_flags
& MS_RDONLY
))
1254 if (!ufs_read_cylinder_structures(sb
))
1262 ubh_brelse_uspi (uspi
);
1265 sb
->s_fs_info
= NULL
;
1266 UFSD("EXIT (FAILED)\n");
1270 UFSD("EXIT (NOMEM)\n");
1274 static int ufs_remount (struct super_block
*sb
, int *mount_flags
, char *data
)
1276 struct ufs_sb_private_info
* uspi
;
1277 struct ufs_super_block_first
* usb1
;
1278 struct ufs_super_block_third
* usb3
;
1279 unsigned new_mount_opt
, ufstype
;
1284 uspi
= UFS_SB(sb
)->s_uspi
;
1285 flags
= UFS_SB(sb
)->s_flags
;
1286 usb1
= ubh_get_usb_first(uspi
);
1287 usb3
= ubh_get_usb_third(uspi
);
1290 * Allow the "check" option to be passed as a remount option.
1291 * It is not possible to change ufstype option during remount
1293 ufstype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1295 ufs_set_opt (new_mount_opt
, ONERROR_LOCK
);
1296 if (!ufs_parse_options (data
, &new_mount_opt
)) {
1301 if (!(new_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
1302 new_mount_opt
|= ufstype
;
1303 } else if ((new_mount_opt
& UFS_MOUNT_UFSTYPE
) != ufstype
) {
1304 printk("ufstype can't be changed during remount\n");
1310 if ((*mount_flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
)) {
1311 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1318 * fs was mouted as rw, remounting ro
1320 if (*mount_flags
& MS_RDONLY
) {
1321 ufs_put_super_internal(sb
);
1322 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1323 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1324 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
1325 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1326 ufs_set_fs_state(sb
, usb1
, usb3
,
1327 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1328 ubh_mark_buffer_dirty (USPI_UBH(uspi
));
1329 sb
->s_flags
|= MS_RDONLY
;
1332 * fs was mounted as ro, remounting rw
1334 #ifndef CONFIG_UFS_FS_WRITE
1335 printk("ufs was compiled with read-only support, "
1336 "can't be mounted as read-write\n");
1341 if (ufstype
!= UFS_MOUNT_UFSTYPE_SUN
&&
1342 ufstype
!= UFS_MOUNT_UFSTYPE_SUNOS
&&
1343 ufstype
!= UFS_MOUNT_UFSTYPE_44BSD
&&
1344 ufstype
!= UFS_MOUNT_UFSTYPE_SUNx86
&&
1345 ufstype
!= UFS_MOUNT_UFSTYPE_UFS2
) {
1346 printk("this ufstype is read-only supported\n");
1351 if (!ufs_read_cylinder_structures(sb
)) {
1352 printk("failed during remounting\n");
1357 sb
->s_flags
&= ~MS_RDONLY
;
1360 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1366 static int ufs_show_options(struct seq_file
*seq
, struct dentry
*root
)
1368 struct ufs_sb_info
*sbi
= UFS_SB(root
->d_sb
);
1369 unsigned mval
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1370 const struct match_token
*tp
= tokens
;
1372 while (tp
->token
!= Opt_onerror_panic
&& tp
->token
!= mval
)
1374 BUG_ON(tp
->token
== Opt_onerror_panic
);
1375 seq_printf(seq
, ",%s", tp
->pattern
);
1377 mval
= sbi
->s_mount_opt
& UFS_MOUNT_ONERROR
;
1378 while (tp
->token
!= Opt_err
&& tp
->token
!= mval
)
1380 BUG_ON(tp
->token
== Opt_err
);
1381 seq_printf(seq
, ",%s", tp
->pattern
);
1386 static int ufs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1388 struct super_block
*sb
= dentry
->d_sb
;
1389 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
1390 unsigned flags
= UFS_SB(sb
)->s_flags
;
1391 struct ufs_super_block_first
*usb1
;
1392 struct ufs_super_block_second
*usb2
;
1393 struct ufs_super_block_third
*usb3
;
1394 u64 id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
1398 usb1
= ubh_get_usb_first(uspi
);
1399 usb2
= ubh_get_usb_second(uspi
);
1400 usb3
= ubh_get_usb_third(uspi
);
1402 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1403 buf
->f_type
= UFS2_MAGIC
;
1404 buf
->f_blocks
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1406 buf
->f_type
= UFS_MAGIC
;
1407 buf
->f_blocks
= uspi
->s_dsize
;
1409 buf
->f_bfree
= ufs_blkstofrags(uspi
->cs_total
.cs_nbfree
) +
1410 uspi
->cs_total
.cs_nffree
;
1411 buf
->f_ffree
= uspi
->cs_total
.cs_nifree
;
1412 buf
->f_bsize
= sb
->s_blocksize
;
1413 buf
->f_bavail
= (buf
->f_bfree
> (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
))
1414 ? (buf
->f_bfree
- (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
)) : 0;
1415 buf
->f_files
= uspi
->s_ncg
* uspi
->s_ipg
;
1416 buf
->f_namelen
= UFS_MAXNAMLEN
;
1417 buf
->f_fsid
.val
[0] = (u32
)id
;
1418 buf
->f_fsid
.val
[1] = (u32
)(id
>> 32);
1425 static struct kmem_cache
* ufs_inode_cachep
;
1427 static struct inode
*ufs_alloc_inode(struct super_block
*sb
)
1429 struct ufs_inode_info
*ei
;
1430 ei
= (struct ufs_inode_info
*)kmem_cache_alloc(ufs_inode_cachep
, GFP_NOFS
);
1433 ei
->vfs_inode
.i_version
= 1;
1434 return &ei
->vfs_inode
;
1437 static void ufs_i_callback(struct rcu_head
*head
)
1439 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
1440 kmem_cache_free(ufs_inode_cachep
, UFS_I(inode
));
1443 static void ufs_destroy_inode(struct inode
*inode
)
1445 call_rcu(&inode
->i_rcu
, ufs_i_callback
);
1448 static void init_once(void *foo
)
1450 struct ufs_inode_info
*ei
= (struct ufs_inode_info
*) foo
;
1452 inode_init_once(&ei
->vfs_inode
);
1455 static int init_inodecache(void)
1457 ufs_inode_cachep
= kmem_cache_create("ufs_inode_cache",
1458 sizeof(struct ufs_inode_info
),
1459 0, (SLAB_RECLAIM_ACCOUNT
|
1462 if (ufs_inode_cachep
== NULL
)
1467 static void destroy_inodecache(void)
1469 kmem_cache_destroy(ufs_inode_cachep
);
1472 static const struct super_operations ufs_super_ops
= {
1473 .alloc_inode
= ufs_alloc_inode
,
1474 .destroy_inode
= ufs_destroy_inode
,
1475 .write_inode
= ufs_write_inode
,
1476 .evict_inode
= ufs_evict_inode
,
1477 .put_super
= ufs_put_super
,
1478 .sync_fs
= ufs_sync_fs
,
1479 .statfs
= ufs_statfs
,
1480 .remount_fs
= ufs_remount
,
1481 .show_options
= ufs_show_options
,
1484 static struct dentry
*ufs_mount(struct file_system_type
*fs_type
,
1485 int flags
, const char *dev_name
, void *data
)
1487 return mount_bdev(fs_type
, flags
, dev_name
, data
, ufs_fill_super
);
1490 static struct file_system_type ufs_fs_type
= {
1491 .owner
= THIS_MODULE
,
1494 .kill_sb
= kill_block_super
,
1495 .fs_flags
= FS_REQUIRES_DEV
,
1498 static int __init
init_ufs_fs(void)
1500 int err
= init_inodecache();
1503 err
= register_filesystem(&ufs_fs_type
);
1508 destroy_inodecache();
1513 static void __exit
exit_ufs_fs(void)
1515 unregister_filesystem(&ufs_fs_type
);
1516 destroy_inodecache();
1519 module_init(init_ufs_fs
)
1520 module_exit(exit_ufs_fs
)
1521 MODULE_LICENSE("GPL");