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
68 #include <linux/exportfs.h>
69 #include <linux/module.h>
70 #include <linux/bitops.h>
74 #include <asm/uaccess.h>
76 #include <linux/errno.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/backing-dev.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 static struct inode
*ufs_nfs_get_inode(struct super_block
*sb
, u64 ino
, u32 generation
)
99 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
102 if (ino
< UFS_ROOTINO
|| ino
> uspi
->s_ncg
* uspi
->s_ipg
)
103 return ERR_PTR(-ESTALE
);
105 inode
= ufs_iget(sb
, ino
);
107 return ERR_CAST(inode
);
108 if (generation
&& inode
->i_generation
!= generation
) {
110 return ERR_PTR(-ESTALE
);
115 static struct dentry
*ufs_fh_to_dentry(struct super_block
*sb
, struct fid
*fid
,
116 int fh_len
, int fh_type
)
118 return generic_fh_to_dentry(sb
, fid
, fh_len
, fh_type
, ufs_nfs_get_inode
);
121 static struct dentry
*ufs_fh_to_parent(struct super_block
*sb
, struct fid
*fid
,
122 int fh_len
, int fh_type
)
124 return generic_fh_to_parent(sb
, fid
, fh_len
, fh_type
, ufs_nfs_get_inode
);
127 static struct dentry
*ufs_get_parent(struct dentry
*child
)
129 struct qstr dot_dot
= QSTR_INIT("..", 2);
132 ino
= ufs_inode_by_name(d_inode(child
), &dot_dot
);
134 return ERR_PTR(-ENOENT
);
135 return d_obtain_alias(ufs_iget(d_inode(child
)->i_sb
, ino
));
138 static const struct export_operations ufs_export_ops
= {
139 .fh_to_dentry
= ufs_fh_to_dentry
,
140 .fh_to_parent
= ufs_fh_to_parent
,
141 .get_parent
= ufs_get_parent
,
144 #ifdef CONFIG_UFS_DEBUG
146 * Print contents of ufs_super_block, useful for debugging
148 static void ufs_print_super_stuff(struct super_block
*sb
,
149 struct ufs_super_block_first
*usb1
,
150 struct ufs_super_block_second
*usb2
,
151 struct ufs_super_block_third
*usb3
)
153 u32 magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
155 pr_debug("ufs_print_super_stuff\n");
156 pr_debug(" magic: 0x%x\n", magic
);
157 if (fs32_to_cpu(sb
, usb3
->fs_magic
) == UFS2_MAGIC
) {
158 pr_debug(" fs_size: %llu\n", (unsigned long long)
159 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
));
160 pr_debug(" fs_dsize: %llu\n", (unsigned long long)
161 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
));
162 pr_debug(" bsize: %u\n",
163 fs32_to_cpu(sb
, usb1
->fs_bsize
));
164 pr_debug(" fsize: %u\n",
165 fs32_to_cpu(sb
, usb1
->fs_fsize
));
166 pr_debug(" fs_volname: %s\n", usb2
->fs_un
.fs_u2
.fs_volname
);
167 pr_debug(" fs_sblockloc: %llu\n", (unsigned long long)
168 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.fs_sblockloc
));
169 pr_debug(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
170 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
));
171 pr_debug(" cs_nbfree(No of free blocks): %llu\n",
173 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
));
174 pr_info(" cs_nifree(Num of free inodes): %llu\n",
176 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
));
177 pr_info(" cs_nffree(Num of free frags): %llu\n",
179 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
));
180 pr_info(" fs_maxsymlinklen: %u\n",
181 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
));
183 pr_debug(" sblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_sblkno
));
184 pr_debug(" cblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_cblkno
));
185 pr_debug(" iblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_iblkno
));
186 pr_debug(" dblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_dblkno
));
187 pr_debug(" cgoffset: %u\n",
188 fs32_to_cpu(sb
, usb1
->fs_cgoffset
));
189 pr_debug(" ~cgmask: 0x%x\n",
190 ~fs32_to_cpu(sb
, usb1
->fs_cgmask
));
191 pr_debug(" size: %u\n", fs32_to_cpu(sb
, usb1
->fs_size
));
192 pr_debug(" dsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_dsize
));
193 pr_debug(" ncg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ncg
));
194 pr_debug(" bsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_bsize
));
195 pr_debug(" fsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_fsize
));
196 pr_debug(" frag: %u\n", fs32_to_cpu(sb
, usb1
->fs_frag
));
197 pr_debug(" fragshift: %u\n",
198 fs32_to_cpu(sb
, usb1
->fs_fragshift
));
199 pr_debug(" ~fmask: %u\n", ~fs32_to_cpu(sb
, usb1
->fs_fmask
));
200 pr_debug(" fshift: %u\n", fs32_to_cpu(sb
, usb1
->fs_fshift
));
201 pr_debug(" sbsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_sbsize
));
202 pr_debug(" spc: %u\n", fs32_to_cpu(sb
, usb1
->fs_spc
));
203 pr_debug(" cpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_cpg
));
204 pr_debug(" ipg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ipg
));
205 pr_debug(" fpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_fpg
));
206 pr_debug(" csaddr: %u\n", fs32_to_cpu(sb
, usb1
->fs_csaddr
));
207 pr_debug(" cssize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cssize
));
208 pr_debug(" cgsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cgsize
));
209 pr_debug(" fstodb: %u\n",
210 fs32_to_cpu(sb
, usb1
->fs_fsbtodb
));
211 pr_debug(" nrpos: %u\n", fs32_to_cpu(sb
, usb3
->fs_nrpos
));
212 pr_debug(" ndir %u\n",
213 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
));
214 pr_debug(" nifree %u\n",
215 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
));
216 pr_debug(" nbfree %u\n",
217 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
));
218 pr_debug(" nffree %u\n",
219 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
));
225 * Print contents of ufs_cylinder_group, useful for debugging
227 static void ufs_print_cylinder_stuff(struct super_block
*sb
,
228 struct ufs_cylinder_group
*cg
)
230 pr_debug("\nufs_print_cylinder_stuff\n");
231 pr_debug("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group
));
232 pr_debug(" magic: %x\n", fs32_to_cpu(sb
, cg
->cg_magic
));
233 pr_debug(" time: %u\n", fs32_to_cpu(sb
, cg
->cg_time
));
234 pr_debug(" cgx: %u\n", fs32_to_cpu(sb
, cg
->cg_cgx
));
235 pr_debug(" ncyl: %u\n", fs16_to_cpu(sb
, cg
->cg_ncyl
));
236 pr_debug(" niblk: %u\n", fs16_to_cpu(sb
, cg
->cg_niblk
));
237 pr_debug(" ndblk: %u\n", fs32_to_cpu(sb
, cg
->cg_ndblk
));
238 pr_debug(" cs_ndir: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_ndir
));
239 pr_debug(" cs_nbfree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nbfree
));
240 pr_debug(" cs_nifree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nifree
));
241 pr_debug(" cs_nffree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nffree
));
242 pr_debug(" rotor: %u\n", fs32_to_cpu(sb
, cg
->cg_rotor
));
243 pr_debug(" frotor: %u\n", fs32_to_cpu(sb
, cg
->cg_frotor
));
244 pr_debug(" irotor: %u\n", fs32_to_cpu(sb
, cg
->cg_irotor
));
245 pr_debug(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
246 fs32_to_cpu(sb
, cg
->cg_frsum
[0]), fs32_to_cpu(sb
, cg
->cg_frsum
[1]),
247 fs32_to_cpu(sb
, cg
->cg_frsum
[2]), fs32_to_cpu(sb
, cg
->cg_frsum
[3]),
248 fs32_to_cpu(sb
, cg
->cg_frsum
[4]), fs32_to_cpu(sb
, cg
->cg_frsum
[5]),
249 fs32_to_cpu(sb
, cg
->cg_frsum
[6]), fs32_to_cpu(sb
, cg
->cg_frsum
[7]));
250 pr_debug(" btotoff: %u\n", fs32_to_cpu(sb
, cg
->cg_btotoff
));
251 pr_debug(" boff: %u\n", fs32_to_cpu(sb
, cg
->cg_boff
));
252 pr_debug(" iuseoff: %u\n", fs32_to_cpu(sb
, cg
->cg_iusedoff
));
253 pr_debug(" freeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_freeoff
));
254 pr_debug(" nextfreeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_nextfreeoff
));
255 pr_debug(" clustersumoff %u\n",
256 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clustersumoff
));
257 pr_debug(" clusteroff %u\n",
258 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clusteroff
));
259 pr_debug(" nclusterblks %u\n",
260 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_nclusterblks
));
264 # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
265 # define ufs_print_cylinder_stuff(sb, cg) /**/
266 #endif /* CONFIG_UFS_DEBUG */
268 static const struct super_operations ufs_super_ops
;
270 void ufs_error (struct super_block
* sb
, const char * function
,
271 const char * fmt
, ...)
273 struct ufs_sb_private_info
* uspi
;
274 struct ufs_super_block_first
* usb1
;
275 struct va_format vaf
;
278 uspi
= UFS_SB(sb
)->s_uspi
;
279 usb1
= ubh_get_usb_first(uspi
);
281 if (!(sb
->s_flags
& MS_RDONLY
)) {
282 usb1
->fs_clean
= UFS_FSBAD
;
283 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
284 ufs_mark_sb_dirty(sb
);
285 sb
->s_flags
|= MS_RDONLY
;
290 switch (UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_ONERROR
) {
291 case UFS_MOUNT_ONERROR_PANIC
:
292 panic("panic (device %s): %s: %pV\n",
293 sb
->s_id
, function
, &vaf
);
295 case UFS_MOUNT_ONERROR_LOCK
:
296 case UFS_MOUNT_ONERROR_UMOUNT
:
297 case UFS_MOUNT_ONERROR_REPAIR
:
298 pr_crit("error (device %s): %s: %pV\n",
299 sb
->s_id
, function
, &vaf
);
304 void ufs_panic (struct super_block
* sb
, const char * function
,
305 const char * fmt
, ...)
307 struct ufs_sb_private_info
* uspi
;
308 struct ufs_super_block_first
* usb1
;
309 struct va_format vaf
;
312 uspi
= UFS_SB(sb
)->s_uspi
;
313 usb1
= ubh_get_usb_first(uspi
);
315 if (!(sb
->s_flags
& MS_RDONLY
)) {
316 usb1
->fs_clean
= UFS_FSBAD
;
317 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
318 ufs_mark_sb_dirty(sb
);
323 sb
->s_flags
|= MS_RDONLY
;
324 pr_crit("panic (device %s): %s: %pV\n",
325 sb
->s_id
, function
, &vaf
);
329 void ufs_warning (struct super_block
* sb
, const char * function
,
330 const char * fmt
, ...)
332 struct va_format vaf
;
338 pr_warn("(device %s): %s: %pV\n",
339 sb
->s_id
, function
, &vaf
);
344 Opt_type_old
= UFS_MOUNT_UFSTYPE_OLD
,
345 Opt_type_sunx86
= UFS_MOUNT_UFSTYPE_SUNx86
,
346 Opt_type_sun
= UFS_MOUNT_UFSTYPE_SUN
,
347 Opt_type_sunos
= UFS_MOUNT_UFSTYPE_SUNOS
,
348 Opt_type_44bsd
= UFS_MOUNT_UFSTYPE_44BSD
,
349 Opt_type_ufs2
= UFS_MOUNT_UFSTYPE_UFS2
,
350 Opt_type_hp
= UFS_MOUNT_UFSTYPE_HP
,
351 Opt_type_nextstepcd
= UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
,
352 Opt_type_nextstep
= UFS_MOUNT_UFSTYPE_NEXTSTEP
,
353 Opt_type_openstep
= UFS_MOUNT_UFSTYPE_OPENSTEP
,
354 Opt_onerror_panic
= UFS_MOUNT_ONERROR_PANIC
,
355 Opt_onerror_lock
= UFS_MOUNT_ONERROR_LOCK
,
356 Opt_onerror_umount
= UFS_MOUNT_ONERROR_UMOUNT
,
357 Opt_onerror_repair
= UFS_MOUNT_ONERROR_REPAIR
,
361 static const match_table_t tokens
= {
362 {Opt_type_old
, "ufstype=old"},
363 {Opt_type_sunx86
, "ufstype=sunx86"},
364 {Opt_type_sun
, "ufstype=sun"},
365 {Opt_type_sunos
, "ufstype=sunos"},
366 {Opt_type_44bsd
, "ufstype=44bsd"},
367 {Opt_type_ufs2
, "ufstype=ufs2"},
368 {Opt_type_ufs2
, "ufstype=5xbsd"},
369 {Opt_type_hp
, "ufstype=hp"},
370 {Opt_type_nextstepcd
, "ufstype=nextstep-cd"},
371 {Opt_type_nextstep
, "ufstype=nextstep"},
372 {Opt_type_openstep
, "ufstype=openstep"},
373 /*end of possible ufs types */
374 {Opt_onerror_panic
, "onerror=panic"},
375 {Opt_onerror_lock
, "onerror=lock"},
376 {Opt_onerror_umount
, "onerror=umount"},
377 {Opt_onerror_repair
, "onerror=repair"},
381 static int ufs_parse_options (char * options
, unsigned * mount_options
)
390 while ((p
= strsep(&options
, ",")) != NULL
) {
391 substring_t args
[MAX_OPT_ARGS
];
396 token
= match_token(p
, tokens
, args
);
399 ufs_clear_opt (*mount_options
, UFSTYPE
);
400 ufs_set_opt (*mount_options
, UFSTYPE_OLD
);
402 case Opt_type_sunx86
:
403 ufs_clear_opt (*mount_options
, UFSTYPE
);
404 ufs_set_opt (*mount_options
, UFSTYPE_SUNx86
);
407 ufs_clear_opt (*mount_options
, UFSTYPE
);
408 ufs_set_opt (*mount_options
, UFSTYPE_SUN
);
411 ufs_clear_opt(*mount_options
, UFSTYPE
);
412 ufs_set_opt(*mount_options
, UFSTYPE_SUNOS
);
415 ufs_clear_opt (*mount_options
, UFSTYPE
);
416 ufs_set_opt (*mount_options
, UFSTYPE_44BSD
);
419 ufs_clear_opt(*mount_options
, UFSTYPE
);
420 ufs_set_opt(*mount_options
, UFSTYPE_UFS2
);
423 ufs_clear_opt (*mount_options
, UFSTYPE
);
424 ufs_set_opt (*mount_options
, UFSTYPE_HP
);
426 case Opt_type_nextstepcd
:
427 ufs_clear_opt (*mount_options
, UFSTYPE
);
428 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP_CD
);
430 case Opt_type_nextstep
:
431 ufs_clear_opt (*mount_options
, UFSTYPE
);
432 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP
);
434 case Opt_type_openstep
:
435 ufs_clear_opt (*mount_options
, UFSTYPE
);
436 ufs_set_opt (*mount_options
, UFSTYPE_OPENSTEP
);
438 case Opt_onerror_panic
:
439 ufs_clear_opt (*mount_options
, ONERROR
);
440 ufs_set_opt (*mount_options
, ONERROR_PANIC
);
442 case Opt_onerror_lock
:
443 ufs_clear_opt (*mount_options
, ONERROR
);
444 ufs_set_opt (*mount_options
, ONERROR_LOCK
);
446 case Opt_onerror_umount
:
447 ufs_clear_opt (*mount_options
, ONERROR
);
448 ufs_set_opt (*mount_options
, ONERROR_UMOUNT
);
450 case Opt_onerror_repair
:
451 pr_err("Unable to do repair on error, will lock lock instead\n");
452 ufs_clear_opt (*mount_options
, ONERROR
);
453 ufs_set_opt (*mount_options
, ONERROR_REPAIR
);
456 pr_err("Invalid option: \"%s\" or missing value\n", p
);
464 * Different types of UFS hold fs_cstotal in different
465 * places, and use different data structure for it.
466 * To make things simpler we just copy fs_cstotal to ufs_sb_private_info
468 static void ufs_setup_cstotal(struct super_block
*sb
)
470 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
471 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
472 struct ufs_super_block_first
*usb1
;
473 struct ufs_super_block_second
*usb2
;
474 struct ufs_super_block_third
*usb3
;
475 unsigned mtype
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
477 UFSD("ENTER, mtype=%u\n", mtype
);
478 usb1
= ubh_get_usb_first(uspi
);
479 usb2
= ubh_get_usb_second(uspi
);
480 usb3
= ubh_get_usb_third(uspi
);
482 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
483 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
484 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
485 /*we have statistic in different place, then usual*/
486 uspi
->cs_total
.cs_ndir
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
);
487 uspi
->cs_total
.cs_nbfree
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
);
488 uspi
->cs_total
.cs_nifree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
);
489 uspi
->cs_total
.cs_nffree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
);
491 uspi
->cs_total
.cs_ndir
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
);
492 uspi
->cs_total
.cs_nbfree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
);
493 uspi
->cs_total
.cs_nifree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
);
494 uspi
->cs_total
.cs_nffree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
);
500 * Read on-disk structures associated with cylinder groups
502 static int ufs_read_cylinder_structures(struct super_block
*sb
)
504 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
505 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
506 struct ufs_buffer_head
* ubh
;
507 unsigned char * base
, * space
;
508 unsigned size
, blks
, i
;
513 * Read cs structures from (usually) first data block
516 size
= uspi
->s_cssize
;
517 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
518 base
= space
= kmalloc(size
, GFP_NOFS
);
521 sbi
->s_csp
= (struct ufs_csum
*)space
;
522 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
523 size
= uspi
->s_bsize
;
524 if (i
+ uspi
->s_fpb
> blks
)
525 size
= (blks
- i
) * uspi
->s_fsize
;
527 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
532 ubh_ubhcpymem (space
, ubh
, size
);
540 * Read cylinder group (we read only first fragment from block
541 * at this time) and prepare internal data structures for cg caching.
543 if (!(sbi
->s_ucg
= kmalloc (sizeof(struct buffer_head
*) * uspi
->s_ncg
, GFP_NOFS
)))
545 for (i
= 0; i
< uspi
->s_ncg
; i
++)
546 sbi
->s_ucg
[i
] = NULL
;
547 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
548 sbi
->s_ucpi
[i
] = NULL
;
549 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
551 for (i
= 0; i
< uspi
->s_ncg
; i
++) {
552 UFSD("read cg %u\n", i
);
553 if (!(sbi
->s_ucg
[i
] = sb_bread(sb
, ufs_cgcmin(i
))))
555 if (!ufs_cg_chkmagic (sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
))
558 ufs_print_cylinder_stuff(sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
);
560 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
561 if (!(sbi
->s_ucpi
[i
] = kmalloc (sizeof(struct ufs_cg_private_info
), GFP_NOFS
)))
563 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
565 sbi
->s_cg_loaded
= 0;
572 for (i
= 0; i
< uspi
->s_ncg
; i
++)
574 brelse (sbi
->s_ucg
[i
]);
576 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++)
577 kfree (sbi
->s_ucpi
[i
]);
579 UFSD("EXIT (FAILED)\n");
584 * Sync our internal copy of fs_cstotal with disk
586 static void ufs_put_cstotal(struct super_block
*sb
)
588 unsigned mtype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
589 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
590 struct ufs_super_block_first
*usb1
;
591 struct ufs_super_block_second
*usb2
;
592 struct ufs_super_block_third
*usb3
;
595 usb1
= ubh_get_usb_first(uspi
);
596 usb2
= ubh_get_usb_second(uspi
);
597 usb3
= ubh_get_usb_third(uspi
);
599 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
600 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
601 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
602 /*we have statistic in different place, then usual*/
603 usb2
->fs_un
.fs_u2
.cs_ndir
=
604 cpu_to_fs64(sb
, uspi
->cs_total
.cs_ndir
);
605 usb2
->fs_un
.fs_u2
.cs_nbfree
=
606 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nbfree
);
607 usb3
->fs_un1
.fs_u2
.cs_nifree
=
608 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nifree
);
609 usb3
->fs_un1
.fs_u2
.cs_nffree
=
610 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nffree
);
612 usb1
->fs_cstotal
.cs_ndir
=
613 cpu_to_fs32(sb
, uspi
->cs_total
.cs_ndir
);
614 usb1
->fs_cstotal
.cs_nbfree
=
615 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nbfree
);
616 usb1
->fs_cstotal
.cs_nifree
=
617 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nifree
);
618 usb1
->fs_cstotal
.cs_nffree
=
619 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nffree
);
621 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
622 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
627 * ufs_put_super_internal() - put on-disk intrenal structures
628 * @sb: pointer to super_block structure
629 * Put on-disk structures associated with cylinder groups
630 * and write them back to disk, also update cs_total on disk
632 static void ufs_put_super_internal(struct super_block
*sb
)
634 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
635 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
636 struct ufs_buffer_head
* ubh
;
637 unsigned char * base
, * space
;
638 unsigned blks
, size
, i
;
644 size
= uspi
->s_cssize
;
645 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
646 base
= space
= (char*) sbi
->s_csp
;
647 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
648 size
= uspi
->s_bsize
;
649 if (i
+ uspi
->s_fpb
> blks
)
650 size
= (blks
- i
) * uspi
->s_fsize
;
652 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
654 ubh_memcpyubh (ubh
, space
, size
);
656 ubh_mark_buffer_uptodate (ubh
, 1);
657 ubh_mark_buffer_dirty (ubh
);
660 for (i
= 0; i
< sbi
->s_cg_loaded
; i
++) {
661 ufs_put_cylinder (sb
, i
);
662 kfree (sbi
->s_ucpi
[i
]);
664 for (; i
< UFS_MAX_GROUP_LOADED
; i
++)
665 kfree (sbi
->s_ucpi
[i
]);
666 for (i
= 0; i
< uspi
->s_ncg
; i
++)
667 brelse (sbi
->s_ucg
[i
]);
674 static int ufs_sync_fs(struct super_block
*sb
, int wait
)
676 struct ufs_sb_private_info
* uspi
;
677 struct ufs_super_block_first
* usb1
;
678 struct ufs_super_block_third
* usb3
;
681 mutex_lock(&UFS_SB(sb
)->s_lock
);
685 flags
= UFS_SB(sb
)->s_flags
;
686 uspi
= UFS_SB(sb
)->s_uspi
;
687 usb1
= ubh_get_usb_first(uspi
);
688 usb3
= ubh_get_usb_third(uspi
);
690 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
691 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
692 (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
||
693 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
694 ufs_set_fs_state(sb
, usb1
, usb3
,
695 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
699 mutex_unlock(&UFS_SB(sb
)->s_lock
);
704 static void delayed_sync_fs(struct work_struct
*work
)
706 struct ufs_sb_info
*sbi
;
708 sbi
= container_of(work
, struct ufs_sb_info
, sync_work
.work
);
710 spin_lock(&sbi
->work_lock
);
711 sbi
->work_queued
= 0;
712 spin_unlock(&sbi
->work_lock
);
714 ufs_sync_fs(sbi
->sb
, 1);
717 void ufs_mark_sb_dirty(struct super_block
*sb
)
719 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
722 spin_lock(&sbi
->work_lock
);
723 if (!sbi
->work_queued
) {
724 delay
= msecs_to_jiffies(dirty_writeback_interval
* 10);
725 queue_delayed_work(system_long_wq
, &sbi
->sync_work
, delay
);
726 sbi
->work_queued
= 1;
728 spin_unlock(&sbi
->work_lock
);
731 static void ufs_put_super(struct super_block
*sb
)
733 struct ufs_sb_info
* sbi
= UFS_SB(sb
);
737 if (!(sb
->s_flags
& MS_RDONLY
))
738 ufs_put_super_internal(sb
);
739 cancel_delayed_work_sync(&sbi
->sync_work
);
741 ubh_brelse_uspi (sbi
->s_uspi
);
744 sb
->s_fs_info
= NULL
;
749 static u64
ufs_max_bytes(struct super_block
*sb
)
751 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
752 int bits
= uspi
->s_apbshift
;
758 res
= UFS_NDADDR
+ (1LL << bits
) + (1LL << (2*bits
)) +
761 if (res
>= (MAX_LFS_FILESIZE
>> uspi
->s_bshift
))
762 return MAX_LFS_FILESIZE
;
763 return res
<< uspi
->s_bshift
;
766 static int ufs_fill_super(struct super_block
*sb
, void *data
, int silent
)
768 struct ufs_sb_info
* sbi
;
769 struct ufs_sb_private_info
* uspi
;
770 struct ufs_super_block_first
* usb1
;
771 struct ufs_super_block_second
* usb2
;
772 struct ufs_super_block_third
* usb3
;
773 struct ufs_buffer_head
* ubh
;
775 unsigned block_size
, super_block_size
;
777 unsigned super_block_offset
;
787 #ifndef CONFIG_UFS_FS_WRITE
788 if (!(sb
->s_flags
& MS_RDONLY
)) {
789 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
794 sbi
= kzalloc(sizeof(struct ufs_sb_info
), GFP_KERNEL
);
800 UFSD("flag %u\n", (int)(sb
->s_flags
& MS_RDONLY
));
802 mutex_init(&sbi
->s_lock
);
803 spin_lock_init(&sbi
->work_lock
);
804 INIT_DELAYED_WORK(&sbi
->sync_work
, delayed_sync_fs
);
806 * Set default mount options
807 * Parse mount options
809 sbi
->s_mount_opt
= 0;
810 ufs_set_opt (sbi
->s_mount_opt
, ONERROR_LOCK
);
811 if (!ufs_parse_options ((char *) data
, &sbi
->s_mount_opt
)) {
812 pr_err("wrong mount options\n");
815 if (!(sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
817 pr_err("You didn't specify the type of your ufs filesystem\n\n"
818 "mount -t ufs -o ufstype="
819 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
820 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
821 "default is ufstype=old\n");
822 ufs_set_opt (sbi
->s_mount_opt
, UFSTYPE_OLD
);
825 uspi
= kzalloc(sizeof(struct ufs_sb_private_info
), GFP_KERNEL
);
829 uspi
->s_dirblksize
= UFS_SECTOR_SIZE
;
830 super_block_offset
=UFS_SBLOCK
;
832 /* Keep 2Gig file limit. Some UFS variants need to override
833 this but as I don't know which I'll let those in the know loosen
835 switch (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) {
836 case UFS_MOUNT_UFSTYPE_44BSD
:
837 UFSD("ufstype=44bsd\n");
838 uspi
->s_fsize
= block_size
= 512;
839 uspi
->s_fmask
= ~(512 - 1);
841 uspi
->s_sbsize
= super_block_size
= 1536;
843 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
845 case UFS_MOUNT_UFSTYPE_UFS2
:
846 UFSD("ufstype=ufs2\n");
847 super_block_offset
=SBLOCK_UFS2
;
848 uspi
->s_fsize
= block_size
= 512;
849 uspi
->s_fmask
= ~(512 - 1);
851 uspi
->s_sbsize
= super_block_size
= 1536;
853 flags
|= UFS_TYPE_UFS2
| UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
856 case UFS_MOUNT_UFSTYPE_SUN
:
857 UFSD("ufstype=sun\n");
858 uspi
->s_fsize
= block_size
= 1024;
859 uspi
->s_fmask
= ~(1024 - 1);
861 uspi
->s_sbsize
= super_block_size
= 2048;
863 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
864 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUN
| UFS_CG_SUN
;
867 case UFS_MOUNT_UFSTYPE_SUNOS
:
868 UFSD("ufstype=sunos\n");
869 uspi
->s_fsize
= block_size
= 1024;
870 uspi
->s_fmask
= ~(1024 - 1);
872 uspi
->s_sbsize
= 2048;
873 super_block_size
= 2048;
875 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
876 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_SUNOS
| UFS_CG_SUN
;
879 case UFS_MOUNT_UFSTYPE_SUNx86
:
880 UFSD("ufstype=sunx86\n");
881 uspi
->s_fsize
= block_size
= 1024;
882 uspi
->s_fmask
= ~(1024 - 1);
884 uspi
->s_sbsize
= super_block_size
= 2048;
886 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
887 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUNx86
| UFS_CG_SUN
;
890 case UFS_MOUNT_UFSTYPE_OLD
:
891 UFSD("ufstype=old\n");
892 uspi
->s_fsize
= block_size
= 1024;
893 uspi
->s_fmask
= ~(1024 - 1);
895 uspi
->s_sbsize
= super_block_size
= 2048;
897 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
898 if (!(sb
->s_flags
& MS_RDONLY
)) {
900 pr_info("ufstype=old is supported read-only\n");
901 sb
->s_flags
|= MS_RDONLY
;
905 case UFS_MOUNT_UFSTYPE_NEXTSTEP
:
906 UFSD("ufstype=nextstep\n");
907 uspi
->s_fsize
= block_size
= 1024;
908 uspi
->s_fmask
= ~(1024 - 1);
910 uspi
->s_sbsize
= super_block_size
= 2048;
912 uspi
->s_dirblksize
= 1024;
913 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
914 if (!(sb
->s_flags
& MS_RDONLY
)) {
916 pr_info("ufstype=nextstep is supported read-only\n");
917 sb
->s_flags
|= MS_RDONLY
;
921 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
:
922 UFSD("ufstype=nextstep-cd\n");
923 uspi
->s_fsize
= block_size
= 2048;
924 uspi
->s_fmask
= ~(2048 - 1);
926 uspi
->s_sbsize
= super_block_size
= 2048;
928 uspi
->s_dirblksize
= 1024;
929 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
930 if (!(sb
->s_flags
& MS_RDONLY
)) {
932 pr_info("ufstype=nextstep-cd is supported read-only\n");
933 sb
->s_flags
|= MS_RDONLY
;
937 case UFS_MOUNT_UFSTYPE_OPENSTEP
:
938 UFSD("ufstype=openstep\n");
939 uspi
->s_fsize
= block_size
= 1024;
940 uspi
->s_fmask
= ~(1024 - 1);
942 uspi
->s_sbsize
= super_block_size
= 2048;
944 uspi
->s_dirblksize
= 1024;
945 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
946 if (!(sb
->s_flags
& MS_RDONLY
)) {
948 pr_info("ufstype=openstep is supported read-only\n");
949 sb
->s_flags
|= MS_RDONLY
;
953 case UFS_MOUNT_UFSTYPE_HP
:
954 UFSD("ufstype=hp\n");
955 uspi
->s_fsize
= block_size
= 1024;
956 uspi
->s_fmask
= ~(1024 - 1);
958 uspi
->s_sbsize
= super_block_size
= 2048;
960 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
961 if (!(sb
->s_flags
& MS_RDONLY
)) {
963 pr_info("ufstype=hp is supported read-only\n");
964 sb
->s_flags
|= MS_RDONLY
;
969 pr_err("unknown ufstype\n");
974 if (!sb_set_blocksize(sb
, block_size
)) {
975 pr_err("failed to set blocksize\n");
980 * read ufs super block from device
983 ubh
= ubh_bread_uspi(uspi
, sb
, uspi
->s_sbbase
+ super_block_offset
/block_size
, super_block_size
);
988 usb1
= ubh_get_usb_first(uspi
);
989 usb2
= ubh_get_usb_second(uspi
);
990 usb3
= ubh_get_usb_third(uspi
);
992 /* Sort out mod used on SunOS 4.1.3 for fs_state */
993 uspi
->s_postblformat
= fs32_to_cpu(sb
, usb3
->fs_postblformat
);
994 if (((flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
) &&
995 (uspi
->s_postblformat
!= UFS_42POSTBLFMT
)) {
996 flags
&= ~UFS_ST_MASK
;
1001 * Check ufs magic number
1003 sbi
->s_bytesex
= BYTESEX_LE
;
1004 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
1013 sbi
->s_bytesex
= BYTESEX_BE
;
1014 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
1024 if ((((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP
)
1025 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
)
1026 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_OPENSTEP
))
1027 && uspi
->s_sbbase
< 256) {
1028 ubh_brelse_uspi(uspi
);
1030 uspi
->s_sbbase
+= 8;
1034 pr_err("%s(): bad magic number\n", __func__
);
1039 * Check block and fragment sizes
1041 uspi
->s_bsize
= fs32_to_cpu(sb
, usb1
->fs_bsize
);
1042 uspi
->s_fsize
= fs32_to_cpu(sb
, usb1
->fs_fsize
);
1043 uspi
->s_sbsize
= fs32_to_cpu(sb
, usb1
->fs_sbsize
);
1044 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
1045 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
1047 if (!is_power_of_2(uspi
->s_fsize
)) {
1048 pr_err("%s(): fragment size %u is not a power of 2\n",
1049 __func__
, uspi
->s_fsize
);
1052 if (uspi
->s_fsize
< 512) {
1053 pr_err("%s(): fragment size %u is too small\n",
1054 __func__
, uspi
->s_fsize
);
1057 if (uspi
->s_fsize
> 4096) {
1058 pr_err("%s(): fragment size %u is too large\n",
1059 __func__
, uspi
->s_fsize
);
1062 if (!is_power_of_2(uspi
->s_bsize
)) {
1063 pr_err("%s(): block size %u is not a power of 2\n",
1064 __func__
, uspi
->s_bsize
);
1067 if (uspi
->s_bsize
< 4096) {
1068 pr_err("%s(): block size %u is too small\n",
1069 __func__
, uspi
->s_bsize
);
1072 if (uspi
->s_bsize
/ uspi
->s_fsize
> 8) {
1073 pr_err("%s(): too many fragments per block (%u)\n",
1074 __func__
, uspi
->s_bsize
/ uspi
->s_fsize
);
1077 if (uspi
->s_fsize
!= block_size
|| uspi
->s_sbsize
!= super_block_size
) {
1078 ubh_brelse_uspi(uspi
);
1080 block_size
= uspi
->s_fsize
;
1081 super_block_size
= uspi
->s_sbsize
;
1082 UFSD("another value of block_size or super_block_size %u, %u\n", block_size
, super_block_size
);
1086 sbi
->s_flags
= flags
;/*after that line some functions use s_flags*/
1087 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
1090 * Check, if file system was correctly unmounted.
1091 * If not, make it read only.
1093 if (((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
) ||
1094 ((flags
& UFS_ST_MASK
) == UFS_ST_OLD
) ||
1095 (((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
1096 (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
||
1097 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
) &&
1098 (ufs_get_fs_state(sb
, usb1
, usb3
) == (UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
))))) {
1099 switch(usb1
->fs_clean
) {
1101 UFSD("fs is clean\n");
1104 UFSD("fs is stable\n");
1107 UFSD("fs is logging fs\n");
1110 UFSD("fs is DEC OSF/1\n");
1113 pr_err("%s(): fs is active\n", __func__
);
1114 sb
->s_flags
|= MS_RDONLY
;
1117 pr_err("%s(): fs is bad\n", __func__
);
1118 sb
->s_flags
|= MS_RDONLY
;
1121 pr_err("%s(): can't grok fs_clean 0x%x\n",
1122 __func__
, usb1
->fs_clean
);
1123 sb
->s_flags
|= MS_RDONLY
;
1127 pr_err("%s(): fs needs fsck\n", __func__
);
1128 sb
->s_flags
|= MS_RDONLY
;
1132 * Read ufs_super_block into internal data structures
1134 sb
->s_op
= &ufs_super_ops
;
1135 sb
->s_export_op
= &ufs_export_ops
;
1137 sb
->s_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
1139 uspi
->s_sblkno
= fs32_to_cpu(sb
, usb1
->fs_sblkno
);
1140 uspi
->s_cblkno
= fs32_to_cpu(sb
, usb1
->fs_cblkno
);
1141 uspi
->s_iblkno
= fs32_to_cpu(sb
, usb1
->fs_iblkno
);
1142 uspi
->s_dblkno
= fs32_to_cpu(sb
, usb1
->fs_dblkno
);
1143 uspi
->s_cgoffset
= fs32_to_cpu(sb
, usb1
->fs_cgoffset
);
1144 uspi
->s_cgmask
= fs32_to_cpu(sb
, usb1
->fs_cgmask
);
1146 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1147 uspi
->s_u2_size
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
);
1148 uspi
->s_u2_dsize
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1150 uspi
->s_size
= fs32_to_cpu(sb
, usb1
->fs_size
);
1151 uspi
->s_dsize
= fs32_to_cpu(sb
, usb1
->fs_dsize
);
1154 uspi
->s_ncg
= fs32_to_cpu(sb
, usb1
->fs_ncg
);
1155 /* s_bsize already set */
1156 /* s_fsize already set */
1157 uspi
->s_fpb
= fs32_to_cpu(sb
, usb1
->fs_frag
);
1158 uspi
->s_minfree
= fs32_to_cpu(sb
, usb1
->fs_minfree
);
1159 uspi
->s_bmask
= fs32_to_cpu(sb
, usb1
->fs_bmask
);
1160 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
1161 uspi
->s_bshift
= fs32_to_cpu(sb
, usb1
->fs_bshift
);
1162 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
1163 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi
->s_bshift
,
1165 uspi
->s_fpbshift
= fs32_to_cpu(sb
, usb1
->fs_fragshift
);
1166 uspi
->s_fsbtodb
= fs32_to_cpu(sb
, usb1
->fs_fsbtodb
);
1167 /* s_sbsize already set */
1168 uspi
->s_csmask
= fs32_to_cpu(sb
, usb1
->fs_csmask
);
1169 uspi
->s_csshift
= fs32_to_cpu(sb
, usb1
->fs_csshift
);
1170 uspi
->s_nindir
= fs32_to_cpu(sb
, usb1
->fs_nindir
);
1171 uspi
->s_inopb
= fs32_to_cpu(sb
, usb1
->fs_inopb
);
1172 uspi
->s_nspf
= fs32_to_cpu(sb
, usb1
->fs_nspf
);
1173 uspi
->s_npsect
= ufs_get_fs_npsect(sb
, usb1
, usb3
);
1174 uspi
->s_interleave
= fs32_to_cpu(sb
, usb1
->fs_interleave
);
1175 uspi
->s_trackskew
= fs32_to_cpu(sb
, usb1
->fs_trackskew
);
1177 if (uspi
->fs_magic
== UFS2_MAGIC
)
1178 uspi
->s_csaddr
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_csaddr
);
1180 uspi
->s_csaddr
= fs32_to_cpu(sb
, usb1
->fs_csaddr
);
1182 uspi
->s_cssize
= fs32_to_cpu(sb
, usb1
->fs_cssize
);
1183 uspi
->s_cgsize
= fs32_to_cpu(sb
, usb1
->fs_cgsize
);
1184 uspi
->s_ntrak
= fs32_to_cpu(sb
, usb1
->fs_ntrak
);
1185 uspi
->s_nsect
= fs32_to_cpu(sb
, usb1
->fs_nsect
);
1186 uspi
->s_spc
= fs32_to_cpu(sb
, usb1
->fs_spc
);
1187 uspi
->s_ipg
= fs32_to_cpu(sb
, usb1
->fs_ipg
);
1188 uspi
->s_fpg
= fs32_to_cpu(sb
, usb1
->fs_fpg
);
1189 uspi
->s_cpc
= fs32_to_cpu(sb
, usb2
->fs_un
.fs_u1
.fs_cpc
);
1190 uspi
->s_contigsumsize
= fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_contigsumsize
);
1191 uspi
->s_qbmask
= ufs_get_fs_qbmask(sb
, usb3
);
1192 uspi
->s_qfmask
= ufs_get_fs_qfmask(sb
, usb3
);
1193 uspi
->s_nrpos
= fs32_to_cpu(sb
, usb3
->fs_nrpos
);
1194 uspi
->s_postbloff
= fs32_to_cpu(sb
, usb3
->fs_postbloff
);
1195 uspi
->s_rotbloff
= fs32_to_cpu(sb
, usb3
->fs_rotbloff
);
1198 * Compute another frequently used values
1200 uspi
->s_fpbmask
= uspi
->s_fpb
- 1;
1201 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
1202 uspi
->s_apbshift
= uspi
->s_bshift
- 3;
1204 uspi
->s_apbshift
= uspi
->s_bshift
- 2;
1206 uspi
->s_2apbshift
= uspi
->s_apbshift
* 2;
1207 uspi
->s_3apbshift
= uspi
->s_apbshift
* 3;
1208 uspi
->s_apb
= 1 << uspi
->s_apbshift
;
1209 uspi
->s_2apb
= 1 << uspi
->s_2apbshift
;
1210 uspi
->s_3apb
= 1 << uspi
->s_3apbshift
;
1211 uspi
->s_apbmask
= uspi
->s_apb
- 1;
1212 uspi
->s_nspfshift
= uspi
->s_fshift
- UFS_SECTOR_BITS
;
1213 uspi
->s_nspb
= uspi
->s_nspf
<< uspi
->s_fpbshift
;
1214 uspi
->s_inopf
= uspi
->s_inopb
>> uspi
->s_fpbshift
;
1215 uspi
->s_bpf
= uspi
->s_fsize
<< 3;
1216 uspi
->s_bpfshift
= uspi
->s_fshift
+ 3;
1217 uspi
->s_bpfmask
= uspi
->s_bpf
- 1;
1218 if ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_44BSD
||
1219 (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_UFS2
)
1220 uspi
->s_maxsymlinklen
=
1221 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
);
1223 if (uspi
->fs_magic
== UFS2_MAGIC
)
1224 maxsymlen
= 2 * 4 * (UFS_NDADDR
+ UFS_NINDIR
);
1226 maxsymlen
= 4 * (UFS_NDADDR
+ UFS_NINDIR
);
1227 if (uspi
->s_maxsymlinklen
> maxsymlen
) {
1228 ufs_warning(sb
, __func__
, "ufs_read_super: excessive maximum "
1229 "fast symlink size (%u)\n", uspi
->s_maxsymlinklen
);
1230 uspi
->s_maxsymlinklen
= maxsymlen
;
1232 sb
->s_maxbytes
= ufs_max_bytes(sb
);
1233 sb
->s_max_links
= UFS_LINK_MAX
;
1235 inode
= ufs_iget(sb
, UFS_ROOTINO
);
1236 if (IS_ERR(inode
)) {
1237 ret
= PTR_ERR(inode
);
1240 sb
->s_root
= d_make_root(inode
);
1246 ufs_setup_cstotal(sb
);
1248 * Read cylinder group structures
1250 if (!(sb
->s_flags
& MS_RDONLY
))
1251 if (!ufs_read_cylinder_structures(sb
))
1259 ubh_brelse_uspi (uspi
);
1262 sb
->s_fs_info
= NULL
;
1263 UFSD("EXIT (FAILED)\n");
1267 UFSD("EXIT (NOMEM)\n");
1271 static int ufs_remount (struct super_block
*sb
, int *mount_flags
, char *data
)
1273 struct ufs_sb_private_info
* uspi
;
1274 struct ufs_super_block_first
* usb1
;
1275 struct ufs_super_block_third
* usb3
;
1276 unsigned new_mount_opt
, ufstype
;
1279 sync_filesystem(sb
);
1280 mutex_lock(&UFS_SB(sb
)->s_lock
);
1281 uspi
= UFS_SB(sb
)->s_uspi
;
1282 flags
= UFS_SB(sb
)->s_flags
;
1283 usb1
= ubh_get_usb_first(uspi
);
1284 usb3
= ubh_get_usb_third(uspi
);
1287 * Allow the "check" option to be passed as a remount option.
1288 * It is not possible to change ufstype option during remount
1290 ufstype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1292 ufs_set_opt (new_mount_opt
, ONERROR_LOCK
);
1293 if (!ufs_parse_options (data
, &new_mount_opt
)) {
1294 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1297 if (!(new_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
1298 new_mount_opt
|= ufstype
;
1299 } else if ((new_mount_opt
& UFS_MOUNT_UFSTYPE
) != ufstype
) {
1300 pr_err("ufstype can't be changed during remount\n");
1301 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1305 if ((*mount_flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
)) {
1306 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1307 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1312 * fs was mouted as rw, remounting ro
1314 if (*mount_flags
& MS_RDONLY
) {
1315 ufs_put_super_internal(sb
);
1316 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1317 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1318 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
1319 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1320 ufs_set_fs_state(sb
, usb1
, usb3
,
1321 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1322 ubh_mark_buffer_dirty (USPI_UBH(uspi
));
1323 sb
->s_flags
|= MS_RDONLY
;
1326 * fs was mounted as ro, remounting rw
1328 #ifndef CONFIG_UFS_FS_WRITE
1329 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
1330 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1333 if (ufstype
!= UFS_MOUNT_UFSTYPE_SUN
&&
1334 ufstype
!= UFS_MOUNT_UFSTYPE_SUNOS
&&
1335 ufstype
!= UFS_MOUNT_UFSTYPE_44BSD
&&
1336 ufstype
!= UFS_MOUNT_UFSTYPE_SUNx86
&&
1337 ufstype
!= UFS_MOUNT_UFSTYPE_UFS2
) {
1338 pr_err("this ufstype is read-only supported\n");
1339 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1342 if (!ufs_read_cylinder_structures(sb
)) {
1343 pr_err("failed during remounting\n");
1344 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1347 sb
->s_flags
&= ~MS_RDONLY
;
1350 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1351 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1355 static int ufs_show_options(struct seq_file
*seq
, struct dentry
*root
)
1357 struct ufs_sb_info
*sbi
= UFS_SB(root
->d_sb
);
1358 unsigned mval
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1359 const struct match_token
*tp
= tokens
;
1361 while (tp
->token
!= Opt_onerror_panic
&& tp
->token
!= mval
)
1363 BUG_ON(tp
->token
== Opt_onerror_panic
);
1364 seq_printf(seq
, ",%s", tp
->pattern
);
1366 mval
= sbi
->s_mount_opt
& UFS_MOUNT_ONERROR
;
1367 while (tp
->token
!= Opt_err
&& tp
->token
!= mval
)
1369 BUG_ON(tp
->token
== Opt_err
);
1370 seq_printf(seq
, ",%s", tp
->pattern
);
1375 static int ufs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1377 struct super_block
*sb
= dentry
->d_sb
;
1378 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
1379 unsigned flags
= UFS_SB(sb
)->s_flags
;
1380 struct ufs_super_block_third
*usb3
;
1381 u64 id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
1383 mutex_lock(&UFS_SB(sb
)->s_lock
);
1384 usb3
= ubh_get_usb_third(uspi
);
1386 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1387 buf
->f_type
= UFS2_MAGIC
;
1388 buf
->f_blocks
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1390 buf
->f_type
= UFS_MAGIC
;
1391 buf
->f_blocks
= uspi
->s_dsize
;
1393 buf
->f_bfree
= ufs_blkstofrags(uspi
->cs_total
.cs_nbfree
) +
1394 uspi
->cs_total
.cs_nffree
;
1395 buf
->f_ffree
= uspi
->cs_total
.cs_nifree
;
1396 buf
->f_bsize
= sb
->s_blocksize
;
1397 buf
->f_bavail
= (buf
->f_bfree
> (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
))
1398 ? (buf
->f_bfree
- (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
)) : 0;
1399 buf
->f_files
= uspi
->s_ncg
* uspi
->s_ipg
;
1400 buf
->f_namelen
= UFS_MAXNAMLEN
;
1401 buf
->f_fsid
.val
[0] = (u32
)id
;
1402 buf
->f_fsid
.val
[1] = (u32
)(id
>> 32);
1404 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1409 static struct kmem_cache
* ufs_inode_cachep
;
1411 static struct inode
*ufs_alloc_inode(struct super_block
*sb
)
1413 struct ufs_inode_info
*ei
;
1415 ei
= kmem_cache_alloc(ufs_inode_cachep
, GFP_NOFS
);
1419 ei
->vfs_inode
.i_version
= 1;
1420 seqlock_init(&ei
->meta_lock
);
1421 mutex_init(&ei
->truncate_mutex
);
1422 return &ei
->vfs_inode
;
1425 static void ufs_i_callback(struct rcu_head
*head
)
1427 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
1428 kmem_cache_free(ufs_inode_cachep
, UFS_I(inode
));
1431 static void ufs_destroy_inode(struct inode
*inode
)
1433 call_rcu(&inode
->i_rcu
, ufs_i_callback
);
1436 static void init_once(void *foo
)
1438 struct ufs_inode_info
*ei
= (struct ufs_inode_info
*) foo
;
1440 inode_init_once(&ei
->vfs_inode
);
1443 static int __init
init_inodecache(void)
1445 ufs_inode_cachep
= kmem_cache_create("ufs_inode_cache",
1446 sizeof(struct ufs_inode_info
),
1447 0, (SLAB_RECLAIM_ACCOUNT
|
1450 if (ufs_inode_cachep
== NULL
)
1455 static void destroy_inodecache(void)
1458 * Make sure all delayed rcu free inodes are flushed before we
1462 kmem_cache_destroy(ufs_inode_cachep
);
1465 static const struct super_operations ufs_super_ops
= {
1466 .alloc_inode
= ufs_alloc_inode
,
1467 .destroy_inode
= ufs_destroy_inode
,
1468 .write_inode
= ufs_write_inode
,
1469 .evict_inode
= ufs_evict_inode
,
1470 .put_super
= ufs_put_super
,
1471 .sync_fs
= ufs_sync_fs
,
1472 .statfs
= ufs_statfs
,
1473 .remount_fs
= ufs_remount
,
1474 .show_options
= ufs_show_options
,
1477 static struct dentry
*ufs_mount(struct file_system_type
*fs_type
,
1478 int flags
, const char *dev_name
, void *data
)
1480 return mount_bdev(fs_type
, flags
, dev_name
, data
, ufs_fill_super
);
1483 static struct file_system_type ufs_fs_type
= {
1484 .owner
= THIS_MODULE
,
1487 .kill_sb
= kill_block_super
,
1488 .fs_flags
= FS_REQUIRES_DEV
,
1490 MODULE_ALIAS_FS("ufs");
1492 static int __init
init_ufs_fs(void)
1494 int err
= init_inodecache();
1497 err
= register_filesystem(&ufs_fs_type
);
1502 destroy_inodecache();
1507 static void __exit
exit_ufs_fs(void)
1509 unregister_filesystem(&ufs_fs_type
);
1510 destroy_inodecache();
1513 module_init(init_ufs_fs
)
1514 module_exit(exit_ufs_fs
)
1515 MODULE_LICENSE("GPL");