2019-05-20 20:08:00 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-01-05 11:46:24 +03:00
|
|
|
/*
|
|
|
|
* Squashfs - a compressed read only filesystem for Linux
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
|
2011-05-26 13:39:56 +04:00
|
|
|
* Phillip Lougher <phillip@squashfs.org.uk>
|
2009-01-05 11:46:24 +03:00
|
|
|
*
|
|
|
|
* symlink.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file implements code to handle symbolic links.
|
|
|
|
*
|
|
|
|
* The data contents of symbolic links are stored inside the symbolic
|
|
|
|
* link inode within the inode table. This allows the normally small symbolic
|
|
|
|
* link to be compressed as part of the inode table, achieving much greater
|
|
|
|
* compression than if the symbolic link was compressed individually.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/vfs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/pagemap.h>
|
2010-05-17 07:06:56 +04:00
|
|
|
#include <linux/xattr.h>
|
2009-01-05 11:46:24 +03:00
|
|
|
|
|
|
|
#include "squashfs_fs.h"
|
|
|
|
#include "squashfs_fs_sb.h"
|
|
|
|
#include "squashfs_fs_i.h"
|
|
|
|
#include "squashfs.h"
|
2010-05-17 22:39:02 +04:00
|
|
|
#include "xattr.h"
|
2009-01-05 11:46:24 +03:00
|
|
|
|
|
|
|
static int squashfs_symlink_readpage(struct file *file, struct page *page)
|
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct squashfs_sb_info *msblk = sb->s_fs_info;
|
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 15:29:47 +03:00
|
|
|
int index = page->index << PAGE_SHIFT;
|
2009-01-05 11:46:24 +03:00
|
|
|
u64 block = squashfs_i(inode)->start;
|
|
|
|
int offset = squashfs_i(inode)->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 15:29:47 +03:00
|
|
|
int length = min_t(int, i_size_read(inode) - index, PAGE_SIZE);
|
2009-01-05 11:46:24 +03:00
|
|
|
int bytes, copied;
|
|
|
|
void *pageaddr;
|
|
|
|
struct squashfs_cache_entry *entry;
|
|
|
|
|
|
|
|
TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
|
|
|
|
"%llx, offset %x\n", page->index, block, offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip index bytes into symlink metadata.
|
|
|
|
*/
|
|
|
|
if (index) {
|
|
|
|
bytes = squashfs_read_metadata(sb, NULL, &block, &offset,
|
|
|
|
index);
|
|
|
|
if (bytes < 0) {
|
|
|
|
ERROR("Unable to read symlink [%llx:%x]\n",
|
|
|
|
squashfs_i(inode)->start,
|
|
|
|
squashfs_i(inode)->offset);
|
|
|
|
goto error_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read length bytes from symlink metadata. Squashfs_read_metadata
|
|
|
|
* is not used here because it can sleep and we want to use
|
|
|
|
* kmap_atomic to map the page. Instead call the underlying
|
|
|
|
* squashfs_cache_get routine. As length bytes may overlap metadata
|
|
|
|
* blocks, we may need to call squashfs_cache_get multiple times.
|
|
|
|
*/
|
|
|
|
for (bytes = 0; bytes < length; offset = 0, bytes += copied) {
|
|
|
|
entry = squashfs_cache_get(sb, msblk->block_cache, block, 0);
|
|
|
|
if (entry->error) {
|
|
|
|
ERROR("Unable to read symlink [%llx:%x]\n",
|
|
|
|
squashfs_i(inode)->start,
|
|
|
|
squashfs_i(inode)->offset);
|
|
|
|
squashfs_cache_put(entry);
|
|
|
|
goto error_out;
|
|
|
|
}
|
|
|
|
|
2011-11-25 19:14:36 +04:00
|
|
|
pageaddr = kmap_atomic(page);
|
2009-01-05 11:46:24 +03:00
|
|
|
copied = squashfs_copy_data(pageaddr + bytes, entry, offset,
|
|
|
|
length - bytes);
|
|
|
|
if (copied == length - bytes)
|
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 15:29:47 +03:00
|
|
|
memset(pageaddr + length, 0, PAGE_SIZE - length);
|
2009-01-05 11:46:24 +03:00
|
|
|
else
|
|
|
|
block = entry->next_index;
|
2011-11-25 19:14:36 +04:00
|
|
|
kunmap_atomic(pageaddr);
|
2009-01-05 11:46:24 +03:00
|
|
|
squashfs_cache_put(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
flush_dcache_page(page);
|
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
SetPageError(page);
|
|
|
|
unlock_page(page);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct address_space_operations squashfs_symlink_aops = {
|
|
|
|
.readpage = squashfs_symlink_readpage
|
|
|
|
};
|
2010-05-17 07:06:56 +04:00
|
|
|
|
|
|
|
const struct inode_operations squashfs_symlink_inode_ops = {
|
2015-11-17 18:20:54 +03:00
|
|
|
.get_link = page_get_link,
|
2010-05-17 07:06:56 +04:00
|
|
|
.listxattr = squashfs_listxattr
|
|
|
|
};
|
|
|
|
|