70 #include <linux/module.h>
71 #include <linux/bitops.h>
75 #include <asm/uaccess.h>
77 #include <linux/errno.h>
79 #include <linux/slab.h>
80 #include <linux/time.h>
81 #include <linux/stat.h>
82 #include <linux/string.h>
99 #if defined(CONFIG_SMP) || defined (CONFIG_PREEMPT)
109 #if defined(CONFIG_SMP) || defined (CONFIG_PREEMPT)
122 if (ino < UFS_ROOTINO || ino > uspi->
s_ncg * uspi->
s_ipg)
127 return ERR_CAST(inode);
136 int fh_len,
int fh_type)
142 int fh_len,
int fh_type)
159 .fh_to_dentry = ufs_fh_to_dentry,
160 .fh_to_parent = ufs_fh_to_parent,
161 .get_parent = ufs_get_parent,
164 #ifdef CONFIG_UFS_DEBUG
175 printk(
"ufs_print_super_stuff\n");
176 printk(
" magic: 0x%x\n", magic);
178 printk(
" fs_size: %llu\n", (
unsigned long long)
180 printk(
" fs_dsize: %llu\n", (
unsigned long long)
187 printk(
" fs_sblockloc: %llu\n", (
unsigned long long)
188 fs64_to_cpu(sb, usb2->
fs_un.
fs_u2.fs_sblockloc));
189 printk(
" cs_ndir(No of dirs): %llu\n", (
unsigned long long)
191 printk(
" cs_nbfree(No of free blocks): %llu\n",
193 fs64_to_cpu(sb, usb2->
fs_un.
fs_u2.cs_nbfree));
201 fs32_to_cpu(sb, usb3->
fs_un2.
fs_44.fs_maxsymlinklen));
209 printk(
" ~cgmask: 0x%x\n",
217 printk(
" fragshift: %u\n",
250 printk(
"\nufs_print_cylinder_stuff\n");
258 printk(
" cs_ndir: %u\n", fs32_to_cpu(sb, cg->
cg_cs.cs_ndir));
259 printk(
" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->
cg_cs.cs_nbfree));
260 printk(
" cs_nifree: %u\n", fs32_to_cpu(sb, cg->
cg_cs.cs_nifree));
261 printk(
" cs_nffree: %u\n", fs32_to_cpu(sb, cg->
cg_cs.cs_nffree));
265 printk(
" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
275 printk(
" clustersumoff %u\n",
276 fs32_to_cpu(sb, cg->
cg_u.
cg_44.cg_clustersumoff));
277 printk(
" clusteroff %u\n",
278 fs32_to_cpu(sb, cg->
cg_u.
cg_44.cg_clusteroff));
279 printk(
" nclusterblks %u\n",
280 fs32_to_cpu(sb, cg->
cg_u.
cg_44.cg_nclusterblks));
284 # define ufs_print_super_stuff(sb, usb1, usb2, usb3)
285 # define ufs_print_cylinder_stuff(sb, cg)
290 static char error_buf[1024];
293 const char *
fmt, ...)
299 uspi = UFS_SB(sb)->s_uspi;
309 vsnprintf (error_buf,
sizeof(error_buf), fmt, args);
313 panic (
"UFS-fs panic (device %s): %s: %s\n",
314 sb->
s_id,
function, error_buf);
320 sb->
s_id,
function, error_buf);
325 const char *
fmt, ...)
331 uspi = UFS_SB(sb)->s_uspi;
340 vsnprintf (error_buf,
sizeof(error_buf), fmt, args);
344 sb->
s_id,
function, error_buf);
348 const char *
fmt, ...)
353 vsnprintf (error_buf,
sizeof(error_buf), fmt, args);
356 sb->
s_id,
function, error_buf);
467 printk(
"UFS-fs: Unable to do repair on error, "
468 "will lock lock instead\n");
473 printk(
"UFS-fs: Invalid option: \"%s\" "
474 "or missing value\n", p);
486 static void ufs_setup_cstotal(
struct super_block *sb)
495 UFSD(
"ENTER, mtype=%u\n", mtype);
520 static int ufs_read_cylinder_structures(
struct super_block *sb)
525 unsigned char *
base, * space;
526 unsigned size, blks,
i;
542 for (i = 0; i < blks; i += uspi->
s_fpb) {
544 if (i + uspi->
s_fpb > blks)
565 for (i = 0; i < uspi->
s_ncg; i++)
571 for (i = 0; i < uspi->
s_ncg; i++) {
572 UFSD(
"read cg %u\n", i);
592 for (i = 0; i < uspi->
s_ncg; i++)
594 brelse (sbi->
s_ucg[i]);
599 UFSD(
"EXIT (FAILED)\n");
606 static void ufs_put_cstotal(
struct super_block *sb)
624 cpu_to_fs64(sb, uspi->
cs_total.cs_ndir);
626 cpu_to_fs64(sb, uspi->
cs_total.cs_nbfree);
628 cpu_to_fs64(sb, uspi->
cs_total.cs_nifree);
630 cpu_to_fs64(sb, uspi->
cs_total.cs_nffree);
633 cpu_to_fs32(sb, uspi->
cs_total.cs_ndir);
635 cpu_to_fs32(sb, uspi->
cs_total.cs_nbfree);
637 cpu_to_fs32(sb, uspi->
cs_total.cs_nifree);
639 cpu_to_fs32(sb, uspi->
cs_total.cs_nffree);
652 static void ufs_put_super_internal(
struct super_block *sb)
657 unsigned char * base, * space;
658 unsigned blks,
size,
i;
666 base = space = (
char*) sbi->
s_csp;
667 for (i = 0; i < blks; i += uspi->
s_fpb) {
669 if (i + uspi->
s_fpb > blks)
686 for (i = 0; i < uspi->
s_ncg; i++)
687 brelse (sbi->
s_ucg[i]);
706 flags = UFS_SB(sb)->s_flags;
707 uspi = UFS_SB(sb)->s_uspi;
715 ufs_set_fs_state(sb, usb1, usb3,
736 ufs_sync_fs(sbi->
sb, 1);
760 ufs_put_super_internal(sb);
771 static int ufs_fill_super(
struct super_block *sb,
void *
data,
int silent)
782 unsigned super_block_offset;
800 #ifndef CONFIG_UFS_FS_WRITE
802 printk(
"ufs was compiled with read-only support, "
803 "can't be mounted as read-write\n");
817 if (!ufs_parse_options ((
char *) data, &sbi->
s_mount_opt)) {
818 printk(
"wrong mount options\n");
823 printk(
"You didn't specify the type of your ufs filesystem\n\n"
824 "mount -t ufs -o ufstype="
825 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
826 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
827 "default is ufstype=old\n");
843 UFSD(
"ufstype=44bsd\n");
844 uspi->
s_fsize = block_size = 512;
847 uspi->
s_sbsize = super_block_size = 1536;
852 UFSD(
"ufstype=ufs2\n");
854 uspi->
s_fsize = block_size = 512;
857 uspi->
s_sbsize = super_block_size = 1536;
863 UFSD(
"ufstype=sun\n");
864 uspi->
s_fsize = block_size = 1024;
867 uspi->
s_sbsize = super_block_size = 2048;
874 UFSD((
"ufstype=sunos\n"))
875 uspi->s_fsize = block_size = 1024;
876 uspi->s_fmask = ~(1024 - 1);
878 uspi->s_sbsize = 2048;
879 super_block_size = 2048;
881 uspi->s_maxsymlinklen = 0;
886 UFSD("ufstype=sunx86\
n");
887 uspi->s_fsize = block_size = 1024;
888 uspi->s_fmask = ~(1024 - 1);
890 uspi->s_sbsize = super_block_size = 2048;
892 uspi->s_maxsymlinklen = 0;
897 UFSD("ufstype=old\n");
898 uspi->s_fsize = block_size = 1024;
899 uspi->s_fmask = ~(1024 - 1);
901 uspi->s_sbsize = super_block_size = 2048;
912 UFSD(
"ufstype=nextstep\n");
913 uspi->
s_fsize = block_size = 1024;
916 uspi->
s_sbsize = super_block_size = 2048;
920 if (!(sb->
s_flags & MS_RDONLY)) {
928 UFSD(
"ufstype=nextstep-cd\n");
929 uspi->
s_fsize = block_size = 2048;
932 uspi->
s_sbsize = super_block_size = 2048;
936 if (!(sb->
s_flags & MS_RDONLY)) {
944 UFSD(
"ufstype=openstep\n");
945 uspi->
s_fsize = block_size = 1024;
948 uspi->
s_sbsize = super_block_size = 2048;
952 if (!(sb->
s_flags & MS_RDONLY)) {
960 UFSD(
"ufstype=hp\n");
961 uspi->
s_fsize = block_size = 1024;
964 uspi->
s_sbsize = super_block_size = 2048;
967 if (!(sb->
s_flags & MS_RDONLY)) {
975 printk(
"unknown ufstype\n");
1002 flags &= ~UFS_ST_MASK;
1040 printk(
"ufs_read_super: bad magic number\n");
1054 printk(
KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n",
1059 printk(
KERN_ERR "ufs_read_super: fragment size %u is too small\n",
1064 printk(
KERN_ERR "ufs_read_super: fragment size %u is too large\n",
1069 printk(
KERN_ERR "ufs_read_super: block size %u is not a power of 2\n",
1079 printk(
KERN_ERR "ufs_read_super: too many fragments per block (%u)\n",
1083 if (uspi->
s_fsize != block_size || uspi->
s_sbsize != super_block_size) {
1088 UFSD(
"another value of block_size or super_block_size %u, %u\n", block_size, super_block_size);
1104 (ufs_get_fs_state(sb, usb1, usb3) == (
UFS_FSOK - fs32_to_cpu(sb, usb1->
fs_time))))) {
1107 UFSD(
"fs is clean\n");
1110 UFSD(
"fs is stable\n");
1113 UFSD(
"fs is logging fs\n");
1116 UFSD(
"fs is DEC OSF/1\n");
1119 printk(
"ufs_read_super: fs is active\n");
1123 printk(
"ufs_read_super: fs is bad\n");
1127 printk(
"ufs_read_super: can't grok fs_clean 0x%x\n", usb1->
fs_clean);
1132 printk(
"ufs_read_super: fs needs fsck\n");
1139 sb->
s_op = &ufs_super_ops;
1168 UFSD(
"uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->
s_bshift,
1178 uspi->
s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
1196 uspi->
s_qbmask = ufs_get_fs_qbmask(sb, usb3);
1197 uspi->
s_qfmask = ufs_get_fs_qfmask(sb, usb3);
1226 fs32_to_cpu(sb, usb3->
fs_un2.
fs_44.fs_maxsymlinklen);
1233 ufs_warning(sb, __func__,
"ufs_read_super: excessive maximum "
1240 if (IS_ERR(inode)) {
1241 ret = PTR_ERR(inode);
1250 ufs_setup_cstotal(sb);
1254 if (!(sb->
s_flags & MS_RDONLY))
1255 if (!ufs_read_cylinder_structures(sb))
1267 UFSD(
"EXIT (FAILED)\n");
1271 UFSD(
"EXIT (NOMEM)\n");
1275 static int ufs_remount (
struct super_block *sb,
int *mount_flags,
char *data)
1280 unsigned new_mount_opt, ufstype;
1285 uspi = UFS_SB(sb)->s_uspi;
1286 flags = UFS_SB(sb)->s_flags;
1297 if (!ufs_parse_options (data, &new_mount_opt)) {
1303 new_mount_opt |= ufstype;
1304 }
else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
1305 printk(
"ufstype can't be changed during remount\n");
1311 if ((*mount_flags & MS_RDONLY) == (sb->
s_flags & MS_RDONLY)) {
1312 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1321 if (*mount_flags & MS_RDONLY) {
1322 ufs_put_super_internal(sb);
1327 ufs_set_fs_state(sb, usb1, usb3,
1335 #ifndef CONFIG_UFS_FS_WRITE
1336 printk(
"ufs was compiled with read-only support, "
1337 "can't be mounted as read-write\n");
1347 printk(
"this ufstype is read-only supported\n");
1352 if (!ufs_read_cylinder_structures(sb)) {
1353 printk(
"failed during remounting\n");
1361 UFS_SB(sb)->s_mount_opt = new_mount_opt;
1367 static int ufs_show_options(
struct seq_file *seq,
struct dentry *root)
1391 unsigned flags = UFS_SB(sb)->s_flags;
1395 u64 id = huge_encode_dev(sb->
s_bdev->bd_dev);
1428 static struct inode *ufs_alloc_inode(
struct super_block *sb)
1444 static void ufs_destroy_inode(
struct inode *inode)
1449 static void init_once(
void *
foo)
1456 static int init_inodecache(
void)
1463 if (ufs_inode_cachep ==
NULL)
1468 static void destroy_inodecache(
void)
1479 .alloc_inode = ufs_alloc_inode,
1480 .destroy_inode = ufs_destroy_inode,
1483 .put_super = ufs_put_super,
1484 .sync_fs = ufs_sync_fs,
1485 .statfs = ufs_statfs,
1486 .remount_fs = ufs_remount,
1487 .show_options = ufs_show_options,
1491 int flags,
const char *dev_name,
void *data)
1493 return mount_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
1504 static int __init init_ufs_fs(
void)
1506 int err = init_inodecache();
1514 destroy_inodecache();
1519 static void __exit exit_ufs_fs(
void)
1522 destroy_inodecache();