/*
* linux/fs/ufs/super.c
*
* Copyright (C) 1998
* Daniel Pirkl <daniel.pirkl@email.cz>
* Charles University, Faculty of Mathematics and Physics
*/
/* Derived from
*
* linux/fs/ext2/super.c
*
* Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr)
* Laboratoire MASI - Institut Blaise Pascal
* Universite Pierre et Marie Curie (Paris VI)
*
* from
*
* linux/fs/minix/inode.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
*
* Big-endian to little-endian byte-swapping/bitmaps by
* David S. Miller (davem@caip.rutgers.edu), 1995
*/
/*
* Inspired by
*
* linux/fs/ufs/super.c
*
* Copyright (C) 1996
* Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
* Laboratory for Computer Science Research Computing Facility
* Rutgers, The State University of New Jersey
*
* Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
*
* Kernel module support added on 96/04/26 by
* Stefan Reinauer <stepan@home.culture.mipt.ru>
*
* Module usage counts added on 96/04/29 by
* Gertjan van Wingerde <gwingerde@gmail.com>
*
* Clean swab support on 19970406 by
* Francois-Rene Rideau <fare@tunes.org>
*
* 4.4BSD (FreeBSD) support added on February 1st 1998 by
* Niels Kristian Bech Jensen <nkbj@image.dk> partially based
* on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
*
* NeXTstep support added on February 5th 1998 by
* Niels Kristian Bech Jensen <nkbj@image.dk>.
*
* write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
*
* HP/UX hfs filesystem support added by
* Martin K. Petersen <mkp@mkp.net>, August 1999
*
* UFS2 (of FreeBSD 5.x) support added by
* Niraj Kumar <niraj17@iitbombay.org>, Jan 2004
*
* UFS2 write support added by
* Evgeniy Dushistov <dushistov@mail.ru>, 2007
*/
#include <linux/exportfs.h>
#include <linux/module.h>
#include <linux/bitops.h>
#include <stdarg.h>
#include <asm/uaccess.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/time.h>
#include <linux/stat.h>
#include <linux/string.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/init.h>
#include <linux/parser.h>
#include <linux/buffer_head.h>
#include <linux/vfs.h>
#include <linux/log2.h>
#include <linux/mount.h>
#include <linux/seq_file.h>
#include "ufs_fs.h"
#include "ufs.h"
#include "swab.h"
#include "util.h"
static struct inode *ufs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation)
{
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
struct inode *inode;
if (ino < UFS_ROOTINO || ino > uspi->s_ncg * uspi->s_ipg)
return ERR_PTR(-ESTALE);
inode = ufs_iget(sb, ino);
if (IS_ERR(inode))
return ERR_CAST(inode);
if (generation && inode->i_generation != generation) {
iput(inode);
return ERR_PTR(-ESTALE);
}
return inode;
}
static struct dentry *ufs_fh_to_dentry(struct super_block *sb, struct fid *fid,
int fh_len, int fh_type)
{
return generic_fh_to_dentry(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
}
static struct dentry *ufs_fh_to_parent(struct super_block *sb, struct fid *fid,
int fh_len, int fh_type)
{
return generic_fh_to_parent(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
}
static struct dentry *ufs_get_parent(struct dentry *child)
{
struct qstr dot_dot = QSTR_INIT("..", 2);
ino_t ino;
ino = ufs_inode_by_name(d_inode(child), &dot_dot);
if (!ino)
return ERR_PTR(-ENOENT);
return d_obtain_alias(ufs_iget(child->d_sb, ino));
}
static const struct export_operations ufs_export_ops = {
.fh_to_dentry = ufs_fh_to_dentry,
.fh_to_parent = ufs_fh_to_parent,
.get_parent = ufs_get_parent,
};
#ifdef CONFIG_UFS_DEBUG
/*
* Print contents of ufs_super_block, useful for debugging
*/
static void ufs_print_super_stuff(struct super_block *sb,
struct ufs_super_block_first *usb1,
struct ufs_super_block_second *usb2,
struct ufs_super_block_third *usb3)
{
u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
pr_debug("ufs_print_super_stuff\n");
pr_debug(" magic: 0x%x\n", magic);
if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
pr_debug(" fs_size: %llu\n", (unsigned long long)
fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size));
pr_debug(" fs_dsize: %llu\n", (unsigned long long)
fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize));
pr_debug(" bsize: %u\n",
fs32_to_cpu(sb, usb1->fs_bsize));
pr_debug(" fsize: %u\n",
fs32_to_cpu(sb, usb1->fs_fsize));
pr_debug(" fs_volname: %s\n", usb2->fs_un.fs_u2.fs_volname);
pr_debug(" fs_sblockloc: %llu\n", (unsigned long long)
fs64_to_cpu(sb, usb2->fs_un.fs_u2.fs_sblockloc));
pr_debug(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir));
pr_debug(" cs_nbfree(No of free blocks): %llu\n",
(unsigned long long)
fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree));
pr_info(" cs_nifree(Num of free inodes): %llu\n",
(unsigned long long)
fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree));
pr_info(" cs_nffree(Num of free frags): %llu\n",
(unsigned long long)
fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
pr_info(" fs_maxsymlinklen: %u\n",
fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
} else {
pr_debug(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
pr_debug(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
pr_debug(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
pr_debug(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
pr_debug(" cgoffset: %u\n",
fs32_to_cpu(sb, usb1->fs_cgoffset));
pr_debug(" ~cgmask: 0x%x\n",
~fs32_to_cpu(sb, usb1->fs_cgmask));
pr_debug(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
pr_debug(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
pr_debug(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
pr_debug(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
pr_debug(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
pr_debug(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
pr_debug(" fragshift: %u\n",
fs32_to_cpu(sb, usb1->fs_fragshift));
pr_debug(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
pr_debug(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
pr_debug(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
pr_debug(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
pr_debug(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
pr_debug(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
pr_debug(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
pr_debug(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
pr_debug(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
pr_debug(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
pr_debug(" fstodb: %u\n",
fs32_to_cpu(sb, usb1->fs_fsbtodb));
pr_debug(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
pr_debug(" ndir %u\n",
fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
pr_debug(" nifree %u\n",
fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
pr_debug(" nbfree %u\n",
fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
pr_debug(" nffree %u\n",
fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
}
pr_debug("\n");
}
/*
* Print contents of ufs_cylinder_group, useful for debugging
*/
static void ufs_print_cylinder_stuff(struct super_block *sb,
struct ufs_cylinder_group *cg)
{
pr_debug("\nufs_print_cylinder_stuff\n");
pr_debug("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group));
pr_debug(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
pr_debug(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
pr_debug(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
pr_debug(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
pr_debug(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
pr_debug(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
pr_debug(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
pr_debug(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
pr_debug(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
pr_debug(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
pr_debug(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
pr_debug(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
pr_debug(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
pr_debug(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg
|