5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
11 * linux/fs/ext2/super.c
13 * Copyright (C) 1992, 1993, 1994, 1995
14 * Remy Card (card@masi.ibp.fr)
15 * Laboratoire MASI - Institut Blaise Pascal
16 * Universite Pierre et Marie Curie (Paris VI)
20 * linux/fs/minix/inode.c
22 * Copyright (C) 1991, 1992 Linus Torvalds
24 * Big-endian to little-endian byte-swapping/bitmaps by
25 * David S. Miller (davem@caip.rutgers.edu), 1995
31 * linux/fs/ufs/super.c
34 * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
35 * Laboratory for Computer Science Research Computing Facility
36 * Rutgers, The State University of New Jersey
38 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
40 * Kernel module support added on 96/04/26 by
41 * Stefan Reinauer <stepan@home.culture.mipt.ru>
43 * Module usage counts added on 96/04/29 by
44 * Gertjan van Wingerde <gertjan@cs.vu.nl>
46 * Clean swab support on 19970406 by
47 * Francois-Rene Rideau <fare@tunes.org>
49 * 4.4BSD (FreeBSD) support added on February 1st 1998 by
50 * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
51 * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
53 * NeXTstep support added on February 5th 1998 by
54 * Niels Kristian Bech Jensen <nkbj@image.dk>.
56 * write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
58 * HP/UX hfs filesystem support added by
59 * Martin K. Petersen <mkp@mkp.net>, August 1999
61 * UFS2 (of FreeBSD 5.x) support added by
62 * Niraj Kumar <niraj17@iitbombay.org>, Jan 2004
64 * UFS2 write support added by
65 * Evgeniy Dushistov <dushistov@mail.ru>, 2007
69 #include <linux/module.h>
70 #include <linux/bitops.h>
74 #include <asm/uaccess.h>
75 #include <asm/system.h>
77 #include <linux/errno.h>
79 #include <linux/ufs_fs.h>
80 #include <linux/slab.h>
81 #include <linux/time.h>
82 #include <linux/stat.h>
83 #include <linux/string.h>
84 #include <linux/blkdev.h>
85 #include <linux/init.h>
86 #include <linux/parser.h>
87 #include <linux/smp_lock.h>
88 #include <linux/buffer_head.h>
89 #include <linux/vfs.h>
94 #ifdef CONFIG_UFS_DEBUG
96 * Print contents of ufs_super_block, useful for debugging
98 static void ufs_print_super_stuff(struct super_block
*sb
,
99 struct ufs_super_block_first
*usb1
,
100 struct ufs_super_block_second
*usb2
,
101 struct ufs_super_block_third
*usb3
)
103 u32 magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
105 printk("ufs_print_super_stuff\n");
106 printk(" magic: 0x%x\n", magic
);
107 if (fs32_to_cpu(sb
, usb3
->fs_magic
) == UFS2_MAGIC
) {
108 printk(" fs_size: %llu\n", (unsigned long long)
109 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
));
110 printk(" fs_dsize: %llu\n", (unsigned long long)
111 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
));
112 printk(" bsize: %u\n",
113 fs32_to_cpu(sb
, usb1
->fs_bsize
));
114 printk(" fsize: %u\n",
115 fs32_to_cpu(sb
, usb1
->fs_fsize
));
116 printk(" fs_volname: %s\n", usb2
->fs_un
.fs_u2
.fs_volname
);
117 printk(" fs_sblockloc: %llu\n", (unsigned long long)
118 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.fs_sblockloc
));
119 printk(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
120 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
));
121 printk(" cs_nbfree(No of free blocks): %llu\n",
123 fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
));
124 printk(KERN_INFO
" cs_nifree(Num of free inodes): %llu\n",
126 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
));
127 printk(KERN_INFO
" cs_nffree(Num of free frags): %llu\n",
129 fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
));
131 printk(" sblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_sblkno
));
132 printk(" cblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_cblkno
));
133 printk(" iblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_iblkno
));
134 printk(" dblkno: %u\n", fs32_to_cpu(sb
, usb1
->fs_dblkno
));
135 printk(" cgoffset: %u\n",
136 fs32_to_cpu(sb
, usb1
->fs_cgoffset
));
137 printk(" ~cgmask: 0x%x\n",
138 ~fs32_to_cpu(sb
, usb1
->fs_cgmask
));
139 printk(" size: %u\n", fs32_to_cpu(sb
, usb1
->fs_size
));
140 printk(" dsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_dsize
));
141 printk(" ncg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ncg
));
142 printk(" bsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_bsize
));
143 printk(" fsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_fsize
));
144 printk(" frag: %u\n", fs32_to_cpu(sb
, usb1
->fs_frag
));
145 printk(" fragshift: %u\n",
146 fs32_to_cpu(sb
, usb1
->fs_fragshift
));
147 printk(" ~fmask: %u\n", ~fs32_to_cpu(sb
, usb1
->fs_fmask
));
148 printk(" fshift: %u\n", fs32_to_cpu(sb
, usb1
->fs_fshift
));
149 printk(" sbsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_sbsize
));
150 printk(" spc: %u\n", fs32_to_cpu(sb
, usb1
->fs_spc
));
151 printk(" cpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_cpg
));
152 printk(" ipg: %u\n", fs32_to_cpu(sb
, usb1
->fs_ipg
));
153 printk(" fpg: %u\n", fs32_to_cpu(sb
, usb1
->fs_fpg
));
154 printk(" csaddr: %u\n", fs32_to_cpu(sb
, usb1
->fs_csaddr
));
155 printk(" cssize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cssize
));
156 printk(" cgsize: %u\n", fs32_to_cpu(sb
, usb1
->fs_cgsize
));
157 printk(" fstodb: %u\n",
158 fs32_to_cpu(sb
, usb1
->fs_fsbtodb
));
159 printk(" nrpos: %u\n", fs32_to_cpu(sb
, usb3
->fs_nrpos
));
161 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
));
162 printk(" nifree %u\n",
163 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
));
164 printk(" nbfree %u\n",
165 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
));
166 printk(" nffree %u\n",
167 fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
));
173 * Print contents of ufs_cylinder_group, useful for debugging
175 static void ufs_print_cylinder_stuff(struct super_block
*sb
,
176 struct ufs_cylinder_group
*cg
)
178 printk("\nufs_print_cylinder_stuff\n");
179 printk("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group
));
180 printk(" magic: %x\n", fs32_to_cpu(sb
, cg
->cg_magic
));
181 printk(" time: %u\n", fs32_to_cpu(sb
, cg
->cg_time
));
182 printk(" cgx: %u\n", fs32_to_cpu(sb
, cg
->cg_cgx
));
183 printk(" ncyl: %u\n", fs16_to_cpu(sb
, cg
->cg_ncyl
));
184 printk(" niblk: %u\n", fs16_to_cpu(sb
, cg
->cg_niblk
));
185 printk(" ndblk: %u\n", fs32_to_cpu(sb
, cg
->cg_ndblk
));
186 printk(" cs_ndir: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_ndir
));
187 printk(" cs_nbfree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nbfree
));
188 printk(" cs_nifree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nifree
));
189 printk(" cs_nffree: %u\n", fs32_to_cpu(sb
, cg
->cg_cs
.cs_nffree
));
190 printk(" rotor: %u\n", fs32_to_cpu(sb
, cg
->cg_rotor
));
191 printk(" frotor: %u\n", fs32_to_cpu(sb
, cg
->cg_frotor
));
192 printk(" irotor: %u\n", fs32_to_cpu(sb
, cg
->cg_irotor
));
193 printk(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
194 fs32_to_cpu(sb
, cg
->cg_frsum
[0]), fs32_to_cpu(sb
, cg
->cg_frsum
[1]),
195 fs32_to_cpu(sb
, cg
->cg_frsum
[2]), fs32_to_cpu(sb
, cg
->cg_frsum
[3]),
196 fs32_to_cpu(sb
, cg
->cg_frsum
[4]), fs32_to_cpu(sb
, cg
->cg_frsum
[5]),
197 fs32_to_cpu(sb
, cg
->cg_frsum
[6]), fs32_to_cpu(sb
, cg
->cg_frsum
[7]));
198 printk(" btotoff: %u\n", fs32_to_cpu(sb
, cg
->cg_btotoff
));
199 printk(" boff: %u\n", fs32_to_cpu(sb
, cg
->cg_boff
));
200 printk(" iuseoff: %u\n", fs32_to_cpu(sb
, cg
->cg_iusedoff
));
201 printk(" freeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_freeoff
));
202 printk(" nextfreeoff: %u\n", fs32_to_cpu(sb
, cg
->cg_nextfreeoff
));
203 printk(" clustersumoff %u\n",
204 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clustersumoff
));
205 printk(" clusteroff %u\n",
206 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_clusteroff
));
207 printk(" nclusterblks %u\n",
208 fs32_to_cpu(sb
, cg
->cg_u
.cg_44
.cg_nclusterblks
));
212 # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
213 # define ufs_print_cylinder_stuff(sb, cg) /**/
214 #endif /* CONFIG_UFS_DEBUG */
216 static const struct super_operations ufs_super_ops
;
218 static char error_buf
[1024];
220 void ufs_error (struct super_block
* sb
, const char * function
,
221 const char * fmt
, ...)
223 struct ufs_sb_private_info
* uspi
;
224 struct ufs_super_block_first
* usb1
;
227 uspi
= UFS_SB(sb
)->s_uspi
;
228 usb1
= ubh_get_usb_first(uspi
);
230 if (!(sb
->s_flags
& MS_RDONLY
)) {
231 usb1
->fs_clean
= UFS_FSBAD
;
232 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
234 sb
->s_flags
|= MS_RDONLY
;
236 va_start (args
, fmt
);
237 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
239 switch (UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_ONERROR
) {
240 case UFS_MOUNT_ONERROR_PANIC
:
241 panic ("UFS-fs panic (device %s): %s: %s\n",
242 sb
->s_id
, function
, error_buf
);
244 case UFS_MOUNT_ONERROR_LOCK
:
245 case UFS_MOUNT_ONERROR_UMOUNT
:
246 case UFS_MOUNT_ONERROR_REPAIR
:
247 printk (KERN_CRIT
"UFS-fs error (device %s): %s: %s\n",
248 sb
->s_id
, function
, error_buf
);
252 void ufs_panic (struct super_block
* sb
, const char * function
,
253 const char * fmt
, ...)
255 struct ufs_sb_private_info
* uspi
;
256 struct ufs_super_block_first
* usb1
;
259 uspi
= UFS_SB(sb
)->s_uspi
;
260 usb1
= ubh_get_usb_first(uspi
);
262 if (!(sb
->s_flags
& MS_RDONLY
)) {
263 usb1
->fs_clean
= UFS_FSBAD
;
264 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
267 va_start (args
, fmt
);
268 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
270 sb
->s_flags
|= MS_RDONLY
;
271 printk (KERN_CRIT
"UFS-fs panic (device %s): %s: %s\n",
272 sb
->s_id
, function
, error_buf
);
275 void ufs_warning (struct super_block
* sb
, const char * function
,
276 const char * fmt
, ...)
280 va_start (args
, fmt
);
281 vsnprintf (error_buf
, sizeof(error_buf
), fmt
, args
);
283 printk (KERN_WARNING
"UFS-fs warning (device %s): %s: %s\n",
284 sb
->s_id
, function
, error_buf
);
288 Opt_type_old
, Opt_type_sunx86
, Opt_type_sun
, Opt_type_44bsd
,
289 Opt_type_ufs2
, Opt_type_hp
, Opt_type_nextstepcd
, Opt_type_nextstep
,
290 Opt_type_openstep
, Opt_onerror_panic
, Opt_onerror_lock
,
291 Opt_onerror_umount
, Opt_onerror_repair
, Opt_err
294 static match_table_t tokens
= {
295 {Opt_type_old
, "ufstype=old"},
296 {Opt_type_sunx86
, "ufstype=sunx86"},
297 {Opt_type_sun
, "ufstype=sun"},
298 {Opt_type_44bsd
, "ufstype=44bsd"},
299 {Opt_type_ufs2
, "ufstype=ufs2"},
300 {Opt_type_ufs2
, "ufstype=5xbsd"},
301 {Opt_type_hp
, "ufstype=hp"},
302 {Opt_type_nextstepcd
, "ufstype=nextstep-cd"},
303 {Opt_type_nextstep
, "ufstype=nextstep"},
304 {Opt_type_openstep
, "ufstype=openstep"},
305 {Opt_onerror_panic
, "onerror=panic"},
306 {Opt_onerror_lock
, "onerror=lock"},
307 {Opt_onerror_umount
, "onerror=umount"},
308 {Opt_onerror_repair
, "onerror=repair"},
312 static int ufs_parse_options (char * options
, unsigned * mount_options
)
321 while ((p
= strsep(&options
, ",")) != NULL
) {
322 substring_t args
[MAX_OPT_ARGS
];
327 token
= match_token(p
, tokens
, args
);
330 ufs_clear_opt (*mount_options
, UFSTYPE
);
331 ufs_set_opt (*mount_options
, UFSTYPE_OLD
);
333 case Opt_type_sunx86
:
334 ufs_clear_opt (*mount_options
, UFSTYPE
);
335 ufs_set_opt (*mount_options
, UFSTYPE_SUNx86
);
338 ufs_clear_opt (*mount_options
, UFSTYPE
);
339 ufs_set_opt (*mount_options
, UFSTYPE_SUN
);
342 ufs_clear_opt (*mount_options
, UFSTYPE
);
343 ufs_set_opt (*mount_options
, UFSTYPE_44BSD
);
346 ufs_clear_opt(*mount_options
, UFSTYPE
);
347 ufs_set_opt(*mount_options
, UFSTYPE_UFS2
);
350 ufs_clear_opt (*mount_options
, UFSTYPE
);
351 ufs_set_opt (*mount_options
, UFSTYPE_HP
);
353 case Opt_type_nextstepcd
:
354 ufs_clear_opt (*mount_options
, UFSTYPE
);
355 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP_CD
);
357 case Opt_type_nextstep
:
358 ufs_clear_opt (*mount_options
, UFSTYPE
);
359 ufs_set_opt (*mount_options
, UFSTYPE_NEXTSTEP
);
361 case Opt_type_openstep
:
362 ufs_clear_opt (*mount_options
, UFSTYPE
);
363 ufs_set_opt (*mount_options
, UFSTYPE_OPENSTEP
);
365 case Opt_onerror_panic
:
366 ufs_clear_opt (*mount_options
, ONERROR
);
367 ufs_set_opt (*mount_options
, ONERROR_PANIC
);
369 case Opt_onerror_lock
:
370 ufs_clear_opt (*mount_options
, ONERROR
);
371 ufs_set_opt (*mount_options
, ONERROR_LOCK
);
373 case Opt_onerror_umount
:
374 ufs_clear_opt (*mount_options
, ONERROR
);
375 ufs_set_opt (*mount_options
, ONERROR_UMOUNT
);
377 case Opt_onerror_repair
:
378 printk("UFS-fs: Unable to do repair on error, "
379 "will lock lock instead\n");
380 ufs_clear_opt (*mount_options
, ONERROR
);
381 ufs_set_opt (*mount_options
, ONERROR_REPAIR
);
384 printk("UFS-fs: Invalid option: \"%s\" "
385 "or missing value\n", p
);
393 * Diffrent types of UFS hold fs_cstotal in different
394 * places, and use diffrent data structure for it.
395 * To make things simplier we just copy fs_cstotal to ufs_sb_private_info
397 static void ufs_setup_cstotal(struct super_block
*sb
)
399 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
400 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
401 struct ufs_super_block_first
*usb1
;
402 struct ufs_super_block_second
*usb2
;
403 struct ufs_super_block_third
*usb3
;
404 unsigned mtype
= sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
406 UFSD("ENTER, mtype=%u\n", mtype
);
407 usb1
= ubh_get_usb_first(uspi
);
408 usb2
= ubh_get_usb_second(uspi
);
409 usb3
= ubh_get_usb_third(uspi
);
411 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
412 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
413 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
414 /*we have statistic in different place, then usual*/
415 uspi
->cs_total
.cs_ndir
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_ndir
);
416 uspi
->cs_total
.cs_nbfree
= fs64_to_cpu(sb
, usb2
->fs_un
.fs_u2
.cs_nbfree
);
417 uspi
->cs_total
.cs_nifree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nifree
);
418 uspi
->cs_total
.cs_nffree
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.cs_nffree
);
420 uspi
->cs_total
.cs_ndir
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_ndir
);
421 uspi
->cs_total
.cs_nbfree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nbfree
);
422 uspi
->cs_total
.cs_nifree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nifree
);
423 uspi
->cs_total
.cs_nffree
= fs32_to_cpu(sb
, usb1
->fs_cstotal
.cs_nffree
);
429 * Read on-disk structures associated with cylinder groups
431 static int ufs_read_cylinder_structures(struct super_block
*sb
)
433 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
434 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
435 struct ufs_buffer_head
* ubh
;
436 unsigned char * base
, * space
;
437 unsigned size
, blks
, i
;
438 struct ufs_super_block_third
*usb3
;
442 usb3
= ubh_get_usb_third(uspi
);
444 * Read cs structures from (usually) first data block
447 size
= uspi
->s_cssize
;
448 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
449 base
= space
= kmalloc(size
, GFP_KERNEL
);
452 sbi
->s_csp
= (struct ufs_csum
*)space
;
453 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
454 size
= uspi
->s_bsize
;
455 if (i
+ uspi
->s_fpb
> blks
)
456 size
= (blks
- i
) * uspi
->s_fsize
;
458 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
463 ubh_ubhcpymem (space
, ubh
, size
);
471 * Read cylinder group (we read only first fragment from block
472 * at this time) and prepare internal data structures for cg caching.
474 if (!(sbi
->s_ucg
= kmalloc (sizeof(struct buffer_head
*) * uspi
->s_ncg
, GFP_KERNEL
)))
476 for (i
= 0; i
< uspi
->s_ncg
; i
++)
477 sbi
->s_ucg
[i
] = NULL
;
478 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
479 sbi
->s_ucpi
[i
] = NULL
;
480 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
482 for (i
= 0; i
< uspi
->s_ncg
; i
++) {
483 UFSD("read cg %u\n", i
);
484 if (!(sbi
->s_ucg
[i
] = sb_bread(sb
, ufs_cgcmin(i
))))
486 if (!ufs_cg_chkmagic (sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
))
489 ufs_print_cylinder_stuff(sb
, (struct ufs_cylinder_group
*) sbi
->s_ucg
[i
]->b_data
);
491 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++) {
492 if (!(sbi
->s_ucpi
[i
] = kmalloc (sizeof(struct ufs_cg_private_info
), GFP_KERNEL
)))
494 sbi
->s_cgno
[i
] = UFS_CGNO_EMPTY
;
496 sbi
->s_cg_loaded
= 0;
503 for (i
= 0; i
< uspi
->s_ncg
; i
++)
505 brelse (sbi
->s_ucg
[i
]);
507 for (i
= 0; i
< UFS_MAX_GROUP_LOADED
; i
++)
508 kfree (sbi
->s_ucpi
[i
]);
510 UFSD("EXIT (FAILED)\n");
515 * Sync our internal copy of fs_cstotal with disk
517 static void ufs_put_cstotal(struct super_block
*sb
)
519 unsigned mtype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
520 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
521 struct ufs_super_block_first
*usb1
;
522 struct ufs_super_block_second
*usb2
;
523 struct ufs_super_block_third
*usb3
;
526 usb1
= ubh_get_usb_first(uspi
);
527 usb2
= ubh_get_usb_second(uspi
);
528 usb3
= ubh_get_usb_third(uspi
);
530 if ((mtype
== UFS_MOUNT_UFSTYPE_44BSD
&&
531 (usb1
->fs_flags
& UFS_FLAGS_UPDATED
)) ||
532 mtype
== UFS_MOUNT_UFSTYPE_UFS2
) {
533 /*we have statistic in different place, then usual*/
534 usb2
->fs_un
.fs_u2
.cs_ndir
=
535 cpu_to_fs64(sb
, uspi
->cs_total
.cs_ndir
);
536 usb2
->fs_un
.fs_u2
.cs_nbfree
=
537 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nbfree
);
538 usb3
->fs_un1
.fs_u2
.cs_nifree
=
539 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nifree
);
540 usb3
->fs_un1
.fs_u2
.cs_nffree
=
541 cpu_to_fs64(sb
, uspi
->cs_total
.cs_nffree
);
543 usb1
->fs_cstotal
.cs_ndir
=
544 cpu_to_fs32(sb
, uspi
->cs_total
.cs_ndir
);
545 usb1
->fs_cstotal
.cs_nbfree
=
546 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nbfree
);
547 usb1
->fs_cstotal
.cs_nifree
=
548 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nifree
);
549 usb1
->fs_cstotal
.cs_nffree
=
550 cpu_to_fs32(sb
, uspi
->cs_total
.cs_nffree
);
552 ubh_mark_buffer_dirty(USPI_UBH(uspi
));
553 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
558 * ufs_put_super_internal() - put on-disk intrenal structures
559 * @sb: pointer to super_block structure
560 * Put on-disk structures associated with cylinder groups
561 * and write them back to disk, also update cs_total on disk
563 static void ufs_put_super_internal(struct super_block
*sb
)
565 struct ufs_sb_info
*sbi
= UFS_SB(sb
);
566 struct ufs_sb_private_info
*uspi
= sbi
->s_uspi
;
567 struct ufs_buffer_head
* ubh
;
568 unsigned char * base
, * space
;
569 unsigned blks
, size
, i
;
574 size
= uspi
->s_cssize
;
575 blks
= (size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
576 base
= space
= (char*) sbi
->s_csp
;
577 for (i
= 0; i
< blks
; i
+= uspi
->s_fpb
) {
578 size
= uspi
->s_bsize
;
579 if (i
+ uspi
->s_fpb
> blks
)
580 size
= (blks
- i
) * uspi
->s_fsize
;
582 ubh
= ubh_bread(sb
, uspi
->s_csaddr
+ i
, size
);
584 ubh_memcpyubh (ubh
, space
, size
);
586 ubh_mark_buffer_uptodate (ubh
, 1);
587 ubh_mark_buffer_dirty (ubh
);
590 for (i
= 0; i
< sbi
->s_cg_loaded
; i
++) {
591 ufs_put_cylinder (sb
, i
);
592 kfree (sbi
->s_ucpi
[i
]);
594 for (; i
< UFS_MAX_GROUP_LOADED
; i
++)
595 kfree (sbi
->s_ucpi
[i
]);
596 for (i
= 0; i
< uspi
->s_ncg
; i
++)
597 brelse (sbi
->s_ucg
[i
]);
603 static int ufs_fill_super(struct super_block
*sb
, void *data
, int silent
)
605 struct ufs_sb_info
* sbi
;
606 struct ufs_sb_private_info
* uspi
;
607 struct ufs_super_block_first
* usb1
;
608 struct ufs_super_block_second
* usb2
;
609 struct ufs_super_block_third
* usb3
;
610 struct ufs_buffer_head
* ubh
;
612 unsigned block_size
, super_block_size
;
614 unsigned super_block_offset
;
622 sbi
= kzalloc(sizeof(struct ufs_sb_info
), GFP_KERNEL
);
627 UFSD("flag %u\n", (int)(sb
->s_flags
& MS_RDONLY
));
629 #ifndef CONFIG_UFS_FS_WRITE
630 if (!(sb
->s_flags
& MS_RDONLY
)) {
631 printk("ufs was compiled with read-only support, "
632 "can't be mounted as read-write\n");
637 * Set default mount options
638 * Parse mount options
640 sbi
->s_mount_opt
= 0;
641 ufs_set_opt (sbi
->s_mount_opt
, ONERROR_LOCK
);
642 if (!ufs_parse_options ((char *) data
, &sbi
->s_mount_opt
)) {
643 printk("wrong mount options\n");
646 if (!(sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
648 printk("You didn't specify the type of your ufs filesystem\n\n"
649 "mount -t ufs -o ufstype="
650 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
651 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
652 "default is ufstype=old\n");
653 ufs_set_opt (sbi
->s_mount_opt
, UFSTYPE_OLD
);
657 kmalloc (sizeof(struct ufs_sb_private_info
), GFP_KERNEL
);
660 uspi
->s_dirblksize
= UFS_SECTOR_SIZE
;
661 super_block_offset
=UFS_SBLOCK
;
663 /* Keep 2Gig file limit. Some UFS variants need to override
664 this but as I don't know which I'll let those in the know loosen
666 switch (sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) {
667 case UFS_MOUNT_UFSTYPE_44BSD
:
668 UFSD("ufstype=44bsd\n");
669 uspi
->s_fsize
= block_size
= 512;
670 uspi
->s_fmask
= ~(512 - 1);
672 uspi
->s_sbsize
= super_block_size
= 1536;
674 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
676 case UFS_MOUNT_UFSTYPE_UFS2
:
677 UFSD("ufstype=ufs2\n");
678 super_block_offset
=SBLOCK_UFS2
;
679 uspi
->s_fsize
= block_size
= 512;
680 uspi
->s_fmask
= ~(512 - 1);
682 uspi
->s_sbsize
= super_block_size
= 1536;
684 flags
|= UFS_TYPE_UFS2
| UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
687 case UFS_MOUNT_UFSTYPE_SUN
:
688 UFSD("ufstype=sun\n");
689 uspi
->s_fsize
= block_size
= 1024;
690 uspi
->s_fmask
= ~(1024 - 1);
692 uspi
->s_sbsize
= super_block_size
= 2048;
694 uspi
->s_maxsymlinklen
= 56;
695 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUN
| UFS_CG_SUN
;
698 case UFS_MOUNT_UFSTYPE_SUNx86
:
699 UFSD("ufstype=sunx86\n");
700 uspi
->s_fsize
= block_size
= 1024;
701 uspi
->s_fmask
= ~(1024 - 1);
703 uspi
->s_sbsize
= super_block_size
= 2048;
705 uspi
->s_maxsymlinklen
= 56;
706 flags
|= UFS_DE_OLD
| UFS_UID_EFT
| UFS_ST_SUNx86
| UFS_CG_SUN
;
709 case UFS_MOUNT_UFSTYPE_OLD
:
710 UFSD("ufstype=old\n");
711 uspi
->s_fsize
= block_size
= 1024;
712 uspi
->s_fmask
= ~(1024 - 1);
714 uspi
->s_sbsize
= super_block_size
= 2048;
716 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
717 if (!(sb
->s_flags
& MS_RDONLY
)) {
719 printk(KERN_INFO
"ufstype=old is supported read-only\n");
720 sb
->s_flags
|= MS_RDONLY
;
724 case UFS_MOUNT_UFSTYPE_NEXTSTEP
:
725 /*TODO: check may be we need set special dir block size?*/
726 UFSD("ufstype=nextstep\n");
727 uspi
->s_fsize
= block_size
= 1024;
728 uspi
->s_fmask
= ~(1024 - 1);
730 uspi
->s_sbsize
= super_block_size
= 2048;
732 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
733 if (!(sb
->s_flags
& MS_RDONLY
)) {
735 printk(KERN_INFO
"ufstype=nextstep is supported read-only\n");
736 sb
->s_flags
|= MS_RDONLY
;
740 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
:
741 /*TODO: check may be we need set special dir block size?*/
742 UFSD("ufstype=nextstep-cd\n");
743 uspi
->s_fsize
= block_size
= 2048;
744 uspi
->s_fmask
= ~(2048 - 1);
746 uspi
->s_sbsize
= super_block_size
= 2048;
748 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
749 if (!(sb
->s_flags
& MS_RDONLY
)) {
751 printk(KERN_INFO
"ufstype=nextstep-cd is supported read-only\n");
752 sb
->s_flags
|= MS_RDONLY
;
756 case UFS_MOUNT_UFSTYPE_OPENSTEP
:
757 UFSD("ufstype=openstep\n");
758 uspi
->s_fsize
= block_size
= 1024;
759 uspi
->s_fmask
= ~(1024 - 1);
761 uspi
->s_sbsize
= super_block_size
= 2048;
763 uspi
->s_dirblksize
= 1024;
764 flags
|= UFS_DE_44BSD
| UFS_UID_44BSD
| UFS_ST_44BSD
| UFS_CG_44BSD
;
765 if (!(sb
->s_flags
& MS_RDONLY
)) {
767 printk(KERN_INFO
"ufstype=openstep is supported read-only\n");
768 sb
->s_flags
|= MS_RDONLY
;
772 case UFS_MOUNT_UFSTYPE_HP
:
773 UFSD("ufstype=hp\n");
774 uspi
->s_fsize
= block_size
= 1024;
775 uspi
->s_fmask
= ~(1024 - 1);
777 uspi
->s_sbsize
= super_block_size
= 2048;
779 flags
|= UFS_DE_OLD
| UFS_UID_OLD
| UFS_ST_OLD
| UFS_CG_OLD
;
780 if (!(sb
->s_flags
& MS_RDONLY
)) {
782 printk(KERN_INFO
"ufstype=hp is supported read-only\n");
783 sb
->s_flags
|= MS_RDONLY
;
788 printk("unknown ufstype\n");
793 if (!sb_set_blocksize(sb
, block_size
)) {
794 printk(KERN_ERR
"UFS: failed to set blocksize\n");
799 * read ufs super block from device
802 ubh
= ubh_bread_uspi(uspi
, sb
, uspi
->s_sbbase
+ super_block_offset
/block_size
, super_block_size
);
808 usb1
= ubh_get_usb_first(uspi
);
809 usb2
= ubh_get_usb_second(uspi
);
810 usb3
= ubh_get_usb_third(uspi
);
813 * Check ufs magic number
815 sbi
->s_bytesex
= BYTESEX_LE
;
816 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
824 sbi
->s_bytesex
= BYTESEX_BE
;
825 switch ((uspi
->fs_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
))) {
834 if ((((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP
)
835 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD
)
836 || ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) == UFS_MOUNT_UFSTYPE_OPENSTEP
))
837 && uspi
->s_sbbase
< 256) {
838 ubh_brelse_uspi(uspi
);
844 printk("ufs_read_super: bad magic number\n");
849 * Check block and fragment sizes
851 uspi
->s_bsize
= fs32_to_cpu(sb
, usb1
->fs_bsize
);
852 uspi
->s_fsize
= fs32_to_cpu(sb
, usb1
->fs_fsize
);
853 uspi
->s_sbsize
= fs32_to_cpu(sb
, usb1
->fs_sbsize
);
854 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
855 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
857 if (uspi
->s_fsize
& (uspi
->s_fsize
- 1)) {
858 printk(KERN_ERR
"ufs_read_super: fragment size %u is not a power of 2\n",
862 if (uspi
->s_fsize
< 512) {
863 printk(KERN_ERR
"ufs_read_super: fragment size %u is too small\n",
867 if (uspi
->s_fsize
> 4096) {
868 printk(KERN_ERR
"ufs_read_super: fragment size %u is too large\n",
872 if (uspi
->s_bsize
& (uspi
->s_bsize
- 1)) {
873 printk(KERN_ERR
"ufs_read_super: block size %u is not a power of 2\n",
877 if (uspi
->s_bsize
< 4096) {
878 printk(KERN_ERR
"ufs_read_super: block size %u is too small\n",
882 if (uspi
->s_bsize
/ uspi
->s_fsize
> 8) {
883 printk(KERN_ERR
"ufs_read_super: too many fragments per block (%u)\n",
884 uspi
->s_bsize
/ uspi
->s_fsize
);
887 if (uspi
->s_fsize
!= block_size
|| uspi
->s_sbsize
!= super_block_size
) {
888 ubh_brelse_uspi(uspi
);
890 block_size
= uspi
->s_fsize
;
891 super_block_size
= uspi
->s_sbsize
;
892 UFSD("another value of block_size or super_block_size %u, %u\n", block_size
, super_block_size
);
897 ufs_print_super_stuff(sb
, usb1
, usb2
, usb3
);
900 * Check, if file system was correctly unmounted.
901 * If not, make it read only.
903 if (((flags
& UFS_ST_MASK
) == UFS_ST_44BSD
) ||
904 ((flags
& UFS_ST_MASK
) == UFS_ST_OLD
) ||
905 (((flags
& UFS_ST_MASK
) == UFS_ST_SUN
||
906 (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
) &&
907 (ufs_get_fs_state(sb
, usb1
, usb3
) == (UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
))))) {
908 switch(usb1
->fs_clean
) {
910 UFSD("fs is clean\n");
913 UFSD("fs is stable\n");
916 UFSD("fs is DEC OSF/1\n");
919 printk("ufs_read_super: fs is active\n");
920 sb
->s_flags
|= MS_RDONLY
;
923 printk("ufs_read_super: fs is bad\n");
924 sb
->s_flags
|= MS_RDONLY
;
927 printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1
->fs_clean
);
928 sb
->s_flags
|= MS_RDONLY
;
932 printk("ufs_read_super: fs needs fsck\n");
933 sb
->s_flags
|= MS_RDONLY
;
937 * Read ufs_super_block into internal data structures
939 sb
->s_op
= &ufs_super_ops
;
940 sb
->dq_op
= NULL
; /***/
941 sb
->s_magic
= fs32_to_cpu(sb
, usb3
->fs_magic
);
943 uspi
->s_sblkno
= fs32_to_cpu(sb
, usb1
->fs_sblkno
);
944 uspi
->s_cblkno
= fs32_to_cpu(sb
, usb1
->fs_cblkno
);
945 uspi
->s_iblkno
= fs32_to_cpu(sb
, usb1
->fs_iblkno
);
946 uspi
->s_dblkno
= fs32_to_cpu(sb
, usb1
->fs_dblkno
);
947 uspi
->s_cgoffset
= fs32_to_cpu(sb
, usb1
->fs_cgoffset
);
948 uspi
->s_cgmask
= fs32_to_cpu(sb
, usb1
->fs_cgmask
);
950 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
951 uspi
->s_u2_size
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_size
);
952 uspi
->s_u2_dsize
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
954 uspi
->s_size
= fs32_to_cpu(sb
, usb1
->fs_size
);
955 uspi
->s_dsize
= fs32_to_cpu(sb
, usb1
->fs_dsize
);
958 uspi
->s_ncg
= fs32_to_cpu(sb
, usb1
->fs_ncg
);
959 /* s_bsize already set */
960 /* s_fsize already set */
961 uspi
->s_fpb
= fs32_to_cpu(sb
, usb1
->fs_frag
);
962 uspi
->s_minfree
= fs32_to_cpu(sb
, usb1
->fs_minfree
);
963 uspi
->s_bmask
= fs32_to_cpu(sb
, usb1
->fs_bmask
);
964 uspi
->s_fmask
= fs32_to_cpu(sb
, usb1
->fs_fmask
);
965 uspi
->s_bshift
= fs32_to_cpu(sb
, usb1
->fs_bshift
);
966 uspi
->s_fshift
= fs32_to_cpu(sb
, usb1
->fs_fshift
);
967 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi
->s_bshift
,
969 uspi
->s_fpbshift
= fs32_to_cpu(sb
, usb1
->fs_fragshift
);
970 uspi
->s_fsbtodb
= fs32_to_cpu(sb
, usb1
->fs_fsbtodb
);
971 /* s_sbsize already set */
972 uspi
->s_csmask
= fs32_to_cpu(sb
, usb1
->fs_csmask
);
973 uspi
->s_csshift
= fs32_to_cpu(sb
, usb1
->fs_csshift
);
974 uspi
->s_nindir
= fs32_to_cpu(sb
, usb1
->fs_nindir
);
975 uspi
->s_inopb
= fs32_to_cpu(sb
, usb1
->fs_inopb
);
976 uspi
->s_nspf
= fs32_to_cpu(sb
, usb1
->fs_nspf
);
977 uspi
->s_npsect
= ufs_get_fs_npsect(sb
, usb1
, usb3
);
978 uspi
->s_interleave
= fs32_to_cpu(sb
, usb1
->fs_interleave
);
979 uspi
->s_trackskew
= fs32_to_cpu(sb
, usb1
->fs_trackskew
);
981 if (uspi
->fs_magic
== UFS2_MAGIC
)
982 uspi
->s_csaddr
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_csaddr
);
984 uspi
->s_csaddr
= fs32_to_cpu(sb
, usb1
->fs_csaddr
);
986 uspi
->s_cssize
= fs32_to_cpu(sb
, usb1
->fs_cssize
);
987 uspi
->s_cgsize
= fs32_to_cpu(sb
, usb1
->fs_cgsize
);
988 uspi
->s_ntrak
= fs32_to_cpu(sb
, usb1
->fs_ntrak
);
989 uspi
->s_nsect
= fs32_to_cpu(sb
, usb1
->fs_nsect
);
990 uspi
->s_spc
= fs32_to_cpu(sb
, usb1
->fs_spc
);
991 uspi
->s_ipg
= fs32_to_cpu(sb
, usb1
->fs_ipg
);
992 uspi
->s_fpg
= fs32_to_cpu(sb
, usb1
->fs_fpg
);
993 uspi
->s_cpc
= fs32_to_cpu(sb
, usb2
->fs_un
.fs_u1
.fs_cpc
);
994 uspi
->s_contigsumsize
= fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_contigsumsize
);
995 uspi
->s_qbmask
= ufs_get_fs_qbmask(sb
, usb3
);
996 uspi
->s_qfmask
= ufs_get_fs_qfmask(sb
, usb3
);
997 uspi
->s_postblformat
= fs32_to_cpu(sb
, usb3
->fs_postblformat
);
998 uspi
->s_nrpos
= fs32_to_cpu(sb
, usb3
->fs_nrpos
);
999 uspi
->s_postbloff
= fs32_to_cpu(sb
, usb3
->fs_postbloff
);
1000 uspi
->s_rotbloff
= fs32_to_cpu(sb
, usb3
->fs_rotbloff
);
1003 * Compute another frequently used values
1005 uspi
->s_fpbmask
= uspi
->s_fpb
- 1;
1006 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
1007 uspi
->s_apbshift
= uspi
->s_bshift
- 3;
1009 uspi
->s_apbshift
= uspi
->s_bshift
- 2;
1011 uspi
->s_2apbshift
= uspi
->s_apbshift
* 2;
1012 uspi
->s_3apbshift
= uspi
->s_apbshift
* 3;
1013 uspi
->s_apb
= 1 << uspi
->s_apbshift
;
1014 uspi
->s_2apb
= 1 << uspi
->s_2apbshift
;
1015 uspi
->s_3apb
= 1 << uspi
->s_3apbshift
;
1016 uspi
->s_apbmask
= uspi
->s_apb
- 1;
1017 uspi
->s_nspfshift
= uspi
->s_fshift
- UFS_SECTOR_BITS
;
1018 uspi
->s_nspb
= uspi
->s_nspf
<< uspi
->s_fpbshift
;
1019 uspi
->s_inopf
= uspi
->s_inopb
>> uspi
->s_fpbshift
;
1020 uspi
->s_bpf
= uspi
->s_fsize
<< 3;
1021 uspi
->s_bpfshift
= uspi
->s_fshift
+ 3;
1022 uspi
->s_bpfmask
= uspi
->s_bpf
- 1;
1023 if ((sbi
->s_mount_opt
& UFS_MOUNT_UFSTYPE
) ==
1024 UFS_MOUNT_UFSTYPE_44BSD
)
1025 uspi
->s_maxsymlinklen
=
1026 fs32_to_cpu(sb
, usb3
->fs_un2
.fs_44
.fs_maxsymlinklen
);
1028 sbi
->s_flags
= flags
;
1030 inode
= iget(sb
, UFS_ROOTINO
);
1031 if (!inode
|| is_bad_inode(inode
))
1033 sb
->s_root
= d_alloc_root(inode
);
1037 ufs_setup_cstotal(sb
);
1039 * Read cylinder group structures
1041 if (!(sb
->s_flags
& MS_RDONLY
))
1042 if (!ufs_read_cylinder_structures(sb
))
1052 ubh_brelse_uspi (uspi
);
1055 sb
->s_fs_info
= NULL
;
1056 UFSD("EXIT (FAILED)\n");
1060 UFSD("EXIT (NOMEM)\n");
1064 static void ufs_write_super(struct super_block
*sb
)
1066 struct ufs_sb_private_info
* uspi
;
1067 struct ufs_super_block_first
* usb1
;
1068 struct ufs_super_block_third
* usb3
;
1073 flags
= UFS_SB(sb
)->s_flags
;
1074 uspi
= UFS_SB(sb
)->s_uspi
;
1075 usb1
= ubh_get_usb_first(uspi
);
1076 usb3
= ubh_get_usb_third(uspi
);
1078 if (!(sb
->s_flags
& MS_RDONLY
)) {
1079 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1080 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1081 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1082 ufs_set_fs_state(sb
, usb1
, usb3
,
1083 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1084 ufs_put_cstotal(sb
);
1091 static void ufs_put_super(struct super_block
*sb
)
1093 struct ufs_sb_info
* sbi
= UFS_SB(sb
);
1097 if (!(sb
->s_flags
& MS_RDONLY
))
1098 ufs_put_super_internal(sb
);
1100 ubh_brelse_uspi (sbi
->s_uspi
);
1101 kfree (sbi
->s_uspi
);
1103 sb
->s_fs_info
= NULL
;
1109 static int ufs_remount (struct super_block
*sb
, int *mount_flags
, char *data
)
1111 struct ufs_sb_private_info
* uspi
;
1112 struct ufs_super_block_first
* usb1
;
1113 struct ufs_super_block_third
* usb3
;
1114 unsigned new_mount_opt
, ufstype
;
1117 uspi
= UFS_SB(sb
)->s_uspi
;
1118 flags
= UFS_SB(sb
)->s_flags
;
1119 usb1
= ubh_get_usb_first(uspi
);
1120 usb3
= ubh_get_usb_third(uspi
);
1123 * Allow the "check" option to be passed as a remount option.
1124 * It is not possible to change ufstype option during remount
1126 ufstype
= UFS_SB(sb
)->s_mount_opt
& UFS_MOUNT_UFSTYPE
;
1128 ufs_set_opt (new_mount_opt
, ONERROR_LOCK
);
1129 if (!ufs_parse_options (data
, &new_mount_opt
))
1131 if (!(new_mount_opt
& UFS_MOUNT_UFSTYPE
)) {
1132 new_mount_opt
|= ufstype
;
1133 } else if ((new_mount_opt
& UFS_MOUNT_UFSTYPE
) != ufstype
) {
1134 printk("ufstype can't be changed during remount\n");
1138 if ((*mount_flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
)) {
1139 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1144 * fs was mouted as rw, remounting ro
1146 if (*mount_flags
& MS_RDONLY
) {
1147 ufs_put_super_internal(sb
);
1148 usb1
->fs_time
= cpu_to_fs32(sb
, get_seconds());
1149 if ((flags
& UFS_ST_MASK
) == UFS_ST_SUN
1150 || (flags
& UFS_ST_MASK
) == UFS_ST_SUNx86
)
1151 ufs_set_fs_state(sb
, usb1
, usb3
,
1152 UFS_FSOK
- fs32_to_cpu(sb
, usb1
->fs_time
));
1153 ubh_mark_buffer_dirty (USPI_UBH(uspi
));
1155 sb
->s_flags
|= MS_RDONLY
;
1158 * fs was mounted as ro, remounting rw
1160 #ifndef CONFIG_UFS_FS_WRITE
1161 printk("ufs was compiled with read-only support, "
1162 "can't be mounted as read-write\n");
1165 if (ufstype
!= UFS_MOUNT_UFSTYPE_SUN
&&
1166 ufstype
!= UFS_MOUNT_UFSTYPE_44BSD
&&
1167 ufstype
!= UFS_MOUNT_UFSTYPE_SUNx86
&&
1168 ufstype
!= UFS_MOUNT_UFSTYPE_UFS2
) {
1169 printk("this ufstype is read-only supported\n");
1172 if (!ufs_read_cylinder_structures(sb
)) {
1173 printk("failed during remounting\n");
1176 sb
->s_flags
&= ~MS_RDONLY
;
1179 UFS_SB(sb
)->s_mount_opt
= new_mount_opt
;
1183 static int ufs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1185 struct super_block
*sb
= dentry
->d_sb
;
1186 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
1187 unsigned flags
= UFS_SB(sb
)->s_flags
;
1188 struct ufs_super_block_first
*usb1
;
1189 struct ufs_super_block_second
*usb2
;
1190 struct ufs_super_block_third
*usb3
;
1194 usb1
= ubh_get_usb_first(uspi
);
1195 usb2
= ubh_get_usb_second(uspi
);
1196 usb3
= ubh_get_usb_third(uspi
);
1198 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
) {
1199 buf
->f_type
= UFS2_MAGIC
;
1200 buf
->f_blocks
= fs64_to_cpu(sb
, usb3
->fs_un1
.fs_u2
.fs_dsize
);
1202 buf
->f_type
= UFS_MAGIC
;
1203 buf
->f_blocks
= uspi
->s_dsize
;
1205 buf
->f_bfree
= ufs_blkstofrags(uspi
->cs_total
.cs_nbfree
) +
1206 uspi
->cs_total
.cs_nffree
;
1207 buf
->f_ffree
= uspi
->cs_total
.cs_nifree
;
1208 buf
->f_bsize
= sb
->s_blocksize
;
1209 buf
->f_bavail
= (buf
->f_bfree
> (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
))
1210 ? (buf
->f_bfree
- (((long)buf
->f_blocks
/ 100) * uspi
->s_minfree
)) : 0;
1211 buf
->f_files
= uspi
->s_ncg
* uspi
->s_ipg
;
1212 buf
->f_namelen
= UFS_MAXNAMLEN
;
1219 static struct kmem_cache
* ufs_inode_cachep
;
1221 static struct inode
*ufs_alloc_inode(struct super_block
*sb
)
1223 struct ufs_inode_info
*ei
;
1224 ei
= (struct ufs_inode_info
*)kmem_cache_alloc(ufs_inode_cachep
, GFP_KERNEL
);
1227 ei
->vfs_inode
.i_version
= 1;
1228 return &ei
->vfs_inode
;
1231 static void ufs_destroy_inode(struct inode
*inode
)
1233 kmem_cache_free(ufs_inode_cachep
, UFS_I(inode
));
1236 static void init_once(void * foo
, struct kmem_cache
* cachep
, unsigned long flags
)
1238 struct ufs_inode_info
*ei
= (struct ufs_inode_info
*) foo
;
1240 inode_init_once(&ei
->vfs_inode
);
1243 static int init_inodecache(void)
1245 ufs_inode_cachep
= kmem_cache_create("ufs_inode_cache",
1246 sizeof(struct ufs_inode_info
),
1247 0, (SLAB_RECLAIM_ACCOUNT
|
1250 if (ufs_inode_cachep
== NULL
)
1255 static void destroy_inodecache(void)
1257 kmem_cache_destroy(ufs_inode_cachep
);
1261 static ssize_t
ufs_quota_read(struct super_block
*, int, char *,size_t, loff_t
);
1262 static ssize_t
ufs_quota_write(struct super_block
*, int, const char *, size_t, loff_t
);
1265 static const struct super_operations ufs_super_ops
= {
1266 .alloc_inode
= ufs_alloc_inode
,
1267 .destroy_inode
= ufs_destroy_inode
,
1268 .read_inode
= ufs_read_inode
,
1269 .write_inode
= ufs_write_inode
,
1270 .delete_inode
= ufs_delete_inode
,
1271 .put_super
= ufs_put_super
,
1272 .write_super
= ufs_write_super
,
1273 .statfs
= ufs_statfs
,
1274 .remount_fs
= ufs_remount
,
1276 .quota_read
= ufs_quota_read
,
1277 .quota_write
= ufs_quota_write
,
1283 /* Read data from quotafile - avoid pagecache and such because we cannot afford
1284 * acquiring the locks... As quota files are never truncated and quota code
1285 * itself serializes the operations (and noone else should touch the files)
1286 * we don't have to be afraid of races */
1287 static ssize_t
ufs_quota_read(struct super_block
*sb
, int type
, char *data
,
1288 size_t len
, loff_t off
)
1290 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1291 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1293 int offset
= off
& (sb
->s_blocksize
- 1);
1296 struct buffer_head
*bh
;
1297 loff_t i_size
= i_size_read(inode
);
1301 if (off
+len
> i_size
)
1304 while (toread
> 0) {
1305 tocopy
= sb
->s_blocksize
- offset
< toread
?
1306 sb
->s_blocksize
- offset
: toread
;
1308 bh
= ufs_bread(inode
, blk
, 0, &err
);
1311 if (!bh
) /* A hole? */
1312 memset(data
, 0, tocopy
);
1314 memcpy(data
, bh
->b_data
+offset
, tocopy
);
1325 /* Write to quotafile */
1326 static ssize_t
ufs_quota_write(struct super_block
*sb
, int type
,
1327 const char *data
, size_t len
, loff_t off
)
1329 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
1330 sector_t blk
= off
>> sb
->s_blocksize_bits
;
1332 int offset
= off
& (sb
->s_blocksize
- 1);
1334 size_t towrite
= len
;
1335 struct buffer_head
*bh
;
1337 mutex_lock_nested(&inode
->i_mutex
, I_MUTEX_QUOTA
);
1338 while (towrite
> 0) {
1339 tocopy
= sb
->s_blocksize
- offset
< towrite
?
1340 sb
->s_blocksize
- offset
: towrite
;
1342 bh
= ufs_bread(inode
, blk
, 1, &err
);
1346 memcpy(bh
->b_data
+offset
, data
, tocopy
);
1347 flush_dcache_page(bh
->b_page
);
1348 set_buffer_uptodate(bh
);
1349 mark_buffer_dirty(bh
);
1358 if (len
== towrite
) {
1359 mutex_unlock(&inode
->i_mutex
);
1362 if (inode
->i_size
< off
+len
-towrite
)
1363 i_size_write(inode
, off
+len
-towrite
);
1365 inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME_SEC
;
1366 mark_inode_dirty(inode
);
1367 mutex_unlock(&inode
->i_mutex
);
1368 return len
- towrite
;
1373 static int ufs_get_sb(struct file_system_type
*fs_type
,
1374 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
1376 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, ufs_fill_super
, mnt
);
1379 static struct file_system_type ufs_fs_type
= {
1380 .owner
= THIS_MODULE
,
1382 .get_sb
= ufs_get_sb
,
1383 .kill_sb
= kill_block_super
,
1384 .fs_flags
= FS_REQUIRES_DEV
,
1387 static int __init
init_ufs_fs(void)
1389 int err
= init_inodecache();
1392 err
= register_filesystem(&ufs_fs_type
);
1397 destroy_inodecache();
1402 static void __exit
exit_ufs_fs(void)
1404 unregister_filesystem(&ufs_fs_type
);
1405 destroy_inodecache();
1408 module_init(init_ufs_fs
)
1409 module_exit(exit_ufs_fs
)
1410 MODULE_LICENSE("GPL");