2019-05-28 10:10:12 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-25 19:45:16 -07:00
|
|
|
/*
|
|
|
|
* OMFS (as used by RIO Karma) file operations.
|
|
|
|
* Copyright (C) 2005 Bob Copeland <me@bobcopeland.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/mpage.h>
|
|
|
|
#include "omfs.h"
|
|
|
|
|
2008-08-15 00:40:47 -07:00
|
|
|
static u32 omfs_max_extents(struct omfs_sb_info *sbi, int offset)
|
|
|
|
{
|
|
|
|
return (sbi->s_sys_blocksize - offset -
|
|
|
|
sizeof(struct omfs_extent)) /
|
fs: omfs: Use flexible-array member in struct omfs_extent
Memory for 'struct omfs_extent' and a 'e_extent_count' number of extent
entries is indirectly allocated through 'bh->b_data', which is a pointer
to data within the page. This implies that the member 'e_entry'
(which is the start of extent entries) functions more like an array than
a single object of type 'struct omfs_extent_entry'.
So we better turn this object into a proper array, in this case a
flexible-array member, and with that, fix the following
-Wstringop-overflow warning seen after building s390 architecture with
allyesconfig (GCC 13):
fs/omfs/file.c: In function 'omfs_grow_extent':
include/linux/fortify-string.h:57:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
57 | #define __underlying_memcpy __builtin_memcpy
| ^
include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy'
648 | __underlying_##op(p, q, __fortify_size); \
| ^~~~~~~~~~~~~
include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk'
693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \
| ^~~~~~~~~~~~~~~~~~~~
fs/omfs/file.c:170:9: note: in expansion of macro 'memcpy'
170 | memcpy(terminator, entry, sizeof(struct omfs_extent_entry));
| ^~~~~~
In file included from fs/omfs/omfs.h:8,
from fs/omfs/file.c:11:
fs/omfs/omfs_fs.h:80:34: note: at offset 16 into destination object 'e_entry' of size 16
80 | struct omfs_extent_entry e_entry; /* start of extent entries */
| ^~~~~~~
There are some binary differences before and after changes, but this are
expected due to the change in the size of 'struct omfs_extent' and the
necessary adjusments.
This helps with the ongoing efforts to globally enable
-Wstringop-overflow.
Link: https://github.com/KSPP/linux/issues/330
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2023-07-14 12:56:37 -07:00
|
|
|
sizeof(struct omfs_extent_entry);
|
2008-08-15 00:40:47 -07:00
|
|
|
}
|
|
|
|
|
2008-07-25 19:45:16 -07:00
|
|
|
void omfs_make_empty_table(struct buffer_head *bh, int offset)
|
|
|
|
{
|
|
|
|
struct omfs_extent *oe = (struct omfs_extent *) &bh->b_data[offset];
|
|
|
|
|
2008-07-29 22:33:46 -07:00
|
|
|
oe->e_next = ~cpu_to_be64(0ULL);
|
2008-07-25 19:45:16 -07:00
|
|
|
oe->e_extent_count = cpu_to_be32(1),
|
|
|
|
oe->e_fill = cpu_to_be32(0x22),
|
fs: omfs: Use flexible-array member in struct omfs_extent
Memory for 'struct omfs_extent' and a 'e_extent_count' number of extent
entries is indirectly allocated through 'bh->b_data', which is a pointer
to data within the page. This implies that the member 'e_entry'
(which is the start of extent entries) functions more like an array than
a single object of type 'struct omfs_extent_entry'.
So we better turn this object into a proper array, in this case a
flexible-array member, and with that, fix the following
-Wstringop-overflow warning seen after building s390 architecture with
allyesconfig (GCC 13):
fs/omfs/file.c: In function 'omfs_grow_extent':
include/linux/fortify-string.h:57:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
57 | #define __underlying_memcpy __builtin_memcpy
| ^
include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy'
648 | __underlying_##op(p, q, __fortify_size); \
| ^~~~~~~~~~~~~
include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk'
693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \
| ^~~~~~~~~~~~~~~~~~~~
fs/omfs/file.c:170:9: note: in expansion of macro 'memcpy'
170 | memcpy(terminator, entry, sizeof(struct omfs_extent_entry));
| ^~~~~~
In file included from fs/omfs/omfs.h:8,
from fs/omfs/file.c:11:
fs/omfs/omfs_fs.h:80:34: note: at offset 16 into destination object 'e_entry' of size 16
80 | struct omfs_extent_entry e_entry; /* start of extent entries */
| ^~~~~~~
There are some binary differences before and after changes, but this are
expected due to the change in the size of 'struct omfs_extent' and the
necessary adjusments.
This helps with the ongoing efforts to globally enable
-Wstringop-overflow.
Link: https://github.com/KSPP/linux/issues/330
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2023-07-14 12:56:37 -07:00
|
|
|
oe->e_entry[0].e_cluster = ~cpu_to_be64(0ULL);
|
|
|
|
oe->e_entry[0].e_blocks = ~cpu_to_be64(0ULL);
|
2008-07-25 19:45:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int omfs_shrink_inode(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
|
|
|
|
struct omfs_extent *oe;
|
|
|
|
struct omfs_extent_entry *entry;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
u64 next, last;
|
|
|
|
u32 extent_count;
|
2008-08-15 00:40:47 -07:00
|
|
|
u32 max_extents;
|
2008-07-25 19:45:16 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* traverse extent table, freeing each entry that is greater
|
|
|
|
* than inode->i_size;
|
|
|
|
*/
|
|
|
|
next = inode->i_ino;
|
|
|
|
|
|
|
|
/* only support truncate -> 0 for now */
|
|
|
|
ret = -EIO;
|
|
|
|
if (inode->i_size != 0)
|
|
|
|
goto out;
|
|
|
|
|
2008-09-06 14:51:53 -07:00
|
|
|
bh = omfs_bread(inode->i_sb, next);
|
2008-07-25 19:45:16 -07:00
|
|
|
if (!bh)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
oe = (struct omfs_extent *)(&bh->b_data[OMFS_EXTENT_START]);
|
2008-08-15 00:40:47 -07:00
|
|
|
max_extents = omfs_max_extents(sbi, OMFS_EXTENT_START);
|
2008-07-25 19:45:16 -07:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
2008-08-15 00:40:47 -07:00
|
|
|
if (omfs_is_bad(sbi, (struct omfs_header *) bh->b_data, next))
|
|
|
|
goto out_brelse;
|
2008-07-25 19:45:16 -07:00
|
|
|
|
|
|
|
extent_count = be32_to_cpu(oe->e_extent_count);
|
2008-08-15 00:40:47 -07:00
|
|
|
|
|
|
|
if (extent_count > max_extents)
|
|
|
|
goto out_brelse;
|
|
|
|
|
2008-07-25 19:45:16 -07:00
|
|
|
last = next;
|
|
|
|
next = be64_to_cpu(oe->e_next);
|
fs: omfs: Use flexible-array member in struct omfs_extent
Memory for 'struct omfs_extent' and a 'e_extent_count' number of extent
entries is indirectly allocated through 'bh->b_data', which is a pointer
to data within the page. This implies that the member 'e_entry'
(which is the start of extent entries) functions more like an array than
a single object of type 'struct omfs_extent_entry'.
So we better turn this object into a proper array, in this case a
flexible-array member, and with that, fix the following
-Wstringop-overflow warning seen after building s390 architecture with
allyesconfig (GCC 13):
fs/omfs/file.c: In function 'omfs_grow_extent':
include/linux/fortify-string.h:57:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
57 | #define __underlying_memcpy __builtin_memcpy
| ^
include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy'
648 | __underlying_##op(p, q, __fortify_size); \
| ^~~~~~~~~~~~~
include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk'
693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \
| ^~~~~~~~~~~~~~~~~~~~
fs/omfs/file.c:170:9: note: in expansion of macro 'memcpy'
170 | memcpy(terminator, entry, sizeof(struct omfs_extent_entry));
| ^~~~~~
In file included from fs/omfs/omfs.h:8,
from fs/omfs/file.c:11:
fs/omfs/omfs_fs.h:80:34: note: at offset 16 into destination object 'e_entry' of size 16
80 | struct omfs_extent_entry e_entry; /* start of extent entries */
| ^~~~~~~
There are some binary differences before and after changes, but this are
expected due to the change in the size of 'struct omfs_extent' and the
necessary adjusments.
This helps with the ongoing efforts to globally enable
-Wstringop-overflow.
Link: https://github.com/KSPP/linux/issues/330
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2023-07-14 12:56:37 -07:00
|
|
|
entry = oe->e_entry;
|
2008-07-25 19:45:16 -07:00
|
|
|
|
|
|
|
/* ignore last entry as it is the terminator */
|
|
|
|
for (; extent_count > 1; extent_count--) {
|
|
|
|
u64 start, count;
|
|
|
|
start = be64_to_cpu(entry->e_cluster);
|
|
|
|
count = be64_to_cpu(entry->e_blocks);
|
|
|
|
|
|
|
|
omfs_clear_range(inode->i_sb, start, (int) count);
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
omfs_make_empty_table(bh, (char *) oe - bh->b_data);
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
brelse(bh);
|
|
|
|
|
|
|
|
if (last != inode->i_ino)
|
|
|
|
omfs_clear_range(inode->i_sb, last, sbi->s_mirrors);
|
|
|
|
|
|
|
|
if (next == ~0)
|
|
|
|
break;
|
|
|
|
|
2008-09-06 14:51:53 -07:00
|
|
|
bh = omfs_bread(inode->i_sb, next);
|
2008-07-25 19:45:16 -07:00
|
|
|
if (!bh)
|
|
|
|
goto out;
|
|
|
|
oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]);
|
2008-08-15 00:40:47 -07:00
|
|
|
max_extents = omfs_max_extents(sbi, OMFS_EXTENT_CONT);
|
2008-07-25 19:45:16 -07:00
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
2008-08-15 00:40:47 -07:00
|
|
|
out_brelse:
|
|
|
|
brelse(bh);
|
|
|
|
return ret;
|
2008-07-25 19:45:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void omfs_truncate(struct inode *inode)
|
|
|
|
{
|
|
|
|
omfs_shrink_inode(inode);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add new blocks to the current extent, or create new entries/continuations
|
|
|
|
* as necessary.
|
|
|
|
*/
|
|
|
|
static int omfs_grow_extent(struct inode *inode, struct omfs_extent *oe,
|
|
|
|
u64 *ret_block)
|
|
|
|
{
|
|
|
|
struct omfs_extent_entry *terminator;
|
fs: omfs: Use flexible-array member in struct omfs_extent
Memory for 'struct omfs_extent' and a 'e_extent_count' number of extent
entries is indirectly allocated through 'bh->b_data', which is a pointer
to data within the page. This implies that the member 'e_entry'
(which is the start of extent entries) functions more like an array than
a single object of type 'struct omfs_extent_entry'.
So we better turn this object into a proper array, in this case a
flexible-array member, and with that, fix the following
-Wstringop-overflow warning seen after building s390 architecture with
allyesconfig (GCC 13):
fs/omfs/file.c: In function 'omfs_grow_extent':
include/linux/fortify-string.h:57:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
57 | #define __underlying_memcpy __builtin_memcpy
| ^
include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy'
648 | __underlying_##op(p, q, __fortify_size); \
| ^~~~~~~~~~~~~
include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk'
693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \
| ^~~~~~~~~~~~~~~~~~~~
fs/omfs/file.c:170:9: note: in expansion of macro 'memcpy'
170 | memcpy(terminator, entry, sizeof(struct omfs_extent_entry));
| ^~~~~~
In file included from fs/omfs/omfs.h:8,
from fs/omfs/file.c:11:
fs/omfs/omfs_fs.h:80:34: note: at offset 16 into destination object 'e_entry' of size 16
80 | struct omfs_extent_entry e_entry; /* start of extent entries */
| ^~~~~~~
There are some binary differences before and after changes, but this are
expected due to the change in the size of 'struct omfs_extent' and the
necessary adjusments.
This helps with the ongoing efforts to globally enable
-Wstringop-overflow.
Link: https://github.com/KSPP/linux/issues/330
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2023-07-14 12:56:37 -07:00
|
|
|
struct omfs_extent_entry *entry = oe->e_entry;
|
2008-07-25 19:45:16 -07:00
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
|
|
|
|
u32 extent_count = be32_to_cpu(oe->e_extent_count);
|
|
|
|
u64 new_block = 0;
|
|
|
|
u32 max_count;
|
|
|
|
int new_count;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* reached the end of the extent table with no blocks mapped.
|
|
|
|
* there are three possibilities for adding: grow last extent,
|
|
|
|
* add a new extent to the current extent table, and add a
|
|
|
|
* continuation inode. in last two cases need an allocator for
|
|
|
|
* sbi->s_cluster_size
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: handle holes */
|
|
|
|
|
|
|
|
/* should always have a terminator */
|
|
|
|
if (extent_count < 1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* trivially grow current extent, if next block is not taken */
|
|
|
|
terminator = entry + extent_count - 1;
|
|
|
|
if (extent_count > 1) {
|
|
|
|
entry = terminator-1;
|
|
|
|
new_block = be64_to_cpu(entry->e_cluster) +
|
|
|
|
be64_to_cpu(entry->e_blocks);
|
|
|
|
|
|
|
|
if (omfs_allocate_block(inode->i_sb, new_block)) {
|
2012-10-04 17:16:53 -07:00
|
|
|
be64_add_cpu(&entry->e_blocks, 1);
|
2008-07-25 19:45:16 -07:00
|
|
|
terminator->e_blocks = ~(cpu_to_be64(
|
|
|
|
be64_to_cpu(~terminator->e_blocks) + 1));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2008-08-15 00:40:47 -07:00
|
|
|
max_count = omfs_max_extents(sbi, OMFS_EXTENT_START);
|
2008-07-25 19:45:16 -07:00
|
|
|
|
|
|
|
/* TODO: add a continuation block here */
|
|
|
|
if (be32_to_cpu(oe->e_extent_count) > max_count-1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* try to allocate a new cluster */
|
|
|
|
ret = omfs_allocate_range(inode->i_sb, 1, sbi->s_clustersize,
|
|
|
|
&new_block, &new_count);
|
|
|
|
if (ret)
|
|
|
|
goto out_fail;
|
|
|
|
|
|
|
|
/* copy terminator down an entry */
|
|
|
|
entry = terminator;
|
|
|
|
terminator++;
|
|
|
|
memcpy(terminator, entry, sizeof(struct omfs_extent_entry));
|
|
|
|
|
|
|
|
entry->e_cluster = cpu_to_be64(new_block);
|
|
|
|
entry->e_blocks = cpu_to_be64((u64) new_count);
|
|
|
|
|
|
|
|
terminator->e_blocks = ~(cpu_to_be64(
|
|
|
|
be64_to_cpu(~terminator->e_blocks) + (u64) new_count));
|
|
|
|
|
|
|
|
/* write in new entry */
|
2012-10-04 17:16:53 -07:00
|
|
|
be32_add_cpu(&oe->e_extent_count, 1);
|
2008-07-25 19:45:16 -07:00
|
|
|
|
|
|
|
out:
|
|
|
|
*ret_block = new_block;
|
|
|
|
out_fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scans across the directory table for a given file block number.
|
|
|
|
* If block not found, return 0.
|
|
|
|
*/
|
|
|
|
static sector_t find_block(struct inode *inode, struct omfs_extent_entry *ent,
|
|
|
|
sector_t block, int count, int *left)
|
|
|
|
{
|
|
|
|
/* count > 1 because of terminator */
|
|
|
|
sector_t searched = 0;
|
|
|
|
for (; count > 1; count--) {
|
|
|
|
int numblocks = clus_to_blk(OMFS_SB(inode->i_sb),
|
|
|
|
be64_to_cpu(ent->e_blocks));
|
|
|
|
|
|
|
|
if (block >= searched &&
|
|
|
|
block < searched + numblocks) {
|
|
|
|
/*
|
|
|
|
* found it at cluster + (block - searched)
|
|
|
|
* numblocks - (block - searched) is remainder
|
|
|
|
*/
|
|
|
|
*left = numblocks - (block - searched);
|
|
|
|
return clus_to_blk(OMFS_SB(inode->i_sb),
|
|
|
|
be64_to_cpu(ent->e_cluster)) +
|
|
|
|
block - searched;
|
|
|
|
}
|
|
|
|
searched += numblocks;
|
|
|
|
ent++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omfs_get_block(struct inode *inode, sector_t block,
|
|
|
|
struct buffer_head *bh_result, int create)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh;
|
|
|
|
sector_t next, offset;
|
|
|
|
int ret;
|
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.
In preparation for removing[2] the[3] macro[4], remove all remaining
needless uses with the following script:
git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
xargs perl -pi -e \
's/\buninitialized_var\(([^\)]+)\)/\1/g;
s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'
drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
pathological white-space.
No outstanding warnings were found building allmodconfig with GCC 9.3.0
for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
alpha, and m68k.
[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/
Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers
Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs
Signed-off-by: Kees Cook <keescook@chromium.org>
2020-06-03 13:09:38 -07:00
|
|
|
u64 new_block;
|
2008-08-15 00:40:47 -07:00
|
|
|
u32 max_extents;
|
2008-07-25 19:45:16 -07:00
|
|
|
int extent_count;
|
|
|
|
struct omfs_extent *oe;
|
|
|
|
struct omfs_extent_entry *entry;
|
|
|
|
struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
|
|
|
|
int max_blocks = bh_result->b_size >> inode->i_blkbits;
|
|
|
|
int remain;
|
|
|
|
|
|
|
|
ret = -EIO;
|
2008-09-06 14:51:53 -07:00
|
|
|
bh = omfs_bread(inode->i_sb, inode->i_ino);
|
2008-07-25 19:45:16 -07:00
|
|
|
if (!bh)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
oe = (struct omfs_extent *)(&bh->b_data[OMFS_EXTENT_START]);
|
2008-08-15 00:40:47 -07:00
|
|
|
max_extents = omfs_max_extents(sbi, OMFS_EXTENT_START);
|
2008-07-25 19:45:16 -07:00
|
|
|
next = inode->i_ino;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
if (omfs_is_bad(sbi, (struct omfs_header *) bh->b_data, next))
|
|
|
|
goto out_brelse;
|
|
|
|
|
|
|
|
extent_count = be32_to_cpu(oe->e_extent_count);
|
|
|
|
next = be64_to_cpu(oe->e_next);
|
fs: omfs: Use flexible-array member in struct omfs_extent
Memory for 'struct omfs_extent' and a 'e_extent_count' number of extent
entries is indirectly allocated through 'bh->b_data', which is a pointer
to data within the page. This implies that the member 'e_entry'
(which is the start of extent entries) functions more like an array than
a single object of type 'struct omfs_extent_entry'.
So we better turn this object into a proper array, in this case a
flexible-array member, and with that, fix the following
-Wstringop-overflow warning seen after building s390 architecture with
allyesconfig (GCC 13):
fs/omfs/file.c: In function 'omfs_grow_extent':
include/linux/fortify-string.h:57:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
57 | #define __underlying_memcpy __builtin_memcpy
| ^
include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy'
648 | __underlying_##op(p, q, __fortify_size); \
| ^~~~~~~~~~~~~
include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk'
693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \
| ^~~~~~~~~~~~~~~~~~~~
fs/omfs/file.c:170:9: note: in expansion of macro 'memcpy'
170 | memcpy(terminator, entry, sizeof(struct omfs_extent_entry));
| ^~~~~~
In file included from fs/omfs/omfs.h:8,
from fs/omfs/file.c:11:
fs/omfs/omfs_fs.h:80:34: note: at offset 16 into destination object 'e_entry' of size 16
80 | struct omfs_extent_entry e_entry; /* start of extent entries */
| ^~~~~~~
There are some binary differences before and after changes, but this are
expected due to the change in the size of 'struct omfs_extent' and the
necessary adjusments.
This helps with the ongoing efforts to globally enable
-Wstringop-overflow.
Link: https://github.com/KSPP/linux/issues/330
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2023-07-14 12:56:37 -07:00
|
|
|
entry = oe->e_entry;
|
2008-07-25 19:45:16 -07:00
|
|
|
|
2008-08-15 00:40:47 -07:00
|
|
|
if (extent_count > max_extents)
|
|
|
|
goto out_brelse;
|
|
|
|
|
2008-07-25 19:45:16 -07:00
|
|
|
offset = find_block(inode, entry, block, extent_count, &remain);
|
|
|
|
if (offset > 0) {
|
|
|
|
ret = 0;
|
|
|
|
map_bh(bh_result, inode->i_sb, offset);
|
|
|
|
if (remain > max_blocks)
|
|
|
|
remain = max_blocks;
|
|
|
|
bh_result->b_size = (remain << inode->i_blkbits);
|
|
|
|
goto out_brelse;
|
|
|
|
}
|
|
|
|
if (next == ~0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
brelse(bh);
|
2008-09-06 14:51:53 -07:00
|
|
|
bh = omfs_bread(inode->i_sb, next);
|
2008-07-25 19:45:16 -07:00
|
|
|
if (!bh)
|
|
|
|
goto out;
|
|
|
|
oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]);
|
2008-08-15 00:40:47 -07:00
|
|
|
max_extents = omfs_max_extents(sbi, OMFS_EXTENT_CONT);
|
2008-07-25 19:45:16 -07:00
|
|
|
}
|
|
|
|
if (create) {
|
|
|
|
ret = omfs_grow_extent(inode, oe, &new_block);
|
|
|
|
if (ret == 0) {
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
map_bh(bh_result, inode->i_sb,
|
|
|
|
clus_to_blk(sbi, new_block));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out_brelse:
|
|
|
|
brelse(bh);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-04-29 07:40:40 -07:00
|
|
|
static int omfs_read_folio(struct file *file, struct folio *folio)
|
2008-07-25 19:45:16 -07:00
|
|
|
{
|
2022-04-29 07:40:40 -07:00
|
|
|
return block_read_full_folio(folio, omfs_get_block);
|
2008-07-25 19:45:16 -07:00
|
|
|
}
|
|
|
|
|
fs: convert mpage_readpages to mpage_readahead
Implement the new readahead aop and convert all callers (block_dev,
exfat, ext2, fat, gfs2, hpfs, isofs, jfs, nilfs2, ocfs2, omfs, qnx6,
reiserfs & udf).
The callers are all trivial except for GFS2 & OCFS2.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com> # ocfs2
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> # ocfs2
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Cc: Chao Yu <yuchao0@huawei.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Darrick J. Wong <darrick.wong@oracle.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Gao Xiang <gaoxiang25@huawei.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Miklos Szeredi <mszeredi@redhat.com>
Link: http://lkml.kernel.org/r/20200414150233.24495-17-willy@infradead.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-01 21:47:02 -07:00
|
|
|
static void omfs_readahead(struct readahead_control *rac)
|
2008-07-25 19:45:16 -07:00
|
|
|
{
|
fs: convert mpage_readpages to mpage_readahead
Implement the new readahead aop and convert all callers (block_dev,
exfat, ext2, fat, gfs2, hpfs, isofs, jfs, nilfs2, ocfs2, omfs, qnx6,
reiserfs & udf).
The callers are all trivial except for GFS2 & OCFS2.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com> # ocfs2
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> # ocfs2
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Cc: Chao Yu <yuchao0@huawei.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Darrick J. Wong <darrick.wong@oracle.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Gao Xiang <gaoxiang25@huawei.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Miklos Szeredi <mszeredi@redhat.com>
Link: http://lkml.kernel.org/r/20200414150233.24495-17-willy@infradead.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-01 21:47:02 -07:00
|
|
|
mpage_readahead(rac, omfs_get_block);
|
2008-07-25 19:45:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
omfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
return mpage_writepages(mapping, wbc, omfs_get_block);
|
|
|
|
}
|
|
|
|
|
2012-12-15 03:49:42 -07:00
|
|
|
static void omfs_write_failed(struct address_space *mapping, loff_t to)
|
|
|
|
{
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
|
|
|
if (to > inode->i_size) {
|
2013-09-12 15:13:56 -07:00
|
|
|
truncate_pagecache(inode, inode->i_size);
|
2012-12-15 03:49:42 -07:00
|
|
|
omfs_truncate(inode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-25 19:45:16 -07:00
|
|
|
static int omfs_write_begin(struct file *file, struct address_space *mapping,
|
2022-02-22 12:31:43 -07:00
|
|
|
loff_t pos, unsigned len,
|
2024-07-15 11:24:01 -07:00
|
|
|
struct folio **foliop, void **fsdata)
|
2008-07-25 19:45:16 -07:00
|
|
|
{
|
2010-06-04 02:29:58 -07:00
|
|
|
int ret;
|
|
|
|
|
2024-07-15 11:24:01 -07:00
|
|
|
ret = block_write_begin(mapping, pos, len, foliop, omfs_get_block);
|
2012-12-15 03:49:42 -07:00
|
|
|
if (unlikely(ret))
|
|
|
|
omfs_write_failed(mapping, pos + len);
|
2010-06-04 02:29:58 -07:00
|
|
|
|
|
|
|
return ret;
|
2008-07-25 19:45:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static sector_t omfs_bmap(struct address_space *mapping, sector_t block)
|
|
|
|
{
|
|
|
|
return generic_block_bmap(mapping, block, omfs_get_block);
|
|
|
|
}
|
|
|
|
|
2009-10-01 15:43:56 -07:00
|
|
|
const struct file_operations omfs_file_operations = {
|
2008-07-25 19:45:16 -07:00
|
|
|
.llseek = generic_file_llseek,
|
2014-04-02 11:33:16 -07:00
|
|
|
.read_iter = generic_file_read_iter,
|
2014-04-03 00:17:43 -07:00
|
|
|
.write_iter = generic_file_write_iter,
|
2008-07-25 19:45:16 -07:00
|
|
|
.mmap = generic_file_mmap,
|
2010-05-26 08:53:41 -07:00
|
|
|
.fsync = generic_file_fsync,
|
2023-05-22 06:50:15 -07:00
|
|
|
.splice_read = filemap_splice_read,
|
2008-07-25 19:45:16 -07:00
|
|
|
};
|
|
|
|
|
2023-01-13 04:49:11 -07:00
|
|
|
static int omfs_setattr(struct mnt_idmap *idmap,
|
2021-01-21 06:19:43 -07:00
|
|
|
struct dentry *dentry, struct iattr *attr)
|
2010-06-04 02:29:59 -07:00
|
|
|
{
|
2015-03-17 15:25:59 -07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2010-06-04 02:29:59 -07:00
|
|
|
int error;
|
|
|
|
|
2023-01-13 04:49:11 -07:00
|
|
|
error = setattr_prepare(&nop_mnt_idmap, dentry, attr);
|
2010-06-04 02:29:59 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
2010-06-04 02:30:02 -07:00
|
|
|
|
|
|
|
if ((attr->ia_valid & ATTR_SIZE) &&
|
|
|
|
attr->ia_size != i_size_read(inode)) {
|
2012-12-15 03:49:42 -07:00
|
|
|
error = inode_newsize_ok(inode, attr->ia_size);
|
2010-06-04 02:30:02 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
2012-12-15 03:49:42 -07:00
|
|
|
truncate_setsize(inode, attr->ia_size);
|
|
|
|
omfs_truncate(inode);
|
2010-06-04 02:30:02 -07:00
|
|
|
}
|
|
|
|
|
2023-01-13 04:49:11 -07:00
|
|
|
setattr_copy(&nop_mnt_idmap, inode, attr);
|
2010-06-04 02:30:02 -07:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return 0;
|
2010-06-04 02:29:59 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 17:01:11 -07:00
|
|
|
const struct inode_operations omfs_file_inops = {
|
2010-06-04 02:29:59 -07:00
|
|
|
.setattr = omfs_setattr,
|
2008-07-25 19:45:16 -07:00
|
|
|
};
|
|
|
|
|
2009-09-21 17:01:10 -07:00
|
|
|
const struct address_space_operations omfs_aops = {
|
2022-02-09 13:22:12 -07:00
|
|
|
.dirty_folio = block_dirty_folio,
|
2022-02-09 13:21:34 -07:00
|
|
|
.invalidate_folio = block_invalidate_folio,
|
2022-04-29 07:40:40 -07:00
|
|
|
.read_folio = omfs_read_folio,
|
fs: convert mpage_readpages to mpage_readahead
Implement the new readahead aop and convert all callers (block_dev,
exfat, ext2, fat, gfs2, hpfs, isofs, jfs, nilfs2, ocfs2, omfs, qnx6,
reiserfs & udf).
The callers are all trivial except for GFS2 & OCFS2.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com> # ocfs2
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> # ocfs2
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Cc: Chao Yu <yuchao0@huawei.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Darrick J. Wong <darrick.wong@oracle.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Gao Xiang <gaoxiang25@huawei.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Miklos Szeredi <mszeredi@redhat.com>
Link: http://lkml.kernel.org/r/20200414150233.24495-17-willy@infradead.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-01 21:47:02 -07:00
|
|
|
.readahead = omfs_readahead,
|
2008-07-25 19:45:16 -07:00
|
|
|
.writepages = omfs_writepages,
|
|
|
|
.write_begin = omfs_write_begin,
|
|
|
|
.write_end = generic_write_end,
|
|
|
|
.bmap = omfs_bmap,
|
2022-12-02 03:26:44 -07:00
|
|
|
.migrate_folio = buffer_migrate_folio,
|
2008-07-25 19:45:16 -07:00
|
|
|
};
|
|
|
|
|