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 <linux/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>
91 #include <linux/iversion.h>
98 static struct inode
*ufs_nfs_get_inode(struct super_block
*sb
, u64 ino
, u32 generation
)
100 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
103 if (ino
< UFS_ROOTINO
|| ino
> uspi
->s_ncg
* uspi
->s_ipg
)
104 return ERR_PTR(-ESTALE
);
106 inode
= ufs_iget(sb
, ino
);
108 return ERR_CAST(inode
);
109 if (generation
&& inode
->i_generation
!= generation
) {
111 return ERR_PTR(-ESTALE
);
116 static struct dentry
*ufs_fh_to_dentry(struct super_block
*sb
, struct fid
*fid
,
117 int fh_len
, int fh_type
)
119 return generic_fh_to_dentry(sb
, fid
, fh_len
, fh_type
, ufs_nfs_get_inode
);
122 static struct dentry
*ufs_fh_to_parent(struct super_block
*sb
, struct fid
*fid
,
123 int fh_len
, int fh_type
)
125 return generic_fh_to_parent(sb
, fid
, fh_len
, fh_type
, ufs_nfs_get_inode
);
128 static struct dentry
*ufs_get_parent(struct dentry
*child
)
130 struct qstr dot_dot
= QSTR_INIT("..", 2);
133 ino
= ufs_inode_by_name(d_inode(child
), &dot_dot
);
135 return ERR_PTR(-ENOENT
);
136 return d_obtain_alias(ufs_iget(child
->d_sb
, ino
));
139 static const struct export_operations ufs_export_ops
= {
140 .fh_to_dentry
= ufs_fh_to_dentry
,
141 .fh_to_parent
= ufs_fh_to_parent
,
142 .get_parent
= ufs_get_parent
,
145 #ifdef CONFIG_UFS_DEBUG
147 * Print contents of ufs_super_block, useful for debugging
149 static void ufs_print_super_stuff(struct super_block
*sb
,
150 struct ufs_super_block_first
*usb1
,
151 struct ufs_super_block_second
*usb2
,
152 struct ufs_super_block_third
*usb3
)
154 u32 magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
156 pr_debug("ufs_print_super_stuff\n");
157 pr_debug(" magic: 0x%x\n", magic
);
158 if (fs32_to_cpu(sb
, usb3
->fs_magic
) == UFS2_MAGIC
) {
159 pr_debug(" fs_size: %llu\n", (unsigned long long)
160 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
));
161 pr_debug(" fs_dsize: %llu\n", (unsigned long long)
162 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
));
163 pr_debug(" bsize: %u\n",
164 fs32_to_cpu(sb
, usb1
->fs_bsize
));
165 pr_debug(" fsize: %u\n",
166 fs32_to_cpu(sb
, usb1
->fs_fsize
));
167 pr_debug(" fs_volname: %s\n", usb2
->fs_un
.fs_u2
.fs_volname
);
168 pr_debug(" fs_sblockloc: %llu\n", (unsigned long long)
169 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.fs_sblockloc
));
170 pr_debug(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
171 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
));
172 pr_debug(" cs_nbfree(No of free blocks): %llu\n",
174 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
));
175 pr_info(" cs_nifree(Num of free inodes): %llu\n",
177 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
));
178 pr_info(" cs_nffree(Num of free frags): %llu\n",
180 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
));
181 pr_info(" fs_maxsymlinklen: %u\n",
182 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
));
184 pr_debug(" sblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_sblkno
));
185 pr_debug(" cblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_cblkno
));
186 pr_debug(" iblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_iblkno
));
187 pr_debug(" dblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_dblkno
));
188 pr_debug(" cgoffset: %u\n",
189 fs32_to_cpu(sb
, usb1
->fs_cgoffset
));
190 pr_debug(" ~cgmask: 0x%x\n",
191 ~fs32_to_cpu(sb
, usb1
->fs_cgmask
));
192 pr_debug(" size: %u\n", fs32_to_cpu(sb
, usb1
->fs_size
));
193 pr_debug(" dsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_dsize
));
194 pr_debug(" ncg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ncg
));
195 pr_debug(" bsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_bsize
));
196 pr_debug(" fsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_fsize
));
197 pr_debug(" frag: %u\n", fs32_to_cpu(sb
, usb1
->fs_frag
));
198 pr_debug(" fragshift: %u\n",
199 fs32_to_cpu(sb
, usb1
->fs_fragshift
));
200 pr_debug(" ~fmask: %u\n", ~fs32_to_cpu(sb
, usb1
->fs_fmask
));
201 pr_debug(" fshift: %u\n", fs32_to_cpu(sb
, usb1
->fs_fshift
));
202 pr_debug(" sbsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_sbsize
));
203 pr_debug(" spc: %u\n", fs32_to_cpu(sb
, usb1
->fs_spc
));
204 pr_debug(" cpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_cpg
));
205 pr_debug(" ipg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ipg
));
206 pr_debug(" fpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_fpg
));
207 pr_debug(" csaddr: %u\n", fs32_to_cpu(sb
, usb1
->fs_csaddr
));
208 pr_debug(" cssize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cssize
));
209 pr_debug(" cgsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cgsize
));
210 pr_debug(" fstodb: %u\n",
211 fs32_to_cpu(sb
, usb1
->fs_fsbtodb
));
212 pr_debug(" nrpos: %u\n", fs32_to_cpu(sb
, usb3
->fs_nrpos
));
213 pr_debug(" ndir %u\n",
214 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
));
215 pr_debug(" nifree %u\n",
216 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
));
217 pr_debug(" nbfree %u\n",
218 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
));
219 pr_debug(" nffree %u\n",
220 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
));
226 * Print contents of ufs_cylinder_group, useful for debugging
228 static void ufs_print_cylinder_stuff(struct super_block
*sb
,
229 struct ufs_cylinder_group
*cg
)
231 pr_debug("\nufs_print_cylinder_stuff\n");
232 pr_debug("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group
));
233 pr_debug(" magic: %x\n", fs32_to_cpu(sb
, cg
->cg_magic
));
234 pr_debug(" time: %u\n", fs32_to_cpu(sb
, cg
->cg_time
));
235 pr_debug(" cgx: %u\n", fs32_to_cpu(sb
, cg
->cg_cgx
));
236 pr_debug(" ncyl: %u\n", fs16_to_cpu(sb
, cg
->cg_ncyl
));
237 pr_debug(" niblk: %u\n", fs16_to_cpu(sb
, cg
->cg_niblk
));
238 pr_debug(" ndblk: %u\n", fs32_to_cpu(sb
, cg
->cg_ndblk
));
239 pr_debug(" cs_ndir: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_ndir
));
240 pr_debug(" cs_nbfree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nbfree
));
241 pr_debug(" cs_nifree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nifree
));
242 pr_debug(" cs_nffree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nffree
));
243 pr_debug(" rotor: %u\n", fs32_to_cpu(sb
, cg
->cg_rotor
));
244 pr_debug(" frotor: %u\n", fs32_to_cpu(sb
, cg
->cg_frotor
));
245 pr_debug(" irotor: %u\n", fs32_to_cpu(sb
, cg
->cg_irotor
));
246 pr_debug(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
247 fs32_to_cpu(sb
, cg
->cg_frsum
[0]), fs32_to_cpu(sb
, cg
->cg_frsum
[1]),
248 fs32_to_cpu(sb
, cg
->cg_frsum
[2]), fs32_to_cpu(sb
, cg
->cg_frsum
[3]),
249 fs32_to_cpu(sb
, cg
->cg_frsum
[4]), fs32_to_cpu(sb
, cg
->cg_frsum
[5]),
250 fs32_to_cpu(sb
, cg
->cg_frsum
[6]), fs32_to_cpu(sb
, cg
->cg_frsum
[7]));
251 pr_debug(" btotoff: %u\n", fs32_to_cpu(sb
, cg
->cg_btotoff
));
252 pr_debug(" boff: %u\n", fs32_to_cpu(sb
, cg
->cg_boff
));
253 pr_debug(" iuseoff: %u\n", fs32_to_cpu(sb
, cg
->cg_iusedoff
));
254 pr_debug(" freeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_freeoff
));
255 pr_debug(" nextfreeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_nextfreeoff
));
256 pr_debug(" clustersumoff %u\n",
257 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clustersumoff
));
258 pr_debug(" clusteroff %u\n",
259 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clusteroff
));
260 pr_debug(" nclusterblks %u\n",
261 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_nclusterblks
));
265 # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
266 # define ufs_print_cylinder_stuff(sb, cg) /**/
267 #endif /* CONFIG_UFS_DEBUG */
269 static const struct super_operations ufs_super_ops
;
271 void ufs_error (struct super_block
* sb
, const char * function
,
272 const char * fmt
, ...)
274 struct ufs_sb_private_info
* uspi
;
275 struct ufs_super_block_first
* usb1
;
276 struct va_format vaf
;
279 uspi
= UFS_SB(sb
)->s_uspi
;
280 usb1
= ubh_get_usb_first(uspi
);
282 if (!sb_rdonly(sb
)) {
283 usb1
->fs_clean
= UFS_FSBAD
;
284 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
285 ufs_mark_sb_dirty(sb
);
286 sb
->s_flags
|= SB_RDONLY
;
291 switch (UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_ONERROR
) {
292 case UFS_MOUNT_ONERROR_PANIC
:
293 panic("panic (device %s): %s: %pV\n",
294 sb
->s_id
, function
, &vaf
);
296 case UFS_MOUNT_ONERROR_LOCK
:
297 case UFS_MOUNT_ONERROR_UMOUNT
:
298 case UFS_MOUNT_ONERROR_REPAIR
:
299 pr_crit("error (device %s): %s: %pV\n",
300 sb
->s_id
, function
, &vaf
);
305 void ufs_panic (struct super_block
* sb
, const char * function
,
306 const char * fmt
, ...)
308 struct ufs_sb_private_info
* uspi
;
309 struct ufs_super_block_first
* usb1
;
310 struct va_format vaf
;
313 uspi
= UFS_SB(sb
)->s_uspi
;
314 usb1
= ubh_get_usb_first(uspi
);
316 if (!sb_rdonly(sb
)) {
317 usb1
->fs_clean
= UFS_FSBAD
;
318 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
319 ufs_mark_sb_dirty(sb
);
324 sb
->s_flags
|= SB_RDONLY
;
325 pr_crit("panic (device %s): %s: %pV\n",
326 sb
->s_id
, function
, &vaf
);
330 void ufs_warning (struct super_block
* sb
, const char * function
,
331 const char * fmt
, ...)
333 struct va_format vaf
;
339 pr_warn("(device %s): %s: %pV\n",
340 sb
->s_id
, function
, &vaf
);
345 Opt_type_old
= UFS_MOUNT_UFSTYPE_OLD
,
346 Opt_type_sunx86
= UFS_MOUNT_UFSTYPE_SUNx86
,
347 Opt_type_sun
= UFS_MOUNT_UFSTYPE_SUN
,
348 Opt_type_sunos
= UFS_MOUNT_UFSTYPE_SUNOS
,
349 Opt_type_44bsd
= UFS_MOUNT_UFSTYPE_44BSD
,
350 Opt_type_ufs2
= UFS_MOUNT_UFSTYPE_UFS2
,
351 Opt_type_hp
= UFS_MOUNT_UFSTYPE_HP
,
352 Opt_type_nextstepcd
= UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
,
353 Opt_type_nextstep
= UFS_MOUNT_UFSTYPE_NEXTSTEP
,
354 Opt_type_openstep
= UFS_MOUNT_UFSTYPE_OPENSTEP
,
355 Opt_onerror_panic
= UFS_MOUNT_ONERROR_PANIC
,
356 Opt_onerror_lock
= UFS_MOUNT_ONERROR_LOCK
,
357 Opt_onerror_umount
= UFS_MOUNT_ONERROR_UMOUNT
,
358 Opt_onerror_repair
= UFS_MOUNT_ONERROR_REPAIR
,
362 static const match_table_t tokens
= {
363 {Opt_type_old
, "ufstype=old"},
364 {Opt_type_sunx86
, "ufstype=sunx86"},
365 {Opt_type_sun
, "ufstype=sun"},
366 {Opt_type_sunos
, "ufstype=sunos"},
367 {Opt_type_44bsd
, "ufstype=44bsd"},
368 {Opt_type_ufs2
, "ufstype=ufs2"},
369 {Opt_type_ufs2
, "ufstype=5xbsd"},
370 {Opt_type_hp
, "ufstype=hp"},
371 {Opt_type_nextstepcd
, "ufstype=nextstep-cd"},
372 {Opt_type_nextstep
, "ufstype=nextstep"},
373 {Opt_type_openstep
, "ufstype=openstep"},
374 /*end of possible ufs types */
375 {Opt_onerror_panic
, "onerror=panic"},
376 {Opt_onerror_lock
, "onerror=lock"},
377 {Opt_onerror_umount
, "onerror=umount"},
378 {Opt_onerror_repair
, "onerror=repair"},
382 static int ufs_parse_options (char * options
, unsigned * mount_options
)
391 while ((p
= strsep(&options
, ",")) != NULL
) {
392 substring_t args
[MAX_OPT_ARGS
];
397 token
= match_token(p
, tokens
, args
);
400 ufs_clear_opt (*mount_options
, UFSTYPE
);
401 ufs_set_opt (*mount_options
, UFSTYPE_OLD
);
403 case Opt_type_sunx86
:
404 ufs_clear_opt (*mount_options
, UFSTYPE
);
405 ufs_set_opt (*mount_options
, UFSTYPE_SUNx86
);
408 ufs_clear_opt (*mount_options
, UFSTYPE
);
409 ufs_set_opt (*mount_options
, UFSTYPE_SUN
);
412 ufs_clear_opt(*mount_options
, UFSTYPE
);
413 ufs_set_opt(*mount_options
, UFSTYPE_SUNOS
);
416 ufs_clear_opt (*mount_options
, UFSTYPE
);
417 ufs_set_opt (*mount_options
, UFSTYPE_44BSD
);
420 ufs_clear_opt(*mount_options
, UFSTYPE
);
421 ufs_set_opt(*mount_options
, UFSTYPE_UFS2
);
424 ufs_clear_opt (*mount_options
, UFSTYPE
);
425 ufs_set_opt (*mount_options
, UFSTYPE_HP
);
427 case Opt_type_nextstepcd
:
428 ufs_clear_opt (*mount_options
, UFSTYPE
);
429 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP_CD
);
431 case Opt_type_nextstep
:
432 ufs_clear_opt (*mount_options
, UFSTYPE
);
433 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP
);
435 case Opt_type_openstep
:
436 ufs_clear_opt (*mount_options
, UFSTYPE
);
437 ufs_set_opt (*mount_options
, UFSTYPE_OPENSTEP
);
439 case Opt_onerror_panic
:
440 ufs_clear_opt (*mount_options
, ONERROR
);
441 ufs_set_opt (*mount_options
, ONERROR_PANIC
);
443 case Opt_onerror_lock
:
444 ufs_clear_opt (*mount_options
, ONERROR
);
445 ufs_set_opt (*mount_options
, ONERROR_LOCK
);
447 case Opt_onerror_umount
:
448 ufs_clear_opt (*mount_options
, ONERROR
);
449 ufs_set_opt (*mount_options
, ONERROR_UMOUNT
);
451 case Opt_onerror_repair
:
452 pr_err("Unable to do repair on error, will lock lock instead\n");
453 ufs_clear_opt (*mount_options
, ONERROR
);
454 ufs_set_opt (*mount_options
, ONERROR_REPAIR
);
457 pr_err("Invalid option: \"%s\" or missing value\n", p
);
465 * Different types of UFS hold fs_cstotal in different
466 * places, and use different data structure for it.
467 * To make things simpler we just copy fs_cstotal to ufs_sb_private_info
469 static void ufs_setup_cstotal(struct super_block
*sb
)
471 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
472 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
473 struct ufs_super_block_first
*usb1
;
474 struct ufs_super_block_second
*usb2
;
475 struct ufs_super_block_third
*usb3
;
476 unsigned mtype
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
478 UFSD("ENTER, mtype=%u\n", mtype
);
479 usb1
= ubh_get_usb_first(uspi
);
480 usb2
= ubh_get_usb_second(uspi
);
481 usb3
= ubh_get_usb_third(uspi
);
483 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
484 (usb2
->fs_un
.fs_u2
.fs_maxbsize
== usb1
->fs_bsize
)) ||
485 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
486 /*we have statistic in different place, then usual*/
487 uspi
->cs_total
.cs_ndir
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
);
488 uspi
->cs_total
.cs_nbfree
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
);
489 uspi
->cs_total
.cs_nifree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
);
490 uspi
->cs_total
.cs_nffree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
);
492 uspi
->cs_total
.cs_ndir
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
);
493 uspi
->cs_total
.cs_nbfree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
);
494 uspi
->cs_total
.cs_nifree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
);
495 uspi
->cs_total
.cs_nffree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
);
501 * Read on-disk structures associated with cylinder groups
503 static int ufs_read_cylinder_structures(struct super_block
*sb
)
505 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
506 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
507 struct ufs_buffer_head
* ubh
;
508 unsigned char * base
, * space
;
509 unsigned size
, blks
, i
;
514 * Read cs structures from (usually) first data block
517 size
= uspi
->s_cssize
;
518 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
519 base
= space
= kmalloc(size
, GFP_NOFS
);
522 sbi
->s_csp
= (struct ufs_csum
*)space
;
523 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
524 size
= uspi
->s_bsize
;
525 if (i
+ uspi
->s_fpb
> blks
)
526 size
= (blks
- i
) * uspi
->s_fsize
;
528 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
533 ubh_ubhcpymem (space
, ubh
, size
);
541 * Read cylinder group (we read only first fragment from block
542 * at this time) and prepare internal data structures for cg caching.
544 if (!(sbi
->s_ucg
= kmalloc (sizeof(struct buffer_head
*) * uspi
->s_ncg
, GFP_NOFS
)))
546 for (i
= 0; i
< uspi
->s_ncg
; i
++)
547 sbi
->s_ucg
[i
] = NULL
;
548 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
549 sbi
->s_ucpi
[i
] = NULL
;
550 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
552 for (i
= 0; i
< uspi
->s_ncg
; i
++) {
553 UFSD("read cg %u\n", i
);
554 if (!(sbi
->s_ucg
[i
] = sb_bread(sb
, ufs_cgcmin(i
))))
556 if (!ufs_cg_chkmagic (sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
))
559 ufs_print_cylinder_stuff(sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
);
561 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
562 if (!(sbi
->s_ucpi
[i
] = kmalloc (sizeof(struct ufs_cg_private_info
), GFP_NOFS
)))
564 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
566 sbi
->s_cg_loaded
= 0;
573 for (i
= 0; i
< uspi
->s_ncg
; i
++)
575 brelse (sbi
->s_ucg
[i
]);
577 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++)
578 kfree (sbi
->s_ucpi
[i
]);
580 UFSD("EXIT (FAILED)\n");
585 * Sync our internal copy of fs_cstotal with disk
587 static void ufs_put_cstotal(struct super_block
*sb
)
589 unsigned mtype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
590 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
591 struct ufs_super_block_first
*usb1
;
592 struct ufs_super_block_second
*usb2
;
593 struct ufs_super_block_third
*usb3
;
596 usb1
= ubh_get_usb_first(uspi
);
597 usb2
= ubh_get_usb_second(uspi
);
598 usb3
= ubh_get_usb_third(uspi
);
600 if (mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
601 /*we have statistic in different place, then usual*/
602 usb2
->fs_un
.fs_u2
.cs_ndir
=
603 cpu_to_fs64(sb
, uspi
->cs_total
.cs_ndir
);
604 usb2
->fs_un
.fs_u2
.cs_nbfree
=
605 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nbfree
);
606 usb3
->fs_un1
.fs_u2
.cs_nifree
=
607 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nifree
);
608 usb3
->fs_un1
.fs_u2
.cs_nffree
=
609 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nffree
);
613 if (mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
614 (usb2
->fs_un
.fs_u2
.fs_maxbsize
== usb1
->fs_bsize
)) {
615 /* store stats in both old and new places */
616 usb2
->fs_un
.fs_u2
.cs_ndir
=
617 cpu_to_fs64(sb
, uspi
->cs_total
.cs_ndir
);
618 usb2
->fs_un
.fs_u2
.cs_nbfree
=
619 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nbfree
);
620 usb3
->fs_un1
.fs_u2
.cs_nifree
=
621 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nifree
);
622 usb3
->fs_un1
.fs_u2
.cs_nffree
=
623 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nffree
);
625 usb1
->fs_cstotal
.cs_ndir
= cpu_to_fs32(sb
, uspi
->cs_total
.cs_ndir
);
626 usb1
->fs_cstotal
.cs_nbfree
= cpu_to_fs32(sb
, uspi
->cs_total
.cs_nbfree
);
627 usb1
->fs_cstotal
.cs_nifree
= cpu_to_fs32(sb
, uspi
->cs_total
.cs_nifree
);
628 usb1
->fs_cstotal
.cs_nffree
= cpu_to_fs32(sb
, uspi
->cs_total
.cs_nffree
);
630 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
631 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
636 * ufs_put_super_internal() - put on-disk intrenal structures
637 * @sb: pointer to super_block structure
638 * Put on-disk structures associated with cylinder groups
639 * and write them back to disk, also update cs_total on disk
641 static void ufs_put_super_internal(struct super_block
*sb
)
643 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
644 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
645 struct ufs_buffer_head
* ubh
;
646 unsigned char * base
, * space
;
647 unsigned blks
, size
, i
;
653 size
= uspi
->s_cssize
;
654 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
655 base
= space
= (char*) sbi
->s_csp
;
656 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
657 size
= uspi
->s_bsize
;
658 if (i
+ uspi
->s_fpb
> blks
)
659 size
= (blks
- i
) * uspi
->s_fsize
;
661 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
663 ubh_memcpyubh (ubh
, space
, size
);
665 ubh_mark_buffer_uptodate (ubh
, 1);
666 ubh_mark_buffer_dirty (ubh
);
669 for (i
= 0; i
< sbi
->s_cg_loaded
; i
++) {
670 ufs_put_cylinder (sb
, i
);
671 kfree (sbi
->s_ucpi
[i
]);
673 for (; i
< UFS_MAX_GROUP_LOADED
; i
++)
674 kfree (sbi
->s_ucpi
[i
]);
675 for (i
= 0; i
< uspi
->s_ncg
; i
++)
676 brelse (sbi
->s_ucg
[i
]);
683 static int ufs_sync_fs(struct super_block
*sb
, int wait
)
685 struct ufs_sb_private_info
* uspi
;
686 struct ufs_super_block_first
* usb1
;
687 struct ufs_super_block_third
* usb3
;
690 mutex_lock(&UFS_SB(sb
)->s_lock
);
694 flags
= UFS_SB(sb
)->s_flags
;
695 uspi
= UFS_SB(sb
)->s_uspi
;
696 usb1
= ubh_get_usb_first(uspi
);
697 usb3
= ubh_get_usb_third(uspi
);
699 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
700 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
701 (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
||
702 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
703 ufs_set_fs_state(sb
, usb1
, usb3
,
704 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
708 mutex_unlock(&UFS_SB(sb
)->s_lock
);
713 static void delayed_sync_fs(struct work_struct
*work
)
715 struct ufs_sb_info
*sbi
;
717 sbi
= container_of(work
, struct ufs_sb_info
, sync_work
.work
);
719 spin_lock(&sbi
->work_lock
);
720 sbi
->work_queued
= 0;
721 spin_unlock(&sbi
->work_lock
);
723 ufs_sync_fs(sbi
->sb
, 1);
726 void ufs_mark_sb_dirty(struct super_block
*sb
)
728 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
731 spin_lock(&sbi
->work_lock
);
732 if (!sbi
->work_queued
) {
733 delay
= msecs_to_jiffies(dirty_writeback_interval
* 10);
734 queue_delayed_work(system_long_wq
, &sbi
->sync_work
, delay
);
735 sbi
->work_queued
= 1;
737 spin_unlock(&sbi
->work_lock
);
740 static void ufs_put_super(struct super_block
*sb
)
742 struct ufs_sb_info
* sbi
= UFS_SB(sb
);
747 ufs_put_super_internal(sb
);
748 cancel_delayed_work_sync(&sbi
->sync_work
);
750 ubh_brelse_uspi (sbi
->s_uspi
);
753 sb
->s_fs_info
= NULL
;
758 static u64
ufs_max_bytes(struct super_block
*sb
)
760 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
761 int bits
= uspi
->s_apbshift
;
767 res
= UFS_NDADDR
+ (1LL << bits
) + (1LL << (2*bits
)) +
770 if (res
>= (MAX_LFS_FILESIZE
>> uspi
->s_bshift
))
771 return MAX_LFS_FILESIZE
;
772 return res
<< uspi
->s_bshift
;
775 static int ufs_fill_super(struct super_block
*sb
, void *data
, int silent
)
777 struct ufs_sb_info
* sbi
;
778 struct ufs_sb_private_info
* uspi
;
779 struct ufs_super_block_first
* usb1
;
780 struct ufs_super_block_second
* usb2
;
781 struct ufs_super_block_third
* usb3
;
782 struct ufs_buffer_head
* ubh
;
784 unsigned block_size
, super_block_size
;
786 unsigned super_block_offset
;
796 #ifndef CONFIG_UFS_FS_WRITE
797 if (!sb_rdonly(sb
)) {
798 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
803 sbi
= kzalloc(sizeof(struct ufs_sb_info
), GFP_KERNEL
);
809 UFSD("flag %u\n", (int)(sb_rdonly(sb
)));
811 mutex_init(&sbi
->s_lock
);
812 spin_lock_init(&sbi
->work_lock
);
813 INIT_DELAYED_WORK(&sbi
->sync_work
, delayed_sync_fs
);
815 * Set default mount options
816 * Parse mount options
818 sbi
->s_mount_opt
= 0;
819 ufs_set_opt (sbi
->s_mount_opt
, ONERROR_LOCK
);
820 if (!ufs_parse_options ((char *) data
, &sbi
->s_mount_opt
)) {
821 pr_err("wrong mount options\n");
824 if (!(sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
826 pr_err("You didn't specify the type of your ufs filesystem\n\n"
827 "mount -t ufs -o ufstype="
828 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
829 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
830 "default is ufstype=old\n");
831 ufs_set_opt (sbi
->s_mount_opt
, UFSTYPE_OLD
);
834 uspi
= kzalloc(sizeof(struct ufs_sb_private_info
), GFP_KERNEL
);
838 uspi
->s_dirblksize
= UFS_SECTOR_SIZE
;
839 super_block_offset
=UFS_SBLOCK
;
841 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
843 switch (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) {
844 case UFS_MOUNT_UFSTYPE_44BSD
:
845 UFSD("ufstype=44bsd\n");
846 uspi
->s_fsize
= block_size
= 512;
847 uspi
->s_fmask
= ~(512 - 1);
849 uspi
->s_sbsize
= super_block_size
= 1536;
851 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
853 case UFS_MOUNT_UFSTYPE_UFS2
:
854 UFSD("ufstype=ufs2\n");
855 super_block_offset
=SBLOCK_UFS2
;
856 uspi
->s_fsize
= block_size
= 512;
857 uspi
->s_fmask
= ~(512 - 1);
859 uspi
->s_sbsize
= super_block_size
= 1536;
861 flags
|= UFS_TYPE_UFS2
| UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
864 case UFS_MOUNT_UFSTYPE_SUN
:
865 UFSD("ufstype=sun\n");
866 uspi
->s_fsize
= block_size
= 1024;
867 uspi
->s_fmask
= ~(1024 - 1);
869 uspi
->s_sbsize
= super_block_size
= 2048;
871 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
872 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUN
| UFS_CG_SUN
;
875 case UFS_MOUNT_UFSTYPE_SUNOS
:
876 UFSD("ufstype=sunos\n");
877 uspi
->s_fsize
= block_size
= 1024;
878 uspi
->s_fmask
= ~(1024 - 1);
880 uspi
->s_sbsize
= 2048;
881 super_block_size
= 2048;
883 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
884 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_SUNOS
| UFS_CG_SUN
;
887 case UFS_MOUNT_UFSTYPE_SUNx86
:
888 UFSD("ufstype=sunx86\n");
889 uspi
->s_fsize
= block_size
= 1024;
890 uspi
->s_fmask
= ~(1024 - 1);
892 uspi
->s_sbsize
= super_block_size
= 2048;
894 uspi
->s_maxsymlinklen
= 0; /* Not supported on disk */
895 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUNx86
| UFS_CG_SUN
;
898 case UFS_MOUNT_UFSTYPE_OLD
:
899 UFSD("ufstype=old\n");
900 uspi
->s_fsize
= block_size
= 1024;
901 uspi
->s_fmask
= ~(1024 - 1);
903 uspi
->s_sbsize
= super_block_size
= 2048;
905 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
906 if (!sb_rdonly(sb
)) {
908 pr_info("ufstype=old is supported read-only\n");
909 sb
->s_flags
|= SB_RDONLY
;
913 case UFS_MOUNT_UFSTYPE_NEXTSTEP
:
914 UFSD("ufstype=nextstep\n");
915 uspi
->s_fsize
= block_size
= 1024;
916 uspi
->s_fmask
= ~(1024 - 1);
918 uspi
->s_sbsize
= super_block_size
= 2048;
920 uspi
->s_dirblksize
= 1024;
921 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
922 if (!sb_rdonly(sb
)) {
924 pr_info("ufstype=nextstep is supported read-only\n");
925 sb
->s_flags
|= SB_RDONLY
;
929 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
:
930 UFSD("ufstype=nextstep-cd\n");
931 uspi
->s_fsize
= block_size
= 2048;
932 uspi
->s_fmask
= ~(2048 - 1);
934 uspi
->s_sbsize
= super_block_size
= 2048;
936 uspi
->s_dirblksize
= 1024;
937 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
938 if (!sb_rdonly(sb
)) {
940 pr_info("ufstype=nextstep-cd is supported read-only\n");
941 sb
->s_flags
|= SB_RDONLY
;
945 case UFS_MOUNT_UFSTYPE_OPENSTEP
:
946 UFSD("ufstype=openstep\n");
947 uspi
->s_fsize
= block_size
= 1024;
948 uspi
->s_fmask
= ~(1024 - 1);
950 uspi
->s_sbsize
= super_block_size
= 2048;
952 uspi
->s_dirblksize
= 1024;
953 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
954 if (!sb_rdonly(sb
)) {
956 pr_info("ufstype=openstep is supported read-only\n");
957 sb
->s_flags
|= SB_RDONLY
;
961 case UFS_MOUNT_UFSTYPE_HP
:
962 UFSD("ufstype=hp\n");
963 uspi
->s_fsize
= block_size
= 1024;
964 uspi
->s_fmask
= ~(1024 - 1);
966 uspi
->s_sbsize
= super_block_size
= 2048;
968 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
969 if (!sb_rdonly(sb
)) {
971 pr_info("ufstype=hp is supported read-only\n");
972 sb
->s_flags
|= SB_RDONLY
;
977 pr_err("unknown ufstype\n");
982 if (!sb_set_blocksize(sb
, block_size
)) {
983 pr_err("failed to set blocksize\n");
988 * read ufs super block from device
991 ubh
= ubh_bread_uspi(uspi
, sb
, uspi
->s_sbbase
+ super_block_offset
/block_size
, super_block_size
);
996 usb1
= ubh_get_usb_first(uspi
);
997 usb2
= ubh_get_usb_second(uspi
);
998 usb3
= ubh_get_usb_third(uspi
);
1000 /* Sort out mod used on SunOS 4.1.3 for fs_state */
1001 uspi
->s_postblformat
= fs32_to_cpu(sb
, usb3
->fs_postblformat
);
1002 if (((flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
) &&
1003 (uspi
->s_postblformat
!= UFS_42POSTBLFMT
)) {
1004 flags
&= ~UFS_ST_MASK
;
1005 flags
|= UFS_ST_SUN
;
1008 if ((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
&&
1009 uspi
->s_postblformat
== UFS_42POSTBLFMT
) {
1011 pr_err("this is not a 44bsd filesystem");
1016 * Check ufs magic number
1018 sbi
->s_bytesex
= BYTESEX_LE
;
1019 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
1028 sbi
->s_bytesex
= BYTESEX_BE
;
1029 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
1039 if ((((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP
)
1040 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
)
1041 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_OPENSTEP
))
1042 && uspi
->s_sbbase
< 256) {
1043 ubh_brelse_uspi(uspi
);
1045 uspi
->s_sbbase
+= 8;
1049 pr_err("%s(): bad magic number\n", __func__
);
1054 * Check block and fragment sizes
1056 uspi
->s_bsize
= fs32_to_cpu(sb
, usb1
->fs_bsize
);
1057 uspi
->s_fsize
= fs32_to_cpu(sb
, usb1
->fs_fsize
);
1058 uspi
->s_sbsize
= fs32_to_cpu(sb
, usb1
->fs_sbsize
);
1059 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
1060 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
1062 if (!is_power_of_2(uspi
->s_fsize
)) {
1063 pr_err("%s(): fragment size %u is not a power of 2\n",
1064 __func__
, uspi
->s_fsize
);
1067 if (uspi
->s_fsize
< 512) {
1068 pr_err("%s(): fragment size %u is too small\n",
1069 __func__
, uspi
->s_fsize
);
1072 if (uspi
->s_fsize
> 4096) {
1073 pr_err("%s(): fragment size %u is too large\n",
1074 __func__
, uspi
->s_fsize
);
1077 if (!is_power_of_2(uspi
->s_bsize
)) {
1078 pr_err("%s(): block size %u is not a power of 2\n",
1079 __func__
, uspi
->s_bsize
);
1082 if (uspi
->s_bsize
< 4096) {
1083 pr_err("%s(): block size %u is too small\n",
1084 __func__
, uspi
->s_bsize
);
1087 if (uspi
->s_bsize
/ uspi
->s_fsize
> 8) {
1088 pr_err("%s(): too many fragments per block (%u)\n",
1089 __func__
, uspi
->s_bsize
/ uspi
->s_fsize
);
1092 if (uspi
->s_fsize
!= block_size
|| uspi
->s_sbsize
!= super_block_size
) {
1093 ubh_brelse_uspi(uspi
);
1095 block_size
= uspi
->s_fsize
;
1096 super_block_size
= uspi
->s_sbsize
;
1097 UFSD("another value of block_size or super_block_size %u, %u\n", block_size
, super_block_size
);
1101 sbi
->s_flags
= flags
;/*after that line some functions use s_flags*/
1102 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
1105 * Check, if file system was correctly unmounted.
1106 * If not, make it read only.
1108 if (((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
) ||
1109 ((flags
& UFS_ST_MASK
) == UFS_ST_OLD
) ||
1110 (((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
1111 (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
||
1112 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
) &&
1113 (ufs_get_fs_state(sb
, usb1
, usb3
) == (UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
))))) {
1114 switch(usb1
->fs_clean
) {
1116 UFSD("fs is clean\n");
1119 UFSD("fs is stable\n");
1122 UFSD("fs is logging fs\n");
1125 UFSD("fs is DEC OSF/1\n");
1128 pr_err("%s(): fs is active\n", __func__
);
1129 sb
->s_flags
|= SB_RDONLY
;
1132 pr_err("%s(): fs is bad\n", __func__
);
1133 sb
->s_flags
|= SB_RDONLY
;
1136 pr_err("%s(): can't grok fs_clean 0x%x\n",
1137 __func__
, usb1
->fs_clean
);
1138 sb
->s_flags
|= SB_RDONLY
;
1142 pr_err("%s(): fs needs fsck\n", __func__
);
1143 sb
->s_flags
|= SB_RDONLY
;
1147 * Read ufs_super_block into internal data structures
1149 sb
->s_op
= &ufs_super_ops
;
1150 sb
->s_export_op
= &ufs_export_ops
;
1152 sb
->s_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
1154 uspi
->s_sblkno
= fs32_to_cpu(sb
, usb1
->fs_sblkno
);
1155 uspi
->s_cblkno
= fs32_to_cpu(sb
, usb1
->fs_cblkno
);
1156 uspi
->s_iblkno
= fs32_to_cpu(sb
, usb1
->fs_iblkno
);
1157 uspi
->s_dblkno
= fs32_to_cpu(sb
, usb1
->fs_dblkno
);
1158 uspi
->s_cgoffset
= fs32_to_cpu(sb
, usb1
->fs_cgoffset
);
1159 uspi
->s_cgmask
= fs32_to_cpu(sb
, usb1
->fs_cgmask
);
1161 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1162 uspi
->s_size
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
);
1163 uspi
->s_dsize
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1165 uspi
->s_size
= fs32_to_cpu(sb
, usb1
->fs_size
);
1166 uspi
->s_dsize
= fs32_to_cpu(sb
, usb1
->fs_dsize
);
1169 uspi
->s_ncg
= fs32_to_cpu(sb
, usb1
->fs_ncg
);
1170 /* s_bsize already set */
1171 /* s_fsize already set */
1172 uspi
->s_fpb
= fs32_to_cpu(sb
, usb1
->fs_frag
);
1173 uspi
->s_minfree
= fs32_to_cpu(sb
, usb1
->fs_minfree
);
1174 uspi
->s_bmask
= fs32_to_cpu(sb
, usb1
->fs_bmask
);
1175 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
1176 uspi
->s_bshift
= fs32_to_cpu(sb
, usb1
->fs_bshift
);
1177 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
1178 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi
->s_bshift
,
1180 uspi
->s_fpbshift
= fs32_to_cpu(sb
, usb1
->fs_fragshift
);
1181 uspi
->s_fsbtodb
= fs32_to_cpu(sb
, usb1
->fs_fsbtodb
);
1182 /* s_sbsize already set */
1183 uspi
->s_csmask
= fs32_to_cpu(sb
, usb1
->fs_csmask
);
1184 uspi
->s_csshift
= fs32_to_cpu(sb
, usb1
->fs_csshift
);
1185 uspi
->s_nindir
= fs32_to_cpu(sb
, usb1
->fs_nindir
);
1186 uspi
->s_inopb
= fs32_to_cpu(sb
, usb1
->fs_inopb
);
1187 uspi
->s_nspf
= fs32_to_cpu(sb
, usb1
->fs_nspf
);
1188 uspi
->s_npsect
= ufs_get_fs_npsect(sb
, usb1
, usb3
);
1189 uspi
->s_interleave
= fs32_to_cpu(sb
, usb1
->fs_interleave
);
1190 uspi
->s_trackskew
= fs32_to_cpu(sb
, usb1
->fs_trackskew
);
1192 if (uspi
->fs_magic
== UFS2_MAGIC
)
1193 uspi
->s_csaddr
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_csaddr
);
1195 uspi
->s_csaddr
= fs32_to_cpu(sb
, usb1
->fs_csaddr
);
1197 uspi
->s_cssize
= fs32_to_cpu(sb
, usb1
->fs_cssize
);
1198 uspi
->s_cgsize
= fs32_to_cpu(sb
, usb1
->fs_cgsize
);
1199 uspi
->s_ntrak
= fs32_to_cpu(sb
, usb1
->fs_ntrak
);
1200 uspi
->s_nsect
= fs32_to_cpu(sb
, usb1
->fs_nsect
);
1201 uspi
->s_spc
= fs32_to_cpu(sb
, usb1
->fs_spc
);
1202 uspi
->s_ipg
= fs32_to_cpu(sb
, usb1
->fs_ipg
);
1203 uspi
->s_fpg
= fs32_to_cpu(sb
, usb1
->fs_fpg
);
1204 uspi
->s_cpc
= fs32_to_cpu(sb
, usb2
->fs_un
.fs_u1
.fs_cpc
);
1205 uspi
->s_contigsumsize
= fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_contigsumsize
);
1206 uspi
->s_qbmask
= ufs_get_fs_qbmask(sb
, usb3
);
1207 uspi
->s_qfmask
= ufs_get_fs_qfmask(sb
, usb3
);
1208 uspi
->s_nrpos
= fs32_to_cpu(sb
, usb3
->fs_nrpos
);
1209 uspi
->s_postbloff
= fs32_to_cpu(sb
, usb3
->fs_postbloff
);
1210 uspi
->s_rotbloff
= fs32_to_cpu(sb
, usb3
->fs_rotbloff
);
1212 uspi
->s_root_blocks
= mul_u64_u32_div(uspi
->s_dsize
,
1213 uspi
->s_minfree
, 100);
1214 if (uspi
->s_minfree
<= 5) {
1215 uspi
->s_time_to_space
= ~0ULL;
1216 uspi
->s_space_to_time
= 0;
1217 usb1
->fs_optim
= cpu_to_fs32(sb
, UFS_OPTSPACE
);
1219 uspi
->s_time_to_space
= (uspi
->s_root_blocks
/ 2) + 1;
1220 uspi
->s_space_to_time
= mul_u64_u32_div(uspi
->s_dsize
,
1221 uspi
->s_minfree
- 2, 100) - 1;
1225 * Compute another frequently used values
1227 uspi
->s_fpbmask
= uspi
->s_fpb
- 1;
1228 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
1229 uspi
->s_apbshift
= uspi
->s_bshift
- 3;
1231 uspi
->s_apbshift
= uspi
->s_bshift
- 2;
1233 uspi
->s_2apbshift
= uspi
->s_apbshift
* 2;
1234 uspi
->s_3apbshift
= uspi
->s_apbshift
* 3;
1235 uspi
->s_apb
= 1 << uspi
->s_apbshift
;
1236 uspi
->s_2apb
= 1 << uspi
->s_2apbshift
;
1237 uspi
->s_3apb
= 1 << uspi
->s_3apbshift
;
1238 uspi
->s_apbmask
= uspi
->s_apb
- 1;
1239 uspi
->s_nspfshift
= uspi
->s_fshift
- UFS_SECTOR_BITS
;
1240 uspi
->s_nspb
= uspi
->s_nspf
<< uspi
->s_fpbshift
;
1241 uspi
->s_inopf
= uspi
->s_inopb
>> uspi
->s_fpbshift
;
1242 uspi
->s_bpf
= uspi
->s_fsize
<< 3;
1243 uspi
->s_bpfshift
= uspi
->s_fshift
+ 3;
1244 uspi
->s_bpfmask
= uspi
->s_bpf
- 1;
1245 if ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_44BSD
||
1246 (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_UFS2
)
1247 uspi
->s_maxsymlinklen
=
1248 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
);
1250 if (uspi
->fs_magic
== UFS2_MAGIC
)
1251 maxsymlen
= 2 * 4 * (UFS_NDADDR
+ UFS_NINDIR
);
1253 maxsymlen
= 4 * (UFS_NDADDR
+ UFS_NINDIR
);
1254 if (uspi
->s_maxsymlinklen
> maxsymlen
) {
1255 ufs_warning(sb
, __func__
, "ufs_read_super: excessive maximum "
1256 "fast symlink size (%u)\n", uspi
->s_maxsymlinklen
);
1257 uspi
->s_maxsymlinklen
= maxsymlen
;
1259 sb
->s_maxbytes
= ufs_max_bytes(sb
);
1260 sb
->s_max_links
= UFS_LINK_MAX
;
1262 inode
= ufs_iget(sb
, UFS_ROOTINO
);
1263 if (IS_ERR(inode
)) {
1264 ret
= PTR_ERR(inode
);
1267 sb
->s_root
= d_make_root(inode
);
1273 ufs_setup_cstotal(sb
);
1275 * Read cylinder group structures
1278 if (!ufs_read_cylinder_structures(sb
))
1286 ubh_brelse_uspi (uspi
);
1289 sb
->s_fs_info
= NULL
;
1290 UFSD("EXIT (FAILED)\n");
1294 UFSD("EXIT (NOMEM)\n");
1298 static int ufs_remount (struct super_block
*sb
, int *mount_flags
, char *data
)
1300 struct ufs_sb_private_info
* uspi
;
1301 struct ufs_super_block_first
* usb1
;
1302 struct ufs_super_block_third
* usb3
;
1303 unsigned new_mount_opt
, ufstype
;
1306 sync_filesystem(sb
);
1307 mutex_lock(&UFS_SB(sb
)->s_lock
);
1308 uspi
= UFS_SB(sb
)->s_uspi
;
1309 flags
= UFS_SB(sb
)->s_flags
;
1310 usb1
= ubh_get_usb_first(uspi
);
1311 usb3
= ubh_get_usb_third(uspi
);
1314 * Allow the "check" option to be passed as a remount option.
1315 * It is not possible to change ufstype option during remount
1317 ufstype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1319 ufs_set_opt (new_mount_opt
, ONERROR_LOCK
);
1320 if (!ufs_parse_options (data
, &new_mount_opt
)) {
1321 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1324 if (!(new_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
1325 new_mount_opt
|= ufstype
;
1326 } else if ((new_mount_opt
& UFS_MOUNT_UFSTYPE
) != ufstype
) {
1327 pr_err("ufstype can't be changed during remount\n");
1328 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1332 if ((bool)(*mount_flags
& SB_RDONLY
) == sb_rdonly(sb
)) {
1333 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1334 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1339 * fs was mouted as rw, remounting ro
1341 if (*mount_flags
& SB_RDONLY
) {
1342 ufs_put_super_internal(sb
);
1343 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1344 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1345 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNOS
1346 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1347 ufs_set_fs_state(sb
, usb1
, usb3
,
1348 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1349 ubh_mark_buffer_dirty (USPI_UBH(uspi
));
1350 sb
->s_flags
|= SB_RDONLY
;
1353 * fs was mounted as ro, remounting rw
1355 #ifndef CONFIG_UFS_FS_WRITE
1356 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
1357 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1360 if (ufstype
!= UFS_MOUNT_UFSTYPE_SUN
&&
1361 ufstype
!= UFS_MOUNT_UFSTYPE_SUNOS
&&
1362 ufstype
!= UFS_MOUNT_UFSTYPE_44BSD
&&
1363 ufstype
!= UFS_MOUNT_UFSTYPE_SUNx86
&&
1364 ufstype
!= UFS_MOUNT_UFSTYPE_UFS2
) {
1365 pr_err("this ufstype is read-only supported\n");
1366 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1369 if (!ufs_read_cylinder_structures(sb
)) {
1370 pr_err("failed during remounting\n");
1371 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1374 sb
->s_flags
&= ~SB_RDONLY
;
1377 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1378 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1382 static int ufs_show_options(struct seq_file
*seq
, struct dentry
*root
)
1384 struct ufs_sb_info
*sbi
= UFS_SB(root
->d_sb
);
1385 unsigned mval
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1386 const struct match_token
*tp
= tokens
;
1388 while (tp
->token
!= Opt_onerror_panic
&& tp
->token
!= mval
)
1390 BUG_ON(tp
->token
== Opt_onerror_panic
);
1391 seq_printf(seq
, ",%s", tp
->pattern
);
1393 mval
= sbi
->s_mount_opt
& UFS_MOUNT_ONERROR
;
1394 while (tp
->token
!= Opt_err
&& tp
->token
!= mval
)
1396 BUG_ON(tp
->token
== Opt_err
);
1397 seq_printf(seq
, ",%s", tp
->pattern
);
1402 static int ufs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1404 struct super_block
*sb
= dentry
->d_sb
;
1405 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
1406 unsigned flags
= UFS_SB(sb
)->s_flags
;
1407 struct ufs_super_block_third
*usb3
;
1408 u64 id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
1410 mutex_lock(&UFS_SB(sb
)->s_lock
);
1411 usb3
= ubh_get_usb_third(uspi
);
1413 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
1414 buf
->f_type
= UFS2_MAGIC
;
1416 buf
->f_type
= UFS_MAGIC
;
1418 buf
->f_blocks
= uspi
->s_dsize
;
1419 buf
->f_bfree
= ufs_freefrags(uspi
);
1420 buf
->f_ffree
= uspi
->cs_total
.cs_nifree
;
1421 buf
->f_bsize
= sb
->s_blocksize
;
1422 buf
->f_bavail
= (buf
->f_bfree
> uspi
->s_root_blocks
)
1423 ? (buf
->f_bfree
- uspi
->s_root_blocks
) : 0;
1424 buf
->f_files
= uspi
->s_ncg
* uspi
->s_ipg
;
1425 buf
->f_namelen
= UFS_MAXNAMLEN
;
1426 buf
->f_fsid
.val
[0] = (u32
)id
;
1427 buf
->f_fsid
.val
[1] = (u32
)(id
>> 32);
1429 mutex_unlock(&UFS_SB(sb
)->s_lock
);
1434 static struct kmem_cache
* ufs_inode_cachep
;
1436 static struct inode
*ufs_alloc_inode(struct super_block
*sb
)
1438 struct ufs_inode_info
*ei
;
1440 ei
= kmem_cache_alloc(ufs_inode_cachep
, GFP_NOFS
);
1444 inode_set_iversion(&ei
->vfs_inode
, 1);
1445 seqlock_init(&ei
->meta_lock
);
1446 mutex_init(&ei
->truncate_mutex
);
1447 return &ei
->vfs_inode
;
1450 static void ufs_i_callback(struct rcu_head
*head
)
1452 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
1453 kmem_cache_free(ufs_inode_cachep
, UFS_I(inode
));
1456 static void ufs_destroy_inode(struct inode
*inode
)
1458 call_rcu(&inode
->i_rcu
, ufs_i_callback
);
1461 static void init_once(void *foo
)
1463 struct ufs_inode_info
*ei
= (struct ufs_inode_info
*) foo
;
1465 inode_init_once(&ei
->vfs_inode
);
1468 static int __init
init_inodecache(void)
1470 ufs_inode_cachep
= kmem_cache_create_usercopy("ufs_inode_cache",
1471 sizeof(struct ufs_inode_info
), 0,
1472 (SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
|
1474 offsetof(struct ufs_inode_info
, i_u1
.i_symlink
),
1475 sizeof_field(struct ufs_inode_info
,
1478 if (ufs_inode_cachep
== NULL
)
1483 static void destroy_inodecache(void)
1486 * Make sure all delayed rcu free inodes are flushed before we
1490 kmem_cache_destroy(ufs_inode_cachep
);
1493 static const struct super_operations ufs_super_ops
= {
1494 .alloc_inode
= ufs_alloc_inode
,
1495 .destroy_inode
= ufs_destroy_inode
,
1496 .write_inode
= ufs_write_inode
,
1497 .evict_inode
= ufs_evict_inode
,
1498 .put_super
= ufs_put_super
,
1499 .sync_fs
= ufs_sync_fs
,
1500 .statfs
= ufs_statfs
,
1501 .remount_fs
= ufs_remount
,
1502 .show_options
= ufs_show_options
,
1505 static struct dentry
*ufs_mount(struct file_system_type
*fs_type
,
1506 int flags
, const char *dev_name
, void *data
)
1508 return mount_bdev(fs_type
, flags
, dev_name
, data
, ufs_fill_super
);
1511 static struct file_system_type ufs_fs_type
= {
1512 .owner
= THIS_MODULE
,
1515 .kill_sb
= kill_block_super
,
1516 .fs_flags
= FS_REQUIRES_DEV
,
1518 MODULE_ALIAS_FS("ufs");
1520 static int __init
init_ufs_fs(void)
1522 int err
= init_inodecache();
1525 err
= register_filesystem(&ufs_fs_type
);
1530 destroy_inodecache();
1535 static void __exit
exit_ufs_fs(void)
1537 unregister_filesystem(&ufs_fs_type
);
1538 destroy_inodecache();
1541 module_init(init_ufs_fs
)
1542 module_exit(exit_ufs_fs
)
1543 MODULE_LICENSE("GPL");