2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000-2001 Christoph Hellwig.
|
2016-06-01 07:25:12 +00:00
|
|
|
* Copyright (c) 2016 Krzysztof Blaszkowski
|
2005-04-16 22:20:36 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL").
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Veritas filesystem driver - lookup and other directory related code.
|
|
|
|
*/
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
|
|
|
|
#include "vxfs.h"
|
|
|
|
#include "vxfs_dir.h"
|
|
|
|
#include "vxfs_inode.h"
|
|
|
|
#include "vxfs_extern.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of VxFS blocks per 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 12:29:47 +00:00
|
|
|
#define VXFS_BLOCK_PER_PAGE(sbp) ((PAGE_SIZE / (sbp)->s_blocksize))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
2012-06-10 21:13:09 +00:00
|
|
|
static struct dentry * vxfs_lookup(struct inode *, struct dentry *, unsigned int);
|
2013-05-18 07:15:00 +00:00
|
|
|
static int vxfs_readdir(struct file *, struct dir_context *);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-02-12 08:55:38 +00:00
|
|
|
const struct inode_operations vxfs_dir_inode_ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.lookup = vxfs_lookup,
|
|
|
|
};
|
|
|
|
|
2006-03-28 09:56:42 +00:00
|
|
|
const struct file_operations vxfs_dir_operations = {
|
2010-05-26 21:44:53 +00:00
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read = generic_read_dir,
|
2016-05-01 02:37:34 +00:00
|
|
|
.iterate_shared = vxfs_readdir,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vxfs_find_entry - find a mathing directory entry for a dentry
|
|
|
|
* @ip: directory inode
|
|
|
|
* @dp: dentry for which we want to find a direct
|
|
|
|
* @ppp: gets filled with the page the return value sits in
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* vxfs_find_entry finds a &struct vxfs_direct for the VFS directory
|
|
|
|
* cache entry @dp. @ppp will be filled with the page the return
|
|
|
|
* value resides in.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The wanted direct on success, else a NULL pointer.
|
|
|
|
*/
|
|
|
|
static struct vxfs_direct *
|
|
|
|
vxfs_find_entry(struct inode *ip, struct dentry *dp, struct page **ppp)
|
|
|
|
{
|
2016-06-12 17:26:45 +00:00
|
|
|
u_long bsize = ip->i_sb->s_blocksize;
|
|
|
|
const char *name = dp->d_name.name;
|
|
|
|
int namelen = dp->d_name.len;
|
|
|
|
loff_t limit = VXFS_DIRROUND(ip->i_size);
|
|
|
|
struct vxfs_direct *de_exit = NULL;
|
|
|
|
loff_t pos = 0;
|
|
|
|
struct vxfs_sb_info *sbi = VXFS_SBI(ip->i_sb);
|
|
|
|
|
|
|
|
while (pos < limit) {
|
|
|
|
struct page *pp;
|
|
|
|
char *kaddr;
|
|
|
|
int pg_ofs = pos & ~PAGE_MASK;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
pp = vxfs_get_page(ip->i_mapping, pos >> PAGE_SHIFT);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_ERR(pp))
|
2016-06-12 17:26:45 +00:00
|
|
|
return NULL;
|
|
|
|
kaddr = (char *)page_address(pp);
|
|
|
|
|
|
|
|
while (pg_ofs < PAGE_SIZE && pos < limit) {
|
|
|
|
struct vxfs_direct *de;
|
|
|
|
|
|
|
|
if ((pos & (bsize - 1)) < 4) {
|
|
|
|
struct vxfs_dirblk *dbp =
|
|
|
|
(struct vxfs_dirblk *)
|
|
|
|
(kaddr + (pos & ~PAGE_MASK));
|
|
|
|
int overhead = VXFS_DIRBLKOV(sbi, dbp);
|
|
|
|
|
|
|
|
pos += overhead;
|
|
|
|
pg_ofs += overhead;
|
|
|
|
}
|
|
|
|
de = (struct vxfs_direct *)(kaddr + pg_ofs);
|
|
|
|
|
|
|
|
if (!de->d_reclen) {
|
|
|
|
pos += bsize - 1;
|
|
|
|
pos &= ~(bsize - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pg_ofs += fs16_to_cpu(sbi, de->d_reclen);
|
|
|
|
pos += fs16_to_cpu(sbi, de->d_reclen);
|
|
|
|
if (!de->d_ino)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (namelen != fs16_to_cpu(sbi, de->d_namelen))
|
|
|
|
continue;
|
|
|
|
if (!memcmp(name, de->d_name, namelen)) {
|
|
|
|
*ppp = pp;
|
|
|
|
de_exit = de;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-12 17:26:45 +00:00
|
|
|
if (!de_exit)
|
|
|
|
vxfs_put_page(pp);
|
|
|
|
else
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
return de_exit;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vxfs_inode_by_name - find inode number for dentry
|
|
|
|
* @dip: directory to search in
|
2011-03-31 01:57:33 +00:00
|
|
|
* @dp: dentry we search for
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* vxfs_inode_by_name finds out the inode number of
|
|
|
|
* the path component described by @dp in @dip.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The wanted inode number on success, else Zero.
|
|
|
|
*/
|
|
|
|
static ino_t
|
|
|
|
vxfs_inode_by_name(struct inode *dip, struct dentry *dp)
|
|
|
|
{
|
|
|
|
struct vxfs_direct *de;
|
|
|
|
struct page *pp;
|
|
|
|
ino_t ino = 0;
|
|
|
|
|
|
|
|
de = vxfs_find_entry(dip, dp, &pp);
|
|
|
|
if (de) {
|
2016-05-31 06:45:13 +00:00
|
|
|
ino = fs32_to_cpu(VXFS_SBI(dip->i_sb), de->d_ino);
|
2005-04-16 22:20:36 +00:00
|
|
|
kunmap(pp);
|
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 12:29:47 +00:00
|
|
|
put_page(pp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (ino);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vxfs_lookup - lookup pathname component
|
|
|
|
* @dip: dir in which we lookup
|
|
|
|
* @dp: dentry we lookup
|
2014-04-03 21:46:31 +00:00
|
|
|
* @flags: lookup flags
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* vxfs_lookup tries to lookup the pathname component described
|
|
|
|
* by @dp in @dip.
|
|
|
|
*
|
|
|
|
* Returns:
|
2015-05-21 12:12:29 +00:00
|
|
|
* A NULL-pointer on success, else a negative error code encoded
|
2005-04-16 22:20:36 +00:00
|
|
|
* in the return pointer.
|
|
|
|
*/
|
|
|
|
static struct dentry *
|
2012-06-10 21:13:09 +00:00
|
|
|
vxfs_lookup(struct inode *dip, struct dentry *dp, unsigned int flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct inode *ip = NULL;
|
|
|
|
ino_t ino;
|
|
|
|
|
|
|
|
if (dp->d_name.len > VXFS_NAMELEN)
|
|
|
|
return ERR_PTR(-ENAMETOOLONG);
|
|
|
|
|
|
|
|
ino = vxfs_inode_by_name(dip, dp);
|
2018-04-30 23:20:00 +00:00
|
|
|
if (ino)
|
2008-02-07 08:15:39 +00:00
|
|
|
ip = vxfs_iget(dip->i_sb, ino);
|
2018-04-30 23:20:00 +00:00
|
|
|
return d_splice_alias(ip, dp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vxfs_readdir - read a directory
|
|
|
|
* @fp: the directory to read
|
|
|
|
* @retp: return buffer
|
|
|
|
* @filler: filldir callback
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* vxfs_readdir fills @retp with directory entries from @fp
|
|
|
|
* using the VFS supplied callback @filler.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Zero.
|
|
|
|
*/
|
|
|
|
static int
|
2013-05-18 07:15:00 +00:00
|
|
|
vxfs_readdir(struct file *fp, struct dir_context *ctx)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *ip = file_inode(fp);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct super_block *sbp = ip->i_sb;
|
|
|
|
u_long bsize = sbp->s_blocksize;
|
2016-06-12 17:26:45 +00:00
|
|
|
loff_t pos, limit;
|
|
|
|
struct vxfs_sb_info *sbi = VXFS_SBI(sbp);
|
2016-05-31 06:45:13 +00:00
|
|
|
|
2013-05-18 07:15:00 +00:00
|
|
|
if (ctx->pos == 0) {
|
|
|
|
if (!dir_emit_dot(fp, ctx))
|
2016-06-12 17:26:45 +00:00
|
|
|
goto out;
|
|
|
|
ctx->pos++;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2013-05-18 07:15:00 +00:00
|
|
|
if (ctx->pos == 1) {
|
|
|
|
if (!dir_emit(ctx, "..", 2, VXFS_INO(ip)->vii_dotdot, DT_DIR))
|
2016-06-12 17:26:45 +00:00
|
|
|
goto out;
|
|
|
|
ctx->pos++;
|
2013-05-18 07:15:00 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
limit = VXFS_DIRROUND(ip->i_size);
|
|
|
|
if (ctx->pos > limit)
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
pos = ctx->pos & ~3L;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
while (pos < limit) {
|
|
|
|
struct page *pp;
|
|
|
|
char *kaddr;
|
|
|
|
int pg_ofs = pos & ~PAGE_MASK;
|
|
|
|
int rc = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
pp = vxfs_get_page(ip->i_mapping, pos >> PAGE_SHIFT);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_ERR(pp))
|
2016-06-12 17:26:45 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-05-18 07:15:00 +00:00
|
|
|
kaddr = (char *)page_address(pp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
while (pg_ofs < PAGE_SIZE && pos < limit) {
|
|
|
|
struct vxfs_direct *de;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-12 17:26:45 +00:00
|
|
|
if ((pos & (bsize - 1)) < 4) {
|
|
|
|
struct vxfs_dirblk *dbp =
|
|
|
|
(struct vxfs_dirblk *)
|
|
|
|
(kaddr + (pos & ~PAGE_MASK));
|
|
|
|
int overhead = VXFS_DIRBLKOV(sbi, dbp);
|
|
|
|
|
|
|
|
pos += overhead;
|
|
|
|
pg_ofs += overhead;
|
|
|
|
}
|
|
|
|
de = (struct vxfs_direct *)(kaddr + pg_ofs);
|
|
|
|
|
|
|
|
if (!de->d_reclen) {
|
|
|
|
pos += bsize - 1;
|
|
|
|
pos &= ~(bsize - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pg_ofs += fs16_to_cpu(sbi, de->d_reclen);
|
|
|
|
pos += fs16_to_cpu(sbi, de->d_reclen);
|
|
|
|
if (!de->d_ino)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rc = dir_emit(ctx, de->d_name,
|
|
|
|
fs16_to_cpu(sbi, de->d_namelen),
|
|
|
|
fs32_to_cpu(sbi, de->d_ino),
|
|
|
|
DT_UNKNOWN);
|
|
|
|
if (!rc) {
|
|
|
|
/* the dir entry was not read, fix pos. */
|
|
|
|
pos -= fs16_to_cpu(sbi, de->d_reclen);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
vxfs_put_page(pp);
|
2016-06-12 17:26:45 +00:00
|
|
|
if (!rc)
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2016-06-12 17:26:45 +00:00
|
|
|
|
|
|
|
ctx->pos = pos | 2;
|
|
|
|
|
|
|
|
out:
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|