2008-07-26 06:45:15 +04:00
|
|
|
/*
|
|
|
|
* Optimized MPEG FS - inode and super operations.
|
|
|
|
* Copyright (C) 2006 Bob Copeland <me@bobcopeland.com>
|
|
|
|
* Released under GPL v2.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2008-07-26 06:45:15 +04:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/vfs.h>
|
2017-02-02 19:54:15 +03:00
|
|
|
#include <linux/cred.h>
|
2008-07-26 06:45:15 +04:00
|
|
|
#include <linux/parser.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2010-03-05 11:21:37 +03:00
|
|
|
#include <linux/writeback.h>
|
2017-07-05 18:24:27 +03:00
|
|
|
#include <linux/seq_file.h>
|
2008-07-26 06:45:15 +04:00
|
|
|
#include <linux/crc-itu-t.h>
|
|
|
|
#include "omfs.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Bob Copeland <me@bobcopeland.com>");
|
|
|
|
MODULE_DESCRIPTION("OMFS (ReplayTV/Karma) Filesystem for Linux");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2008-09-07 01:51:53 +04:00
|
|
|
struct buffer_head *omfs_bread(struct super_block *sb, sector_t block)
|
|
|
|
{
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(sb);
|
|
|
|
if (block >= sbi->s_num_blocks)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sb_bread(sb, clus_to_blk(sbi, block));
|
|
|
|
}
|
|
|
|
|
2011-07-25 06:58:10 +04:00
|
|
|
struct inode *omfs_new_inode(struct inode *dir, umode_t mode)
|
2008-07-26 06:45:15 +04:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
u64 new_block;
|
|
|
|
int err;
|
|
|
|
int len;
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(dir->i_sb);
|
|
|
|
|
|
|
|
inode = new_inode(dir->i_sb);
|
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
err = omfs_allocate_range(dir->i_sb, sbi->s_mirrors, sbi->s_mirrors,
|
|
|
|
&new_block, &len);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
inode->i_ino = new_block;
|
2010-03-04 17:32:17 +03:00
|
|
|
inode_init_owner(inode, NULL, mode);
|
2008-07-26 06:45:15 +04:00
|
|
|
inode->i_mapping->a_ops = &omfs_aops;
|
|
|
|
|
2016-09-14 17:48:04 +03:00
|
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
2008-07-26 06:45:15 +04:00
|
|
|
switch (mode & S_IFMT) {
|
|
|
|
case S_IFDIR:
|
|
|
|
inode->i_op = &omfs_dir_inops;
|
|
|
|
inode->i_fop = &omfs_dir_operations;
|
|
|
|
inode->i_size = sbi->s_sys_blocksize;
|
|
|
|
inc_nlink(inode);
|
|
|
|
break;
|
|
|
|
case S_IFREG:
|
|
|
|
inode->i_op = &omfs_file_inops;
|
|
|
|
inode->i_fop = &omfs_file_operations;
|
|
|
|
inode->i_size = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
insert_inode_hash(inode);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return inode;
|
|
|
|
fail:
|
|
|
|
make_bad_inode(inode);
|
|
|
|
iput(inode);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the header checksums for a dirty inode based on its contents.
|
|
|
|
* Caller is expected to hold the buffer head underlying oi and mark it
|
|
|
|
* dirty.
|
|
|
|
*/
|
|
|
|
static void omfs_update_checksums(struct omfs_inode *oi)
|
|
|
|
{
|
|
|
|
int xor, i, ofs = 0, count;
|
|
|
|
u16 crc = 0;
|
|
|
|
unsigned char *ptr = (unsigned char *) oi;
|
|
|
|
|
|
|
|
count = be32_to_cpu(oi->i_head.h_body_size);
|
|
|
|
ofs = sizeof(struct omfs_header);
|
|
|
|
|
|
|
|
crc = crc_itu_t(crc, ptr + ofs, count);
|
|
|
|
oi->i_head.h_crc = cpu_to_be16(crc);
|
|
|
|
|
|
|
|
xor = ptr[0];
|
|
|
|
for (i = 1; i < OMFS_XOR_COUNT; i++)
|
|
|
|
xor ^= ptr[i];
|
|
|
|
|
|
|
|
oi->i_head.h_check_xor = xor;
|
|
|
|
}
|
|
|
|
|
2010-03-05 11:21:37 +03:00
|
|
|
static int __omfs_write_inode(struct inode *inode, int wait)
|
2008-07-26 06:45:15 +04:00
|
|
|
{
|
|
|
|
struct omfs_inode *oi;
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
|
|
|
|
struct buffer_head *bh, *bh2;
|
|
|
|
u64 ctime;
|
|
|
|
int i;
|
|
|
|
int ret = -EIO;
|
|
|
|
int sync_failed = 0;
|
|
|
|
|
|
|
|
/* get current inode since we may have written sibling ptrs etc. */
|
2008-09-07 01:51:53 +04:00
|
|
|
bh = omfs_bread(inode->i_sb, inode->i_ino);
|
2008-07-26 06:45:15 +04:00
|
|
|
if (!bh)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
oi = (struct omfs_inode *) bh->b_data;
|
|
|
|
|
|
|
|
oi->i_head.h_self = cpu_to_be64(inode->i_ino);
|
|
|
|
if (S_ISDIR(inode->i_mode))
|
|
|
|
oi->i_type = OMFS_DIR;
|
|
|
|
else if (S_ISREG(inode->i_mode))
|
|
|
|
oi->i_type = OMFS_FILE;
|
|
|
|
else {
|
|
|
|
printk(KERN_WARNING "omfs: unknown file type: %d\n",
|
|
|
|
inode->i_mode);
|
|
|
|
goto out_brelse;
|
|
|
|
}
|
|
|
|
|
|
|
|
oi->i_head.h_body_size = cpu_to_be32(sbi->s_sys_blocksize -
|
|
|
|
sizeof(struct omfs_header));
|
|
|
|
oi->i_head.h_version = 1;
|
|
|
|
oi->i_head.h_type = OMFS_INODE_NORMAL;
|
|
|
|
oi->i_head.h_magic = OMFS_IMAGIC;
|
|
|
|
oi->i_size = cpu_to_be64(inode->i_size);
|
|
|
|
|
|
|
|
ctime = inode->i_ctime.tv_sec * 1000LL +
|
|
|
|
((inode->i_ctime.tv_nsec + 999)/1000);
|
|
|
|
oi->i_ctime = cpu_to_be64(ctime);
|
|
|
|
|
|
|
|
omfs_update_checksums(oi);
|
|
|
|
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
if (wait) {
|
|
|
|
sync_dirty_buffer(bh);
|
|
|
|
if (buffer_req(bh) && !buffer_uptodate(bh))
|
|
|
|
sync_failed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if mirroring writes, copy to next fsblock */
|
|
|
|
for (i = 1; i < sbi->s_mirrors; i++) {
|
2008-09-07 01:51:53 +04:00
|
|
|
bh2 = omfs_bread(inode->i_sb, inode->i_ino + i);
|
2008-07-26 06:45:15 +04:00
|
|
|
if (!bh2)
|
|
|
|
goto out_brelse;
|
|
|
|
|
|
|
|
memcpy(bh2->b_data, bh->b_data, bh->b_size);
|
|
|
|
mark_buffer_dirty(bh2);
|
|
|
|
if (wait) {
|
|
|
|
sync_dirty_buffer(bh2);
|
|
|
|
if (buffer_req(bh2) && !buffer_uptodate(bh2))
|
|
|
|
sync_failed = 1;
|
|
|
|
}
|
|
|
|
brelse(bh2);
|
|
|
|
}
|
|
|
|
ret = (sync_failed) ? -EIO : 0;
|
|
|
|
out_brelse:
|
|
|
|
brelse(bh);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-05 11:21:37 +03:00
|
|
|
static int omfs_write_inode(struct inode *inode, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
return __omfs_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
|
|
|
|
}
|
|
|
|
|
2008-07-26 06:45:15 +04:00
|
|
|
int omfs_sync_inode(struct inode *inode)
|
|
|
|
{
|
2010-03-05 11:21:37 +03:00
|
|
|
return __omfs_write_inode(inode, 1);
|
2008-07-26 06:45:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called when an entry is deleted, need to clear the bits in the
|
|
|
|
* bitmaps.
|
|
|
|
*/
|
2010-06-06 18:12:01 +04:00
|
|
|
static void omfs_evict_inode(struct inode *inode)
|
2008-07-26 06:45:15 +04:00
|
|
|
{
|
2014-04-04 01:47:49 +04:00
|
|
|
truncate_inode_pages_final(&inode->i_data);
|
2012-05-03 16:48:02 +04:00
|
|
|
clear_inode(inode);
|
2010-06-06 18:12:01 +04:00
|
|
|
|
|
|
|
if (inode->i_nlink)
|
|
|
|
return;
|
2008-07-26 06:45:15 +04:00
|
|
|
|
|
|
|
if (S_ISREG(inode->i_mode)) {
|
|
|
|
inode->i_size = 0;
|
|
|
|
omfs_shrink_inode(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
omfs_clear_range(inode->i_sb, inode->i_ino, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct inode *omfs_iget(struct super_block *sb, ino_t ino)
|
|
|
|
{
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(sb);
|
|
|
|
struct omfs_inode *oi;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
u64 ctime;
|
|
|
|
unsigned long nsecs;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
inode = iget_locked(sb, ino);
|
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
if (!(inode->i_state & I_NEW))
|
|
|
|
return inode;
|
|
|
|
|
2008-09-07 01:51:53 +04:00
|
|
|
bh = omfs_bread(inode->i_sb, ino);
|
2008-07-26 06:45:15 +04:00
|
|
|
if (!bh)
|
|
|
|
goto iget_failed;
|
|
|
|
|
|
|
|
oi = (struct omfs_inode *)bh->b_data;
|
|
|
|
|
|
|
|
/* check self */
|
|
|
|
if (ino != be64_to_cpu(oi->i_head.h_self))
|
|
|
|
goto fail_bh;
|
|
|
|
|
|
|
|
inode->i_uid = sbi->s_uid;
|
|
|
|
inode->i_gid = sbi->s_gid;
|
|
|
|
|
|
|
|
ctime = be64_to_cpu(oi->i_ctime);
|
|
|
|
nsecs = do_div(ctime, 1000) * 1000L;
|
|
|
|
|
|
|
|
inode->i_atime.tv_sec = ctime;
|
|
|
|
inode->i_mtime.tv_sec = ctime;
|
|
|
|
inode->i_ctime.tv_sec = ctime;
|
|
|
|
inode->i_atime.tv_nsec = nsecs;
|
|
|
|
inode->i_mtime.tv_nsec = nsecs;
|
|
|
|
inode->i_ctime.tv_nsec = nsecs;
|
|
|
|
|
|
|
|
inode->i_mapping->a_ops = &omfs_aops;
|
|
|
|
|
|
|
|
switch (oi->i_type) {
|
|
|
|
case OMFS_DIR:
|
|
|
|
inode->i_mode = S_IFDIR | (S_IRWXUGO & ~sbi->s_dmask);
|
|
|
|
inode->i_op = &omfs_dir_inops;
|
|
|
|
inode->i_fop = &omfs_dir_operations;
|
2008-08-15 11:40:46 +04:00
|
|
|
inode->i_size = sbi->s_sys_blocksize;
|
2008-07-26 06:45:15 +04:00
|
|
|
inc_nlink(inode);
|
|
|
|
break;
|
|
|
|
case OMFS_FILE:
|
|
|
|
inode->i_mode = S_IFREG | (S_IRWXUGO & ~sbi->s_fmask);
|
|
|
|
inode->i_fop = &omfs_file_operations;
|
|
|
|
inode->i_size = be64_to_cpu(oi->i_size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
brelse(bh);
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
return inode;
|
|
|
|
fail_bh:
|
|
|
|
brelse(bh);
|
|
|
|
iget_failed:
|
|
|
|
iget_failed(inode);
|
|
|
|
return ERR_PTR(-EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omfs_put_super(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(sb);
|
|
|
|
kfree(sbi->s_imap);
|
|
|
|
kfree(sbi);
|
|
|
|
sb->s_fs_info = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|
|
|
{
|
|
|
|
struct super_block *s = dentry->d_sb;
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(s);
|
2009-04-03 03:59:39 +04:00
|
|
|
u64 id = huge_encode_dev(s->s_bdev->bd_dev);
|
|
|
|
|
2008-07-26 06:45:15 +04:00
|
|
|
buf->f_type = OMFS_MAGIC;
|
|
|
|
buf->f_bsize = sbi->s_blocksize;
|
|
|
|
buf->f_blocks = sbi->s_num_blocks;
|
|
|
|
buf->f_files = sbi->s_num_blocks;
|
|
|
|
buf->f_namelen = OMFS_NAMELEN;
|
2009-04-03 03:59:39 +04:00
|
|
|
buf->f_fsid.val[0] = (u32)id;
|
|
|
|
buf->f_fsid.val[1] = (u32)(id >> 32);
|
2008-07-26 06:45:15 +04:00
|
|
|
|
|
|
|
buf->f_bfree = buf->f_bavail = buf->f_ffree =
|
|
|
|
omfs_count_free(s);
|
2009-04-03 03:59:39 +04:00
|
|
|
|
2008-07-26 06:45:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-05 18:24:27 +03:00
|
|
|
/*
|
|
|
|
* Display the mount options in /proc/mounts.
|
|
|
|
*/
|
|
|
|
static int omfs_show_options(struct seq_file *m, struct dentry *root)
|
|
|
|
{
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(root->d_sb);
|
|
|
|
umode_t cur_umask = current_umask();
|
|
|
|
|
|
|
|
if (!uid_eq(sbi->s_uid, current_uid()))
|
|
|
|
seq_printf(m, ",uid=%u",
|
|
|
|
from_kuid_munged(&init_user_ns, sbi->s_uid));
|
|
|
|
if (!gid_eq(sbi->s_gid, current_gid()))
|
|
|
|
seq_printf(m, ",gid=%u",
|
|
|
|
from_kgid_munged(&init_user_ns, sbi->s_gid));
|
|
|
|
|
|
|
|
if (sbi->s_dmask == sbi->s_fmask) {
|
|
|
|
if (sbi->s_fmask != cur_umask)
|
|
|
|
seq_printf(m, ",umask=%o", sbi->s_fmask);
|
|
|
|
} else {
|
|
|
|
if (sbi->s_dmask != cur_umask)
|
|
|
|
seq_printf(m, ",dmask=%o", sbi->s_dmask);
|
|
|
|
if (sbi->s_fmask != cur_umask)
|
|
|
|
seq_printf(m, ",fmask=%o", sbi->s_fmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-22 04:01:09 +04:00
|
|
|
static const struct super_operations omfs_sops = {
|
2008-07-26 06:45:15 +04:00
|
|
|
.write_inode = omfs_write_inode,
|
2010-06-06 18:12:01 +04:00
|
|
|
.evict_inode = omfs_evict_inode,
|
2008-07-26 06:45:15 +04:00
|
|
|
.put_super = omfs_put_super,
|
|
|
|
.statfs = omfs_statfs,
|
2017-07-05 18:24:27 +03:00
|
|
|
.show_options = omfs_show_options,
|
2008-07-26 06:45:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For Rio Karma, there is an on-disk free bitmap whose location is
|
|
|
|
* stored in the root block. For ReplayTV, there is no such free bitmap
|
|
|
|
* so we have to walk the tree. Both inodes and file data are allocated
|
|
|
|
* from the same map. This array can be big (300k) so we allocate
|
|
|
|
* in units of the blocksize.
|
|
|
|
*/
|
|
|
|
static int omfs_get_imap(struct super_block *sb)
|
|
|
|
{
|
2015-05-29 01:44:35 +03:00
|
|
|
unsigned int bitmap_size, array_size;
|
|
|
|
int count;
|
2008-07-26 06:45:15 +04:00
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(sb);
|
|
|
|
struct buffer_head *bh;
|
|
|
|
unsigned long **ptr;
|
|
|
|
sector_t block;
|
|
|
|
|
|
|
|
bitmap_size = DIV_ROUND_UP(sbi->s_num_blocks, 8);
|
|
|
|
array_size = DIV_ROUND_UP(bitmap_size, sb->s_blocksize);
|
|
|
|
|
|
|
|
if (sbi->s_bitmap_ino == ~0ULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sbi->s_imap_size = array_size;
|
2014-08-09 01:22:41 +04:00
|
|
|
sbi->s_imap = kcalloc(array_size, sizeof(unsigned long *), GFP_KERNEL);
|
2008-07-26 06:45:15 +04:00
|
|
|
if (!sbi->s_imap)
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
block = clus_to_blk(sbi, sbi->s_bitmap_ino);
|
2008-09-07 01:51:53 +04:00
|
|
|
if (block >= sbi->s_num_blocks)
|
|
|
|
goto nomem;
|
|
|
|
|
2008-07-26 06:45:15 +04:00
|
|
|
ptr = sbi->s_imap;
|
|
|
|
for (count = bitmap_size; count > 0; count -= sb->s_blocksize) {
|
|
|
|
bh = sb_bread(sb, block++);
|
|
|
|
if (!bh)
|
|
|
|
goto nomem_free;
|
|
|
|
*ptr = kmalloc(sb->s_blocksize, GFP_KERNEL);
|
|
|
|
if (!*ptr) {
|
|
|
|
brelse(bh);
|
|
|
|
goto nomem_free;
|
|
|
|
}
|
|
|
|
memcpy(*ptr, bh->b_data, sb->s_blocksize);
|
|
|
|
if (count < sb->s_blocksize)
|
|
|
|
memset((void *)*ptr + count, 0xff,
|
|
|
|
sb->s_blocksize - count);
|
|
|
|
brelse(bh);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nomem_free:
|
|
|
|
for (count = 0; count < array_size; count++)
|
|
|
|
kfree(sbi->s_imap[count]);
|
|
|
|
|
|
|
|
kfree(sbi->s_imap);
|
|
|
|
nomem:
|
|
|
|
sbi->s_imap = NULL;
|
|
|
|
sbi->s_imap_size = 0;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
2015-05-29 01:44:29 +03:00
|
|
|
Opt_uid, Opt_gid, Opt_umask, Opt_dmask, Opt_fmask, Opt_err
|
2008-07-26 06:45:15 +04:00
|
|
|
};
|
|
|
|
|
2008-10-13 13:46:57 +04:00
|
|
|
static const match_table_t tokens = {
|
2008-07-26 06:45:15 +04:00
|
|
|
{Opt_uid, "uid=%u"},
|
|
|
|
{Opt_gid, "gid=%u"},
|
|
|
|
{Opt_umask, "umask=%o"},
|
|
|
|
{Opt_dmask, "dmask=%o"},
|
|
|
|
{Opt_fmask, "fmask=%o"},
|
2015-05-29 01:44:29 +03:00
|
|
|
{Opt_err, NULL},
|
2008-07-26 06:45:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_options(char *options, struct omfs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
|
|
|
int option;
|
|
|
|
|
|
|
|
if (!options)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
while ((p = strsep(&options, ",")) != NULL) {
|
|
|
|
int token;
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
token = match_token(p, tokens, args);
|
|
|
|
switch (token) {
|
|
|
|
case Opt_uid:
|
|
|
|
if (match_int(&args[0], &option))
|
|
|
|
return 0;
|
2012-02-08 04:29:49 +04:00
|
|
|
sbi->s_uid = make_kuid(current_user_ns(), option);
|
|
|
|
if (!uid_valid(sbi->s_uid))
|
|
|
|
return 0;
|
2008-07-26 06:45:15 +04:00
|
|
|
break;
|
|
|
|
case Opt_gid:
|
|
|
|
if (match_int(&args[0], &option))
|
|
|
|
return 0;
|
2012-02-08 04:29:49 +04:00
|
|
|
sbi->s_gid = make_kgid(current_user_ns(), option);
|
|
|
|
if (!gid_valid(sbi->s_gid))
|
|
|
|
return 0;
|
2008-07-26 06:45:15 +04:00
|
|
|
break;
|
|
|
|
case Opt_umask:
|
|
|
|
if (match_octal(&args[0], &option))
|
|
|
|
return 0;
|
|
|
|
sbi->s_fmask = sbi->s_dmask = option;
|
|
|
|
break;
|
|
|
|
case Opt_dmask:
|
|
|
|
if (match_octal(&args[0], &option))
|
|
|
|
return 0;
|
|
|
|
sbi->s_dmask = option;
|
|
|
|
break;
|
|
|
|
case Opt_fmask:
|
|
|
|
if (match_octal(&args[0], &option))
|
|
|
|
return 0;
|
|
|
|
sbi->s_fmask = option;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omfs_fill_super(struct super_block *sb, void *data, int silent)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh, *bh2;
|
|
|
|
struct omfs_super_block *omfs_sb;
|
|
|
|
struct omfs_root_block *omfs_rb;
|
|
|
|
struct omfs_sb_info *sbi;
|
|
|
|
struct inode *root;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
sbi = kzalloc(sizeof(struct omfs_sb_info), GFP_KERNEL);
|
|
|
|
if (!sbi)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sb->s_fs_info = sbi;
|
|
|
|
|
2008-11-14 02:38:59 +03:00
|
|
|
sbi->s_uid = current_uid();
|
|
|
|
sbi->s_gid = current_gid();
|
2009-03-30 03:08:22 +04:00
|
|
|
sbi->s_dmask = sbi->s_fmask = current_umask();
|
2008-07-26 06:45:15 +04:00
|
|
|
|
|
|
|
if (!parse_options((char *) data, sbi))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
sb->s_maxbytes = 0xffffffff;
|
|
|
|
|
|
|
|
sb_set_blocksize(sb, 0x200);
|
|
|
|
|
|
|
|
bh = sb_bread(sb, 0);
|
|
|
|
if (!bh)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
omfs_sb = (struct omfs_super_block *)bh->b_data;
|
|
|
|
|
|
|
|
if (omfs_sb->s_magic != cpu_to_be32(OMFS_MAGIC)) {
|
|
|
|
if (!silent)
|
|
|
|
printk(KERN_ERR "omfs: Invalid superblock (%x)\n",
|
|
|
|
omfs_sb->s_magic);
|
|
|
|
goto out_brelse_bh;
|
|
|
|
}
|
|
|
|
sb->s_magic = OMFS_MAGIC;
|
|
|
|
|
|
|
|
sbi->s_num_blocks = be64_to_cpu(omfs_sb->s_num_blocks);
|
|
|
|
sbi->s_blocksize = be32_to_cpu(omfs_sb->s_blocksize);
|
|
|
|
sbi->s_mirrors = be32_to_cpu(omfs_sb->s_mirrors);
|
|
|
|
sbi->s_root_ino = be64_to_cpu(omfs_sb->s_root_block);
|
|
|
|
sbi->s_sys_blocksize = be32_to_cpu(omfs_sb->s_sys_blocksize);
|
|
|
|
mutex_init(&sbi->s_bitmap_lock);
|
|
|
|
|
2014-10-14 02:54:01 +04:00
|
|
|
if (sbi->s_num_blocks > OMFS_MAX_BLOCKS) {
|
|
|
|
printk(KERN_ERR "omfs: sysblock number (%llx) is out of range\n",
|
|
|
|
(unsigned long long)sbi->s_num_blocks);
|
|
|
|
goto out_brelse_bh;
|
|
|
|
}
|
|
|
|
|
2008-07-26 06:45:15 +04:00
|
|
|
if (sbi->s_sys_blocksize > PAGE_SIZE) {
|
|
|
|
printk(KERN_ERR "omfs: sysblock size (%d) is out of range\n",
|
|
|
|
sbi->s_sys_blocksize);
|
|
|
|
goto out_brelse_bh;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sbi->s_blocksize < sbi->s_sys_blocksize ||
|
|
|
|
sbi->s_blocksize > OMFS_MAX_BLOCK_SIZE) {
|
|
|
|
printk(KERN_ERR "omfs: block size (%d) is out of range\n",
|
|
|
|
sbi->s_blocksize);
|
|
|
|
goto out_brelse_bh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use sys_blocksize as the fs block since it is smaller than a
|
|
|
|
* page while the fs blocksize can be larger.
|
|
|
|
*/
|
|
|
|
sb_set_blocksize(sb, sbi->s_sys_blocksize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ...and the difference goes into a shift. sys_blocksize is always
|
|
|
|
* a power of two factor of blocksize.
|
|
|
|
*/
|
|
|
|
sbi->s_block_shift = get_bitmask_order(sbi->s_blocksize) -
|
|
|
|
get_bitmask_order(sbi->s_sys_blocksize);
|
|
|
|
|
2008-09-07 01:51:53 +04:00
|
|
|
bh2 = omfs_bread(sb, be64_to_cpu(omfs_sb->s_root_block));
|
2008-07-26 06:45:15 +04:00
|
|
|
if (!bh2)
|
|
|
|
goto out_brelse_bh;
|
|
|
|
|
|
|
|
omfs_rb = (struct omfs_root_block *)bh2->b_data;
|
|
|
|
|
|
|
|
sbi->s_bitmap_ino = be64_to_cpu(omfs_rb->r_bitmap);
|
|
|
|
sbi->s_clustersize = be32_to_cpu(omfs_rb->r_clustersize);
|
|
|
|
|
|
|
|
if (sbi->s_num_blocks != be64_to_cpu(omfs_rb->r_num_blocks)) {
|
|
|
|
printk(KERN_ERR "omfs: block count discrepancy between "
|
|
|
|
"super and root blocks (%llx, %llx)\n",
|
2008-08-06 00:01:33 +04:00
|
|
|
(unsigned long long)sbi->s_num_blocks,
|
|
|
|
(unsigned long long)be64_to_cpu(omfs_rb->r_num_blocks));
|
2008-07-26 06:45:15 +04:00
|
|
|
goto out_brelse_bh2;
|
|
|
|
}
|
|
|
|
|
2008-08-15 02:43:59 +04:00
|
|
|
if (sbi->s_bitmap_ino != ~0ULL &&
|
|
|
|
sbi->s_bitmap_ino > sbi->s_num_blocks) {
|
|
|
|
printk(KERN_ERR "omfs: free space bitmap location is corrupt "
|
|
|
|
"(%llx, total blocks %llx)\n",
|
|
|
|
(unsigned long long) sbi->s_bitmap_ino,
|
|
|
|
(unsigned long long) sbi->s_num_blocks);
|
|
|
|
goto out_brelse_bh2;
|
|
|
|
}
|
2010-07-06 19:16:46 +04:00
|
|
|
if (sbi->s_clustersize < 1 ||
|
|
|
|
sbi->s_clustersize > OMFS_MAX_CLUSTER_SIZE) {
|
|
|
|
printk(KERN_ERR "omfs: cluster size out of range (%d)",
|
|
|
|
sbi->s_clustersize);
|
|
|
|
goto out_brelse_bh2;
|
|
|
|
}
|
2008-08-15 02:43:59 +04:00
|
|
|
|
2008-07-26 06:45:15 +04:00
|
|
|
ret = omfs_get_imap(sb);
|
|
|
|
if (ret)
|
|
|
|
goto out_brelse_bh2;
|
|
|
|
|
|
|
|
sb->s_op = &omfs_sops;
|
|
|
|
|
|
|
|
root = omfs_iget(sb, be64_to_cpu(omfs_rb->r_root_dir));
|
|
|
|
if (IS_ERR(root)) {
|
|
|
|
ret = PTR_ERR(root);
|
|
|
|
goto out_brelse_bh2;
|
|
|
|
}
|
|
|
|
|
2012-01-09 07:15:13 +04:00
|
|
|
sb->s_root = d_make_root(root);
|
2015-05-29 01:44:32 +03:00
|
|
|
if (!sb->s_root) {
|
|
|
|
ret = -ENOMEM;
|
2008-07-26 06:45:15 +04:00
|
|
|
goto out_brelse_bh2;
|
2015-05-29 01:44:32 +03:00
|
|
|
}
|
2008-07-26 06:45:15 +04:00
|
|
|
printk(KERN_DEBUG "omfs: Mounted volume %s\n", omfs_rb->r_name);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out_brelse_bh2:
|
|
|
|
brelse(bh2);
|
|
|
|
out_brelse_bh:
|
|
|
|
brelse(bh);
|
|
|
|
end:
|
2010-07-06 08:50:58 +04:00
|
|
|
if (ret)
|
|
|
|
kfree(sbi);
|
2008-07-26 06:45:15 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-07-25 00:46:55 +04:00
|
|
|
static struct dentry *omfs_mount(struct file_system_type *fs_type,
|
|
|
|
int flags, const char *dev_name, void *data)
|
2008-07-26 06:45:15 +04:00
|
|
|
{
|
2010-07-25 00:46:55 +04:00
|
|
|
return mount_bdev(fs_type, flags, dev_name, data, omfs_fill_super);
|
2008-07-26 06:45:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type omfs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "omfs",
|
2010-07-25 00:46:55 +04:00
|
|
|
.mount = omfs_mount,
|
2008-07-26 06:45:15 +04:00
|
|
|
.kill_sb = kill_block_super,
|
|
|
|
.fs_flags = FS_REQUIRES_DEV,
|
|
|
|
};
|
2013-03-03 07:39:14 +04:00
|
|
|
MODULE_ALIAS_FS("omfs");
|
2008-07-26 06:45:15 +04:00
|
|
|
|
|
|
|
static int __init init_omfs_fs(void)
|
|
|
|
{
|
|
|
|
return register_filesystem(&omfs_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_omfs_fs(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&omfs_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_omfs_fs);
|
|
|
|
module_exit(exit_omfs_fs);
|