2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Compressed rom filesystem for Linux.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Linus Torvalds.
|
|
|
|
*
|
|
|
|
* This file is released under the GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the VFS interfaces to the compressed rom filesystem.
|
|
|
|
* The actual compression is based on zlib, see the other files.
|
|
|
|
*/
|
|
|
|
|
2014-08-09 04:22:50 +07:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
2017-10-12 13:16:12 +07:00
|
|
|
#include <linux/file.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/pagemap.h>
|
2017-10-12 13:16:12 +07:00
|
|
|
#include <linux/pfn_t.h>
|
|
|
|
#include <linux/ramfs.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/blkdev.h>
|
2017-10-14 03:09:23 +07:00
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/super.h>
|
2019-03-25 23:38:32 +07:00
|
|
|
#include <linux/fs_context.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/vfs.h>
|
2006-03-26 16:37:12 +07:00
|
|
|
#include <linux/mutex.h>
|
2013-12-11 04:54:28 +07:00
|
|
|
#include <uapi/linux/cramfs_fs.h>
|
2014-08-09 04:22:55 +07:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-12-11 04:54:28 +07:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cramfs super-block data in memory
|
|
|
|
*/
|
|
|
|
struct cramfs_sb_info {
|
|
|
|
unsigned long magic;
|
|
|
|
unsigned long size;
|
|
|
|
unsigned long blocks;
|
|
|
|
unsigned long files;
|
|
|
|
unsigned long flags;
|
2017-10-14 03:09:23 +07:00
|
|
|
void *linear_virt_addr;
|
|
|
|
resource_size_t linear_phys_addr;
|
|
|
|
size_t mtd_point_size;
|
2013-12-11 04:54:28 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct cramfs_sb_info *CRAMFS_SB(struct super_block *sb)
|
|
|
|
{
|
|
|
|
return sb->s_fs_info;
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:55:41 +07:00
|
|
|
static const struct super_operations cramfs_ops;
|
2007-02-12 15:55:38 +07:00
|
|
|
static const struct inode_operations cramfs_dir_inode_operations;
|
2006-03-28 16:56:42 +07:00
|
|
|
static const struct file_operations cramfs_directory_operations;
|
2017-10-12 13:16:12 +07:00
|
|
|
static const struct file_operations cramfs_physmem_fops;
|
2006-06-28 18:26:44 +07:00
|
|
|
static const struct address_space_operations cramfs_aops;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-03-26 16:37:12 +07:00
|
|
|
static DEFINE_MUTEX(read_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
|
2011-01-13 08:01:10 +07:00
|
|
|
/* These macros may change in future, to provide better st_ino semantics. */
|
2005-04-17 05:20:36 +07:00
|
|
|
#define OFFSET(x) ((x)->i_ino)
|
|
|
|
|
2011-07-18 06:04:14 +07:00
|
|
|
static unsigned long cramino(const struct cramfs_inode *cino, unsigned int offset)
|
2005-09-07 05:17:40 +07:00
|
|
|
{
|
2011-01-13 08:01:10 +07:00
|
|
|
if (!cino->offset)
|
|
|
|
return offset + 1;
|
|
|
|
if (!cino->size)
|
|
|
|
return offset + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The file mode test fixes buggy mkcramfs implementations where
|
|
|
|
* cramfs_inode->offset is set to a non zero value for entries
|
|
|
|
* which did not contain data, like devices node and fifos.
|
|
|
|
*/
|
|
|
|
switch (cino->mode & S_IFMT) {
|
|
|
|
case S_IFREG:
|
|
|
|
case S_IFDIR:
|
|
|
|
case S_IFLNK:
|
|
|
|
return cino->offset << 2;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return offset + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *get_cramfs_inode(struct super_block *sb,
|
2011-07-18 06:04:14 +07:00
|
|
|
const struct cramfs_inode *cramfs_inode, unsigned int offset)
|
2011-01-13 08:01:10 +07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 09:36:02 +07:00
|
|
|
static struct timespec64 zerotime;
|
2011-01-13 08:01:10 +07:00
|
|
|
|
|
|
|
inode = iget_locked(sb, cramino(cramfs_inode, offset));
|
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
if (!(inode->i_state & I_NEW))
|
|
|
|
return inode;
|
|
|
|
|
|
|
|
switch (cramfs_inode->mode & S_IFMT) {
|
|
|
|
case S_IFREG:
|
|
|
|
inode->i_fop = &generic_ro_fops;
|
|
|
|
inode->i_data.a_ops = &cramfs_aops;
|
2017-10-12 13:16:12 +07:00
|
|
|
if (IS_ENABLED(CONFIG_CRAMFS_MTD) &&
|
|
|
|
CRAMFS_SB(sb)->flags & CRAMFS_FLAG_EXT_BLOCK_POINTERS &&
|
|
|
|
CRAMFS_SB(sb)->linear_phys_addr)
|
|
|
|
inode->i_fop = &cramfs_physmem_fops;
|
2011-01-13 08:01:10 +07:00
|
|
|
break;
|
|
|
|
case S_IFDIR:
|
|
|
|
inode->i_op = &cramfs_dir_inode_operations;
|
|
|
|
inode->i_fop = &cramfs_directory_operations;
|
|
|
|
break;
|
|
|
|
case S_IFLNK:
|
|
|
|
inode->i_op = &page_symlink_inode_operations;
|
2015-11-17 13:07:57 +07:00
|
|
|
inode_nohighmem(inode);
|
2011-01-13 08:01:10 +07:00
|
|
|
inode->i_data.a_ops = &cramfs_aops;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
init_special_inode(inode, cramfs_inode->mode,
|
|
|
|
old_decode_dev(cramfs_inode->size));
|
|
|
|
}
|
|
|
|
|
2010-06-05 08:19:01 +07:00
|
|
|
inode->i_mode = cramfs_inode->mode;
|
2012-02-11 02:06:08 +07:00
|
|
|
i_uid_write(inode, cramfs_inode->uid);
|
|
|
|
i_gid_write(inode, cramfs_inode->gid);
|
2011-01-13 08:01:10 +07:00
|
|
|
|
|
|
|
/* if the lower 2 bits are zero, the inode contains data */
|
|
|
|
if (!(inode->i_ino & 3)) {
|
|
|
|
inode->i_size = cramfs_inode->size;
|
|
|
|
inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
|
|
|
|
}
|
|
|
|
|
2010-06-05 08:19:01 +07:00
|
|
|
/* Struct copy intentional */
|
|
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
|
|
|
|
/* inode->i_nlink is left 1 - arguably wrong for directories,
|
|
|
|
but it's the best we can do without reading the directory
|
|
|
|
contents. 1 yields the right result in GNU find, even
|
|
|
|
without -noleaf option. */
|
2005-09-07 05:17:40 +07:00
|
|
|
|
2011-01-13 08:01:10 +07:00
|
|
|
unlock_new_inode(inode);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have our own block cache: don't fill up the buffer cache
|
|
|
|
* with the rom-image, because the way the filesystem is set
|
|
|
|
* up the accesses should be fairly regular and cached in the
|
|
|
|
* page cache and dentry tree anyway..
|
|
|
|
*
|
|
|
|
* This also acts as a way to guarantee contiguous areas of up to
|
2016-04-01 19:29:48 +07:00
|
|
|
* BLKS_PER_BUF*PAGE_SIZE, so that the caller doesn't need to
|
2005-04-17 05:20:36 +07:00
|
|
|
* worry about end-of-buffer issues even when decompressing a full
|
|
|
|
* page cache.
|
2017-10-14 03:09:23 +07:00
|
|
|
*
|
|
|
|
* Note: This is all optimized away at compile time when
|
|
|
|
* CONFIG_CRAMFS_BLOCKDEV=n.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
#define READ_BUFFERS (2)
|
|
|
|
/* NEXT_BUFFER(): Loop over [0..(READ_BUFFERS-1)]. */
|
|
|
|
#define NEXT_BUFFER(_ix) ((_ix) ^ 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BLKS_PER_BUF_SHIFT should be at least 2 to allow for "compressed"
|
|
|
|
* data that takes up more space than the original and with unlucky
|
|
|
|
* alignment.
|
|
|
|
*/
|
|
|
|
#define BLKS_PER_BUF_SHIFT (2)
|
|
|
|
#define BLKS_PER_BUF (1 << BLKS_PER_BUF_SHIFT)
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
#define BUFFER_SIZE (BLKS_PER_BUF*PAGE_SIZE)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
static unsigned char read_buffers[READ_BUFFERS][BUFFER_SIZE];
|
|
|
|
static unsigned buffer_blocknr[READ_BUFFERS];
|
2014-08-09 04:22:52 +07:00
|
|
|
static struct super_block *buffer_dev[READ_BUFFERS];
|
2005-04-17 05:20:36 +07:00
|
|
|
static int next_buffer;
|
|
|
|
|
|
|
|
/*
|
2017-10-14 03:09:23 +07:00
|
|
|
* Populate our block cache and return a pointer to it.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2017-10-14 03:09:23 +07:00
|
|
|
static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset,
|
|
|
|
unsigned int len)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;
|
|
|
|
struct page *pages[BLKS_PER_BUF];
|
2007-10-18 17:06:54 +07:00
|
|
|
unsigned i, blocknr, buffer;
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long devsize;
|
|
|
|
char *data;
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return NULL;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
blocknr = offset >> PAGE_SHIFT;
|
|
|
|
offset &= PAGE_SIZE - 1;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Check if an existing buffer already has the data.. */
|
|
|
|
for (i = 0; i < READ_BUFFERS; i++) {
|
|
|
|
unsigned int blk_offset;
|
|
|
|
|
|
|
|
if (buffer_dev[i] != sb)
|
|
|
|
continue;
|
|
|
|
if (blocknr < buffer_blocknr[i])
|
|
|
|
continue;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
blk_offset = (blocknr - buffer_blocknr[i]) << PAGE_SHIFT;
|
2005-04-17 05:20:36 +07:00
|
|
|
blk_offset += offset;
|
2018-10-31 00:26:15 +07:00
|
|
|
if (blk_offset > BUFFER_SIZE ||
|
|
|
|
blk_offset + len > BUFFER_SIZE)
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
|
|
|
return read_buffers[i] + blk_offset;
|
|
|
|
}
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
devsize = mapping->host->i_size >> PAGE_SHIFT;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Ok, read in BLKS_PER_BUF pages completely first. */
|
|
|
|
for (i = 0; i < BLKS_PER_BUF; i++) {
|
|
|
|
struct page *page = NULL;
|
|
|
|
|
|
|
|
if (blocknr + i < devsize) {
|
2014-04-04 04:48:18 +07:00
|
|
|
page = read_mapping_page(mapping, blocknr + i, NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
/* synchronous error? */
|
|
|
|
if (IS_ERR(page))
|
|
|
|
page = NULL;
|
|
|
|
}
|
|
|
|
pages[i] = page;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < BLKS_PER_BUF; i++) {
|
|
|
|
struct page *page = pages[i];
|
2014-08-09 04:22:52 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (page) {
|
|
|
|
wait_on_page_locked(page);
|
|
|
|
if (!PageUptodate(page)) {
|
|
|
|
/* asynchronous error */
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
put_page(page);
|
2005-04-17 05:20:36 +07:00
|
|
|
pages[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = next_buffer;
|
|
|
|
next_buffer = NEXT_BUFFER(buffer);
|
|
|
|
buffer_blocknr[buffer] = blocknr;
|
|
|
|
buffer_dev[buffer] = sb;
|
|
|
|
|
|
|
|
data = read_buffers[buffer];
|
|
|
|
for (i = 0; i < BLKS_PER_BUF; i++) {
|
|
|
|
struct page *page = pages[i];
|
2014-08-09 04:22:52 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (page) {
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
memcpy(data, kmap(page), PAGE_SIZE);
|
2005-04-17 05:20:36 +07:00
|
|
|
kunmap(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
put_page(page);
|
2005-04-17 05:20:36 +07:00
|
|
|
} else
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
memset(data, 0, PAGE_SIZE);
|
|
|
|
data += PAGE_SIZE;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
return read_buffers[buffer] + offset;
|
|
|
|
}
|
|
|
|
|
2017-10-14 03:09:23 +07:00
|
|
|
/*
|
|
|
|
* Return a pointer to the linearly addressed cramfs image in memory.
|
|
|
|
*/
|
|
|
|
static void *cramfs_direct_read(struct super_block *sb, unsigned int offset,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return NULL;
|
|
|
|
if (len > sbi->size || offset > sbi->size - len)
|
|
|
|
return page_address(ZERO_PAGE(0));
|
|
|
|
return sbi->linear_virt_addr + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a pointer to a buffer containing at least LEN bytes of
|
|
|
|
* filesystem starting at byte offset OFFSET into the filesystem.
|
|
|
|
*/
|
|
|
|
static void *cramfs_read(struct super_block *sb, unsigned int offset,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_CRAMFS_MTD) && sbi->linear_virt_addr)
|
|
|
|
return cramfs_direct_read(sb, offset, len);
|
|
|
|
else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV))
|
|
|
|
return cramfs_blkdev_read(sb, offset, len);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-12 13:16:12 +07:00
|
|
|
/*
|
|
|
|
* For a mapping to be possible, we need a range of uncompressed and
|
|
|
|
* contiguous blocks. Return the offset for the first block and number of
|
|
|
|
* valid blocks for which that is true, or zero otherwise.
|
|
|
|
*/
|
|
|
|
static u32 cramfs_get_block_range(struct inode *inode, u32 pgoff, u32 *pages)
|
|
|
|
{
|
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(inode->i_sb);
|
|
|
|
int i;
|
|
|
|
u32 *blockptrs, first_block_addr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can dereference memory directly here as this code may be
|
|
|
|
* reached only when there is a direct filesystem image mapping
|
|
|
|
* available in memory.
|
|
|
|
*/
|
|
|
|
blockptrs = (u32 *)(sbi->linear_virt_addr + OFFSET(inode) + pgoff * 4);
|
|
|
|
first_block_addr = blockptrs[0] & ~CRAMFS_BLK_FLAGS;
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
u32 block_off = i * (PAGE_SIZE >> CRAMFS_BLK_DIRECT_PTR_SHIFT);
|
|
|
|
u32 expect = (first_block_addr + block_off) |
|
|
|
|
CRAMFS_BLK_FLAG_DIRECT_PTR |
|
|
|
|
CRAMFS_BLK_FLAG_UNCOMPRESSED;
|
|
|
|
if (blockptrs[i] != expect) {
|
|
|
|
pr_debug("range: block %d/%d got %#x expects %#x\n",
|
|
|
|
pgoff+i, pgoff + *pages - 1,
|
|
|
|
blockptrs[i], expect);
|
|
|
|
if (i == 0)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (++i < *pages);
|
|
|
|
|
|
|
|
*pages = i;
|
|
|
|
return first_block_addr << CRAMFS_BLK_DIRECT_PTR_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true if the last page of a file in the filesystem image contains
|
|
|
|
* some other data that doesn't belong to that file. It is assumed that the
|
|
|
|
* last block is CRAMFS_BLK_FLAG_DIRECT_PTR | CRAMFS_BLK_FLAG_UNCOMPRESSED
|
|
|
|
* (verified by cramfs_get_block_range() and directly accessible in memory.
|
|
|
|
*/
|
|
|
|
static bool cramfs_last_page_is_shared(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(inode->i_sb);
|
|
|
|
u32 partial, last_page, blockaddr, *blockptrs;
|
|
|
|
char *tail_data;
|
|
|
|
|
|
|
|
partial = offset_in_page(inode->i_size);
|
|
|
|
if (!partial)
|
|
|
|
return false;
|
|
|
|
last_page = inode->i_size >> PAGE_SHIFT;
|
|
|
|
blockptrs = (u32 *)(sbi->linear_virt_addr + OFFSET(inode));
|
|
|
|
blockaddr = blockptrs[last_page] & ~CRAMFS_BLK_FLAGS;
|
|
|
|
blockaddr <<= CRAMFS_BLK_DIRECT_PTR_SHIFT;
|
|
|
|
tail_data = sbi->linear_virt_addr + blockaddr + partial;
|
|
|
|
return memchr_inv(tail_data, 0, PAGE_SIZE - partial) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cramfs_physmem_mmap(struct file *file, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct inode *inode = file_inode(file);
|
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(inode->i_sb);
|
|
|
|
unsigned int pages, max_pages, offset;
|
|
|
|
unsigned long address, pgoff = vma->vm_pgoff;
|
|
|
|
char *bailout_reason;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = generic_file_readonly_mmap(file, vma);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now try to pre-populate ptes for this vma with a direct
|
|
|
|
* mapping avoiding memory allocation when possible.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Could COW work here? */
|
|
|
|
bailout_reason = "vma is writable";
|
|
|
|
if (vma->vm_flags & VM_WRITE)
|
|
|
|
goto bailout;
|
|
|
|
|
|
|
|
max_pages = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
|
|
bailout_reason = "beyond file limit";
|
|
|
|
if (pgoff >= max_pages)
|
|
|
|
goto bailout;
|
|
|
|
pages = min(vma_pages(vma), max_pages - pgoff);
|
|
|
|
|
|
|
|
offset = cramfs_get_block_range(inode, pgoff, &pages);
|
|
|
|
bailout_reason = "unsuitable block layout";
|
|
|
|
if (!offset)
|
|
|
|
goto bailout;
|
|
|
|
address = sbi->linear_phys_addr + offset;
|
|
|
|
bailout_reason = "data is not page aligned";
|
|
|
|
if (!PAGE_ALIGNED(address))
|
|
|
|
goto bailout;
|
|
|
|
|
|
|
|
/* Don't map the last page if it contains some other data */
|
|
|
|
if (pgoff + pages == max_pages && cramfs_last_page_is_shared(inode)) {
|
|
|
|
pr_debug("mmap: %s: last page is shared\n",
|
|
|
|
file_dentry(file)->d_name.name);
|
|
|
|
pages--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pages) {
|
|
|
|
bailout_reason = "no suitable block remaining";
|
|
|
|
goto bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pages == vma_pages(vma)) {
|
|
|
|
/*
|
|
|
|
* The entire vma is mappable. remap_pfn_range() will
|
|
|
|
* make it distinguishable from a non-direct mapping
|
|
|
|
* in /proc/<pid>/maps by substituting the file offset
|
|
|
|
* with the actual physical address.
|
|
|
|
*/
|
|
|
|
ret = remap_pfn_range(vma, vma->vm_start, address >> PAGE_SHIFT,
|
|
|
|
pages * PAGE_SIZE, vma->vm_page_prot);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Let's create a mixed map if we can't map it all.
|
|
|
|
* The normal paging machinery will take care of the
|
|
|
|
* unpopulated ptes via cramfs_readpage().
|
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
vma->vm_flags |= VM_MIXEDMAP;
|
|
|
|
for (i = 0; i < pages && !ret; i++) {
|
2018-10-27 05:04:06 +07:00
|
|
|
vm_fault_t vmf;
|
2017-10-12 13:16:12 +07:00
|
|
|
unsigned long off = i * PAGE_SIZE;
|
|
|
|
pfn_t pfn = phys_to_pfn_t(address + off, PFN_DEV);
|
2018-10-27 05:04:06 +07:00
|
|
|
vmf = vmf_insert_mixed(vma, vma->vm_start + off, pfn);
|
|
|
|
if (vmf & VM_FAULT_ERROR)
|
|
|
|
ret = vm_fault_to_errno(vmf, 0);
|
2017-10-12 13:16:12 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
pr_debug("mapped %s[%lu] at 0x%08lx (%u/%lu pages) "
|
|
|
|
"to vma 0x%08lx, page_prot 0x%llx\n",
|
|
|
|
file_dentry(file)->d_name.name, pgoff,
|
|
|
|
address, pages, vma_pages(vma), vma->vm_start,
|
|
|
|
(unsigned long long)pgprot_val(vma->vm_page_prot));
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
bailout:
|
|
|
|
pr_debug("%s[%lu]: direct mmap impossible: %s\n",
|
|
|
|
file_dentry(file)->d_name.name, pgoff, bailout_reason);
|
|
|
|
/* Didn't manage any direct map, but normal paging is still possible */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_MMU */
|
|
|
|
|
|
|
|
static int cramfs_physmem_mmap(struct file *file, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
return vma->vm_flags & (VM_SHARED | VM_MAYSHARE) ? 0 : -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long cramfs_physmem_get_unmapped_area(struct file *file,
|
|
|
|
unsigned long addr, unsigned long len,
|
|
|
|
unsigned long pgoff, unsigned long flags)
|
|
|
|
{
|
|
|
|
struct inode *inode = file_inode(file);
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
|
|
|
|
unsigned int pages, block_pages, max_pages, offset;
|
|
|
|
|
|
|
|
pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
|
|
max_pages = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
|
|
if (pgoff >= max_pages || pages > max_pages - pgoff)
|
|
|
|
return -EINVAL;
|
|
|
|
block_pages = pages;
|
|
|
|
offset = cramfs_get_block_range(inode, pgoff, &block_pages);
|
|
|
|
if (!offset || block_pages != pages)
|
|
|
|
return -ENOSYS;
|
|
|
|
addr = sbi->linear_phys_addr + offset;
|
|
|
|
pr_debug("get_unmapped for %s ofs %#lx siz %lu at 0x%08lx\n",
|
|
|
|
file_dentry(file)->d_name.name, pgoff*PAGE_SIZE, len, addr);
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int cramfs_physmem_mmap_capabilities(struct file *file)
|
|
|
|
{
|
|
|
|
return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT |
|
|
|
|
NOMMU_MAP_READ | NOMMU_MAP_EXEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_MMU */
|
|
|
|
|
|
|
|
static const struct file_operations cramfs_physmem_fops = {
|
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read_iter = generic_file_read_iter,
|
|
|
|
.splice_read = generic_file_splice_read,
|
|
|
|
.mmap = cramfs_physmem_mmap,
|
|
|
|
#ifndef CONFIG_MMU
|
|
|
|
.get_unmapped_area = cramfs_physmem_get_unmapped_area,
|
|
|
|
.mmap_capabilities = cramfs_physmem_mmap_capabilities,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-12-11 04:35:14 +07:00
|
|
|
static void cramfs_kill_sb(struct super_block *sb)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-12-11 04:54:28 +07:00
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
|
2014-08-09 04:22:52 +07:00
|
|
|
|
2018-05-14 05:05:47 +07:00
|
|
|
if (IS_ENABLED(CONFIG_CRAMFS_MTD) && sb->s_mtd) {
|
2017-10-14 03:09:23 +07:00
|
|
|
if (sbi && sbi->mtd_point_size)
|
|
|
|
mtd_unpoint(sb->s_mtd, 0, sbi->mtd_point_size);
|
|
|
|
kill_mtd_super(sb);
|
|
|
|
} else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) {
|
|
|
|
kill_block_super(sb);
|
|
|
|
}
|
2013-12-11 04:35:14 +07:00
|
|
|
kfree(sbi);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2019-03-25 23:38:32 +07:00
|
|
|
static int cramfs_reconfigure(struct fs_context *fc)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2019-03-25 23:38:32 +07:00
|
|
|
sync_filesystem(fc->root->d_sb);
|
|
|
|
fc->sb_flags |= SB_RDONLY;
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-25 23:38:32 +07:00
|
|
|
static int cramfs_read_super(struct super_block *sb, struct fs_context *fc,
|
|
|
|
struct cramfs_super *super)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2017-10-14 03:09:23 +07:00
|
|
|
struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long root_offset;
|
2019-03-25 23:38:32 +07:00
|
|
|
bool silent = fc->sb_flags & SB_SILENT;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2017-10-14 03:09:23 +07:00
|
|
|
/* We don't know the real size yet */
|
|
|
|
sbi->size = PAGE_SIZE;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Read the first block and get the superblock from it */
|
2017-10-14 03:09:23 +07:00
|
|
|
mutex_lock(&read_mutex);
|
|
|
|
memcpy(super, cramfs_read(sb, 0, sizeof(*super)), sizeof(*super));
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_unlock(&read_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Do sanity checks on the superblock */
|
2017-10-14 03:09:23 +07:00
|
|
|
if (super->magic != CRAMFS_MAGIC) {
|
2012-02-11 19:35:12 +07:00
|
|
|
/* check for wrong endianness */
|
2017-10-14 03:09:23 +07:00
|
|
|
if (super->magic == CRAMFS_MAGIC_WEND) {
|
2007-10-17 13:27:12 +07:00
|
|
|
if (!silent)
|
2019-03-25 23:38:32 +07:00
|
|
|
errorf(fc, "cramfs: wrong endianness");
|
2013-12-11 04:35:14 +07:00
|
|
|
return -EINVAL;
|
2007-10-17 13:27:12 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* check at 512 byte offset */
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_lock(&read_mutex);
|
2017-10-14 03:09:23 +07:00
|
|
|
memcpy(super,
|
|
|
|
cramfs_read(sb, 512, sizeof(*super)),
|
|
|
|
sizeof(*super));
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_unlock(&read_mutex);
|
2017-10-14 03:09:23 +07:00
|
|
|
if (super->magic != CRAMFS_MAGIC) {
|
|
|
|
if (super->magic == CRAMFS_MAGIC_WEND && !silent)
|
2019-03-25 23:38:32 +07:00
|
|
|
errorf(fc, "cramfs: wrong endianness");
|
2007-10-17 13:27:12 +07:00
|
|
|
else if (!silent)
|
2019-03-25 23:38:32 +07:00
|
|
|
errorf(fc, "cramfs: wrong magic");
|
2013-12-11 04:35:14 +07:00
|
|
|
return -EINVAL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get feature flags first */
|
2017-10-14 03:09:23 +07:00
|
|
|
if (super->flags & ~CRAMFS_SUPPORTED_FLAGS) {
|
2019-03-25 23:38:32 +07:00
|
|
|
errorf(fc, "cramfs: unsupported filesystem features");
|
2013-12-11 04:35:14 +07:00
|
|
|
return -EINVAL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the root inode is in a sane state */
|
2017-10-14 03:09:23 +07:00
|
|
|
if (!S_ISDIR(super->root.mode)) {
|
2019-03-25 23:38:32 +07:00
|
|
|
errorf(fc, "cramfs: root is not a directory");
|
2013-12-11 04:35:14 +07:00
|
|
|
return -EINVAL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2011-01-13 08:01:10 +07:00
|
|
|
/* correct strange, hard-coded permissions of mkcramfs */
|
2017-10-14 03:09:23 +07:00
|
|
|
super->root.mode |= 0555;
|
2011-01-13 08:01:10 +07:00
|
|
|
|
2017-10-14 03:09:23 +07:00
|
|
|
root_offset = super->root.offset << 2;
|
|
|
|
if (super->flags & CRAMFS_FLAG_FSID_VERSION_2) {
|
|
|
|
sbi->size = super->size;
|
|
|
|
sbi->blocks = super->fsid.blocks;
|
|
|
|
sbi->files = super->fsid.files;
|
2005-04-17 05:20:36 +07:00
|
|
|
} else {
|
2014-08-09 04:22:52 +07:00
|
|
|
sbi->size = 1<<28;
|
|
|
|
sbi->blocks = 0;
|
|
|
|
sbi->files = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2017-10-14 03:09:23 +07:00
|
|
|
sbi->magic = super->magic;
|
|
|
|
sbi->flags = super->flags;
|
2005-04-17 05:20:36 +07:00
|
|
|
if (root_offset == 0)
|
2019-03-25 23:38:32 +07:00
|
|
|
infof(fc, "cramfs: empty filesystem");
|
2017-10-14 03:09:23 +07:00
|
|
|
else if (!(super->flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
|
2005-04-17 05:20:36 +07:00
|
|
|
((root_offset != sizeof(struct cramfs_super)) &&
|
|
|
|
(root_offset != 512 + sizeof(struct cramfs_super))))
|
|
|
|
{
|
2019-03-25 23:38:32 +07:00
|
|
|
errorf(fc, "cramfs: bad root offset %lu", root_offset);
|
2013-12-11 04:35:14 +07:00
|
|
|
return -EINVAL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2017-10-14 03:09:23 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cramfs_finalize_super(struct super_block *sb,
|
|
|
|
struct cramfs_inode *cramfs_root)
|
|
|
|
{
|
|
|
|
struct inode *root;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Set it all up.. */
|
2017-11-28 04:05:09 +07:00
|
|
|
sb->s_flags |= SB_RDONLY;
|
2019-07-30 22:22:29 +07:00
|
|
|
sb->s_time_min = 0;
|
|
|
|
sb->s_time_max = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
sb->s_op = &cramfs_ops;
|
2017-10-14 03:09:23 +07:00
|
|
|
root = get_cramfs_inode(sb, cramfs_root, 0);
|
2011-07-18 06:04:14 +07:00
|
|
|
if (IS_ERR(root))
|
2013-12-11 04:35:14 +07:00
|
|
|
return PTR_ERR(root);
|
2012-01-09 10:15:13 +07:00
|
|
|
sb->s_root = d_make_root(root);
|
|
|
|
if (!sb->s_root)
|
2013-12-11 04:35:14 +07:00
|
|
|
return -ENOMEM;
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-25 23:38:32 +07:00
|
|
|
static int cramfs_blkdev_fill_super(struct super_block *sb, struct fs_context *fc)
|
2017-10-14 03:09:23 +07:00
|
|
|
{
|
|
|
|
struct cramfs_sb_info *sbi;
|
|
|
|
struct cramfs_super super;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
sbi = kzalloc(sizeof(struct cramfs_sb_info), GFP_KERNEL);
|
|
|
|
if (!sbi)
|
|
|
|
return -ENOMEM;
|
|
|
|
sb->s_fs_info = sbi;
|
|
|
|
|
|
|
|
/* Invalidate the read buffers on mount: think disk change.. */
|
|
|
|
for (i = 0; i < READ_BUFFERS; i++)
|
|
|
|
buffer_blocknr[i] = -1;
|
|
|
|
|
2019-03-25 23:38:32 +07:00
|
|
|
err = cramfs_read_super(sb, fc, &super);
|
2017-10-14 03:09:23 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
return cramfs_finalize_super(sb, &super.root);
|
|
|
|
}
|
|
|
|
|
2019-03-25 23:38:32 +07:00
|
|
|
static int cramfs_mtd_fill_super(struct super_block *sb, struct fs_context *fc)
|
2017-10-14 03:09:23 +07:00
|
|
|
{
|
|
|
|
struct cramfs_sb_info *sbi;
|
|
|
|
struct cramfs_super super;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
sbi = kzalloc(sizeof(struct cramfs_sb_info), GFP_KERNEL);
|
|
|
|
if (!sbi)
|
|
|
|
return -ENOMEM;
|
|
|
|
sb->s_fs_info = sbi;
|
|
|
|
|
|
|
|
/* Map only one page for now. Will remap it when fs size is known. */
|
|
|
|
err = mtd_point(sb->s_mtd, 0, PAGE_SIZE, &sbi->mtd_point_size,
|
|
|
|
&sbi->linear_virt_addr, &sbi->linear_phys_addr);
|
|
|
|
if (err || sbi->mtd_point_size != PAGE_SIZE) {
|
|
|
|
pr_err("unable to get direct memory access to mtd:%s\n",
|
|
|
|
sb->s_mtd->name);
|
|
|
|
return err ? : -ENODATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_info("checking physical address %pap for linear cramfs image\n",
|
|
|
|
&sbi->linear_phys_addr);
|
2019-03-25 23:38:32 +07:00
|
|
|
err = cramfs_read_super(sb, fc, &super);
|
2017-10-14 03:09:23 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Remap the whole filesystem now */
|
|
|
|
pr_info("linear cramfs image on mtd:%s appears to be %lu KB in size\n",
|
|
|
|
sb->s_mtd->name, sbi->size/1024);
|
|
|
|
mtd_unpoint(sb->s_mtd, 0, PAGE_SIZE);
|
|
|
|
err = mtd_point(sb->s_mtd, 0, sbi->size, &sbi->mtd_point_size,
|
|
|
|
&sbi->linear_virt_addr, &sbi->linear_phys_addr);
|
|
|
|
if (err || sbi->mtd_point_size != sbi->size) {
|
|
|
|
pr_err("unable to get direct memory access to mtd:%s\n",
|
|
|
|
sb->s_mtd->name);
|
|
|
|
return err ? : -ENODATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cramfs_finalize_super(sb, &super.root);
|
|
|
|
}
|
|
|
|
|
2006-06-23 16:02:58 +07:00
|
|
|
static int cramfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-06-23 16:02:58 +07:00
|
|
|
struct super_block *sb = dentry->d_sb;
|
2017-10-14 03:09:23 +07:00
|
|
|
u64 id = 0;
|
|
|
|
|
|
|
|
if (sb->s_bdev)
|
|
|
|
id = huge_encode_dev(sb->s_bdev->bd_dev);
|
|
|
|
else if (sb->s_dev)
|
|
|
|
id = huge_encode_dev(sb->s_dev);
|
2006-06-23 16:02:58 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
buf->f_type = CRAMFS_MAGIC;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
buf->f_bsize = PAGE_SIZE;
|
2005-04-17 05:20:36 +07:00
|
|
|
buf->f_blocks = CRAMFS_SB(sb)->blocks;
|
|
|
|
buf->f_bfree = 0;
|
|
|
|
buf->f_bavail = 0;
|
|
|
|
buf->f_files = CRAMFS_SB(sb)->files;
|
|
|
|
buf->f_ffree = 0;
|
2009-04-03 06:59:33 +07:00
|
|
|
buf->f_fsid.val[0] = (u32)id;
|
|
|
|
buf->f_fsid.val[1] = (u32)(id >> 32);
|
2005-04-17 05:20:36 +07:00
|
|
|
buf->f_namelen = CRAMFS_MAXPATHLEN;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a cramfs directory entry.
|
|
|
|
*/
|
2013-05-18 05:02:17 +07:00
|
|
|
static int cramfs_readdir(struct file *file, struct dir_context *ctx)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-05-18 05:02:17 +07:00
|
|
|
struct inode *inode = file_inode(file);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
char *buf;
|
|
|
|
unsigned int offset;
|
|
|
|
|
|
|
|
/* Offset within the thing. */
|
2013-05-18 05:02:17 +07:00
|
|
|
if (ctx->pos >= inode->i_size)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
2013-05-18 05:02:17 +07:00
|
|
|
offset = ctx->pos;
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Directory entries are always 4-byte aligned */
|
|
|
|
if (offset & 3)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-10-18 17:06:55 +07:00
|
|
|
buf = kmalloc(CRAMFS_MAXPATHLEN, GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
while (offset < inode->i_size) {
|
|
|
|
struct cramfs_inode *de;
|
|
|
|
unsigned long nextoffset;
|
|
|
|
char *name;
|
|
|
|
ino_t ino;
|
2011-07-26 14:30:54 +07:00
|
|
|
umode_t mode;
|
2013-05-18 05:02:17 +07:00
|
|
|
int namelen;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_lock(&read_mutex);
|
2007-10-18 17:06:55 +07:00
|
|
|
de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+CRAMFS_MAXPATHLEN);
|
2005-04-17 05:20:36 +07:00
|
|
|
name = (char *)(de+1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Namelengths on disk are shifted by two
|
|
|
|
* and the name padded out to 4-byte boundaries
|
|
|
|
* with zeroes.
|
|
|
|
*/
|
|
|
|
namelen = de->namelen << 2;
|
|
|
|
memcpy(buf, name, namelen);
|
2011-01-13 08:01:10 +07:00
|
|
|
ino = cramino(de, OFFSET(inode) + offset);
|
2005-04-17 05:20:36 +07:00
|
|
|
mode = de->mode;
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_unlock(&read_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
nextoffset = offset + sizeof(*de) + namelen;
|
|
|
|
for (;;) {
|
|
|
|
if (!namelen) {
|
|
|
|
kfree(buf);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
if (buf[namelen-1])
|
|
|
|
break;
|
|
|
|
namelen--;
|
|
|
|
}
|
2013-05-18 05:02:17 +07:00
|
|
|
if (!dir_emit(ctx, buf, namelen, ino, mode >> 12))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
2013-05-18 05:02:17 +07:00
|
|
|
ctx->pos = offset = nextoffset;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
kfree(buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup and fill in the inode data..
|
|
|
|
*/
|
2014-08-09 04:22:52 +07:00
|
|
|
static struct dentry *cramfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
unsigned int offset = 0;
|
2011-07-18 06:04:14 +07:00
|
|
|
struct inode *inode = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
int sorted;
|
|
|
|
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_lock(&read_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
sorted = CRAMFS_SB(dir->i_sb)->flags & CRAMFS_FLAG_SORTED_DIRS;
|
|
|
|
while (offset < dir->i_size) {
|
|
|
|
struct cramfs_inode *de;
|
|
|
|
char *name;
|
|
|
|
int namelen, retval;
|
2011-01-13 08:01:10 +07:00
|
|
|
int dir_off = OFFSET(dir) + offset;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-01-13 08:01:10 +07:00
|
|
|
de = cramfs_read(dir->i_sb, dir_off, sizeof(*de)+CRAMFS_MAXPATHLEN);
|
2005-04-17 05:20:36 +07:00
|
|
|
name = (char *)(de+1);
|
|
|
|
|
|
|
|
/* Try to take advantage of sorted directories */
|
|
|
|
if (sorted && (dentry->d_name.name[0] < name[0]))
|
|
|
|
break;
|
|
|
|
|
|
|
|
namelen = de->namelen << 2;
|
|
|
|
offset += sizeof(*de) + namelen;
|
|
|
|
|
|
|
|
/* Quick check that the name is roughly the right length */
|
|
|
|
if (((dentry->d_name.len + 3) & ~3) != namelen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!namelen) {
|
2011-07-18 06:04:14 +07:00
|
|
|
inode = ERR_PTR(-EIO);
|
|
|
|
goto out;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
if (name[namelen-1])
|
|
|
|
break;
|
|
|
|
namelen--;
|
|
|
|
}
|
|
|
|
if (namelen != dentry->d_name.len)
|
|
|
|
continue;
|
|
|
|
retval = memcmp(dentry->d_name.name, name, namelen);
|
|
|
|
if (retval > 0)
|
|
|
|
continue;
|
|
|
|
if (!retval) {
|
2011-07-18 06:04:14 +07:00
|
|
|
inode = get_cramfs_inode(dir->i_sb, de, dir_off);
|
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
/* else (retval < 0) */
|
|
|
|
if (sorted)
|
|
|
|
break;
|
|
|
|
}
|
2011-07-18 06:04:14 +07:00
|
|
|
out:
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_unlock(&read_mutex);
|
2018-05-01 06:18:26 +07:00
|
|
|
return d_splice_alias(inode, dentry);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2014-08-09 04:22:52 +07:00
|
|
|
static int cramfs_readpage(struct file *file, struct page *page)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
2009-04-03 06:59:15 +07:00
|
|
|
u32 maxblock;
|
|
|
|
int bytes_filled;
|
2005-04-17 05:20:36 +07:00
|
|
|
void *pgdata;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
maxblock = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
2005-04-17 05:20:36 +07:00
|
|
|
bytes_filled = 0;
|
2009-04-03 06:59:15 +07:00
|
|
|
pgdata = kmap(page);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (page->index < maxblock) {
|
|
|
|
struct super_block *sb = inode->i_sb;
|
2017-10-12 13:16:11 +07:00
|
|
|
u32 blkptr_offset = OFFSET(inode) + page->index * 4;
|
|
|
|
u32 block_ptr, block_start, block_len;
|
|
|
|
bool uncompressed, direct;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-03-26 16:37:12 +07:00
|
|
|
mutex_lock(&read_mutex);
|
2017-10-12 13:16:11 +07:00
|
|
|
block_ptr = *(u32 *) cramfs_read(sb, blkptr_offset, 4);
|
|
|
|
uncompressed = (block_ptr & CRAMFS_BLK_FLAG_UNCOMPRESSED);
|
|
|
|
direct = (block_ptr & CRAMFS_BLK_FLAG_DIRECT_PTR);
|
|
|
|
block_ptr &= ~CRAMFS_BLK_FLAGS;
|
|
|
|
|
|
|
|
if (direct) {
|
|
|
|
/*
|
|
|
|
* The block pointer is an absolute start pointer,
|
|
|
|
* shifted by 2 bits. The size is included in the
|
|
|
|
* first 2 bytes of the data block when compressed,
|
|
|
|
* or PAGE_SIZE otherwise.
|
|
|
|
*/
|
|
|
|
block_start = block_ptr << CRAMFS_BLK_DIRECT_PTR_SHIFT;
|
|
|
|
if (uncompressed) {
|
|
|
|
block_len = PAGE_SIZE;
|
|
|
|
/* if last block: cap to file length */
|
|
|
|
if (page->index == maxblock - 1)
|
|
|
|
block_len =
|
|
|
|
offset_in_page(inode->i_size);
|
|
|
|
} else {
|
|
|
|
block_len = *(u16 *)
|
|
|
|
cramfs_read(sb, block_start, 2);
|
|
|
|
block_start += 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The block pointer indicates one past the end of
|
|
|
|
* the current block (start of next block). If this
|
|
|
|
* is the first block then it starts where the block
|
|
|
|
* pointer table ends, otherwise its start comes
|
|
|
|
* from the previous block's pointer.
|
|
|
|
*/
|
|
|
|
block_start = OFFSET(inode) + maxblock * 4;
|
|
|
|
if (page->index)
|
|
|
|
block_start = *(u32 *)
|
|
|
|
cramfs_read(sb, blkptr_offset - 4, 4);
|
|
|
|
/* Beware... previous ptr might be a direct ptr */
|
|
|
|
if (unlikely(block_start & CRAMFS_BLK_FLAG_DIRECT_PTR)) {
|
|
|
|
/* See comments on earlier code. */
|
|
|
|
u32 prev_start = block_start;
|
2018-10-31 01:22:58 +07:00
|
|
|
block_start = prev_start & ~CRAMFS_BLK_FLAGS;
|
|
|
|
block_start <<= CRAMFS_BLK_DIRECT_PTR_SHIFT;
|
2017-10-12 13:16:11 +07:00
|
|
|
if (prev_start & CRAMFS_BLK_FLAG_UNCOMPRESSED) {
|
|
|
|
block_start += PAGE_SIZE;
|
|
|
|
} else {
|
|
|
|
block_len = *(u16 *)
|
|
|
|
cramfs_read(sb, block_start, 2);
|
|
|
|
block_start += 2 + block_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
block_start &= ~CRAMFS_BLK_FLAGS;
|
|
|
|
block_len = block_ptr - block_start;
|
|
|
|
}
|
2009-04-03 06:59:15 +07:00
|
|
|
|
2017-10-12 13:16:11 +07:00
|
|
|
if (block_len == 0)
|
2005-04-17 05:20:36 +07:00
|
|
|
; /* hole */
|
2017-10-12 13:16:11 +07:00
|
|
|
else if (unlikely(block_len > 2*PAGE_SIZE ||
|
|
|
|
(uncompressed && block_len > PAGE_SIZE))) {
|
|
|
|
mutex_unlock(&read_mutex);
|
|
|
|
pr_err("bad data blocksize %u\n", block_len);
|
2009-04-03 06:59:15 +07:00
|
|
|
goto err;
|
2017-10-12 13:16:11 +07:00
|
|
|
} else if (uncompressed) {
|
|
|
|
memcpy(pgdata,
|
|
|
|
cramfs_read(sb, block_start, block_len),
|
|
|
|
block_len);
|
|
|
|
bytes_filled = block_len;
|
2009-04-03 06:59:15 +07:00
|
|
|
} else {
|
2005-04-17 05:20:36 +07:00
|
|
|
bytes_filled = cramfs_uncompress_block(pgdata,
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
PAGE_SIZE,
|
2017-10-12 13:16:11 +07:00
|
|
|
cramfs_read(sb, block_start, block_len),
|
|
|
|
block_len);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2017-10-12 13:16:11 +07:00
|
|
|
mutex_unlock(&read_mutex);
|
|
|
|
if (unlikely(bytes_filled < 0))
|
|
|
|
goto err;
|
2009-04-03 06:59:15 +07:00
|
|
|
}
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
memset(pgdata + bytes_filled, 0, PAGE_SIZE - bytes_filled);
|
2005-04-17 05:20:36 +07:00
|
|
|
flush_dcache_page(page);
|
2009-04-03 06:59:15 +07:00
|
|
|
kunmap(page);
|
2005-04-17 05:20:36 +07:00
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
|
|
|
return 0;
|
2009-04-03 06:59:15 +07:00
|
|
|
|
|
|
|
err:
|
|
|
|
kunmap(page);
|
|
|
|
ClearPageUptodate(page);
|
|
|
|
SetPageError(page);
|
|
|
|
unlock_page(page);
|
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-06-28 18:26:44 +07:00
|
|
|
static const struct address_space_operations cramfs_aops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.readpage = cramfs_readpage
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our operations:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A directory can only readdir
|
|
|
|
*/
|
2006-03-28 16:56:42 +07:00
|
|
|
static const struct file_operations cramfs_directory_operations = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read = generic_read_dir,
|
2016-05-01 09:37:34 +07:00
|
|
|
.iterate_shared = cramfs_readdir,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2007-02-12 15:55:38 +07:00
|
|
|
static const struct inode_operations cramfs_dir_inode_operations = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.lookup = cramfs_lookup,
|
|
|
|
};
|
|
|
|
|
2007-02-12 15:55:41 +07:00
|
|
|
static const struct super_operations cramfs_ops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.statfs = cramfs_statfs,
|
|
|
|
};
|
|
|
|
|
2019-03-25 23:38:32 +07:00
|
|
|
static int cramfs_get_tree(struct fs_context *fc)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2019-03-25 23:38:32 +07:00
|
|
|
int ret = -ENOPROTOOPT;
|
2017-10-14 03:09:23 +07:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_CRAMFS_MTD)) {
|
2019-03-25 23:38:32 +07:00
|
|
|
ret = get_tree_mtd(fc, cramfs_mtd_fill_super);
|
|
|
|
if (ret < 0)
|
2017-10-14 03:09:23 +07:00
|
|
|
return ret;
|
|
|
|
}
|
2019-03-25 23:38:32 +07:00
|
|
|
if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV))
|
|
|
|
ret = get_tree_bdev(fc, cramfs_blkdev_fill_super);
|
2017-10-14 03:09:23 +07:00
|
|
|
return ret;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2019-03-25 23:38:32 +07:00
|
|
|
static const struct fs_context_operations cramfs_context_ops = {
|
|
|
|
.get_tree = cramfs_get_tree,
|
|
|
|
.reconfigure = cramfs_reconfigure,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the filesystem mount context.
|
|
|
|
*/
|
|
|
|
static int cramfs_init_fs_context(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
fc->ops = &cramfs_context_ops;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
static struct file_system_type cramfs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "cramfs",
|
2019-03-25 23:38:32 +07:00
|
|
|
.init_fs_context = cramfs_init_fs_context,
|
2013-12-11 04:35:14 +07:00
|
|
|
.kill_sb = cramfs_kill_sb,
|
2005-04-17 05:20:36 +07:00
|
|
|
.fs_flags = FS_REQUIRES_DEV,
|
|
|
|
};
|
2013-03-03 10:39:14 +07:00
|
|
|
MODULE_ALIAS_FS("cramfs");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
static int __init init_cramfs_fs(void)
|
|
|
|
{
|
2006-09-29 16:01:04 +07:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = cramfs_uncompress_init();
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
|
|
|
rv = register_filesystem(&cramfs_fs_type);
|
|
|
|
if (rv < 0)
|
|
|
|
cramfs_uncompress_exit();
|
|
|
|
return rv;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_cramfs_fs(void)
|
|
|
|
{
|
|
|
|
cramfs_uncompress_exit();
|
|
|
|
unregister_filesystem(&cramfs_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_cramfs_fs)
|
|
|
|
module_exit(exit_cramfs_fs)
|
|
|
|
MODULE_LICENSE("GPL");
|