2019-05-20 17:08:00 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-01-05 08:46:24 +00:00
|
|
|
/*
|
|
|
|
* Squashfs - a compressed read only filesystem for Linux
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
|
2011-05-26 09:39:56 +00:00
|
|
|
* Phillip Lougher <phillip@squashfs.org.uk>
|
2009-01-05 08:46:24 +00: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 03:06:56 +00:00
|
|
|
#include <linux/xattr.h>
|
2009-01-05 08:46:24 +00:00
|
|
|
|
|
|
|
#include "squashfs_fs.h"
|
|
|
|
#include "squashfs_fs_sb.h"
|
|
|
|
#include "squashfs_fs_i.h"
|
|
|
|
#include "squashfs.h"
|
2010-05-17 18:39:02 +00:00
|
|
|
#include "xattr.h"
|
2009-01-05 08:46:24 +00:00
|
|
|
|
2022-04-29 15:12:16 +00:00
|
|
|
static int squashfs_symlink_read_folio(struct file *file, struct folio *folio)
|
2009-01-05 08:46:24 +00:00
|
|
|
{
|
2024-04-20 02:50:17 +00:00
|
|
|
struct inode *inode = folio->mapping->host;
|
2009-01-05 08:46:24 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct squashfs_sb_info *msblk = sb->s_fs_info;
|
2024-04-20 02:50:17 +00:00
|
|
|
int index = folio_pos(folio);
|
2009-01-05 08:46:24 +00: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 12:29:47 +00:00
|
|
|
int length = min_t(int, i_size_read(inode) - index, PAGE_SIZE);
|
2024-04-20 02:50:17 +00:00
|
|
|
int bytes, copied, error;
|
2009-01-05 08:46:24 +00:00
|
|
|
void *pageaddr;
|
|
|
|
struct squashfs_cache_entry *entry;
|
|
|
|
|
|
|
|
TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
|
2024-04-20 02:50:17 +00:00
|
|
|
"%llx, offset %x\n", folio->index, block, offset);
|
2009-01-05 08:46:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2024-04-20 02:50:17 +00:00
|
|
|
error = bytes;
|
|
|
|
goto out;
|
2009-01-05 08:46:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read length bytes from symlink metadata. Squashfs_read_metadata
|
|
|
|
* is not used here because it can sleep and we want to use
|
2024-04-20 02:50:17 +00:00
|
|
|
* kmap_local to map the folio. Instead call the underlying
|
2009-01-05 08:46:24 +00:00
|
|
|
* 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);
|
2024-04-20 02:50:17 +00:00
|
|
|
error = entry->error;
|
|
|
|
goto out;
|
2009-01-05 08:46:24 +00:00
|
|
|
}
|
|
|
|
|
2024-04-20 02:50:17 +00:00
|
|
|
pageaddr = kmap_local_folio(folio, 0);
|
2009-01-05 08:46:24 +00: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 12:29:47 +00:00
|
|
|
memset(pageaddr + length, 0, PAGE_SIZE - length);
|
2009-01-05 08:46:24 +00:00
|
|
|
else
|
|
|
|
block = entry->next_index;
|
2024-04-20 02:50:17 +00:00
|
|
|
kunmap_local(pageaddr);
|
2009-01-05 08:46:24 +00:00
|
|
|
squashfs_cache_put(entry);
|
|
|
|
}
|
|
|
|
|
2024-04-20 02:50:17 +00:00
|
|
|
flush_dcache_folio(folio);
|
|
|
|
error = 0;
|
|
|
|
out:
|
|
|
|
folio_end_read(folio, error == 0);
|
|
|
|
return error;
|
2009-01-05 08:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct address_space_operations squashfs_symlink_aops = {
|
2022-04-29 15:12:16 +00:00
|
|
|
.read_folio = squashfs_symlink_read_folio
|
2009-01-05 08:46:24 +00:00
|
|
|
};
|
2010-05-17 03:06:56 +00:00
|
|
|
|
|
|
|
const struct inode_operations squashfs_symlink_inode_ops = {
|
2015-11-17 15:20:54 +00:00
|
|
|
.get_link = page_get_link,
|
2010-05-17 03:06:56 +00:00
|
|
|
.listxattr = squashfs_listxattr
|
|
|
|
};
|
|
|
|
|