2019-05-19 12:08:20 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2009-03-21 22:18:57 +00:00
|
|
|
* Gertjan van Wingerde <gwingerde@gmail.com>
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2007-02-12 08:54:30 +00:00
|
|
|
* UFS2 write support added by
|
|
|
|
* Evgeniy Dushistov <dushistov@mail.ru>, 2007
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2009-12-16 00:46:51 +00:00
|
|
|
#include <linux/exportfs.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#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>
|
2015-05-22 21:13:32 +00:00
|
|
|
#include <linux/backing-dev.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/parser.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/vfs.h>
|
2007-07-16 06:41:36 +00:00
|
|
|
#include <linux/log2.h>
|
2007-10-17 06:26:32 +00:00
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/seq_file.h>
|
2017-12-11 11:35:18 +00:00
|
|
|
#include <linux/iversion.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:21:31 +00:00
|
|
|
#include "ufs_fs.h"
|
2007-10-17 06:26:51 +00:00
|
|
|
#include "ufs.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "swab.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2009-12-16 00:46:51 +00:00
|
|
|
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)
|
|
|
|
{
|
2012-05-10 20:14:12 +00:00
|
|
|
struct qstr dot_dot = QSTR_INIT("..", 2);
|
2009-12-16 00:46:51 +00:00
|
|
|
ino_t ino;
|
|
|
|
|
2015-03-17 22:25:59 +00:00
|
|
|
ino = ufs_inode_by_name(d_inode(child), &dot_dot);
|
2009-12-16 00:46:51 +00:00
|
|
|
if (!ino)
|
|
|
|
return ERR_PTR(-ENOENT);
|
2016-04-10 05:33:30 +00:00
|
|
|
return d_obtain_alias(ufs_iget(child->d_sb, ino));
|
2009-12-16 00:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
#ifdef CONFIG_UFS_DEBUG
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Print contents of ufs_super_block, useful for debugging
|
|
|
|
*/
|
2007-02-12 08:54:31 +00:00
|
|
|
static void ufs_print_super_stuff(struct super_block *sb,
|
2006-06-25 12:47:29 +00:00
|
|
|
struct ufs_super_block_first *usb1,
|
|
|
|
struct ufs_super_block_second *usb2,
|
|
|
|
struct ufs_super_block_third *usb3)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-02-12 08:54:31 +00:00
|
|
|
u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
|
|
|
|
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_debug("ufs_print_super_stuff\n");
|
|
|
|
pr_debug(" magic: 0x%x\n", magic);
|
2007-02-12 08:54:31 +00:00
|
|
|
if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
|
2014-08-08 21:20:57 +00:00
|
|
|
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));
|
2006-06-25 12:47:29 +00:00
|
|
|
} else {
|
2014-08-08 21:20:57 +00:00
|
|
|
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));
|
2006-06-25 12:47:29 +00:00
|
|
|
}
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_debug("\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print contents of ufs_cylinder_group, useful for debugging
|
|
|
|
*/
|
2006-06-25 12:47:29 +00:00
|
|
|
static void ufs_print_cylinder_stuff(struct super_block *sb,
|
|
|
|
struct ufs_cylinder_group *cg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-08-08 21:20:57 +00:00
|
|
|
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",
|
2005-04-16 22:20:36 +00:00
|
|
|
fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
|
|
|
|
fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
|
|
|
|
fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
|
|
|
|
fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_debug(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
|
|
|
|
pr_debug(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
|
|
|
|
pr_debug(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
|
|
|
|
pr_debug(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
|
|
|
|
pr_debug(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
|
|
|
|
pr_debug(" clustersumoff %u\n",
|
|
|
|
fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
|
|
|
|
pr_debug(" clusteroff %u\n",
|
|
|
|
fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
|
|
|
|
pr_debug(" nclusterblks %u\n",
|
|
|
|
fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
|
|
|
|
pr_debug("\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-06-25 12:47:29 +00:00
|
|
|
#else
|
2007-02-12 08:54:31 +00:00
|
|
|
# define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
|
2006-06-25 12:47:29 +00:00
|
|
|
# define ufs_print_cylinder_stuff(sb, cg) /**/
|
2006-06-25 12:47:24 +00:00
|
|
|
#endif /* CONFIG_UFS_DEBUG */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-02-12 08:55:41 +00:00
|
|
|
static const struct super_operations ufs_super_ops;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
void ufs_error (struct super_block * sb, const char * function,
|
|
|
|
const char * fmt, ...)
|
|
|
|
{
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_super_block_first * usb1;
|
2014-08-08 21:21:03 +00:00
|
|
|
struct va_format vaf;
|
2005-04-16 22:20:36 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
2006-01-14 08:42:06 +00:00
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
usb1->fs_clean = UFS_FSBAD;
|
2006-06-25 12:47:22 +00:00
|
|
|
ubh_mark_buffer_dirty(USPI_UBH(uspi));
|
2012-07-12 13:28:08 +00:00
|
|
|
ufs_mark_sb_dirty(sb);
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2014-08-08 21:21:03 +00:00
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
|
|
|
|
case UFS_MOUNT_ONERROR_PANIC:
|
2014-08-08 21:21:03 +00:00
|
|
|
panic("panic (device %s): %s: %pV\n",
|
|
|
|
sb->s_id, function, &vaf);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case UFS_MOUNT_ONERROR_LOCK:
|
|
|
|
case UFS_MOUNT_ONERROR_UMOUNT:
|
|
|
|
case UFS_MOUNT_ONERROR_REPAIR:
|
2014-08-08 21:21:03 +00:00
|
|
|
pr_crit("error (device %s): %s: %pV\n",
|
|
|
|
sb->s_id, function, &vaf);
|
|
|
|
}
|
|
|
|
va_end(args);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ufs_panic (struct super_block * sb, const char * function,
|
|
|
|
const char * fmt, ...)
|
|
|
|
{
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_super_block_first * usb1;
|
2014-08-08 21:21:03 +00:00
|
|
|
struct va_format vaf;
|
2005-04-16 22:20:36 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
2006-01-14 08:42:06 +00:00
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
usb1->fs_clean = UFS_FSBAD;
|
2006-06-25 12:47:22 +00:00
|
|
|
ubh_mark_buffer_dirty(USPI_UBH(uspi));
|
2012-07-12 13:28:08 +00:00
|
|
|
ufs_mark_sb_dirty(sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2014-08-08 21:21:03 +00:00
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2014-08-08 21:21:03 +00:00
|
|
|
pr_crit("panic (device %s): %s: %pV\n",
|
|
|
|
sb->s_id, function, &vaf);
|
|
|
|
va_end(args);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ufs_warning (struct super_block * sb, const char * function,
|
|
|
|
const char * fmt, ...)
|
|
|
|
{
|
2014-08-08 21:21:03 +00:00
|
|
|
struct va_format vaf;
|
2005-04-16 22:20:36 +00:00
|
|
|
va_list args;
|
|
|
|
|
2014-08-08 21:21:03 +00:00
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
|
|
|
pr_warn("(device %s): %s: %pV\n",
|
|
|
|
sb->s_id, function, &vaf);
|
|
|
|
va_end(args);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
2007-10-17 06:26:32 +00:00
|
|
|
Opt_type_old = UFS_MOUNT_UFSTYPE_OLD,
|
|
|
|
Opt_type_sunx86 = UFS_MOUNT_UFSTYPE_SUNx86,
|
|
|
|
Opt_type_sun = UFS_MOUNT_UFSTYPE_SUN,
|
|
|
|
Opt_type_sunos = UFS_MOUNT_UFSTYPE_SUNOS,
|
|
|
|
Opt_type_44bsd = UFS_MOUNT_UFSTYPE_44BSD,
|
|
|
|
Opt_type_ufs2 = UFS_MOUNT_UFSTYPE_UFS2,
|
|
|
|
Opt_type_hp = UFS_MOUNT_UFSTYPE_HP,
|
|
|
|
Opt_type_nextstepcd = UFS_MOUNT_UFSTYPE_NEXTSTEP_CD,
|
|
|
|
Opt_type_nextstep = UFS_MOUNT_UFSTYPE_NEXTSTEP,
|
|
|
|
Opt_type_openstep = UFS_MOUNT_UFSTYPE_OPENSTEP,
|
|
|
|
Opt_onerror_panic = UFS_MOUNT_ONERROR_PANIC,
|
|
|
|
Opt_onerror_lock = UFS_MOUNT_ONERROR_LOCK,
|
|
|
|
Opt_onerror_umount = UFS_MOUNT_ONERROR_UMOUNT,
|
|
|
|
Opt_onerror_repair = UFS_MOUNT_ONERROR_REPAIR,
|
|
|
|
Opt_err
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2008-10-13 09:46:57 +00:00
|
|
|
static const match_table_t tokens = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{Opt_type_old, "ufstype=old"},
|
|
|
|
{Opt_type_sunx86, "ufstype=sunx86"},
|
|
|
|
{Opt_type_sun, "ufstype=sun"},
|
2007-10-17 06:26:31 +00:00
|
|
|
{Opt_type_sunos, "ufstype=sunos"},
|
2005-04-16 22:20:36 +00:00
|
|
|
{Opt_type_44bsd, "ufstype=44bsd"},
|
|
|
|
{Opt_type_ufs2, "ufstype=ufs2"},
|
|
|
|
{Opt_type_ufs2, "ufstype=5xbsd"},
|
|
|
|
{Opt_type_hp, "ufstype=hp"},
|
|
|
|
{Opt_type_nextstepcd, "ufstype=nextstep-cd"},
|
|
|
|
{Opt_type_nextstep, "ufstype=nextstep"},
|
|
|
|
{Opt_type_openstep, "ufstype=openstep"},
|
2007-10-17 06:26:32 +00:00
|
|
|
/*end of possible ufs types */
|
2005-04-16 22:20:36 +00:00
|
|
|
{Opt_onerror_panic, "onerror=panic"},
|
|
|
|
{Opt_onerror_lock, "onerror=lock"},
|
|
|
|
{Opt_onerror_umount, "onerror=umount"},
|
|
|
|
{Opt_onerror_repair, "onerror=repair"},
|
|
|
|
{Opt_err, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ufs_parse_options (char * options, unsigned * mount_options)
|
|
|
|
{
|
|
|
|
char * p;
|
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ENTER\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!options)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
while ((p = strsep(&options, ",")) != NULL) {
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
|
|
|
int token;
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
token = match_token(p, tokens, args);
|
|
|
|
switch (token) {
|
|
|
|
case Opt_type_old:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_OLD);
|
|
|
|
break;
|
|
|
|
case Opt_type_sunx86:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
|
|
|
|
break;
|
|
|
|
case Opt_type_sun:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_SUN);
|
|
|
|
break;
|
2007-10-17 06:26:31 +00:00
|
|
|
case Opt_type_sunos:
|
|
|
|
ufs_clear_opt(*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt(*mount_options, UFSTYPE_SUNOS);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
case Opt_type_44bsd:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_44BSD);
|
|
|
|
break;
|
|
|
|
case Opt_type_ufs2:
|
|
|
|
ufs_clear_opt(*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt(*mount_options, UFSTYPE_UFS2);
|
|
|
|
break;
|
|
|
|
case Opt_type_hp:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_HP);
|
|
|
|
break;
|
|
|
|
case Opt_type_nextstepcd:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
|
|
|
|
break;
|
|
|
|
case Opt_type_nextstep:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
|
|
|
|
break;
|
|
|
|
case Opt_type_openstep:
|
|
|
|
ufs_clear_opt (*mount_options, UFSTYPE);
|
|
|
|
ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
|
|
|
|
break;
|
|
|
|
case Opt_onerror_panic:
|
|
|
|
ufs_clear_opt (*mount_options, ONERROR);
|
|
|
|
ufs_set_opt (*mount_options, ONERROR_PANIC);
|
|
|
|
break;
|
|
|
|
case Opt_onerror_lock:
|
|
|
|
ufs_clear_opt (*mount_options, ONERROR);
|
|
|
|
ufs_set_opt (*mount_options, ONERROR_LOCK);
|
|
|
|
break;
|
|
|
|
case Opt_onerror_umount:
|
|
|
|
ufs_clear_opt (*mount_options, ONERROR);
|
|
|
|
ufs_set_opt (*mount_options, ONERROR_UMOUNT);
|
|
|
|
break;
|
|
|
|
case Opt_onerror_repair:
|
2014-08-08 21:20:59 +00:00
|
|
|
pr_err("Unable to do repair on error, will lock lock instead\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ufs_clear_opt (*mount_options, ONERROR);
|
|
|
|
ufs_set_opt (*mount_options, ONERROR_REPAIR);
|
|
|
|
break;
|
|
|
|
default:
|
2014-08-08 21:20:59 +00:00
|
|
|
pr_err("Invalid option: \"%s\" or missing value\n", p);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-31 01:57:33 +00:00
|
|
|
* Different types of UFS hold fs_cstotal in different
|
|
|
|
* places, and use different data structure for it.
|
|
|
|
* To make things simpler we just copy fs_cstotal to ufs_sb_private_info
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2006-06-25 12:47:30 +00:00
|
|
|
static void ufs_setup_cstotal(struct super_block *sb)
|
2006-02-03 11:04:04 +00:00
|
|
|
{
|
2006-06-25 12:47:29 +00:00
|
|
|
struct ufs_sb_info *sbi = UFS_SB(sb);
|
|
|
|
struct ufs_sb_private_info *uspi = sbi->s_uspi;
|
2006-06-25 12:47:30 +00:00
|
|
|
struct ufs_super_block_first *usb1;
|
|
|
|
struct ufs_super_block_second *usb2;
|
2006-06-25 12:47:29 +00:00
|
|
|
struct ufs_super_block_third *usb3;
|
2006-06-25 12:47:30 +00:00
|
|
|
unsigned mtype = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
|
|
|
|
|
|
|
|
UFSD("ENTER, mtype=%u\n", mtype);
|
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
|
|
|
usb2 = ubh_get_usb_second(uspi);
|
|
|
|
usb3 = ubh_get_usb_third(uspi);
|
|
|
|
|
|
|
|
if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
|
2017-06-14 19:17:32 +00:00
|
|
|
(usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) ||
|
2006-06-25 12:47:30 +00:00
|
|
|
mtype == UFS_MOUNT_UFSTYPE_UFS2) {
|
|
|
|
/*we have statistic in different place, then usual*/
|
|
|
|
uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
|
|
|
|
uspi->cs_total.cs_nbfree = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree);
|
|
|
|
uspi->cs_total.cs_nifree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree);
|
|
|
|
uspi->cs_total.cs_nffree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree);
|
|
|
|
} else {
|
|
|
|
uspi->cs_total.cs_ndir = fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir);
|
|
|
|
uspi->cs_total.cs_nbfree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree);
|
|
|
|
uspi->cs_total.cs_nifree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
|
|
|
|
uspi->cs_total.cs_nffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
|
|
|
|
}
|
|
|
|
UFSD("EXIT\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read on-disk structures associated with cylinder groups
|
|
|
|
*/
|
|
|
|
static int ufs_read_cylinder_structures(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ufs_sb_info *sbi = UFS_SB(sb);
|
|
|
|
struct ufs_sb_private_info *uspi = sbi->s_uspi;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ufs_buffer_head * ubh;
|
|
|
|
unsigned char * base, * space;
|
|
|
|
unsigned size, blks, i;
|
2006-06-25 12:47:30 +00:00
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ENTER\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read cs structures from (usually) first data block
|
|
|
|
* on the device.
|
|
|
|
*/
|
|
|
|
size = uspi->s_cssize;
|
|
|
|
blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
|
2011-01-24 09:14:12 +00:00
|
|
|
base = space = kmalloc(size, GFP_NOFS);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!base)
|
|
|
|
goto failed;
|
2006-02-03 11:04:04 +00:00
|
|
|
sbi->s_csp = (struct ufs_csum *)space;
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < blks; i += uspi->s_fpb) {
|
|
|
|
size = uspi->s_bsize;
|
|
|
|
if (i + uspi->s_fpb > blks)
|
|
|
|
size = (blks - i) * uspi->s_fsize;
|
|
|
|
|
2007-02-12 08:54:31 +00:00
|
|
|
ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
|
2006-01-14 08:42:06 +00:00
|
|
|
|
|
|
|
if (!ubh)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
ubh_ubhcpymem (space, ubh, size);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
space += size;
|
|
|
|
ubh_brelse (ubh);
|
|
|
|
ubh = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read cylinder group (we read only first fragment from block
|
|
|
|
* at this time) and prepare internal data structures for cg caching.
|
|
|
|
*/
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
sbi->s_ucg = kmalloc_array(uspi->s_ncg, sizeof(struct buffer_head *),
|
|
|
|
GFP_NOFS);
|
|
|
|
if (!sbi->s_ucg)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
for (i = 0; i < uspi->s_ncg; i++)
|
|
|
|
sbi->s_ucg[i] = NULL;
|
|
|
|
for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
|
|
|
|
sbi->s_ucpi[i] = NULL;
|
|
|
|
sbi->s_cgno[i] = UFS_CGNO_EMPTY;
|
|
|
|
}
|
|
|
|
for (i = 0; i < uspi->s_ncg; i++) {
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("read cg %u\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
|
|
|
|
goto failed;
|
|
|
|
if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
|
|
|
|
goto failed;
|
2006-06-25 12:47:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
|
|
|
|
}
|
|
|
|
for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
|
2011-01-24 09:14:12 +00:00
|
|
|
if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_NOFS)))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
sbi->s_cgno[i] = UFS_CGNO_EMPTY;
|
|
|
|
}
|
|
|
|
sbi->s_cg_loaded = 0;
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
failed:
|
2005-11-07 09:01:34 +00:00
|
|
|
kfree (base);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (sbi->s_ucg) {
|
|
|
|
for (i = 0; i < uspi->s_ncg; i++)
|
2005-11-07 09:01:34 +00:00
|
|
|
if (sbi->s_ucg[i])
|
|
|
|
brelse (sbi->s_ucg[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree (sbi->s_ucg);
|
|
|
|
for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
|
2005-11-07 09:01:34 +00:00
|
|
|
kfree (sbi->s_ucpi[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT (FAILED)\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-06-25 12:47:30 +00:00
|
|
|
* Sync our internal copy of fs_cstotal with disk
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2006-06-25 12:47:30 +00:00
|
|
|
static void ufs_put_cstotal(struct super_block *sb)
|
2006-02-03 11:04:04 +00:00
|
|
|
{
|
2006-06-25 12:47:30 +00:00
|
|
|
unsigned mtype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
struct ufs_super_block_first *usb1;
|
|
|
|
struct ufs_super_block_second *usb2;
|
|
|
|
struct ufs_super_block_third *usb3;
|
|
|
|
|
|
|
|
UFSD("ENTER\n");
|
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
|
|
|
usb2 = ubh_get_usb_second(uspi);
|
|
|
|
usb3 = ubh_get_usb_third(uspi);
|
|
|
|
|
2017-06-14 19:17:32 +00:00
|
|
|
if (mtype == UFS_MOUNT_UFSTYPE_UFS2) {
|
2006-06-25 12:47:30 +00:00
|
|
|
/*we have statistic in different place, then usual*/
|
|
|
|
usb2->fs_un.fs_u2.cs_ndir =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
|
|
|
|
usb2->fs_un.fs_u2.cs_nbfree =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
|
|
|
|
usb3->fs_un1.fs_u2.cs_nifree =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
|
|
|
|
usb3->fs_un1.fs_u2.cs_nffree =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
|
2017-06-14 19:17:32 +00:00
|
|
|
goto out;
|
2006-06-25 12:47:30 +00:00
|
|
|
}
|
2017-06-14 19:17:32 +00:00
|
|
|
|
|
|
|
if (mtype == UFS_MOUNT_UFSTYPE_44BSD &&
|
|
|
|
(usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) {
|
|
|
|
/* store stats in both old and new places */
|
|
|
|
usb2->fs_un.fs_u2.cs_ndir =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
|
|
|
|
usb2->fs_un.fs_u2.cs_nbfree =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
|
|
|
|
usb3->fs_un1.fs_u2.cs_nifree =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
|
|
|
|
usb3->fs_un1.fs_u2.cs_nffree =
|
|
|
|
cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
|
2006-06-25 12:47:30 +00:00
|
|
|
}
|
2017-06-14 19:17:32 +00:00
|
|
|
usb1->fs_cstotal.cs_ndir = cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
|
|
|
|
usb1->fs_cstotal.cs_nbfree = cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
|
|
|
|
usb1->fs_cstotal.cs_nifree = cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
|
|
|
|
usb1->fs_cstotal.cs_nffree = cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
|
|
|
|
out:
|
2006-06-25 12:47:30 +00:00
|
|
|
ubh_mark_buffer_dirty(USPI_UBH(uspi));
|
2007-02-12 08:54:31 +00:00
|
|
|
ufs_print_super_stuff(sb, usb1, usb2, usb3);
|
2006-06-25 12:47:30 +00:00
|
|
|
UFSD("EXIT\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ufs_put_super_internal() - put on-disk intrenal structures
|
|
|
|
* @sb: pointer to super_block structure
|
|
|
|
* Put on-disk structures associated with cylinder groups
|
|
|
|
* and write them back to disk, also update cs_total on disk
|
|
|
|
*/
|
|
|
|
static void ufs_put_super_internal(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ufs_sb_info *sbi = UFS_SB(sb);
|
|
|
|
struct ufs_sb_private_info *uspi = sbi->s_uspi;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ufs_buffer_head * ubh;
|
|
|
|
unsigned char * base, * space;
|
|
|
|
unsigned blks, size, i;
|
2006-06-25 12:47:30 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ENTER\n");
|
push BKL down into ->put_super
Move BKL into ->put_super from the only caller. A couple of
filesystems had trivial enough ->put_super (only kfree and NULLing of
s_fs_info + stuff in there) to not get any locking: coda, cramfs, efs,
hugetlbfs, omfs, qnx4, shmem, all others got the full treatment. Most
of them probably don't need it, but I'd rather sort that out individually.
Preferably after all the other BKL pushdowns in that area.
[AV: original used to move lock_super() down as well; these changes are
removed since we don't do lock_super() at all in generic_shutdown_super()
now]
[AV: fuse, btrfs and xfs are known to need no damn BKL, exempt]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2009-05-05 13:40:36 +00:00
|
|
|
|
2006-06-25 12:47:30 +00:00
|
|
|
ufs_put_cstotal(sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
size = uspi->s_cssize;
|
|
|
|
blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
|
2006-02-03 11:04:04 +00:00
|
|
|
base = space = (char*) sbi->s_csp;
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < blks; i += uspi->s_fpb) {
|
|
|
|
size = uspi->s_bsize;
|
|
|
|
if (i + uspi->s_fpb > blks)
|
|
|
|
size = (blks - i) * uspi->s_fsize;
|
2007-02-12 08:54:31 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
|
2007-02-12 08:54:31 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ubh_memcpyubh (ubh, space, size);
|
|
|
|
space += size;
|
|
|
|
ubh_mark_buffer_uptodate (ubh, 1);
|
|
|
|
ubh_mark_buffer_dirty (ubh);
|
|
|
|
ubh_brelse (ubh);
|
|
|
|
}
|
|
|
|
for (i = 0; i < sbi->s_cg_loaded; i++) {
|
|
|
|
ufs_put_cylinder (sb, i);
|
|
|
|
kfree (sbi->s_ucpi[i]);
|
|
|
|
}
|
|
|
|
for (; i < UFS_MAX_GROUP_LOADED; i++)
|
|
|
|
kfree (sbi->s_ucpi[i]);
|
|
|
|
for (i = 0; i < uspi->s_ncg; i++)
|
|
|
|
brelse (sbi->s_ucg[i]);
|
|
|
|
kfree (sbi->s_ucg);
|
|
|
|
kfree (base);
|
push BKL down into ->put_super
Move BKL into ->put_super from the only caller. A couple of
filesystems had trivial enough ->put_super (only kfree and NULLing of
s_fs_info + stuff in there) to not get any locking: coda, cramfs, efs,
hugetlbfs, omfs, qnx4, shmem, all others got the full treatment. Most
of them probably don't need it, but I'd rather sort that out individually.
Preferably after all the other BKL pushdowns in that area.
[AV: original used to move lock_super() down as well; these changes are
removed since we don't do lock_super() at all in generic_shutdown_super()
now]
[AV: fuse, btrfs and xfs are known to need no damn BKL, exempt]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2009-05-05 13:40:36 +00:00
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 13:28:07 +00:00
|
|
|
static int ufs_sync_fs(struct super_block *sb, int wait)
|
|
|
|
{
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_super_block_first * usb1;
|
|
|
|
struct ufs_super_block_third * usb3;
|
|
|
|
unsigned flags;
|
|
|
|
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_lock(&UFS_SB(sb)->s_lock);
|
2012-07-12 13:28:07 +00:00
|
|
|
|
|
|
|
UFSD("ENTER\n");
|
|
|
|
|
|
|
|
flags = UFS_SB(sb)->s_flags;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
|
|
|
usb3 = ubh_get_usb_third(uspi);
|
|
|
|
|
2018-08-17 22:43:47 +00:00
|
|
|
usb1->fs_time = ufs_get_seconds(sb);
|
2012-07-12 13:28:07 +00:00
|
|
|
if ((flags & UFS_ST_MASK) == UFS_ST_SUN ||
|
|
|
|
(flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
|
|
|
|
(flags & UFS_ST_MASK) == UFS_ST_SUNx86)
|
|
|
|
ufs_set_fs_state(sb, usb1, usb3,
|
|
|
|
UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
|
|
|
|
ufs_put_cstotal(sb);
|
|
|
|
|
|
|
|
UFSD("EXIT\n");
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2012-07-12 13:28:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-12 13:28:08 +00:00
|
|
|
static void delayed_sync_fs(struct work_struct *work)
|
2012-07-12 13:28:07 +00:00
|
|
|
{
|
2012-07-12 13:28:08 +00:00
|
|
|
struct ufs_sb_info *sbi;
|
|
|
|
|
|
|
|
sbi = container_of(work, struct ufs_sb_info, sync_work.work);
|
|
|
|
|
|
|
|
spin_lock(&sbi->work_lock);
|
|
|
|
sbi->work_queued = 0;
|
|
|
|
spin_unlock(&sbi->work_lock);
|
|
|
|
|
|
|
|
ufs_sync_fs(sbi->sb, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ufs_mark_sb_dirty(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ufs_sb_info *sbi = UFS_SB(sb);
|
|
|
|
unsigned long delay;
|
|
|
|
|
|
|
|
spin_lock(&sbi->work_lock);
|
|
|
|
if (!sbi->work_queued) {
|
|
|
|
delay = msecs_to_jiffies(dirty_writeback_interval * 10);
|
|
|
|
queue_delayed_work(system_long_wq, &sbi->sync_work, delay);
|
|
|
|
sbi->work_queued = 1;
|
|
|
|
}
|
|
|
|
spin_unlock(&sbi->work_lock);
|
2012-07-12 13:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ufs_put_super(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ufs_sb_info * sbi = UFS_SB(sb);
|
|
|
|
|
|
|
|
UFSD("ENTER\n");
|
|
|
|
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb))
|
2012-07-12 13:28:07 +00:00
|
|
|
ufs_put_super_internal(sb);
|
2012-07-12 13:28:08 +00:00
|
|
|
cancel_delayed_work_sync(&sbi->sync_work);
|
2012-07-12 13:28:07 +00:00
|
|
|
|
|
|
|
ubh_brelse_uspi (sbi->s_uspi);
|
|
|
|
kfree (sbi->s_uspi);
|
|
|
|
kfree (sbi);
|
|
|
|
sb->s_fs_info = NULL;
|
|
|
|
UFSD("EXIT\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-09 01:15:45 +00:00
|
|
|
static u64 ufs_max_bytes(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
int bits = uspi->s_apbshift;
|
|
|
|
u64 res;
|
|
|
|
|
|
|
|
if (bits > 21)
|
|
|
|
res = ~0ULL;
|
|
|
|
else
|
|
|
|
res = UFS_NDADDR + (1LL << bits) + (1LL << (2*bits)) +
|
|
|
|
(1LL << (3*bits));
|
|
|
|
|
|
|
|
if (res >= (MAX_LFS_FILESIZE >> uspi->s_bshift))
|
|
|
|
return MAX_LFS_FILESIZE;
|
|
|
|
return res << uspi->s_bshift;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int ufs_fill_super(struct super_block *sb, void *data, int silent)
|
|
|
|
{
|
|
|
|
struct ufs_sb_info * sbi;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_super_block_first * usb1;
|
|
|
|
struct ufs_super_block_second * usb2;
|
|
|
|
struct ufs_super_block_third * usb3;
|
|
|
|
struct ufs_buffer_head * ubh;
|
|
|
|
struct inode *inode;
|
|
|
|
unsigned block_size, super_block_size;
|
|
|
|
unsigned flags;
|
2006-01-14 08:42:06 +00:00
|
|
|
unsigned super_block_offset;
|
2009-01-08 22:43:48 +00:00
|
|
|
unsigned maxsymlen;
|
2008-02-07 08:15:48 +00:00
|
|
|
int ret = -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
uspi = NULL;
|
|
|
|
ubh = NULL;
|
|
|
|
flags = 0;
|
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ENTER\n");
|
2014-06-06 21:38:34 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_UFS_FS_WRITE
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
|
2014-06-06 21:38:34 +00:00
|
|
|
return -EROFS;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-27 08:49:37 +00:00
|
|
|
sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!sbi)
|
|
|
|
goto failed_nomem;
|
|
|
|
sb->s_fs_info = sbi;
|
2012-07-12 13:28:08 +00:00
|
|
|
sbi->sb = sb;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-07-17 07:45:34 +00:00
|
|
|
UFSD("flag %u\n", (int)(sb_rdonly(sb)));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-17 16:15:45 +00:00
|
|
|
mutex_init(&sbi->s_lock);
|
2012-07-12 13:28:08 +00:00
|
|
|
spin_lock_init(&sbi->work_lock);
|
|
|
|
INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Set default mount options
|
|
|
|
* Parse mount options
|
|
|
|
*/
|
|
|
|
sbi->s_mount_opt = 0;
|
|
|
|
ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
|
|
|
|
if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("wrong mount options\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
|
|
|
|
if (!silent)
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("You didn't specify the type of your ufs filesystem\n\n"
|
2005-04-16 22:20:36 +00:00
|
|
|
"mount -t ufs -o ufstype="
|
2006-03-24 17:21:44 +00:00
|
|
|
"sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
|
2005-04-16 22:20:36 +00:00
|
|
|
">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
|
|
|
|
"default is ufstype=old\n");
|
|
|
|
ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
|
|
|
|
}
|
|
|
|
|
2007-10-17 06:26:31 +00:00
|
|
|
uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
|
|
|
|
sbi->s_uspi = uspi;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!uspi)
|
|
|
|
goto failed;
|
2007-02-08 22:20:25 +00:00
|
|
|
uspi->s_dirblksize = UFS_SECTOR_SIZE;
|
2006-01-14 08:42:06 +00:00
|
|
|
super_block_offset=UFS_SBLOCK;
|
|
|
|
|
2017-06-04 23:23:18 +00:00
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
|
|
|
|
2019-07-30 15:22:29 +00:00
|
|
|
sb->s_time_gran = NSEC_PER_SEC;
|
|
|
|
sb->s_time_min = S32_MIN;
|
|
|
|
sb->s_time_max = S32_MAX;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
|
|
|
|
case UFS_MOUNT_UFSTYPE_44BSD:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=44bsd\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 512;
|
|
|
|
uspi->s_fmask = ~(512 - 1);
|
|
|
|
uspi->s_fshift = 9;
|
|
|
|
uspi->s_sbsize = super_block_size = 1536;
|
|
|
|
uspi->s_sbbase = 0;
|
|
|
|
flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
|
|
|
|
break;
|
|
|
|
case UFS_MOUNT_UFSTYPE_UFS2:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=ufs2\n");
|
2006-01-14 08:42:06 +00:00
|
|
|
super_block_offset=SBLOCK_UFS2;
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 512;
|
|
|
|
uspi->s_fmask = ~(512 - 1);
|
|
|
|
uspi->s_fshift = 9;
|
|
|
|
uspi->s_sbsize = super_block_size = 1536;
|
|
|
|
uspi->s_sbbase = 0;
|
2019-07-30 15:22:29 +00:00
|
|
|
sb->s_time_gran = 1;
|
|
|
|
sb->s_time_min = S64_MIN;
|
|
|
|
sb->s_time_max = S64_MAX;
|
2005-04-16 22:20:36 +00:00
|
|
|
flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UFS_MOUNT_UFSTYPE_SUN:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=sun\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 1024;
|
|
|
|
uspi->s_fmask = ~(1024 - 1);
|
|
|
|
uspi->s_fshift = 10;
|
|
|
|
uspi->s_sbsize = super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
2007-10-17 06:26:31 +00:00
|
|
|
uspi->s_maxsymlinklen = 0; /* Not supported on disk */
|
2005-04-16 22:20:36 +00:00
|
|
|
flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
|
|
|
|
break;
|
|
|
|
|
2007-10-17 06:26:31 +00:00
|
|
|
case UFS_MOUNT_UFSTYPE_SUNOS:
|
2014-08-08 21:21:05 +00:00
|
|
|
UFSD("ufstype=sunos\n");
|
2007-10-17 06:26:31 +00:00
|
|
|
uspi->s_fsize = block_size = 1024;
|
|
|
|
uspi->s_fmask = ~(1024 - 1);
|
|
|
|
uspi->s_fshift = 10;
|
|
|
|
uspi->s_sbsize = 2048;
|
|
|
|
super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
|
|
|
uspi->s_maxsymlinklen = 0; /* Not supported on disk */
|
|
|
|
flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_SUNOS | UFS_CG_SUN;
|
|
|
|
break;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
case UFS_MOUNT_UFSTYPE_SUNx86:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=sunx86\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 1024;
|
|
|
|
uspi->s_fmask = ~(1024 - 1);
|
|
|
|
uspi->s_fshift = 10;
|
|
|
|
uspi->s_sbsize = super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
2007-10-17 06:26:31 +00:00
|
|
|
uspi->s_maxsymlinklen = 0; /* Not supported on disk */
|
2005-04-16 22:20:36 +00:00
|
|
|
flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UFS_MOUNT_UFSTYPE_OLD:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=old\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 1024;
|
|
|
|
uspi->s_fmask = ~(1024 - 1);
|
|
|
|
uspi->s_fshift = 10;
|
|
|
|
uspi->s_sbsize = super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
|
|
|
flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!silent)
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_info("ufstype=old is supported read-only\n");
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UFS_MOUNT_UFSTYPE_NEXTSTEP:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=nextstep\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 1024;
|
|
|
|
uspi->s_fmask = ~(1024 - 1);
|
|
|
|
uspi->s_fshift = 10;
|
|
|
|
uspi->s_sbsize = super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
2007-12-05 07:45:06 +00:00
|
|
|
uspi->s_dirblksize = 1024;
|
2005-04-16 22:20:36 +00:00
|
|
|
flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!silent)
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_info("ufstype=nextstep is supported read-only\n");
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=nextstep-cd\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 2048;
|
|
|
|
uspi->s_fmask = ~(2048 - 1);
|
|
|
|
uspi->s_fshift = 11;
|
|
|
|
uspi->s_sbsize = super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
2007-12-05 07:45:06 +00:00
|
|
|
uspi->s_dirblksize = 1024;
|
2005-04-16 22:20:36 +00:00
|
|
|
flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!silent)
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_info("ufstype=nextstep-cd is supported read-only\n");
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UFS_MOUNT_UFSTYPE_OPENSTEP:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=openstep\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 1024;
|
|
|
|
uspi->s_fmask = ~(1024 - 1);
|
|
|
|
uspi->s_fshift = 10;
|
|
|
|
uspi->s_sbsize = super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
2007-02-08 22:20:25 +00:00
|
|
|
uspi->s_dirblksize = 1024;
|
2005-04-16 22:20:36 +00:00
|
|
|
flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!silent)
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_info("ufstype=openstep is supported read-only\n");
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UFS_MOUNT_UFSTYPE_HP:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ufstype=hp\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fsize = block_size = 1024;
|
|
|
|
uspi->s_fmask = ~(1024 - 1);
|
|
|
|
uspi->s_fshift = 10;
|
|
|
|
uspi->s_sbsize = super_block_size = 2048;
|
|
|
|
uspi->s_sbbase = 0;
|
|
|
|
flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!silent)
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_info("ufstype=hp is supported read-only\n");
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!silent)
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("unknown ufstype\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
again:
|
|
|
|
if (!sb_set_blocksize(sb, block_size)) {
|
2014-08-08 21:20:59 +00:00
|
|
|
pr_err("failed to set blocksize\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read ufs super block from device
|
|
|
|
*/
|
2006-01-14 08:42:06 +00:00
|
|
|
|
|
|
|
ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!ubh)
|
|
|
|
goto failed;
|
|
|
|
|
2006-01-14 08:42:06 +00:00
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
|
|
|
usb2 = ubh_get_usb_second(uspi);
|
|
|
|
usb3 = ubh_get_usb_third(uspi);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-10-17 06:26:31 +00:00
|
|
|
/* Sort out mod used on SunOS 4.1.3 for fs_state */
|
|
|
|
uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
|
|
|
|
if (((flags & UFS_ST_MASK) == UFS_ST_SUNOS) &&
|
|
|
|
(uspi->s_postblformat != UFS_42POSTBLFMT)) {
|
|
|
|
flags &= ~UFS_ST_MASK;
|
|
|
|
flags |= UFS_ST_SUN;
|
|
|
|
}
|
|
|
|
|
2017-06-14 19:17:32 +00:00
|
|
|
if ((flags & UFS_ST_MASK) == UFS_ST_44BSD &&
|
|
|
|
uspi->s_postblformat == UFS_42POSTBLFMT) {
|
|
|
|
if (!silent)
|
|
|
|
pr_err("this is not a 44bsd filesystem");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Check ufs magic number
|
|
|
|
*/
|
|
|
|
sbi->s_bytesex = BYTESEX_LE;
|
|
|
|
switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
|
|
|
|
case UFS_MAGIC:
|
2010-05-26 21:42:33 +00:00
|
|
|
case UFS_MAGIC_BW:
|
2005-04-16 22:20:36 +00:00
|
|
|
case UFS2_MAGIC:
|
|
|
|
case UFS_MAGIC_LFN:
|
|
|
|
case UFS_MAGIC_FEA:
|
|
|
|
case UFS_MAGIC_4GB:
|
|
|
|
goto magic_found;
|
|
|
|
}
|
|
|
|
sbi->s_bytesex = BYTESEX_BE;
|
|
|
|
switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
|
|
|
|
case UFS_MAGIC:
|
2010-05-26 21:42:33 +00:00
|
|
|
case UFS_MAGIC_BW:
|
2005-04-16 22:20:36 +00:00
|
|
|
case UFS2_MAGIC:
|
|
|
|
case UFS_MAGIC_LFN:
|
|
|
|
case UFS_MAGIC_FEA:
|
|
|
|
case UFS_MAGIC_4GB:
|
|
|
|
goto magic_found;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
|
|
|
|
|| ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
|
|
|
|
|| ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
|
|
|
|
&& uspi->s_sbbase < 256) {
|
|
|
|
ubh_brelse_uspi(uspi);
|
|
|
|
ubh = NULL;
|
|
|
|
uspi->s_sbbase += 8;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (!silent)
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): bad magic number\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
|
|
|
|
magic_found:
|
|
|
|
/*
|
|
|
|
* Check block and fragment sizes
|
|
|
|
*/
|
|
|
|
uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
|
|
|
|
uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
|
|
|
|
uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
|
|
|
|
uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
|
|
|
|
uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
|
|
|
|
|
2007-07-16 06:41:36 +00:00
|
|
|
if (!is_power_of_2(uspi->s_fsize)) {
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): fragment size %u is not a power of 2\n",
|
|
|
|
__func__, uspi->s_fsize);
|
2014-08-08 21:20:57 +00:00
|
|
|
goto failed;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (uspi->s_fsize < 512) {
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): fragment size %u is too small\n",
|
|
|
|
__func__, uspi->s_fsize);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
if (uspi->s_fsize > 4096) {
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): fragment size %u is too large\n",
|
|
|
|
__func__, uspi->s_fsize);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
2007-07-16 06:41:36 +00:00
|
|
|
if (!is_power_of_2(uspi->s_bsize)) {
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): block size %u is not a power of 2\n",
|
|
|
|
__func__, uspi->s_bsize);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
if (uspi->s_bsize < 4096) {
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): block size %u is too small\n",
|
|
|
|
__func__, uspi->s_bsize);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
if (uspi->s_bsize / uspi->s_fsize > 8) {
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): too many fragments per block (%u)\n",
|
|
|
|
__func__, uspi->s_bsize / uspi->s_fsize);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
|
|
|
|
ubh_brelse_uspi(uspi);
|
|
|
|
ubh = NULL;
|
|
|
|
block_size = uspi->s_fsize;
|
|
|
|
super_block_size = uspi->s_sbsize;
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
2007-10-29 21:37:21 +00:00
|
|
|
sbi->s_flags = flags;/*after that line some functions use s_flags*/
|
2007-02-12 08:54:31 +00:00
|
|
|
ufs_print_super_stuff(sb, usb1, usb2, usb3);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check, if file system was correctly unmounted.
|
|
|
|
* If not, make it read only.
|
|
|
|
*/
|
2007-10-29 21:37:21 +00:00
|
|
|
if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
|
|
|
|
((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
|
|
|
|
(((flags & UFS_ST_MASK) == UFS_ST_SUN ||
|
|
|
|
(flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
|
|
|
|
(flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
|
|
|
|
(ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
|
2005-04-16 22:20:36 +00:00
|
|
|
switch(usb1->fs_clean) {
|
|
|
|
case UFS_FSCLEAN:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("fs is clean\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case UFS_FSSTABLE:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("fs is stable\n");
|
2010-03-10 23:21:53 +00:00
|
|
|
break;
|
|
|
|
case UFS_FSLOG:
|
|
|
|
UFSD("fs is logging fs\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case UFS_FSOSF1:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("fs is DEC OSF/1\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case UFS_FSACTIVE:
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): fs is active\n", __func__);
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case UFS_FSBAD:
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): fs is bad\n", __func__);
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): can't grok fs_clean 0x%x\n",
|
|
|
|
__func__, usb1->fs_clean);
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-06-25 12:47:30 +00:00
|
|
|
} else {
|
2014-08-08 21:21:01 +00:00
|
|
|
pr_err("%s(): fs needs fsck\n", __func__);
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read ufs_super_block into internal data structures
|
|
|
|
*/
|
|
|
|
sb->s_op = &ufs_super_ops;
|
2009-12-16 00:46:51 +00:00
|
|
|
sb->s_export_op = &ufs_export_ops;
|
2010-05-19 11:16:44 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
|
|
|
|
|
|
|
|
uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
|
|
|
|
uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
|
|
|
|
uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
|
|
|
|
uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
|
|
|
|
uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
|
|
|
|
uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
|
|
|
|
|
|
|
|
if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
|
2017-06-14 20:36:29 +00:00
|
|
|
uspi->s_size = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size);
|
|
|
|
uspi->s_dsize = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
|
2006-06-25 12:47:29 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
|
|
|
|
uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
|
|
|
|
/* s_bsize already set */
|
|
|
|
/* s_fsize already set */
|
|
|
|
uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
|
|
|
|
uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
|
|
|
|
uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
|
|
|
|
uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
|
|
|
|
uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
|
|
|
|
uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
|
|
|
|
uspi->s_fshift);
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
|
|
|
|
uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
|
|
|
|
/* s_sbsize already set */
|
|
|
|
uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
|
|
|
|
uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
|
|
|
|
uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
|
|
|
|
uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
|
|
|
|
uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
|
|
|
|
uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
|
|
|
|
uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
|
|
|
|
uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
|
2007-02-12 08:54:31 +00:00
|
|
|
|
|
|
|
if (uspi->fs_magic == UFS2_MAGIC)
|
|
|
|
uspi->s_csaddr = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_csaddr);
|
|
|
|
else
|
|
|
|
uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
|
|
|
|
uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
|
|
|
|
uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
|
|
|
|
uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
|
|
|
|
uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
|
|
|
|
uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
|
|
|
|
uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
|
2006-06-25 12:47:29 +00:00
|
|
|
uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_un.fs_u1.fs_cpc);
|
|
|
|
uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_contigsumsize);
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
|
|
|
|
uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
|
|
|
|
uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
|
|
|
|
uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
|
|
|
|
uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
|
|
|
|
|
2017-06-14 20:36:29 +00:00
|
|
|
uspi->s_root_blocks = mul_u64_u32_div(uspi->s_dsize,
|
|
|
|
uspi->s_minfree, 100);
|
2017-06-17 19:44:06 +00:00
|
|
|
if (uspi->s_minfree <= 5) {
|
|
|
|
uspi->s_time_to_space = ~0ULL;
|
|
|
|
uspi->s_space_to_time = 0;
|
|
|
|
usb1->fs_optim = cpu_to_fs32(sb, UFS_OPTSPACE);
|
|
|
|
} else {
|
|
|
|
uspi->s_time_to_space = (uspi->s_root_blocks / 2) + 1;
|
|
|
|
uspi->s_space_to_time = mul_u64_u32_div(uspi->s_dsize,
|
|
|
|
uspi->s_minfree - 2, 100) - 1;
|
|
|
|
}
|
2017-06-14 20:36:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Compute another frequently used values
|
|
|
|
*/
|
|
|
|
uspi->s_fpbmask = uspi->s_fpb - 1;
|
2006-06-25 12:47:24 +00:00
|
|
|
if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_apbshift = uspi->s_bshift - 3;
|
2006-06-25 12:47:24 +00:00
|
|
|
else
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_apbshift = uspi->s_bshift - 2;
|
2006-06-25 12:47:24 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_2apbshift = uspi->s_apbshift * 2;
|
|
|
|
uspi->s_3apbshift = uspi->s_apbshift * 3;
|
|
|
|
uspi->s_apb = 1 << uspi->s_apbshift;
|
|
|
|
uspi->s_2apb = 1 << uspi->s_2apbshift;
|
|
|
|
uspi->s_3apb = 1 << uspi->s_3apbshift;
|
|
|
|
uspi->s_apbmask = uspi->s_apb - 1;
|
|
|
|
uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
|
|
|
|
uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
|
|
|
|
uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
|
|
|
|
uspi->s_bpf = uspi->s_fsize << 3;
|
|
|
|
uspi->s_bpfshift = uspi->s_fshift + 3;
|
|
|
|
uspi->s_bpfmask = uspi->s_bpf - 1;
|
2008-02-08 12:20:16 +00:00
|
|
|
if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
|
|
|
|
(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi->s_maxsymlinklen =
|
2006-06-25 12:47:29 +00:00
|
|
|
fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-01-08 22:43:48 +00:00
|
|
|
if (uspi->fs_magic == UFS2_MAGIC)
|
|
|
|
maxsymlen = 2 * 4 * (UFS_NDADDR + UFS_NINDIR);
|
|
|
|
else
|
|
|
|
maxsymlen = 4 * (UFS_NDADDR + UFS_NINDIR);
|
|
|
|
if (uspi->s_maxsymlinklen > maxsymlen) {
|
|
|
|
ufs_warning(sb, __func__, "ufs_read_super: excessive maximum "
|
|
|
|
"fast symlink size (%u)\n", uspi->s_maxsymlinklen);
|
|
|
|
uspi->s_maxsymlinklen = maxsymlen;
|
|
|
|
}
|
2017-06-09 01:15:45 +00:00
|
|
|
sb->s_maxbytes = ufs_max_bytes(sb);
|
2012-02-06 17:45:27 +00:00
|
|
|
sb->s_max_links = UFS_LINK_MAX;
|
2009-01-08 22:43:48 +00:00
|
|
|
|
2008-02-07 08:15:48 +00:00
|
|
|
inode = ufs_iget(sb, UFS_ROOTINO);
|
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
ret = PTR_ERR(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto failed;
|
2008-02-07 08:15:48 +00:00
|
|
|
}
|
2012-01-09 03:15:13 +00:00
|
|
|
sb->s_root = d_make_root(inode);
|
2008-02-07 08:15:48 +00:00
|
|
|
if (!sb->s_root) {
|
|
|
|
ret = -ENOMEM;
|
2012-01-09 03:15:13 +00:00
|
|
|
goto failed;
|
2008-02-07 08:15:48 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-25 12:47:30 +00:00
|
|
|
ufs_setup_cstotal(sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Read cylinder group structures
|
|
|
|
*/
|
2017-07-17 07:45:34 +00:00
|
|
|
if (!sb_rdonly(sb))
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!ufs_read_cylinder_structures(sb))
|
|
|
|
goto failed;
|
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
2005-11-07 09:01:34 +00:00
|
|
|
if (ubh)
|
|
|
|
ubh_brelse_uspi (uspi);
|
|
|
|
kfree (uspi);
|
|
|
|
kfree(sbi);
|
2005-04-16 22:20:36 +00:00
|
|
|
sb->s_fs_info = NULL;
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT (FAILED)\n");
|
2008-02-07 08:15:48 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
failed_nomem:
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT (NOMEM)\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
|
|
|
|
{
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_super_block_first * usb1;
|
|
|
|
struct ufs_super_block_third * usb3;
|
|
|
|
unsigned new_mount_opt, ufstype;
|
|
|
|
unsigned flags;
|
2009-05-12 13:10:54 +00:00
|
|
|
|
2014-03-13 14:14:33 +00:00
|
|
|
sync_filesystem(sb);
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_lock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
flags = UFS_SB(sb)->s_flags;
|
2006-01-14 08:42:06 +00:00
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
|
|
|
usb3 = ubh_get_usb_third(uspi);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow the "check" option to be passed as a remount option.
|
|
|
|
* It is not possible to change ufstype option during remount
|
|
|
|
*/
|
|
|
|
ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
|
|
|
|
new_mount_opt = 0;
|
|
|
|
ufs_set_opt (new_mount_opt, ONERROR_LOCK);
|
2009-05-06 14:43:07 +00:00
|
|
|
if (!ufs_parse_options (data, &new_mount_opt)) {
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
2009-05-06 14:43:07 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
|
|
|
|
new_mount_opt |= ufstype;
|
2006-06-25 12:47:30 +00:00
|
|
|
} else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("ufstype can't be changed during remount\n");
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-11-27 21:05:09 +00:00
|
|
|
if ((bool)(*mount_flags & SB_RDONLY) == sb_rdonly(sb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
UFS_SB(sb)->s_mount_opt = new_mount_opt;
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fs was mouted as rw, remounting ro
|
|
|
|
*/
|
2017-11-27 21:05:09 +00:00
|
|
|
if (*mount_flags & SB_RDONLY) {
|
2006-06-25 12:47:30 +00:00
|
|
|
ufs_put_super_internal(sb);
|
2018-08-17 22:43:47 +00:00
|
|
|
usb1->fs_time = ufs_get_seconds(sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((flags & UFS_ST_MASK) == UFS_ST_SUN
|
2007-10-17 06:26:31 +00:00
|
|
|
|| (flags & UFS_ST_MASK) == UFS_ST_SUNOS
|
2005-04-16 22:20:36 +00:00
|
|
|
|| (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
|
|
|
|
ufs_set_fs_state(sb, usb1, usb3,
|
|
|
|
UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
|
2006-06-25 12:47:22 +00:00
|
|
|
ubh_mark_buffer_dirty (USPI_UBH(uspi));
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2006-06-25 12:47:30 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* fs was mounted as ro, remounting rw
|
|
|
|
*/
|
|
|
|
#ifndef CONFIG_UFS_FS_WRITE
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
#else
|
|
|
|
if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
|
2007-10-17 06:26:31 +00:00
|
|
|
ufstype != UFS_MOUNT_UFSTYPE_SUNOS &&
|
2005-04-16 22:20:36 +00:00
|
|
|
ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
|
2007-02-12 08:54:30 +00:00
|
|
|
ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
|
|
|
|
ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("this ufstype is read-only supported\n");
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2006-06-25 12:47:30 +00:00
|
|
|
if (!ufs_read_cylinder_structures(sb)) {
|
2014-08-08 21:20:57 +00:00
|
|
|
pr_err("failed during remounting\n");
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EPERM;
|
|
|
|
}
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags &= ~SB_RDONLY;
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
UFS_SB(sb)->s_mount_opt = new_mount_opt;
|
2015-06-10 00:09:32 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-09 02:32:45 +00:00
|
|
|
static int ufs_show_options(struct seq_file *seq, struct dentry *root)
|
2007-10-17 06:26:32 +00:00
|
|
|
{
|
2011-12-09 02:32:45 +00:00
|
|
|
struct ufs_sb_info *sbi = UFS_SB(root->d_sb);
|
2007-10-17 06:26:32 +00:00
|
|
|
unsigned mval = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
|
2008-10-13 09:46:57 +00:00
|
|
|
const struct match_token *tp = tokens;
|
2007-10-17 06:26:32 +00:00
|
|
|
|
|
|
|
while (tp->token != Opt_onerror_panic && tp->token != mval)
|
|
|
|
++tp;
|
|
|
|
BUG_ON(tp->token == Opt_onerror_panic);
|
|
|
|
seq_printf(seq, ",%s", tp->pattern);
|
|
|
|
|
|
|
|
mval = sbi->s_mount_opt & UFS_MOUNT_ONERROR;
|
|
|
|
while (tp->token != Opt_err && tp->token != mval)
|
|
|
|
++tp;
|
|
|
|
BUG_ON(tp->token == Opt_err);
|
|
|
|
seq_printf(seq, ",%s", tp->pattern);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-25 12:47:29 +00:00
|
|
|
static int ufs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-23 09:02:58 +00:00
|
|
|
struct super_block *sb = dentry->d_sb;
|
2006-06-25 12:47:29 +00:00
|
|
|
struct ufs_sb_private_info *uspi= UFS_SB(sb)->s_uspi;
|
|
|
|
unsigned flags = UFS_SB(sb)->s_flags;
|
2009-04-02 23:59:44 +00:00
|
|
|
u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-16 08:27:05 +00:00
|
|
|
mutex_lock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-14 20:36:29 +00:00
|
|
|
if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
|
2005-04-16 22:20:36 +00:00
|
|
|
buf->f_type = UFS2_MAGIC;
|
2017-06-14 20:36:29 +00:00
|
|
|
else
|
2005-04-16 22:20:36 +00:00
|
|
|
buf->f_type = UFS_MAGIC;
|
2017-06-14 20:36:29 +00:00
|
|
|
|
|
|
|
buf->f_blocks = uspi->s_dsize;
|
|
|
|
buf->f_bfree = ufs_freefrags(uspi);
|
2006-06-25 12:47:30 +00:00
|
|
|
buf->f_ffree = uspi->cs_total.cs_nifree;
|
2005-04-16 22:20:36 +00:00
|
|
|
buf->f_bsize = sb->s_blocksize;
|
2017-06-14 20:36:29 +00:00
|
|
|
buf->f_bavail = (buf->f_bfree > uspi->s_root_blocks)
|
|
|
|
? (buf->f_bfree - uspi->s_root_blocks) : 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
buf->f_files = uspi->s_ncg * uspi->s_ipg;
|
|
|
|
buf->f_namelen = UFS_MAXNAMLEN;
|
2009-04-02 23:59:44 +00:00
|
|
|
buf->f_fsid.val[0] = (u32)id;
|
|
|
|
buf->f_fsid.val[1] = (u32)(id >> 32);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-16 08:27:05 +00:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-07 04:33:20 +00:00
|
|
|
static struct kmem_cache * ufs_inode_cachep;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static struct inode *ufs_alloc_inode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ufs_inode_info *ei;
|
2015-02-17 21:45:28 +00:00
|
|
|
|
|
|
|
ei = kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!ei)
|
|
|
|
return NULL;
|
2015-02-17 21:45:28 +00:00
|
|
|
|
2017-12-11 11:35:18 +00:00
|
|
|
inode_set_iversion(&ei->vfs_inode, 1);
|
2015-06-17 16:02:56 +00:00
|
|
|
seqlock_init(&ei->meta_lock);
|
|
|
|
mutex_init(&ei->truncate_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return &ei->vfs_inode;
|
|
|
|
}
|
|
|
|
|
2019-04-16 02:29:33 +00:00
|
|
|
static void ufs_free_in_core_inode(struct inode *inode)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
|
|
|
|
}
|
|
|
|
|
2008-07-26 02:45:34 +00:00
|
|
|
static void init_once(void *foo)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
|
|
|
|
|
2007-05-17 05:10:57 +00:00
|
|
|
inode_init_once(&ei->vfs_inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-07-20 01:11:58 +00:00
|
|
|
|
2014-04-07 22:39:55 +00:00
|
|
|
static int __init init_inodecache(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
ufs: Define usercopy region in ufs_inode_cache slab cache
The ufs symlink pathnames, stored in struct ufs_inode_info.i_u1.i_symlink
and therefore contained in the ufs_inode_cache slab cache, need to be
copied to/from userspace.
cache object allocation:
fs/ufs/super.c:
ufs_alloc_inode(...):
...
ei = kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
...
return &ei->vfs_inode;
fs/ufs/ufs.h:
UFS_I(struct inode *inode):
return container_of(inode, struct ufs_inode_info, vfs_inode);
fs/ufs/namei.c:
ufs_symlink(...):
...
inode->i_link = (char *)UFS_I(inode)->i_u1.i_symlink;
example usage trace:
readlink_copy+0x43/0x70
vfs_readlink+0x62/0x110
SyS_readlinkat+0x100/0x130
fs/namei.c:
readlink_copy(..., link):
...
copy_to_user(..., link, len);
(inlined in vfs_readlink)
generic_readlink(dentry, ...):
struct inode *inode = d_inode(dentry);
const char *link = inode->i_link;
...
readlink_copy(..., link);
In support of usercopy hardening, this patch defines a region in the
ufs_inode_cache slab cache in which userspace copy operations are allowed.
This region is known as the slab cache's usercopy region. Slab caches
can now check that each dynamically sized copy operation involving
cache-managed memory falls entirely within the slab's usercopy region.
This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY
whitelisting code in the last public patch of grsecurity/PaX based on my
understanding of the code. Changes or omissions from the original code are
mine and don't reflect the original grsecurity/PaX code.
Signed-off-by: David Windsor <dave@nullcore.net>
[kees: adjust commit log, provide usage trace]
Cc: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-06-11 02:50:40 +00:00
|
|
|
ufs_inode_cachep = kmem_cache_create_usercopy("ufs_inode_cache",
|
|
|
|
sizeof(struct ufs_inode_info), 0,
|
|
|
|
(SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
|
|
|
|
SLAB_ACCOUNT),
|
|
|
|
offsetof(struct ufs_inode_info, i_u1.i_symlink),
|
|
|
|
sizeof_field(struct ufs_inode_info,
|
|
|
|
i_u1.i_symlink),
|
|
|
|
init_once);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ufs_inode_cachep == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_inodecache(void)
|
|
|
|
{
|
2012-09-26 01:33:07 +00:00
|
|
|
/*
|
|
|
|
* Make sure all delayed rcu free inodes are flushed before we
|
|
|
|
* destroy cache.
|
|
|
|
*/
|
|
|
|
rcu_barrier();
|
2006-09-27 08:49:40 +00:00
|
|
|
kmem_cache_destroy(ufs_inode_cachep);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-02-12 08:55:41 +00:00
|
|
|
static const struct super_operations ufs_super_ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.alloc_inode = ufs_alloc_inode,
|
2019-04-16 02:29:33 +00:00
|
|
|
.free_inode = ufs_free_in_core_inode,
|
2005-04-16 22:20:36 +00:00
|
|
|
.write_inode = ufs_write_inode,
|
2010-06-05 23:40:56 +00:00
|
|
|
.evict_inode = ufs_evict_inode,
|
2005-04-16 22:20:36 +00:00
|
|
|
.put_super = ufs_put_super,
|
2009-06-08 08:08:05 +00:00
|
|
|
.sync_fs = ufs_sync_fs,
|
2005-04-16 22:20:36 +00:00
|
|
|
.statfs = ufs_statfs,
|
|
|
|
.remount_fs = ufs_remount,
|
2007-10-17 06:26:32 +00:00
|
|
|
.show_options = ufs_show_options,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2010-07-24 20:46:55 +00:00
|
|
|
static struct dentry *ufs_mount(struct file_system_type *fs_type,
|
|
|
|
int flags, const char *dev_name, void *data)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-07-24 20:46:55 +00:00
|
|
|
return mount_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type ufs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "ufs",
|
2010-07-24 20:46:55 +00:00
|
|
|
.mount = ufs_mount,
|
2005-04-16 22:20:36 +00:00
|
|
|
.kill_sb = kill_block_super,
|
|
|
|
.fs_flags = FS_REQUIRES_DEV,
|
|
|
|
};
|
2013-03-03 03:39:14 +00:00
|
|
|
MODULE_ALIAS_FS("ufs");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int __init init_ufs_fs(void)
|
|
|
|
{
|
|
|
|
int err = init_inodecache();
|
|
|
|
if (err)
|
|
|
|
goto out1;
|
|
|
|
err = register_filesystem(&ufs_fs_type);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
destroy_inodecache();
|
|
|
|
out1:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_ufs_fs(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&ufs_fs_type);
|
|
|
|
destroy_inodecache();
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_ufs_fs)
|
|
|
|
module_exit(exit_ufs_fs)
|
|
|
|
MODULE_LICENSE("GPL");
|