License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/fs/affs/file.c
|
|
|
|
*
|
|
|
|
* (c) 1996 Hans-Joachim Widmaier - Rewritten
|
|
|
|
*
|
|
|
|
* (C) 1993 Ray Burr - Modified for Amiga FFS filesystem.
|
|
|
|
*
|
|
|
|
* (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem.
|
|
|
|
*
|
|
|
|
* (C) 1991 Linus Torvalds - minix filesystem
|
|
|
|
*
|
|
|
|
* affs regular file handling primitives
|
|
|
|
*/
|
|
|
|
|
2015-02-23 00:58:50 +08:00
|
|
|
#include <linux/uio.h>
|
2020-06-20 15:16:41 +08:00
|
|
|
#include <linux/blkdev.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "affs.h"
|
|
|
|
|
|
|
|
static struct buffer_head *affs_get_extblock_slow(struct inode *inode, u32 ext);
|
|
|
|
|
|
|
|
static int
|
|
|
|
affs_file_open(struct inode *inode, struct file *filp)
|
|
|
|
{
|
2014-06-07 05:37:25 +08:00
|
|
|
pr_debug("open(%lu,%d)\n",
|
2008-04-29 23:02:20 +08:00
|
|
|
inode->i_ino, atomic_read(&AFFS_I(inode)->i_opencnt));
|
|
|
|
atomic_inc(&AFFS_I(inode)->i_opencnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
affs_file_release(struct inode *inode, struct file *filp)
|
|
|
|
{
|
2014-06-07 05:37:25 +08:00
|
|
|
pr_debug("release(%lu, %d)\n",
|
2008-04-29 23:02:20 +08:00
|
|
|
inode->i_ino, atomic_read(&AFFS_I(inode)->i_opencnt));
|
|
|
|
|
|
|
|
if (atomic_dec_and_test(&AFFS_I(inode)->i_opencnt)) {
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(inode);
|
2008-04-29 23:02:20 +08:00
|
|
|
if (inode->i_size != AFFS_I(inode)->mmu_private)
|
|
|
|
affs_truncate(inode);
|
2005-04-17 06:20:36 +08:00
|
|
|
affs_free_prealloc(inode);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(inode);
|
2008-04-29 23:02:20 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
affs_grow_extcache(struct inode *inode, u32 lc_idx)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
u32 lc_max;
|
|
|
|
int i, j, key;
|
|
|
|
|
|
|
|
if (!AFFS_I(inode)->i_lc) {
|
|
|
|
char *ptr = (char *)get_zeroed_page(GFP_NOFS);
|
|
|
|
if (!ptr)
|
|
|
|
return -ENOMEM;
|
|
|
|
AFFS_I(inode)->i_lc = (u32 *)ptr;
|
|
|
|
AFFS_I(inode)->i_ac = (struct affs_ext_key *)(ptr + AFFS_CACHE_SIZE / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
lc_max = AFFS_LC_SIZE << AFFS_I(inode)->i_lc_shift;
|
|
|
|
|
|
|
|
if (AFFS_I(inode)->i_extcnt > lc_max) {
|
|
|
|
u32 lc_shift, lc_mask, tmp, off;
|
|
|
|
|
|
|
|
/* need to recalculate linear cache, start from old size */
|
|
|
|
lc_shift = AFFS_I(inode)->i_lc_shift;
|
|
|
|
tmp = (AFFS_I(inode)->i_extcnt / AFFS_LC_SIZE) >> lc_shift;
|
|
|
|
for (; tmp; tmp >>= 1)
|
|
|
|
lc_shift++;
|
|
|
|
lc_mask = (1 << lc_shift) - 1;
|
|
|
|
|
|
|
|
/* fix idx and old size to new shift */
|
|
|
|
lc_idx >>= (lc_shift - AFFS_I(inode)->i_lc_shift);
|
|
|
|
AFFS_I(inode)->i_lc_size >>= (lc_shift - AFFS_I(inode)->i_lc_shift);
|
|
|
|
|
|
|
|
/* first shrink old cache to make more space */
|
|
|
|
off = 1 << (lc_shift - AFFS_I(inode)->i_lc_shift);
|
|
|
|
for (i = 1, j = off; j < AFFS_LC_SIZE; i++, j += off)
|
|
|
|
AFFS_I(inode)->i_ac[i] = AFFS_I(inode)->i_ac[j];
|
|
|
|
|
|
|
|
AFFS_I(inode)->i_lc_shift = lc_shift;
|
|
|
|
AFFS_I(inode)->i_lc_mask = lc_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill cache to the needed index */
|
|
|
|
i = AFFS_I(inode)->i_lc_size;
|
|
|
|
AFFS_I(inode)->i_lc_size = lc_idx + 1;
|
|
|
|
for (; i <= lc_idx; i++) {
|
|
|
|
if (!i) {
|
|
|
|
AFFS_I(inode)->i_lc[0] = inode->i_ino;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
key = AFFS_I(inode)->i_lc[i - 1];
|
|
|
|
j = AFFS_I(inode)->i_lc_mask + 1;
|
|
|
|
// unlock cache
|
|
|
|
for (; j > 0; j--) {
|
|
|
|
bh = affs_bread(sb, key);
|
|
|
|
if (!bh)
|
|
|
|
goto err;
|
|
|
|
key = be32_to_cpu(AFFS_TAIL(sb, bh)->extension);
|
|
|
|
affs_brelse(bh);
|
|
|
|
}
|
|
|
|
// lock cache
|
|
|
|
AFFS_I(inode)->i_lc[i] = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
// lock cache
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct buffer_head *
|
|
|
|
affs_alloc_extblock(struct inode *inode, struct buffer_head *bh, u32 ext)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct buffer_head *new_bh;
|
|
|
|
u32 blocknr, tmp;
|
|
|
|
|
|
|
|
blocknr = affs_alloc_block(inode, bh->b_blocknr);
|
|
|
|
if (!blocknr)
|
|
|
|
return ERR_PTR(-ENOSPC);
|
|
|
|
|
|
|
|
new_bh = affs_getzeroblk(sb, blocknr);
|
|
|
|
if (!new_bh) {
|
|
|
|
affs_free_block(sb, blocknr);
|
|
|
|
return ERR_PTR(-EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
AFFS_HEAD(new_bh)->ptype = cpu_to_be32(T_LIST);
|
|
|
|
AFFS_HEAD(new_bh)->key = cpu_to_be32(blocknr);
|
|
|
|
AFFS_TAIL(sb, new_bh)->stype = cpu_to_be32(ST_FILE);
|
|
|
|
AFFS_TAIL(sb, new_bh)->parent = cpu_to_be32(inode->i_ino);
|
|
|
|
affs_fix_checksum(sb, new_bh);
|
|
|
|
|
|
|
|
mark_buffer_dirty_inode(new_bh, inode);
|
|
|
|
|
|
|
|
tmp = be32_to_cpu(AFFS_TAIL(sb, bh)->extension);
|
|
|
|
if (tmp)
|
|
|
|
affs_warning(sb, "alloc_ext", "previous extension set (%x)", tmp);
|
|
|
|
AFFS_TAIL(sb, bh)->extension = cpu_to_be32(blocknr);
|
|
|
|
affs_adjust_checksum(bh, blocknr - tmp);
|
|
|
|
mark_buffer_dirty_inode(bh, inode);
|
|
|
|
|
|
|
|
AFFS_I(inode)->i_extcnt++;
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
|
|
|
|
return new_bh;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct buffer_head *
|
|
|
|
affs_get_extblock(struct inode *inode, u32 ext)
|
|
|
|
{
|
|
|
|
/* inline the simplest case: same extended block as last time */
|
|
|
|
struct buffer_head *bh = AFFS_I(inode)->i_ext_bh;
|
|
|
|
if (ext == AFFS_I(inode)->i_ext_last)
|
2008-04-29 23:02:20 +08:00
|
|
|
get_bh(bh);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
/* we have to do more (not inlined) */
|
|
|
|
bh = affs_get_extblock_slow(inode, ext);
|
|
|
|
|
|
|
|
return bh;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct buffer_head *
|
|
|
|
affs_get_extblock_slow(struct inode *inode, u32 ext)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
u32 ext_key;
|
|
|
|
u32 lc_idx, lc_off, ac_idx;
|
|
|
|
u32 tmp, idx;
|
|
|
|
|
|
|
|
if (ext == AFFS_I(inode)->i_ext_last + 1) {
|
|
|
|
/* read the next extended block from the current one */
|
|
|
|
bh = AFFS_I(inode)->i_ext_bh;
|
|
|
|
ext_key = be32_to_cpu(AFFS_TAIL(sb, bh)->extension);
|
|
|
|
if (ext < AFFS_I(inode)->i_extcnt)
|
|
|
|
goto read_ext;
|
2015-02-18 05:46:12 +08:00
|
|
|
BUG_ON(ext > AFFS_I(inode)->i_extcnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
bh = affs_alloc_extblock(inode, bh, ext);
|
|
|
|
if (IS_ERR(bh))
|
|
|
|
return bh;
|
|
|
|
goto store_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext == 0) {
|
|
|
|
/* we seek back to the file header block */
|
|
|
|
ext_key = inode->i_ino;
|
|
|
|
goto read_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext >= AFFS_I(inode)->i_extcnt) {
|
|
|
|
struct buffer_head *prev_bh;
|
|
|
|
|
|
|
|
/* allocate a new extended block */
|
2015-02-18 05:46:12 +08:00
|
|
|
BUG_ON(ext > AFFS_I(inode)->i_extcnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* get previous extended block */
|
|
|
|
prev_bh = affs_get_extblock(inode, ext - 1);
|
|
|
|
if (IS_ERR(prev_bh))
|
|
|
|
return prev_bh;
|
|
|
|
bh = affs_alloc_extblock(inode, prev_bh, ext);
|
|
|
|
affs_brelse(prev_bh);
|
|
|
|
if (IS_ERR(bh))
|
|
|
|
return bh;
|
|
|
|
goto store_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
again:
|
|
|
|
/* check if there is an extended cache and whether it's large enough */
|
|
|
|
lc_idx = ext >> AFFS_I(inode)->i_lc_shift;
|
|
|
|
lc_off = ext & AFFS_I(inode)->i_lc_mask;
|
|
|
|
|
|
|
|
if (lc_idx >= AFFS_I(inode)->i_lc_size) {
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = affs_grow_extcache(inode, lc_idx);
|
|
|
|
if (err)
|
|
|
|
return ERR_PTR(err);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* every n'th key we find in the linear cache */
|
|
|
|
if (!lc_off) {
|
|
|
|
ext_key = AFFS_I(inode)->i_lc[lc_idx];
|
|
|
|
goto read_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maybe it's still in the associative cache */
|
|
|
|
ac_idx = (ext - lc_idx - 1) & AFFS_AC_MASK;
|
|
|
|
if (AFFS_I(inode)->i_ac[ac_idx].ext == ext) {
|
|
|
|
ext_key = AFFS_I(inode)->i_ac[ac_idx].key;
|
|
|
|
goto read_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to find one of the previous extended blocks */
|
|
|
|
tmp = ext;
|
|
|
|
idx = ac_idx;
|
|
|
|
while (--tmp, --lc_off > 0) {
|
|
|
|
idx = (idx - 1) & AFFS_AC_MASK;
|
|
|
|
if (AFFS_I(inode)->i_ac[idx].ext == tmp) {
|
|
|
|
ext_key = AFFS_I(inode)->i_ac[idx].key;
|
|
|
|
goto find_ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall back to the linear cache */
|
|
|
|
ext_key = AFFS_I(inode)->i_lc[lc_idx];
|
|
|
|
find_ext:
|
|
|
|
/* read all extended blocks until we find the one we need */
|
|
|
|
//unlock cache
|
|
|
|
do {
|
|
|
|
bh = affs_bread(sb, ext_key);
|
|
|
|
if (!bh)
|
|
|
|
goto err_bread;
|
|
|
|
ext_key = be32_to_cpu(AFFS_TAIL(sb, bh)->extension);
|
|
|
|
affs_brelse(bh);
|
|
|
|
tmp++;
|
|
|
|
} while (tmp < ext);
|
|
|
|
//lock cache
|
|
|
|
|
|
|
|
/* store it in the associative cache */
|
|
|
|
// recalculate ac_idx?
|
|
|
|
AFFS_I(inode)->i_ac[ac_idx].ext = ext;
|
|
|
|
AFFS_I(inode)->i_ac[ac_idx].key = ext_key;
|
|
|
|
|
|
|
|
read_ext:
|
|
|
|
/* finally read the right extended block */
|
|
|
|
//unlock cache
|
|
|
|
bh = affs_bread(sb, ext_key);
|
|
|
|
if (!bh)
|
|
|
|
goto err_bread;
|
|
|
|
//lock cache
|
|
|
|
|
|
|
|
store_ext:
|
|
|
|
/* release old cached extended block and store the new one */
|
|
|
|
affs_brelse(AFFS_I(inode)->i_ext_bh);
|
|
|
|
AFFS_I(inode)->i_ext_last = ext;
|
|
|
|
AFFS_I(inode)->i_ext_bh = bh;
|
2008-04-29 23:02:20 +08:00
|
|
|
get_bh(bh);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return bh;
|
|
|
|
|
|
|
|
err_bread:
|
|
|
|
affs_brelse(bh);
|
|
|
|
return ERR_PTR(-EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
affs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct buffer_head *ext_bh;
|
|
|
|
u32 ext;
|
|
|
|
|
2015-02-18 05:46:10 +08:00
|
|
|
pr_debug("%s(%lu, %llu)\n", __func__, inode->i_ino,
|
|
|
|
(unsigned long long)block);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-29 15:59:12 +08:00
|
|
|
BUG_ON(block > (sector_t)0x7fffffffUL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (block >= AFFS_I(inode)->i_blkcnt) {
|
|
|
|
if (block > AFFS_I(inode)->i_blkcnt || !create)
|
|
|
|
goto err_big;
|
|
|
|
} else
|
|
|
|
create = 0;
|
|
|
|
|
|
|
|
//lock cache
|
|
|
|
affs_lock_ext(inode);
|
|
|
|
|
|
|
|
ext = (u32)block / AFFS_SB(sb)->s_hashsize;
|
|
|
|
block -= ext * AFFS_SB(sb)->s_hashsize;
|
|
|
|
ext_bh = affs_get_extblock(inode, ext);
|
|
|
|
if (IS_ERR(ext_bh))
|
|
|
|
goto err_ext;
|
|
|
|
map_bh(bh_result, sb, (sector_t)be32_to_cpu(AFFS_BLOCK(sb, ext_bh, block)));
|
|
|
|
|
|
|
|
if (create) {
|
|
|
|
u32 blocknr = affs_alloc_block(inode, ext_bh->b_blocknr);
|
|
|
|
if (!blocknr)
|
|
|
|
goto err_alloc;
|
|
|
|
set_buffer_new(bh_result);
|
|
|
|
AFFS_I(inode)->mmu_private += AFFS_SB(sb)->s_data_blksize;
|
|
|
|
AFFS_I(inode)->i_blkcnt++;
|
|
|
|
|
|
|
|
/* store new block */
|
|
|
|
if (bh_result->b_blocknr)
|
2015-02-18 05:46:10 +08:00
|
|
|
affs_warning(sb, "get_block",
|
|
|
|
"block already set (%llx)",
|
|
|
|
(unsigned long long)bh_result->b_blocknr);
|
2005-04-17 06:20:36 +08:00
|
|
|
AFFS_BLOCK(sb, ext_bh, block) = cpu_to_be32(blocknr);
|
|
|
|
AFFS_HEAD(ext_bh)->block_count = cpu_to_be32(block + 1);
|
|
|
|
affs_adjust_checksum(ext_bh, blocknr - bh_result->b_blocknr + 1);
|
|
|
|
bh_result->b_blocknr = blocknr;
|
|
|
|
|
|
|
|
if (!block) {
|
|
|
|
/* insert first block into header block */
|
|
|
|
u32 tmp = be32_to_cpu(AFFS_HEAD(ext_bh)->first_data);
|
|
|
|
if (tmp)
|
|
|
|
affs_warning(sb, "get_block", "first block already set (%d)", tmp);
|
|
|
|
AFFS_HEAD(ext_bh)->first_data = cpu_to_be32(blocknr);
|
|
|
|
affs_adjust_checksum(ext_bh, blocknr - tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
affs_brelse(ext_bh);
|
|
|
|
//unlock cache
|
|
|
|
affs_unlock_ext(inode);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_big:
|
2015-02-18 05:46:10 +08:00
|
|
|
affs_error(inode->i_sb, "get_block", "strange block request %llu",
|
|
|
|
(unsigned long long)block);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
err_ext:
|
|
|
|
// unlock cache
|
|
|
|
affs_unlock_ext(inode);
|
|
|
|
return PTR_ERR(ext_bh);
|
|
|
|
err_alloc:
|
|
|
|
brelse(ext_bh);
|
|
|
|
clear_buffer_mapped(bh_result);
|
|
|
|
bh_result->b_bdev = NULL;
|
|
|
|
// unlock cache
|
|
|
|
affs_unlock_ext(inode);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int affs_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
return block_write_full_page(page, affs_get_block, wbc);
|
|
|
|
}
|
2007-10-16 16:25:24 +08:00
|
|
|
|
2022-04-29 22:40:40 +08:00
|
|
|
static int affs_read_folio(struct file *file, struct folio *folio)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2022-04-29 22:40:40 +08:00
|
|
|
return block_read_full_folio(folio, affs_get_block);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-10-16 16:25:24 +08:00
|
|
|
|
2012-12-15 18:51:53 +08:00
|
|
|
static void affs_write_failed(struct address_space *mapping, loff_t to)
|
|
|
|
{
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
|
|
|
if (to > inode->i_size) {
|
2013-09-13 06:13:56 +08:00
|
|
|
truncate_pagecache(inode, inode->i_size);
|
2012-12-15 18:51:53 +08:00
|
|
|
affs_truncate(inode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-13 08:57:52 +08:00
|
|
|
static ssize_t
|
2016-04-07 23:51:58 +08:00
|
|
|
affs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
|
2014-12-13 08:57:52 +08:00
|
|
|
{
|
|
|
|
struct file *file = iocb->ki_filp;
|
|
|
|
struct address_space *mapping = file->f_mapping;
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
size_t count = iov_iter_count(iter);
|
2016-04-07 23:51:58 +08:00
|
|
|
loff_t offset = iocb->ki_pos;
|
2014-12-13 08:57:52 +08:00
|
|
|
ssize_t ret;
|
|
|
|
|
2015-03-16 19:33:52 +08:00
|
|
|
if (iov_iter_rw(iter) == WRITE) {
|
2015-02-18 05:46:15 +08:00
|
|
|
loff_t size = offset + count;
|
|
|
|
|
|
|
|
if (AFFS_I(inode)->mmu_private < size)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:51:58 +08:00
|
|
|
ret = blockdev_direct_IO(iocb, inode, iter, affs_get_block);
|
2015-03-16 19:33:52 +08:00
|
|
|
if (ret < 0 && iov_iter_rw(iter) == WRITE)
|
2014-12-13 08:57:52 +08:00
|
|
|
affs_write_failed(mapping, offset + count);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 16:25:24 +08:00
|
|
|
static int affs_write_begin(struct file *file, struct address_space *mapping,
|
2022-02-23 03:31:43 +08:00
|
|
|
loff_t pos, unsigned len,
|
2007-10-16 16:25:24 +08:00
|
|
|
struct page **pagep, void **fsdata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-06-04 17:29:55 +08:00
|
|
|
int ret;
|
|
|
|
|
2007-10-16 16:25:24 +08:00
|
|
|
*pagep = NULL;
|
2022-02-23 00:25:12 +08:00
|
|
|
ret = cont_write_begin(file, mapping, pos, len, pagep, fsdata,
|
2007-10-16 16:25:24 +08:00
|
|
|
affs_get_block,
|
|
|
|
&AFFS_I(mapping->host)->mmu_private);
|
2012-12-15 18:51:53 +08:00
|
|
|
if (unlikely(ret))
|
|
|
|
affs_write_failed(mapping, pos + len);
|
2010-06-04 17:29:55 +08:00
|
|
|
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-10-16 16:25:24 +08:00
|
|
|
|
2020-08-27 23:49:00 +08:00
|
|
|
static int affs_write_end(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned int len, unsigned int copied,
|
|
|
|
struct page *page, void *fsdata)
|
|
|
|
{
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
|
|
|
|
|
|
|
|
/* Clear Archived bit on file writes, as AmigaOS would do */
|
|
|
|
if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
|
|
|
|
AFFS_I(inode)->i_protect &= ~FIBF_ARCHIVED;
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static sector_t _affs_bmap(struct address_space *mapping, sector_t block)
|
|
|
|
{
|
|
|
|
return generic_block_bmap(mapping,block,affs_get_block);
|
|
|
|
}
|
2007-10-16 16:25:24 +08:00
|
|
|
|
2006-06-28 19:26:44 +08:00
|
|
|
const struct address_space_operations affs_aops = {
|
2022-02-10 04:22:12 +08:00
|
|
|
.dirty_folio = block_dirty_folio,
|
2022-02-10 04:21:34 +08:00
|
|
|
.invalidate_folio = block_invalidate_folio,
|
2022-04-29 22:40:40 +08:00
|
|
|
.read_folio = affs_read_folio,
|
2005-04-17 06:20:36 +08:00
|
|
|
.writepage = affs_writepage,
|
2007-10-16 16:25:24 +08:00
|
|
|
.write_begin = affs_write_begin,
|
2020-08-27 23:49:00 +08:00
|
|
|
.write_end = affs_write_end,
|
2014-12-13 08:57:52 +08:00
|
|
|
.direct_IO = affs_direct_IO,
|
2005-04-17 06:20:36 +08:00
|
|
|
.bmap = _affs_bmap
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct buffer_head *
|
|
|
|
affs_bread_ino(struct inode *inode, int block, int create)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh, tmp_bh;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
tmp_bh.b_state = 0;
|
|
|
|
err = affs_get_block(inode, block, &tmp_bh, create);
|
|
|
|
if (!err) {
|
|
|
|
bh = affs_bread(inode->i_sb, tmp_bh.b_blocknr);
|
|
|
|
if (bh) {
|
|
|
|
bh->b_state |= tmp_bh.b_state;
|
|
|
|
return bh;
|
|
|
|
}
|
|
|
|
err = -EIO;
|
|
|
|
}
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct buffer_head *
|
|
|
|
affs_getzeroblk_ino(struct inode *inode, int block)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh, tmp_bh;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
tmp_bh.b_state = 0;
|
|
|
|
err = affs_get_block(inode, block, &tmp_bh, 1);
|
|
|
|
if (!err) {
|
|
|
|
bh = affs_getzeroblk(inode->i_sb, tmp_bh.b_blocknr);
|
|
|
|
if (bh) {
|
|
|
|
bh->b_state |= tmp_bh.b_state;
|
|
|
|
return bh;
|
|
|
|
}
|
|
|
|
err = -EIO;
|
|
|
|
}
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct buffer_head *
|
|
|
|
affs_getemptyblk_ino(struct inode *inode, int block)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh, tmp_bh;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
tmp_bh.b_state = 0;
|
|
|
|
err = affs_get_block(inode, block, &tmp_bh, 1);
|
|
|
|
if (!err) {
|
|
|
|
bh = affs_getemptyblk(inode->i_sb, tmp_bh.b_blocknr);
|
|
|
|
if (bh) {
|
|
|
|
bh->b_state |= tmp_bh.b_state;
|
|
|
|
return bh;
|
|
|
|
}
|
|
|
|
err = -EIO;
|
|
|
|
}
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-04-25 04:12:57 +08:00
|
|
|
affs_do_readpage_ofs(struct page *page, unsigned to, int create)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct buffer_head *bh;
|
2014-06-07 05:37:23 +08:00
|
|
|
unsigned pos = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 bidx, boff, bsize;
|
|
|
|
u32 tmp;
|
|
|
|
|
2015-02-18 05:46:10 +08:00
|
|
|
pr_debug("%s(%lu, %ld, 0, %d)\n", __func__, inode->i_ino,
|
2014-06-07 05:37:23 +08:00
|
|
|
page->index, to);
|
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 20:29:47 +08:00
|
|
|
BUG_ON(to > PAGE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
bsize = AFFS_SB(sb)->s_data_blksize;
|
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 20:29:47 +08:00
|
|
|
tmp = page->index << PAGE_SHIFT;
|
2005-04-17 06:20:36 +08:00
|
|
|
bidx = tmp / bsize;
|
|
|
|
boff = tmp % bsize;
|
|
|
|
|
2014-06-07 05:37:23 +08:00
|
|
|
while (pos < to) {
|
2017-04-25 04:12:57 +08:00
|
|
|
bh = affs_bread_ino(inode, bidx, create);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (IS_ERR(bh))
|
|
|
|
return PTR_ERR(bh);
|
2014-06-07 05:37:23 +08:00
|
|
|
tmp = min(bsize - boff, to - pos);
|
|
|
|
BUG_ON(pos + tmp > to || tmp > bsize);
|
2022-07-13 05:30:05 +08:00
|
|
|
memcpy_to_page(page, pos, AFFS_DATA(bh) + boff, tmp);
|
2005-04-17 06:20:36 +08:00
|
|
|
affs_brelse(bh);
|
|
|
|
bidx++;
|
2014-06-07 05:37:23 +08:00
|
|
|
pos += tmp;
|
2005-04-17 06:20:36 +08:00
|
|
|
boff = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
affs_extent_file_ofs(struct inode *inode, u32 newsize)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct buffer_head *bh, *prev_bh;
|
|
|
|
u32 bidx, boff;
|
|
|
|
u32 size, bsize;
|
|
|
|
u32 tmp;
|
|
|
|
|
2015-02-18 05:46:10 +08:00
|
|
|
pr_debug("%s(%lu, %d)\n", __func__, inode->i_ino, newsize);
|
2005-04-17 06:20:36 +08:00
|
|
|
bsize = AFFS_SB(sb)->s_data_blksize;
|
|
|
|
bh = NULL;
|
|
|
|
size = AFFS_I(inode)->mmu_private;
|
|
|
|
bidx = size / bsize;
|
|
|
|
boff = size % bsize;
|
|
|
|
if (boff) {
|
|
|
|
bh = affs_bread_ino(inode, bidx, 0);
|
|
|
|
if (IS_ERR(bh))
|
|
|
|
return PTR_ERR(bh);
|
|
|
|
tmp = min(bsize - boff, newsize - size);
|
2008-04-29 15:59:12 +08:00
|
|
|
BUG_ON(boff + tmp > bsize || tmp > bsize);
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(AFFS_DATA(bh) + boff, 0, tmp);
|
2008-04-30 15:54:47 +08:00
|
|
|
be32_add_cpu(&AFFS_DATA_HEAD(bh)->size, tmp);
|
2005-04-17 06:20:36 +08:00
|
|
|
affs_fix_checksum(sb, bh);
|
|
|
|
mark_buffer_dirty_inode(bh, inode);
|
|
|
|
size += tmp;
|
|
|
|
bidx++;
|
|
|
|
} else if (bidx) {
|
|
|
|
bh = affs_bread_ino(inode, bidx - 1, 0);
|
|
|
|
if (IS_ERR(bh))
|
|
|
|
return PTR_ERR(bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (size < newsize) {
|
|
|
|
prev_bh = bh;
|
|
|
|
bh = affs_getzeroblk_ino(inode, bidx);
|
|
|
|
if (IS_ERR(bh))
|
|
|
|
goto out;
|
|
|
|
tmp = min(bsize, newsize - size);
|
2008-04-29 15:59:12 +08:00
|
|
|
BUG_ON(tmp > bsize);
|
2005-04-17 06:20:36 +08:00
|
|
|
AFFS_DATA_HEAD(bh)->ptype = cpu_to_be32(T_DATA);
|
|
|
|
AFFS_DATA_HEAD(bh)->key = cpu_to_be32(inode->i_ino);
|
|
|
|
AFFS_DATA_HEAD(bh)->sequence = cpu_to_be32(bidx);
|
|
|
|
AFFS_DATA_HEAD(bh)->size = cpu_to_be32(tmp);
|
|
|
|
affs_fix_checksum(sb, bh);
|
|
|
|
bh->b_state &= ~(1UL << BH_New);
|
|
|
|
mark_buffer_dirty_inode(bh, inode);
|
|
|
|
if (prev_bh) {
|
2014-10-14 06:53:54 +08:00
|
|
|
u32 tmp_next = be32_to_cpu(AFFS_DATA_HEAD(prev_bh)->next);
|
|
|
|
|
|
|
|
if (tmp_next)
|
|
|
|
affs_warning(sb, "extent_file_ofs",
|
|
|
|
"next block already set for %d (%d)",
|
|
|
|
bidx, tmp_next);
|
2005-04-17 06:20:36 +08:00
|
|
|
AFFS_DATA_HEAD(prev_bh)->next = cpu_to_be32(bh->b_blocknr);
|
2014-10-14 06:53:54 +08:00
|
|
|
affs_adjust_checksum(prev_bh, bh->b_blocknr - tmp_next);
|
2005-04-17 06:20:36 +08:00
|
|
|
mark_buffer_dirty_inode(prev_bh, inode);
|
|
|
|
affs_brelse(prev_bh);
|
|
|
|
}
|
|
|
|
size += bsize;
|
|
|
|
bidx++;
|
|
|
|
}
|
|
|
|
affs_brelse(bh);
|
|
|
|
inode->i_size = AFFS_I(inode)->mmu_private = newsize;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
inode->i_size = AFFS_I(inode)->mmu_private = newsize;
|
|
|
|
return PTR_ERR(bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-04-29 23:12:16 +08:00
|
|
|
affs_read_folio_ofs(struct file *file, struct folio *folio)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2022-04-29 23:12:16 +08:00
|
|
|
struct page *page = &folio->page;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
u32 to;
|
|
|
|
int err;
|
|
|
|
|
2015-02-18 05:46:10 +08:00
|
|
|
pr_debug("%s(%lu, %ld)\n", __func__, inode->i_ino, page->index);
|
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 20:29:47 +08:00
|
|
|
to = PAGE_SIZE;
|
|
|
|
if (((page->index + 1) << PAGE_SHIFT) > inode->i_size) {
|
|
|
|
to = inode->i_size & ~PAGE_MASK;
|
|
|
|
memset(page_address(page) + to, 0, PAGE_SIZE - to);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 04:12:57 +08:00
|
|
|
err = affs_do_readpage_ofs(page, to, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!err)
|
|
|
|
SetPageUptodate(page);
|
|
|
|
unlock_page(page);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-10-16 16:25:24 +08:00
|
|
|
static int affs_write_begin_ofs(struct file *file, struct address_space *mapping,
|
2022-02-23 03:31:43 +08:00
|
|
|
loff_t pos, unsigned len,
|
2007-10-16 16:25:24 +08:00
|
|
|
struct page **pagep, void **fsdata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-16 16:25:24 +08:00
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
struct page *page;
|
|
|
|
pgoff_t index;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err = 0;
|
|
|
|
|
2015-02-18 05:46:10 +08:00
|
|
|
pr_debug("%s(%lu, %llu, %llu)\n", __func__, inode->i_ino, pos,
|
|
|
|
pos + len);
|
2007-10-16 16:25:24 +08:00
|
|
|
if (pos > AFFS_I(inode)->mmu_private) {
|
|
|
|
/* XXX: this probably leaves a too-big i_size in case of
|
|
|
|
* failure. Should really be updating i_size at write_end time
|
|
|
|
*/
|
|
|
|
err = affs_extent_file_ofs(inode, pos);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
2007-10-16 16:25:24 +08: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 20:29:47 +08:00
|
|
|
index = pos >> PAGE_SHIFT;
|
2022-02-23 00:25:12 +08:00
|
|
|
page = grab_cache_page_write_begin(mapping, index);
|
2007-10-16 16:25:24 +08:00
|
|
|
if (!page)
|
|
|
|
return -ENOMEM;
|
|
|
|
*pagep = page;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (PageUptodate(page))
|
|
|
|
return 0;
|
|
|
|
|
2007-10-16 16:25:24 +08:00
|
|
|
/* XXX: inefficient but safe in the face of short writes */
|
2017-04-25 04:12:57 +08:00
|
|
|
err = affs_do_readpage_ofs(page, PAGE_SIZE, 1);
|
2007-10-16 16:25:24 +08:00
|
|
|
if (err) {
|
|
|
|
unlock_page(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 20:29:47 +08:00
|
|
|
put_page(page);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-10-16 16:25:24 +08:00
|
|
|
static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned copied,
|
|
|
|
struct page *page, void *fsdata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-16 16:25:24 +08:00
|
|
|
struct inode *inode = mapping->host;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct buffer_head *bh, *prev_bh;
|
|
|
|
char *data;
|
|
|
|
u32 bidx, boff, bsize;
|
2007-10-16 16:25:24 +08:00
|
|
|
unsigned from, to;
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 tmp;
|
|
|
|
int written;
|
|
|
|
|
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 20:29:47 +08:00
|
|
|
from = pos & (PAGE_SIZE - 1);
|
2017-04-25 04:13:10 +08:00
|
|
|
to = from + len;
|
2007-10-16 16:25:24 +08:00
|
|
|
/*
|
|
|
|
* XXX: not sure if this can handle short copies (len < copied), but
|
|
|
|
* we don't have to, because the page should always be uptodate here,
|
|
|
|
* due to write_begin.
|
|
|
|
*/
|
|
|
|
|
2015-02-18 05:46:10 +08:00
|
|
|
pr_debug("%s(%lu, %llu, %llu)\n", __func__, inode->i_ino, pos,
|
|
|
|
pos + len);
|
2005-04-17 06:20:36 +08:00
|
|
|
bsize = AFFS_SB(sb)->s_data_blksize;
|
|
|
|
data = page_address(page);
|
|
|
|
|
|
|
|
bh = NULL;
|
|
|
|
written = 0;
|
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 20:29:47 +08:00
|
|
|
tmp = (page->index << PAGE_SHIFT) + from;
|
2005-04-17 06:20:36 +08:00
|
|
|
bidx = tmp / bsize;
|
|
|
|
boff = tmp % bsize;
|
|
|
|
if (boff) {
|
|
|
|
bh = affs_bread_ino(inode, bidx, 0);
|
2015-03-26 06:55:29 +08:00
|
|
|
if (IS_ERR(bh)) {
|
|
|
|
written = PTR_ERR(bh);
|
|
|
|
goto err_first_bh;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp = min(bsize - boff, to - from);
|
2008-04-29 15:59:12 +08:00
|
|
|
BUG_ON(boff + tmp > bsize || tmp > bsize);
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(AFFS_DATA(bh) + boff, data + from, tmp);
|
2008-04-30 15:54:47 +08:00
|
|
|
be32_add_cpu(&AFFS_DATA_HEAD(bh)->size, tmp);
|
2005-04-17 06:20:36 +08:00
|
|
|
affs_fix_checksum(sb, bh);
|
|
|
|
mark_buffer_dirty_inode(bh, inode);
|
|
|
|
written += tmp;
|
|
|
|
from += tmp;
|
|
|
|
bidx++;
|
|
|
|
} else if (bidx) {
|
|
|
|
bh = affs_bread_ino(inode, bidx - 1, 0);
|
2015-03-26 06:55:29 +08:00
|
|
|
if (IS_ERR(bh)) {
|
|
|
|
written = PTR_ERR(bh);
|
|
|
|
goto err_first_bh;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
while (from + bsize <= to) {
|
|
|
|
prev_bh = bh;
|
|
|
|
bh = affs_getemptyblk_ino(inode, bidx);
|
|
|
|
if (IS_ERR(bh))
|
2015-03-26 06:55:29 +08:00
|
|
|
goto err_bh;
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(AFFS_DATA(bh), data + from, bsize);
|
|
|
|
if (buffer_new(bh)) {
|
|
|
|
AFFS_DATA_HEAD(bh)->ptype = cpu_to_be32(T_DATA);
|
|
|
|
AFFS_DATA_HEAD(bh)->key = cpu_to_be32(inode->i_ino);
|
|
|
|
AFFS_DATA_HEAD(bh)->sequence = cpu_to_be32(bidx);
|
|
|
|
AFFS_DATA_HEAD(bh)->size = cpu_to_be32(bsize);
|
|
|
|
AFFS_DATA_HEAD(bh)->next = 0;
|
|
|
|
bh->b_state &= ~(1UL << BH_New);
|
|
|
|
if (prev_bh) {
|
2014-10-14 06:53:54 +08:00
|
|
|
u32 tmp_next = be32_to_cpu(AFFS_DATA_HEAD(prev_bh)->next);
|
|
|
|
|
|
|
|
if (tmp_next)
|
|
|
|
affs_warning(sb, "commit_write_ofs",
|
|
|
|
"next block already set for %d (%d)",
|
|
|
|
bidx, tmp_next);
|
2005-04-17 06:20:36 +08:00
|
|
|
AFFS_DATA_HEAD(prev_bh)->next = cpu_to_be32(bh->b_blocknr);
|
2014-10-14 06:53:54 +08:00
|
|
|
affs_adjust_checksum(prev_bh, bh->b_blocknr - tmp_next);
|
2005-04-17 06:20:36 +08:00
|
|
|
mark_buffer_dirty_inode(prev_bh, inode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
affs_brelse(prev_bh);
|
|
|
|
affs_fix_checksum(sb, bh);
|
|
|
|
mark_buffer_dirty_inode(bh, inode);
|
|
|
|
written += bsize;
|
|
|
|
from += bsize;
|
|
|
|
bidx++;
|
|
|
|
}
|
|
|
|
if (from < to) {
|
|
|
|
prev_bh = bh;
|
|
|
|
bh = affs_bread_ino(inode, bidx, 1);
|
|
|
|
if (IS_ERR(bh))
|
2015-03-26 06:55:29 +08:00
|
|
|
goto err_bh;
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp = min(bsize, to - from);
|
2008-04-29 15:59:12 +08:00
|
|
|
BUG_ON(tmp > bsize);
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(AFFS_DATA(bh), data + from, tmp);
|
|
|
|
if (buffer_new(bh)) {
|
|
|
|
AFFS_DATA_HEAD(bh)->ptype = cpu_to_be32(T_DATA);
|
|
|
|
AFFS_DATA_HEAD(bh)->key = cpu_to_be32(inode->i_ino);
|
|
|
|
AFFS_DATA_HEAD(bh)->sequence = cpu_to_be32(bidx);
|
|
|
|
AFFS_DATA_HEAD(bh)->size = cpu_to_be32(tmp);
|
|
|
|
AFFS_DATA_HEAD(bh)->next = 0;
|
|
|
|
bh->b_state &= ~(1UL << BH_New);
|
|
|
|
if (prev_bh) {
|
2014-10-14 06:53:54 +08:00
|
|
|
u32 tmp_next = be32_to_cpu(AFFS_DATA_HEAD(prev_bh)->next);
|
|
|
|
|
|
|
|
if (tmp_next)
|
|
|
|
affs_warning(sb, "commit_write_ofs",
|
|
|
|
"next block already set for %d (%d)",
|
|
|
|
bidx, tmp_next);
|
2005-04-17 06:20:36 +08:00
|
|
|
AFFS_DATA_HEAD(prev_bh)->next = cpu_to_be32(bh->b_blocknr);
|
2014-10-14 06:53:54 +08:00
|
|
|
affs_adjust_checksum(prev_bh, bh->b_blocknr - tmp_next);
|
2005-04-17 06:20:36 +08:00
|
|
|
mark_buffer_dirty_inode(prev_bh, inode);
|
|
|
|
}
|
|
|
|
} else if (be32_to_cpu(AFFS_DATA_HEAD(bh)->size) < tmp)
|
|
|
|
AFFS_DATA_HEAD(bh)->size = cpu_to_be32(tmp);
|
|
|
|
affs_brelse(prev_bh);
|
|
|
|
affs_fix_checksum(sb, bh);
|
|
|
|
mark_buffer_dirty_inode(bh, inode);
|
|
|
|
written += tmp;
|
|
|
|
from += tmp;
|
|
|
|
bidx++;
|
|
|
|
}
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
|
|
|
done:
|
|
|
|
affs_brelse(bh);
|
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 20:29:47 +08:00
|
|
|
tmp = (page->index << PAGE_SHIFT) + from;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tmp > inode->i_size)
|
|
|
|
inode->i_size = AFFS_I(inode)->mmu_private = tmp;
|
|
|
|
|
2020-08-27 23:49:00 +08:00
|
|
|
/* Clear Archived bit on file writes, as AmigaOS would do */
|
|
|
|
if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
|
|
|
|
AFFS_I(inode)->i_protect &= ~FIBF_ARCHIVED;
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
|
|
|
|
2015-03-26 06:55:29 +08:00
|
|
|
err_first_bh:
|
2007-10-16 16:25:24 +08:00
|
|
|
unlock_page(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 20:29:47 +08:00
|
|
|
put_page(page);
|
2007-10-16 16:25:24 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return written;
|
|
|
|
|
2015-03-26 06:55:29 +08:00
|
|
|
err_bh:
|
2005-04-17 06:20:36 +08:00
|
|
|
bh = prev_bh;
|
|
|
|
if (!written)
|
|
|
|
written = PTR_ERR(bh);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-06-28 19:26:44 +08:00
|
|
|
const struct address_space_operations affs_aops_ofs = {
|
2022-02-10 04:22:12 +08:00
|
|
|
.dirty_folio = block_dirty_folio,
|
2022-02-10 04:21:34 +08:00
|
|
|
.invalidate_folio = block_invalidate_folio,
|
2022-04-29 23:12:16 +08:00
|
|
|
.read_folio = affs_read_folio_ofs,
|
2005-04-17 06:20:36 +08:00
|
|
|
//.writepage = affs_writepage_ofs,
|
2007-10-16 16:25:24 +08:00
|
|
|
.write_begin = affs_write_begin_ofs,
|
|
|
|
.write_end = affs_write_end_ofs
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Free any preallocated blocks. */
|
|
|
|
|
|
|
|
void
|
|
|
|
affs_free_prealloc(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
|
2014-06-07 05:37:25 +08:00
|
|
|
pr_debug("free_prealloc(ino=%lu)\n", inode->i_ino);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
while (AFFS_I(inode)->i_pa_cnt) {
|
|
|
|
AFFS_I(inode)->i_pa_cnt--;
|
|
|
|
affs_free_block(sb, ++AFFS_I(inode)->i_lastalloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Truncate (or enlarge) a file to the requested size. */
|
|
|
|
|
|
|
|
void
|
|
|
|
affs_truncate(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
u32 ext, ext_key;
|
|
|
|
u32 last_blk, blkcnt, blk;
|
|
|
|
u32 size;
|
|
|
|
struct buffer_head *ext_bh;
|
|
|
|
int i;
|
|
|
|
|
2015-02-18 05:46:10 +08:00
|
|
|
pr_debug("truncate(inode=%lu, oldsize=%llu, newsize=%llu)\n",
|
|
|
|
inode->i_ino, AFFS_I(inode)->mmu_private, inode->i_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
last_blk = 0;
|
|
|
|
ext = 0;
|
|
|
|
if (inode->i_size) {
|
|
|
|
last_blk = ((u32)inode->i_size - 1) / AFFS_SB(sb)->s_data_blksize;
|
|
|
|
ext = last_blk / AFFS_SB(sb)->s_hashsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inode->i_size > AFFS_I(inode)->mmu_private) {
|
|
|
|
struct address_space *mapping = inode->i_mapping;
|
|
|
|
struct page *page;
|
2023-01-10 20:49:30 +08:00
|
|
|
void *fsdata = NULL;
|
2014-10-14 06:53:54 +08:00
|
|
|
loff_t isize = inode->i_size;
|
2005-04-17 06:20:36 +08:00
|
|
|
int res;
|
|
|
|
|
2022-02-23 03:31:43 +08:00
|
|
|
res = mapping->a_ops->write_begin(NULL, mapping, isize, 0, &page, &fsdata);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!res)
|
2014-10-14 06:53:54 +08:00
|
|
|
res = mapping->a_ops->write_end(NULL, mapping, isize, 0, 0, page, fsdata);
|
2008-04-29 23:02:20 +08:00
|
|
|
else
|
|
|
|
inode->i_size = AFFS_I(inode)->mmu_private;
|
2005-04-17 06:20:36 +08:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return;
|
|
|
|
} else if (inode->i_size == AFFS_I(inode)->mmu_private)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// lock cache
|
|
|
|
ext_bh = affs_get_extblock(inode, ext);
|
|
|
|
if (IS_ERR(ext_bh)) {
|
2014-12-13 08:57:49 +08:00
|
|
|
affs_warning(sb, "truncate",
|
|
|
|
"unexpected read error for ext block %u (%ld)",
|
2015-02-18 05:46:10 +08:00
|
|
|
ext, PTR_ERR(ext_bh));
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (AFFS_I(inode)->i_lc) {
|
|
|
|
/* clear linear cache */
|
|
|
|
i = (ext + 1) >> AFFS_I(inode)->i_lc_shift;
|
|
|
|
if (AFFS_I(inode)->i_lc_size > i) {
|
|
|
|
AFFS_I(inode)->i_lc_size = i;
|
|
|
|
for (; i < AFFS_LC_SIZE; i++)
|
|
|
|
AFFS_I(inode)->i_lc[i] = 0;
|
|
|
|
}
|
|
|
|
/* clear associative cache */
|
|
|
|
for (i = 0; i < AFFS_AC_SIZE; i++)
|
|
|
|
if (AFFS_I(inode)->i_ac[i].ext >= ext)
|
|
|
|
AFFS_I(inode)->i_ac[i].ext = 0;
|
|
|
|
}
|
|
|
|
ext_key = be32_to_cpu(AFFS_TAIL(sb, ext_bh)->extension);
|
|
|
|
|
|
|
|
blkcnt = AFFS_I(inode)->i_blkcnt;
|
|
|
|
i = 0;
|
|
|
|
blk = last_blk;
|
|
|
|
if (inode->i_size) {
|
|
|
|
i = last_blk % AFFS_SB(sb)->s_hashsize + 1;
|
|
|
|
blk++;
|
|
|
|
} else
|
|
|
|
AFFS_HEAD(ext_bh)->first_data = 0;
|
2008-04-29 23:02:20 +08:00
|
|
|
AFFS_HEAD(ext_bh)->block_count = cpu_to_be32(i);
|
2005-04-17 06:20:36 +08:00
|
|
|
size = AFFS_SB(sb)->s_hashsize;
|
|
|
|
if (size > blkcnt - blk + i)
|
|
|
|
size = blkcnt - blk + i;
|
|
|
|
for (; i < size; i++, blk++) {
|
|
|
|
affs_free_block(sb, be32_to_cpu(AFFS_BLOCK(sb, ext_bh, i)));
|
|
|
|
AFFS_BLOCK(sb, ext_bh, i) = 0;
|
|
|
|
}
|
|
|
|
AFFS_TAIL(sb, ext_bh)->extension = 0;
|
|
|
|
affs_fix_checksum(sb, ext_bh);
|
|
|
|
mark_buffer_dirty_inode(ext_bh, inode);
|
|
|
|
affs_brelse(ext_bh);
|
|
|
|
|
|
|
|
if (inode->i_size) {
|
|
|
|
AFFS_I(inode)->i_blkcnt = last_blk + 1;
|
|
|
|
AFFS_I(inode)->i_extcnt = ext + 1;
|
2015-04-17 03:48:24 +08:00
|
|
|
if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_OFS)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct buffer_head *bh = affs_bread_ino(inode, last_blk, 0);
|
|
|
|
u32 tmp;
|
2010-08-25 15:05:27 +08:00
|
|
|
if (IS_ERR(bh)) {
|
2014-12-13 08:57:49 +08:00
|
|
|
affs_warning(sb, "truncate",
|
|
|
|
"unexpected read error for last block %u (%ld)",
|
2015-02-18 05:46:10 +08:00
|
|
|
ext, PTR_ERR(bh));
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tmp = be32_to_cpu(AFFS_DATA_HEAD(bh)->next);
|
|
|
|
AFFS_DATA_HEAD(bh)->next = 0;
|
|
|
|
affs_adjust_checksum(bh, -tmp);
|
|
|
|
affs_brelse(bh);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
AFFS_I(inode)->i_blkcnt = 0;
|
|
|
|
AFFS_I(inode)->i_extcnt = 1;
|
|
|
|
}
|
|
|
|
AFFS_I(inode)->mmu_private = inode->i_size;
|
|
|
|
// unlock cache
|
|
|
|
|
|
|
|
while (ext_key) {
|
|
|
|
ext_bh = affs_bread(sb, ext_key);
|
|
|
|
size = AFFS_SB(sb)->s_hashsize;
|
|
|
|
if (size > blkcnt - blk)
|
|
|
|
size = blkcnt - blk;
|
|
|
|
for (i = 0; i < size; i++, blk++)
|
|
|
|
affs_free_block(sb, be32_to_cpu(AFFS_BLOCK(sb, ext_bh, i)));
|
|
|
|
affs_free_block(sb, ext_key);
|
|
|
|
ext_key = be32_to_cpu(AFFS_TAIL(sb, ext_bh)->extension);
|
|
|
|
affs_brelse(ext_bh);
|
|
|
|
}
|
|
|
|
affs_free_prealloc(inode);
|
|
|
|
}
|
2009-06-08 13:22:00 +08:00
|
|
|
|
2011-07-17 08:44:56 +08:00
|
|
|
int affs_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
|
2009-06-08 13:22:00 +08:00
|
|
|
{
|
2010-05-26 23:53:25 +08:00
|
|
|
struct inode *inode = filp->f_mapping->host;
|
2009-06-08 13:22:00 +08:00
|
|
|
int ret, err;
|
|
|
|
|
2017-07-08 03:20:52 +08:00
|
|
|
err = file_write_and_wait_range(filp, start, end);
|
2011-07-17 08:44:56 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(inode);
|
2009-06-08 13:22:00 +08:00
|
|
|
ret = write_inode_now(inode, 0);
|
|
|
|
err = sync_blockdev(inode->i_sb->s_bdev);
|
|
|
|
if (!ret)
|
|
|
|
ret = err;
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(inode);
|
2009-06-08 13:22:00 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2014-12-13 08:57:47 +08:00
|
|
|
const struct file_operations affs_file_operations = {
|
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read_iter = generic_file_read_iter,
|
|
|
|
.write_iter = generic_file_write_iter,
|
|
|
|
.mmap = generic_file_mmap,
|
|
|
|
.open = affs_file_open,
|
|
|
|
.release = affs_file_release,
|
|
|
|
.fsync = affs_file_fsync,
|
|
|
|
.splice_read = generic_file_splice_read,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct inode_operations affs_file_inode_operations = {
|
|
|
|
.setattr = affs_notify_change,
|
|
|
|
};
|