2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/fs/ufs/inode.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998
|
|
|
|
* Daniel Pirkl <daniel.pirkl@email.cz>
|
|
|
|
* Charles University, Faculty of Mathematics and Physics
|
|
|
|
*
|
|
|
|
* from
|
|
|
|
*
|
|
|
|
* linux/fs/ext2/inode.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992, 1993, 1994, 1995
|
|
|
|
* Remy Card (card@masi.ibp.fr)
|
|
|
|
* Laboratoire MASI - Institut Blaise Pascal
|
|
|
|
* Universite Pierre et Marie Curie (Paris VI)
|
|
|
|
*
|
|
|
|
* from
|
|
|
|
*
|
|
|
|
* linux/fs/minix/inode.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
*
|
|
|
|
* Goal-directed block allocation by Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
|
|
|
|
* Big-endian to little-endian byte-swapping/bitmaps by
|
|
|
|
* David S. Miller (davem@caip.rutgers.edu), 1995
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/buffer_head.h>
|
2010-03-05 16:21:37 +08:00
|
|
|
#include <linux/writeback.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-08 20:21:31 +08:00
|
|
|
#include "ufs_fs.h"
|
2007-10-17 14:26:51 +08:00
|
|
|
#include "ufs.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "swab.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2015-06-05 02:13:14 +08:00
|
|
|
static int ufs_block_to_path(struct inode *inode, sector_t i_block, unsigned offsets[4])
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(inode->i_sb)->s_uspi;
|
|
|
|
int ptrs = uspi->s_apb;
|
|
|
|
int ptrs_bits = uspi->s_apbshift;
|
|
|
|
const long direct_blocks = UFS_NDADDR,
|
|
|
|
indirect_blocks = ptrs,
|
|
|
|
double_blocks = (1 << (ptrs_bits * 2));
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
|
2006-06-25 20:47:24 +08:00
|
|
|
UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
|
2009-06-18 07:26:28 +08:00
|
|
|
if (i_block < direct_blocks) {
|
2005-04-17 06:20:36 +08:00
|
|
|
offsets[n++] = i_block;
|
|
|
|
} else if ((i_block -= direct_blocks) < indirect_blocks) {
|
|
|
|
offsets[n++] = UFS_IND_BLOCK;
|
|
|
|
offsets[n++] = i_block;
|
|
|
|
} else if ((i_block -= indirect_blocks) < double_blocks) {
|
|
|
|
offsets[n++] = UFS_DIND_BLOCK;
|
|
|
|
offsets[n++] = i_block >> ptrs_bits;
|
|
|
|
offsets[n++] = i_block & (ptrs - 1);
|
|
|
|
} else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) {
|
|
|
|
offsets[n++] = UFS_TIND_BLOCK;
|
|
|
|
offsets[n++] = i_block >> (ptrs_bits * 2);
|
|
|
|
offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1);
|
|
|
|
offsets[n++] = i_block & (ptrs - 1);
|
|
|
|
} else {
|
|
|
|
ufs_warning(inode->i_sb, "ufs_block_to_path", "block > big");
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
typedef struct {
|
|
|
|
void *p;
|
|
|
|
union {
|
|
|
|
__fs32 key32;
|
|
|
|
__fs64 key64;
|
|
|
|
};
|
|
|
|
struct buffer_head *bh;
|
|
|
|
} Indirect;
|
|
|
|
|
|
|
|
static inline int grow_chain32(struct ufs_inode_info *ufsi,
|
|
|
|
struct buffer_head *bh, __fs32 *v,
|
|
|
|
Indirect *from, Indirect *to)
|
|
|
|
{
|
|
|
|
Indirect *p;
|
|
|
|
unsigned seq;
|
|
|
|
to->bh = bh;
|
|
|
|
do {
|
|
|
|
seq = read_seqbegin(&ufsi->meta_lock);
|
|
|
|
to->key32 = *(__fs32 *)(to->p = v);
|
|
|
|
for (p = from; p <= to && p->key32 == *(__fs32 *)p->p; p++)
|
|
|
|
;
|
|
|
|
} while (read_seqretry(&ufsi->meta_lock, seq));
|
|
|
|
return (p > to);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int grow_chain64(struct ufs_inode_info *ufsi,
|
|
|
|
struct buffer_head *bh, __fs64 *v,
|
|
|
|
Indirect *from, Indirect *to)
|
|
|
|
{
|
|
|
|
Indirect *p;
|
|
|
|
unsigned seq;
|
|
|
|
to->bh = bh;
|
|
|
|
do {
|
|
|
|
seq = read_seqbegin(&ufsi->meta_lock);
|
|
|
|
to->key64 = *(__fs64 *)(to->p = v);
|
|
|
|
for (p = from; p <= to && p->key64 == *(__fs64 *)p->p; p++)
|
|
|
|
;
|
|
|
|
} while (read_seqretry(&ufsi->meta_lock, seq));
|
|
|
|
return (p > to);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Returns the location of the fragment from
|
2011-03-31 09:57:33 +08:00
|
|
|
* the beginning of the filesystem.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
static u64 ufs_frag_map(struct inode *inode, sector_t frag)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
u64 mask = (u64) uspi->s_apbmask>>uspi->s_fpbshift;
|
|
|
|
int shift = uspi->s_apbshift-uspi->s_fpbshift;
|
2015-06-18 00:44:14 +08:00
|
|
|
unsigned offsets[4], *p;
|
2015-06-18 00:02:56 +08:00
|
|
|
Indirect chain[4], *q = chain;
|
2005-04-17 06:20:36 +08:00
|
|
|
int depth = ufs_block_to_path(inode, frag >> uspi->s_fpbshift, offsets);
|
|
|
|
unsigned flags = UFS_SB(sb)->s_flags;
|
2015-06-18 00:02:56 +08:00
|
|
|
u64 res = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-25 20:47:24 +08:00
|
|
|
UFSD(": frag = %llu depth = %d\n", (unsigned long long)frag, depth);
|
2006-06-29 17:24:29 +08:00
|
|
|
UFSD(": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",
|
|
|
|
uspi->s_fpbshift, uspi->s_apbmask,
|
|
|
|
(unsigned long long)mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (depth == 0)
|
2015-06-18 00:02:56 +08:00
|
|
|
goto no_block;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
again:
|
2005-04-17 06:20:36 +08:00
|
|
|
p = offsets;
|
|
|
|
|
|
|
|
if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
|
|
|
|
goto ufs2;
|
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
if (!grow_chain32(ufsi, NULL, &ufsi->i_u1.i_data[*p++], chain, q))
|
|
|
|
goto changed;
|
|
|
|
if (!q->key32)
|
|
|
|
goto no_block;
|
2005-04-17 06:20:36 +08:00
|
|
|
while (--depth) {
|
2015-06-18 00:02:56 +08:00
|
|
|
__fs32 *ptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct buffer_head *bh;
|
2015-06-05 02:13:14 +08:00
|
|
|
unsigned n = *p++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
bh = sb_bread(sb, uspi->s_sbbase +
|
|
|
|
fs32_to_cpu(sb, q->key32) + (n>>shift));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!bh)
|
2015-06-18 00:02:56 +08:00
|
|
|
goto no_block;
|
|
|
|
ptr = (__fs32 *)bh->b_data + (n & mask);
|
|
|
|
if (!grow_chain32(ufsi, bh, ptr, chain, ++q))
|
|
|
|
goto changed;
|
|
|
|
if (!q->key32)
|
|
|
|
goto no_block;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2015-06-18 00:02:56 +08:00
|
|
|
res = fs32_to_cpu(sb, q->key32);
|
|
|
|
goto found;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
ufs2:
|
|
|
|
if (!grow_chain64(ufsi, NULL, &ufsi->i_u1.u2_i_data[*p++], chain, q))
|
|
|
|
goto changed;
|
|
|
|
if (!q->key64)
|
|
|
|
goto no_block;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
while (--depth) {
|
2015-06-18 00:02:56 +08:00
|
|
|
__fs64 *ptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct buffer_head *bh;
|
2015-06-05 02:13:14 +08:00
|
|
|
unsigned n = *p++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
bh = sb_bread(sb, uspi->s_sbbase +
|
|
|
|
fs64_to_cpu(sb, q->key64) + (n>>shift));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!bh)
|
2015-06-18 00:02:56 +08:00
|
|
|
goto no_block;
|
|
|
|
ptr = (__fs64 *)bh->b_data + (n & mask);
|
|
|
|
if (!grow_chain64(ufsi, bh, ptr, chain, ++q))
|
|
|
|
goto changed;
|
|
|
|
if (!q->key64)
|
|
|
|
goto no_block;
|
|
|
|
}
|
|
|
|
res = fs64_to_cpu(sb, q->key64);
|
|
|
|
found:
|
|
|
|
res += uspi->s_sbbase + (frag & uspi->s_fpbmask);
|
|
|
|
no_block:
|
|
|
|
while (q > chain) {
|
|
|
|
brelse(q->bh);
|
|
|
|
q--;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2015-06-18 00:02:56 +08:00
|
|
|
return res;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
changed:
|
|
|
|
while (q > chain) {
|
|
|
|
brelse(q->bh);
|
|
|
|
q--;
|
|
|
|
}
|
|
|
|
goto again;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-06-25 20:47:27 +08:00
|
|
|
/**
|
|
|
|
* ufs_inode_getfrag() - allocate new fragment(s)
|
2014-08-09 05:21:08 +08:00
|
|
|
* @inode: pointer to inode
|
|
|
|
* @fragment: number of `fragment' which hold pointer
|
2006-06-25 20:47:27 +08:00
|
|
|
* to new allocated fragment(s)
|
2014-08-09 05:21:08 +08:00
|
|
|
* @new_fragment: number of new allocated fragment(s)
|
|
|
|
* @required: how many fragment(s) we require
|
|
|
|
* @err: we set it if something wrong
|
|
|
|
* @phys: pointer to where we save physical number of new allocated fragments,
|
2006-06-25 20:47:27 +08:00
|
|
|
* NULL if we allocate not data(indirect blocks for example).
|
2014-08-09 05:21:08 +08:00
|
|
|
* @new: we set it if we allocate new block
|
|
|
|
* @locked_page: for ufs_new_fragments()
|
2006-06-25 20:47:27 +08:00
|
|
|
*/
|
|
|
|
static struct buffer_head *
|
2007-02-12 16:54:32 +08:00
|
|
|
ufs_inode_getfrag(struct inode *inode, u64 fragment,
|
2006-06-25 20:47:27 +08:00
|
|
|
sector_t new_fragment, unsigned int required, int *err,
|
|
|
|
long *phys, int *new, struct page *locked_page)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
2006-06-25 20:47:27 +08:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct buffer_head * result;
|
2007-02-12 16:54:32 +08:00
|
|
|
unsigned blockoff, lastblockoff;
|
|
|
|
u64 tmp, goal, lastfrag, block, lastblock;
|
|
|
|
void *p, *p2;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-12 16:54:32 +08:00
|
|
|
UFSD("ENTER, ino %lu, fragment %llu, new_fragment %llu, required %u, "
|
|
|
|
"metadata %d\n", inode->i_ino, (unsigned long long)fragment,
|
2006-06-25 20:47:27 +08:00
|
|
|
(unsigned long long)new_fragment, required, !phys);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* TODO : to be done for write support
|
|
|
|
if ( (flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
|
|
|
|
goto ufs2;
|
|
|
|
*/
|
|
|
|
|
|
|
|
block = ufs_fragstoblks (fragment);
|
|
|
|
blockoff = ufs_fragnum (fragment);
|
2007-02-12 16:54:32 +08:00
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, block);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
goal = 0;
|
|
|
|
|
|
|
|
repeat:
|
2007-02-12 16:54:32 +08:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
lastfrag = ufsi->i_lastfrag;
|
|
|
|
if (tmp && fragment < lastfrag) {
|
2006-06-25 20:47:27 +08:00
|
|
|
if (!phys) {
|
2005-04-17 06:20:36 +08:00
|
|
|
result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
|
2007-02-12 16:54:32 +08:00
|
|
|
if (tmp == ufs_data_ptr_to_cpu(sb, p)) {
|
|
|
|
UFSD("EXIT, result %llu\n",
|
|
|
|
(unsigned long long)tmp + blockoff);
|
2005-04-17 06:20:36 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
brelse (result);
|
|
|
|
goto repeat;
|
|
|
|
} else {
|
[PATCH] ufs: zeroize the rest of block in truncate
This patch fix behaviour in such test scenario:
lseek(fd, BIG_OFFSET)
write(fd, buf, sizeof(buf))
truncate(BIG_OFFSET)
truncate(BIG_OFFSET + sizeof(buf))
read(fd, buf...)
Because of if file big enough(BIG_OFFSET) we start allocate space by block,
ordinary block size > page size, so we should zeroize the rest of block in
truncate(except last framgnet, about which VFS should care), to not get
garbage, when we extend file.
Also patch corrects conversion from pointer to block to physical block number,
this helps in case of not common used UFS types.
And add to debug output inode number.
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-03-17 05:38:09 +08:00
|
|
|
*phys = uspi->s_sbbase + tmp + blockoff;
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastblock = ufs_fragstoblks (lastfrag);
|
|
|
|
lastblockoff = ufs_fragnum (lastfrag);
|
|
|
|
/*
|
|
|
|
* We will extend file into new block beyond last allocated block
|
|
|
|
*/
|
|
|
|
if (lastblock < block) {
|
|
|
|
/*
|
|
|
|
* We must reallocate last allocated block
|
|
|
|
*/
|
|
|
|
if (lastblockoff) {
|
2007-02-12 16:54:32 +08:00
|
|
|
p2 = ufs_get_direct_data_ptr(uspi, ufsi, lastblock);
|
|
|
|
tmp = ufs_new_fragments(inode, p2, lastfrag,
|
|
|
|
ufs_data_ptr_to_cpu(sb, p2),
|
|
|
|
uspi->s_fpb - lastblockoff,
|
|
|
|
err, locked_page);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!tmp) {
|
|
|
|
if (lastfrag != ufsi->i_lastfrag)
|
|
|
|
goto repeat;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
lastfrag = ufsi->i_lastfrag;
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-02-12 16:54:32 +08:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb,
|
|
|
|
ufs_get_direct_data_ptr(uspi, ufsi,
|
|
|
|
lastblock));
|
[PATCH] ufs: write to hole in big file
On UFS, this scenario:
open(O_TRUNC)
lseek(1024 * 1024 * 80)
write("A")
lseek(1024 * 2)
write("A")
may cause access to invalid address.
This happened because of "goal" is calculated in wrong way in block
allocation path, as I see this problem exists also in 2.4.
We use construction like this i_data[lastfrag], i_data array of pointers to
direct blocks, indirect and so on, it has ceratain size ~20 elements, and
lastfrag may have value for example 40000.
Also this patch fixes related to handling such scenario issues, wrong
zeroing metadata, in case of block(not fragment) allocation, and wrong goal
calculation, when we allocate block
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-08-27 16:23:45 +08:00
|
|
|
if (tmp)
|
|
|
|
goal = tmp + uspi->s_fpb;
|
2015-06-18 00:44:14 +08:00
|
|
|
tmp = ufs_new_fragments (inode, p, fragment - blockoff,
|
2006-06-25 20:47:20 +08:00
|
|
|
goal, required + blockoff,
|
2007-01-30 05:19:54 +08:00
|
|
|
err,
|
|
|
|
phys != NULL ? locked_page : NULL);
|
2007-02-12 16:54:32 +08:00
|
|
|
} else if (lastblock == block) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We will extend last allocated block
|
|
|
|
*/
|
2007-02-12 16:54:32 +08:00
|
|
|
tmp = ufs_new_fragments(inode, p, fragment -
|
|
|
|
(blockoff - lastblockoff),
|
|
|
|
ufs_data_ptr_to_cpu(sb, p),
|
|
|
|
required + (blockoff - lastblockoff),
|
2007-01-30 05:19:54 +08:00
|
|
|
err, phys != NULL ? locked_page : NULL);
|
[PATCH] ufs: write to hole in big file
On UFS, this scenario:
open(O_TRUNC)
lseek(1024 * 1024 * 80)
write("A")
lseek(1024 * 2)
write("A")
may cause access to invalid address.
This happened because of "goal" is calculated in wrong way in block
allocation path, as I see this problem exists also in 2.4.
We use construction like this i_data[lastfrag], i_data array of pointers to
direct blocks, indirect and so on, it has ceratain size ~20 elements, and
lastfrag may have value for example 40000.
Also this patch fixes related to handling such scenario issues, wrong
zeroing metadata, in case of block(not fragment) allocation, and wrong goal
calculation, when we allocate block
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-08-27 16:23:45 +08:00
|
|
|
} else /* (lastblock > block) */ {
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We will allocate new block before last allocated block
|
|
|
|
*/
|
[PATCH] ufs: write to hole in big file
On UFS, this scenario:
open(O_TRUNC)
lseek(1024 * 1024 * 80)
write("A")
lseek(1024 * 2)
write("A")
may cause access to invalid address.
This happened because of "goal" is calculated in wrong way in block
allocation path, as I see this problem exists also in 2.4.
We use construction like this i_data[lastfrag], i_data array of pointers to
direct blocks, indirect and so on, it has ceratain size ~20 elements, and
lastfrag may have value for example 40000.
Also this patch fixes related to handling such scenario issues, wrong
zeroing metadata, in case of block(not fragment) allocation, and wrong goal
calculation, when we allocate block
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-08-27 16:23:45 +08:00
|
|
|
if (block) {
|
2007-02-12 16:54:32 +08:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb,
|
|
|
|
ufs_get_direct_data_ptr(uspi, ufsi, block - 1));
|
[PATCH] ufs: write to hole in big file
On UFS, this scenario:
open(O_TRUNC)
lseek(1024 * 1024 * 80)
write("A")
lseek(1024 * 2)
write("A")
may cause access to invalid address.
This happened because of "goal" is calculated in wrong way in block
allocation path, as I see this problem exists also in 2.4.
We use construction like this i_data[lastfrag], i_data array of pointers to
direct blocks, indirect and so on, it has ceratain size ~20 elements, and
lastfrag may have value for example 40000.
Also this patch fixes related to handling such scenario issues, wrong
zeroing metadata, in case of block(not fragment) allocation, and wrong goal
calculation, when we allocate block
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-08-27 16:23:45 +08:00
|
|
|
if (tmp)
|
|
|
|
goal = tmp + uspi->s_fpb;
|
|
|
|
}
|
2006-06-25 20:47:20 +08:00
|
|
|
tmp = ufs_new_fragments(inode, p, fragment - blockoff,
|
2007-01-30 05:19:54 +08:00
|
|
|
goal, uspi->s_fpb, err,
|
|
|
|
phys != NULL ? locked_page : NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (!tmp) {
|
2007-02-12 16:54:32 +08:00
|
|
|
if ((!blockoff && ufs_data_ptr_to_cpu(sb, p)) ||
|
2005-04-17 06:20:36 +08:00
|
|
|
(blockoff && lastfrag != ufsi->i_lastfrag))
|
|
|
|
goto repeat;
|
|
|
|
*err = -ENOSPC;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-25 20:47:27 +08:00
|
|
|
if (!phys) {
|
[PATCH] ufs: zeroize the rest of block in truncate
This patch fix behaviour in such test scenario:
lseek(fd, BIG_OFFSET)
write(fd, buf, sizeof(buf))
truncate(BIG_OFFSET)
truncate(BIG_OFFSET + sizeof(buf))
read(fd, buf...)
Because of if file big enough(BIG_OFFSET) we start allocate space by block,
ordinary block size > page size, so we should zeroize the rest of block in
truncate(except last framgnet, about which VFS should care), to not get
garbage, when we extend file.
Also patch corrects conversion from pointer to block to physical block number,
this helps in case of not common used UFS types.
And add to debug output inode number.
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-03-17 05:38:09 +08:00
|
|
|
result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
[PATCH] ufs: zeroize the rest of block in truncate
This patch fix behaviour in such test scenario:
lseek(fd, BIG_OFFSET)
write(fd, buf, sizeof(buf))
truncate(BIG_OFFSET)
truncate(BIG_OFFSET + sizeof(buf))
read(fd, buf...)
Because of if file big enough(BIG_OFFSET) we start allocate space by block,
ordinary block size > page size, so we should zeroize the rest of block in
truncate(except last framgnet, about which VFS should care), to not get
garbage, when we extend file.
Also patch corrects conversion from pointer to block to physical block number,
this helps in case of not common used UFS types.
And add to debug output inode number.
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-03-17 05:38:09 +08:00
|
|
|
*phys = uspi->s_sbbase + tmp + blockoff;
|
2005-04-17 06:20:36 +08:00
|
|
|
result = NULL;
|
|
|
|
*err = 0;
|
|
|
|
*new = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inode->i_ctime = CURRENT_TIME_SEC;
|
|
|
|
if (IS_SYNC(inode))
|
|
|
|
ufs_sync_inode (inode);
|
|
|
|
mark_inode_dirty(inode);
|
2007-02-12 16:54:32 +08:00
|
|
|
UFSD("EXIT, result %llu\n", (unsigned long long)tmp + blockoff);
|
2005-04-17 06:20:36 +08:00
|
|
|
return result;
|
|
|
|
|
|
|
|
/* This part : To be implemented ....
|
|
|
|
Required only for writing, not required for READ-ONLY.
|
|
|
|
ufs2:
|
|
|
|
|
|
|
|
u2_block = ufs_fragstoblks(fragment);
|
|
|
|
u2_blockoff = ufs_fragnum(fragment);
|
|
|
|
p = ufsi->i_u1.u2_i_data + block;
|
|
|
|
goal = 0;
|
|
|
|
|
|
|
|
repeat2:
|
|
|
|
tmp = fs32_to_cpu(sb, *p);
|
|
|
|
lastfrag = ufsi->i_lastfrag;
|
|
|
|
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2006-06-25 20:47:27 +08:00
|
|
|
/**
|
|
|
|
* ufs_inode_getblock() - allocate new block
|
2014-08-09 05:21:08 +08:00
|
|
|
* @inode: pointer to inode
|
|
|
|
* @bh: pointer to block which hold "pointer" to new allocated block
|
|
|
|
* @fragment: number of `fragment' which hold pointer
|
2006-06-25 20:47:27 +08:00
|
|
|
* to new allocated block
|
2014-08-09 05:21:08 +08:00
|
|
|
* @new_fragment: number of new allocated fragment
|
2006-06-25 20:47:27 +08:00
|
|
|
* (block will hold this fragment and also uspi->s_fpb-1)
|
2014-08-09 05:21:08 +08:00
|
|
|
* @err: see ufs_inode_getfrag()
|
|
|
|
* @phys: see ufs_inode_getfrag()
|
|
|
|
* @new: see ufs_inode_getfrag()
|
|
|
|
* @locked_page: see ufs_inode_getfrag()
|
2006-06-25 20:47:27 +08:00
|
|
|
*/
|
|
|
|
static struct buffer_head *
|
|
|
|
ufs_inode_getblock(struct inode *inode, struct buffer_head *bh,
|
2007-02-12 16:54:32 +08:00
|
|
|
u64 fragment, sector_t new_fragment, int *err,
|
2006-06-25 20:47:27 +08:00
|
|
|
long *phys, int *new, struct page *locked_page)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-06-25 20:47:27 +08:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct buffer_head * result;
|
2007-02-12 16:54:32 +08:00
|
|
|
unsigned blockoff;
|
|
|
|
u64 tmp, goal, block;
|
|
|
|
void *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
block = ufs_fragstoblks (fragment);
|
|
|
|
blockoff = ufs_fragnum (fragment);
|
|
|
|
|
2007-02-12 16:54:32 +08:00
|
|
|
UFSD("ENTER, ino %lu, fragment %llu, new_fragment %llu, metadata %d\n",
|
|
|
|
inode->i_ino, (unsigned long long)fragment,
|
|
|
|
(unsigned long long)new_fragment, !phys);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
if (!bh)
|
|
|
|
goto out;
|
|
|
|
if (!buffer_uptodate(bh)) {
|
|
|
|
ll_rw_block (READ, 1, &bh);
|
|
|
|
wait_on_buffer (bh);
|
|
|
|
if (!buffer_uptodate(bh))
|
|
|
|
goto out;
|
|
|
|
}
|
2007-02-12 16:54:32 +08:00
|
|
|
if (uspi->fs_magic == UFS2_MAGIC)
|
|
|
|
p = (__fs64 *)bh->b_data + block;
|
|
|
|
else
|
|
|
|
p = (__fs32 *)bh->b_data + block;
|
2005-04-17 06:20:36 +08:00
|
|
|
repeat:
|
2007-02-12 16:54:32 +08:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tmp) {
|
2006-06-25 20:47:27 +08:00
|
|
|
if (!phys) {
|
2005-04-17 06:20:36 +08:00
|
|
|
result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
|
2007-02-12 16:54:32 +08:00
|
|
|
if (tmp == ufs_data_ptr_to_cpu(sb, p))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
brelse (result);
|
|
|
|
goto repeat;
|
|
|
|
} else {
|
[PATCH] ufs: zeroize the rest of block in truncate
This patch fix behaviour in such test scenario:
lseek(fd, BIG_OFFSET)
write(fd, buf, sizeof(buf))
truncate(BIG_OFFSET)
truncate(BIG_OFFSET + sizeof(buf))
read(fd, buf...)
Because of if file big enough(BIG_OFFSET) we start allocate space by block,
ordinary block size > page size, so we should zeroize the rest of block in
truncate(except last framgnet, about which VFS should care), to not get
garbage, when we extend file.
Also patch corrects conversion from pointer to block to physical block number,
this helps in case of not common used UFS types.
And add to debug output inode number.
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-03-17 05:38:09 +08:00
|
|
|
*phys = uspi->s_sbbase + tmp + blockoff;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:54:32 +08:00
|
|
|
if (block && (uspi->fs_magic == UFS2_MAGIC ?
|
|
|
|
(tmp = fs64_to_cpu(sb, ((__fs64 *)bh->b_data)[block-1])) :
|
|
|
|
(tmp = fs32_to_cpu(sb, ((__fs32 *)bh->b_data)[block-1]))))
|
2005-04-17 06:20:36 +08:00
|
|
|
goal = tmp + uspi->s_fpb;
|
|
|
|
else
|
|
|
|
goal = bh->b_blocknr + uspi->s_fpb;
|
2006-06-25 20:47:20 +08:00
|
|
|
tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment), goal,
|
|
|
|
uspi->s_fpb, err, locked_page);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!tmp) {
|
2007-02-12 16:54:32 +08:00
|
|
|
if (ufs_data_ptr_to_cpu(sb, p))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto repeat;
|
|
|
|
goto out;
|
2015-06-18 00:44:14 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-25 20:47:19 +08:00
|
|
|
|
2006-06-25 20:47:27 +08:00
|
|
|
if (!phys) {
|
[PATCH] ufs: zeroize the rest of block in truncate
This patch fix behaviour in such test scenario:
lseek(fd, BIG_OFFSET)
write(fd, buf, sizeof(buf))
truncate(BIG_OFFSET)
truncate(BIG_OFFSET + sizeof(buf))
read(fd, buf...)
Because of if file big enough(BIG_OFFSET) we start allocate space by block,
ordinary block size > page size, so we should zeroize the rest of block in
truncate(except last framgnet, about which VFS should care), to not get
garbage, when we extend file.
Also patch corrects conversion from pointer to block to physical block number,
this helps in case of not common used UFS types.
And add to debug output inode number.
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-03-17 05:38:09 +08:00
|
|
|
result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
[PATCH] ufs: zeroize the rest of block in truncate
This patch fix behaviour in such test scenario:
lseek(fd, BIG_OFFSET)
write(fd, buf, sizeof(buf))
truncate(BIG_OFFSET)
truncate(BIG_OFFSET + sizeof(buf))
read(fd, buf...)
Because of if file big enough(BIG_OFFSET) we start allocate space by block,
ordinary block size > page size, so we should zeroize the rest of block in
truncate(except last framgnet, about which VFS should care), to not get
garbage, when we extend file.
Also patch corrects conversion from pointer to block to physical block number,
this helps in case of not common used UFS types.
And add to debug output inode number.
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-03-17 05:38:09 +08:00
|
|
|
*phys = uspi->s_sbbase + tmp + blockoff;
|
2005-04-17 06:20:36 +08:00
|
|
|
*new = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
if (IS_SYNC(inode))
|
|
|
|
sync_dirty_buffer(bh);
|
|
|
|
inode->i_ctime = CURRENT_TIME_SEC;
|
|
|
|
mark_inode_dirty(inode);
|
2007-02-12 16:54:32 +08:00
|
|
|
UFSD("result %llu\n", (unsigned long long)tmp + blockoff);
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
|
|
|
brelse (bh);
|
2006-06-25 20:47:24 +08:00
|
|
|
UFSD("EXIT\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-06-25 20:47:27 +08:00
|
|
|
/**
|
2011-04-09 01:33:07 +08:00
|
|
|
* ufs_getfrag_block() - `get_block_t' function, interface between UFS and
|
2006-06-25 20:47:27 +08:00
|
|
|
* readpage, writepage and so on
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2015-06-18 00:44:14 +08:00
|
|
|
static int ufs_getfrag_block(struct inode *inode, sector_t fragment, struct buffer_head *bh_result, int create)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct super_block * sb = inode->i_sb;
|
2011-01-24 17:14:12 +08:00
|
|
|
struct ufs_sb_info * sbi = UFS_SB(sb);
|
|
|
|
struct ufs_sb_private_info * uspi = sbi->s_uspi;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct buffer_head * bh;
|
|
|
|
int ret, err, new;
|
|
|
|
unsigned long ptr,phys;
|
|
|
|
u64 phys64 = 0;
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!create) {
|
2015-06-18 00:02:56 +08:00
|
|
|
phys64 = ufs_frag_map(inode, fragment);
|
2006-06-29 17:24:29 +08:00
|
|
|
UFSD("phys64 = %llu\n", (unsigned long long)phys64);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (phys64)
|
|
|
|
map_bh(bh_result, sb, phys64);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This code entered only while writing ....? */
|
|
|
|
|
|
|
|
err = -EIO;
|
|
|
|
new = 0;
|
|
|
|
ret = 0;
|
|
|
|
bh = NULL;
|
|
|
|
|
2015-06-18 00:02:56 +08:00
|
|
|
mutex_lock(&UFS_I(inode)->truncate_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-25 20:47:24 +08:00
|
|
|
UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (fragment >
|
|
|
|
((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb)
|
|
|
|
<< uspi->s_fpbshift))
|
|
|
|
goto abort_too_big;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
ptr = fragment;
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* ok, these macros clean the logic up a bit and make
|
|
|
|
* it much more readable:
|
|
|
|
*/
|
|
|
|
#define GET_INODE_DATABLOCK(x) \
|
2007-01-30 05:19:54 +08:00
|
|
|
ufs_inode_getfrag(inode, x, fragment, 1, &err, &phys, &new,\
|
|
|
|
bh_result->b_page)
|
2005-04-17 06:20:36 +08:00
|
|
|
#define GET_INODE_PTR(x) \
|
2007-01-30 05:19:54 +08:00
|
|
|
ufs_inode_getfrag(inode, x, fragment, uspi->s_fpb, &err, NULL, NULL,\
|
|
|
|
bh_result->b_page)
|
2005-04-17 06:20:36 +08:00
|
|
|
#define GET_INDIRECT_DATABLOCK(x) \
|
2006-06-25 20:47:27 +08:00
|
|
|
ufs_inode_getblock(inode, bh, x, fragment, \
|
[PATCH] fix garbage instead of zeroes in UFS
Looks like this is the problem, which point Al Viro some time ago:
ufs's get_block callback allocates 16k of disk at a time, and links that
entire 16k into the file's metadata. But because get_block is called for only
a single buffer_head (a 2k buffer_head in this case?) we are only able to tell
the VFS that this 2k is buffer_new().
So when ufs_getfrag_block() is later called to map some more data in the file,
and when that data resides within the remaining 14k of this fragment,
ufs_getfrag_block() will incorrectly return a !buffer_new() buffer_head.
I don't see _right_ way to do nullification of whole block, if use inode
page cache, some pages may be outside of inode limits (inode size), and
will be lost; if use blockdev page cache it is possible to zero real data,
if later inode page cache will be used.
The simpliest way, as can I see usage of block device page cache, but not only
mark dirty, but also sync it during "nullification". I use my simple tests
collection, which I used for check that create,open,write,read,close works on
ufs, and I see that this patch makes ufs code 18% slower then before.
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2007-01-06 08:37:04 +08:00
|
|
|
&err, &phys, &new, bh_result->b_page)
|
2005-04-17 06:20:36 +08:00
|
|
|
#define GET_INDIRECT_PTR(x) \
|
2006-06-25 20:47:27 +08:00
|
|
|
ufs_inode_getblock(inode, bh, x, fragment, \
|
[PATCH] fix garbage instead of zeroes in UFS
Looks like this is the problem, which point Al Viro some time ago:
ufs's get_block callback allocates 16k of disk at a time, and links that
entire 16k into the file's metadata. But because get_block is called for only
a single buffer_head (a 2k buffer_head in this case?) we are only able to tell
the VFS that this 2k is buffer_new().
So when ufs_getfrag_block() is later called to map some more data in the file,
and when that data resides within the remaining 14k of this fragment,
ufs_getfrag_block() will incorrectly return a !buffer_new() buffer_head.
I don't see _right_ way to do nullification of whole block, if use inode
page cache, some pages may be outside of inode limits (inode size), and
will be lost; if use blockdev page cache it is possible to zero real data,
if later inode page cache will be used.
The simpliest way, as can I see usage of block device page cache, but not only
mark dirty, but also sync it during "nullification". I use my simple tests
collection, which I used for check that create,open,write,read,close works on
ufs, and I see that this patch makes ufs code 18% slower then before.
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2007-01-06 08:37:04 +08:00
|
|
|
&err, NULL, NULL, NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ptr < UFS_NDIR_FRAGMENT) {
|
|
|
|
bh = GET_INODE_DATABLOCK(ptr);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ptr -= UFS_NDIR_FRAGMENT;
|
|
|
|
if (ptr < (1 << (uspi->s_apbshift + uspi->s_fpbshift))) {
|
|
|
|
bh = GET_INODE_PTR(UFS_IND_FRAGMENT + (ptr >> uspi->s_apbshift));
|
|
|
|
goto get_indirect;
|
|
|
|
}
|
|
|
|
ptr -= 1 << (uspi->s_apbshift + uspi->s_fpbshift);
|
|
|
|
if (ptr < (1 << (uspi->s_2apbshift + uspi->s_fpbshift))) {
|
|
|
|
bh = GET_INODE_PTR(UFS_DIND_FRAGMENT + (ptr >> uspi->s_2apbshift));
|
|
|
|
goto get_double;
|
|
|
|
}
|
|
|
|
ptr -= 1 << (uspi->s_2apbshift + uspi->s_fpbshift);
|
|
|
|
bh = GET_INODE_PTR(UFS_TIND_FRAGMENT + (ptr >> uspi->s_3apbshift));
|
|
|
|
bh = GET_INDIRECT_PTR((ptr >> uspi->s_2apbshift) & uspi->s_apbmask);
|
|
|
|
get_double:
|
|
|
|
bh = GET_INDIRECT_PTR((ptr >> uspi->s_apbshift) & uspi->s_apbmask);
|
|
|
|
get_indirect:
|
|
|
|
bh = GET_INDIRECT_DATABLOCK(ptr & uspi->s_apbmask);
|
|
|
|
|
|
|
|
#undef GET_INODE_DATABLOCK
|
|
|
|
#undef GET_INODE_PTR
|
|
|
|
#undef GET_INDIRECT_DATABLOCK
|
|
|
|
#undef GET_INDIRECT_PTR
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (err)
|
|
|
|
goto abort;
|
|
|
|
if (new)
|
|
|
|
set_buffer_new(bh_result);
|
|
|
|
map_bh(bh_result, sb, phys);
|
|
|
|
abort:
|
2015-06-18 00:02:56 +08:00
|
|
|
mutex_unlock(&UFS_I(inode)->truncate_mutex);
|
2011-01-24 17:14:12 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
|
|
|
|
abort_too_big:
|
|
|
|
ufs_warning(sb, "ufs_get_block", "block > big");
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ufs_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
return block_write_full_page(page,ufs_getfrag_block,wbc);
|
|
|
|
}
|
2007-10-16 16:25:19 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int ufs_readpage(struct file *file, struct page *page)
|
|
|
|
{
|
|
|
|
return block_read_full_page(page,ufs_getfrag_block);
|
|
|
|
}
|
2007-10-16 16:25:19 +08:00
|
|
|
|
2010-06-04 17:29:56 +08:00
|
|
|
int ufs_prepare_chunk(struct page *page, loff_t pos, unsigned len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-06-04 17:29:57 +08:00
|
|
|
return __block_write_begin(page, pos, len, ufs_getfrag_block);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-10-16 16:25:19 +08:00
|
|
|
|
2015-06-18 00:44:14 +08:00
|
|
|
static void ufs_truncate_blocks(struct inode *);
|
|
|
|
|
2012-12-15 18:45:14 +08:00
|
|
|
static void ufs_write_failed(struct address_space *mapping, loff_t to)
|
|
|
|
{
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
2015-06-17 06:06:40 +08:00
|
|
|
if (to > inode->i_size) {
|
2013-09-13 06:13:56 +08:00
|
|
|
truncate_pagecache(inode, inode->i_size);
|
2015-06-17 06:06:40 +08:00
|
|
|
ufs_truncate_blocks(inode);
|
|
|
|
}
|
2012-12-15 18:45:14 +08:00
|
|
|
}
|
|
|
|
|
2007-10-16 16:25:19 +08:00
|
|
|
static int ufs_write_begin(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned flags,
|
|
|
|
struct page **pagep, void **fsdata)
|
|
|
|
{
|
2010-06-04 17:29:58 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = block_write_begin(mapping, pos, len, flags, pagep,
|
2010-06-04 17:29:56 +08:00
|
|
|
ufs_getfrag_block);
|
2012-12-15 18:45:14 +08:00
|
|
|
if (unlikely(ret))
|
|
|
|
ufs_write_failed(mapping, pos + len);
|
2010-06-04 17:29:58 +08:00
|
|
|
|
|
|
|
return ret;
|
2007-10-16 16:25:19 +08:00
|
|
|
}
|
|
|
|
|
2015-06-17 06:06:40 +08:00
|
|
|
static int ufs_write_end(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned copied,
|
|
|
|
struct page *page, void *fsdata)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
|
|
|
|
if (ret < len)
|
|
|
|
ufs_write_failed(mapping, pos + len);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static sector_t ufs_bmap(struct address_space *mapping, sector_t block)
|
|
|
|
{
|
|
|
|
return generic_block_bmap(mapping,block,ufs_getfrag_block);
|
|
|
|
}
|
2007-10-16 16:25:19 +08:00
|
|
|
|
2006-06-28 19:26:44 +08:00
|
|
|
const struct address_space_operations ufs_aops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.readpage = ufs_readpage,
|
|
|
|
.writepage = ufs_writepage,
|
2007-10-16 16:25:19 +08:00
|
|
|
.write_begin = ufs_write_begin,
|
2015-06-17 06:06:40 +08:00
|
|
|
.write_end = ufs_write_end,
|
2005-04-17 06:20:36 +08:00
|
|
|
.bmap = ufs_bmap
|
|
|
|
};
|
|
|
|
|
2006-06-25 20:47:21 +08:00
|
|
|
static void ufs_set_inode_ops(struct inode *inode)
|
|
|
|
{
|
|
|
|
if (S_ISREG(inode->i_mode)) {
|
|
|
|
inode->i_op = &ufs_file_inode_operations;
|
|
|
|
inode->i_fop = &ufs_file_operations;
|
|
|
|
inode->i_mapping->a_ops = &ufs_aops;
|
|
|
|
} else if (S_ISDIR(inode->i_mode)) {
|
|
|
|
inode->i_op = &ufs_dir_inode_operations;
|
|
|
|
inode->i_fop = &ufs_dir_operations;
|
|
|
|
inode->i_mapping->a_ops = &ufs_aops;
|
|
|
|
} else if (S_ISLNK(inode->i_mode)) {
|
2015-05-02 22:28:56 +08:00
|
|
|
if (!inode->i_blocks) {
|
2006-06-25 20:47:21 +08:00
|
|
|
inode->i_op = &ufs_fast_symlink_inode_operations;
|
2015-05-02 22:28:56 +08:00
|
|
|
inode->i_link = (char *)UFS_I(inode)->i_u1.i_symlink;
|
|
|
|
} else {
|
2010-04-15 06:56:58 +08:00
|
|
|
inode->i_op = &ufs_symlink_inode_operations;
|
2006-06-25 20:47:21 +08:00
|
|
|
inode->i_mapping->a_ops = &ufs_aops;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
init_special_inode(inode, inode->i_mode,
|
|
|
|
ufs_get_inode_dev(inode->i_sb, UFS_I(inode)));
|
|
|
|
}
|
|
|
|
|
2007-04-17 13:53:24 +08:00
|
|
|
static int ufs1_read_inode(struct inode *inode, struct ufs_inode *ufs_inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
2006-06-27 17:53:59 +08:00
|
|
|
struct super_block *sb = inode->i_sb;
|
2011-07-26 14:49:13 +08:00
|
|
|
umode_t mode;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy data to the in-core inode.
|
|
|
|
*/
|
|
|
|
inode->i_mode = mode = fs16_to_cpu(sb, ufs_inode->ui_mode);
|
2011-10-28 20:13:29 +08:00
|
|
|
set_nlink(inode, fs16_to_cpu(sb, ufs_inode->ui_nlink));
|
2007-04-17 13:53:24 +08:00
|
|
|
if (inode->i_nlink == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ufs_error (sb, "ufs_read_inode", "inode %lu has zero nlink\n", inode->i_ino);
|
2007-04-17 13:53:24 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Linux now has 32-bit uid and gid, so we can support EFT.
|
|
|
|
*/
|
2012-02-11 04:21:22 +08:00
|
|
|
i_uid_write(inode, ufs_get_inode_uid(sb, ufs_inode));
|
|
|
|
i_gid_write(inode, ufs_get_inode_gid(sb, ufs_inode));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
inode->i_size = fs64_to_cpu(sb, ufs_inode->ui_size);
|
|
|
|
inode->i_atime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_atime.tv_sec);
|
|
|
|
inode->i_ctime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_ctime.tv_sec);
|
|
|
|
inode->i_mtime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_mtime.tv_sec);
|
|
|
|
inode->i_mtime.tv_nsec = 0;
|
|
|
|
inode->i_atime.tv_nsec = 0;
|
|
|
|
inode->i_ctime.tv_nsec = 0;
|
|
|
|
inode->i_blocks = fs32_to_cpu(sb, ufs_inode->ui_blocks);
|
2007-02-12 16:54:31 +08:00
|
|
|
inode->i_generation = fs32_to_cpu(sb, ufs_inode->ui_gen);
|
2005-04-17 06:20:36 +08:00
|
|
|
ufsi->i_flags = fs32_to_cpu(sb, ufs_inode->ui_flags);
|
|
|
|
ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
|
|
|
|
ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
|
2006-06-27 17:53:59 +08:00
|
|
|
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(ufsi->i_u1.i_data, &ufs_inode->ui_u2.ui_addr,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_addr));
|
2006-06-25 20:47:25 +08:00
|
|
|
} else {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(ufsi->i_u1.i_symlink, ufs_inode->ui_u2.ui_symlink,
|
2009-01-09 06:43:50 +08:00
|
|
|
sizeof(ufs_inode->ui_u2.ui_symlink) - 1);
|
|
|
|
ufsi->i_u1.i_symlink[sizeof(ufs_inode->ui_u2.ui_symlink) - 1] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-17 13:53:24 +08:00
|
|
|
return 0;
|
2006-06-27 17:53:59 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-17 13:53:24 +08:00
|
|
|
static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode)
|
2006-06-27 17:53:59 +08:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
|
|
|
struct super_block *sb = inode->i_sb;
|
2011-07-26 14:49:13 +08:00
|
|
|
umode_t mode;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-25 20:47:24 +08:00
|
|
|
UFSD("Reading ufs2 inode, ino %lu\n", inode->i_ino);
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copy data to the in-core inode.
|
|
|
|
*/
|
|
|
|
inode->i_mode = mode = fs16_to_cpu(sb, ufs2_inode->ui_mode);
|
2011-10-28 20:13:29 +08:00
|
|
|
set_nlink(inode, fs16_to_cpu(sb, ufs2_inode->ui_nlink));
|
2007-04-17 13:53:24 +08:00
|
|
|
if (inode->i_nlink == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ufs_error (sb, "ufs_read_inode", "inode %lu has zero nlink\n", inode->i_ino);
|
2007-04-17 13:53:24 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Linux now has 32-bit uid and gid, so we can support EFT.
|
|
|
|
*/
|
2012-02-11 04:21:22 +08:00
|
|
|
i_uid_write(inode, fs32_to_cpu(sb, ufs2_inode->ui_uid));
|
|
|
|
i_gid_write(inode, fs32_to_cpu(sb, ufs2_inode->ui_gid));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
inode->i_size = fs64_to_cpu(sb, ufs2_inode->ui_size);
|
2007-03-17 05:38:07 +08:00
|
|
|
inode->i_atime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_atime);
|
|
|
|
inode->i_ctime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_ctime);
|
|
|
|
inode->i_mtime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_mtime);
|
|
|
|
inode->i_atime.tv_nsec = fs32_to_cpu(sb, ufs2_inode->ui_atimensec);
|
|
|
|
inode->i_ctime.tv_nsec = fs32_to_cpu(sb, ufs2_inode->ui_ctimensec);
|
|
|
|
inode->i_mtime.tv_nsec = fs32_to_cpu(sb, ufs2_inode->ui_mtimensec);
|
2005-04-17 06:20:36 +08:00
|
|
|
inode->i_blocks = fs64_to_cpu(sb, ufs2_inode->ui_blocks);
|
2007-02-12 16:54:31 +08:00
|
|
|
inode->i_generation = fs32_to_cpu(sb, ufs2_inode->ui_gen);
|
2005-04-17 06:20:36 +08:00
|
|
|
ufsi->i_flags = fs32_to_cpu(sb, ufs2_inode->ui_flags);
|
|
|
|
/*
|
|
|
|
ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
|
|
|
|
ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(ufsi->i_u1.u2_i_data, &ufs2_inode->ui_u2.ui_addr,
|
|
|
|
sizeof(ufs2_inode->ui_u2.ui_addr));
|
2006-06-27 17:53:59 +08:00
|
|
|
} else {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(ufsi->i_u1.i_symlink, ufs2_inode->ui_u2.ui_symlink,
|
2009-01-09 06:43:50 +08:00
|
|
|
sizeof(ufs2_inode->ui_u2.ui_symlink) - 1);
|
|
|
|
ufsi->i_u1.i_symlink[sizeof(ufs2_inode->ui_u2.ui_symlink) - 1] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-17 13:53:24 +08:00
|
|
|
return 0;
|
2006-06-27 17:53:59 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 16:15:48 +08:00
|
|
|
struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
|
2006-06-27 17:53:59 +08:00
|
|
|
{
|
2008-02-07 16:15:48 +08:00
|
|
|
struct ufs_inode_info *ufsi;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2006-06-27 17:53:59 +08:00
|
|
|
struct buffer_head * bh;
|
2008-02-07 16:15:48 +08:00
|
|
|
struct inode *inode;
|
2007-04-17 13:53:24 +08:00
|
|
|
int err;
|
2006-06-27 17:53:59 +08:00
|
|
|
|
2008-02-07 16:15:48 +08:00
|
|
|
UFSD("ENTER, ino %lu\n", ino);
|
2006-06-27 17:53:59 +08:00
|
|
|
|
2008-02-07 16:15:48 +08:00
|
|
|
if (ino < UFS_ROOTINO || ino > (uspi->s_ncg * uspi->s_ipg)) {
|
2006-06-27 17:53:59 +08:00
|
|
|
ufs_warning(sb, "ufs_read_inode", "bad inode number (%lu)\n",
|
2008-02-07 16:15:48 +08:00
|
|
|
ino);
|
|
|
|
return ERR_PTR(-EIO);
|
2006-06-27 17:53:59 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 16:15:48 +08:00
|
|
|
inode = iget_locked(sb, ino);
|
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
if (!(inode->i_state & I_NEW))
|
|
|
|
return inode;
|
|
|
|
|
|
|
|
ufsi = UFS_I(inode);
|
|
|
|
|
2006-06-27 17:53:59 +08:00
|
|
|
bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino));
|
|
|
|
if (!bh) {
|
|
|
|
ufs_warning(sb, "ufs_read_inode", "unable to read inode %lu\n",
|
|
|
|
inode->i_ino);
|
|
|
|
goto bad_inode;
|
|
|
|
}
|
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
|
|
|
|
struct ufs2_inode *ufs2_inode = (struct ufs2_inode *)bh->b_data;
|
|
|
|
|
2007-04-17 13:53:24 +08:00
|
|
|
err = ufs2_read_inode(inode,
|
|
|
|
ufs2_inode + ufs_inotofsbo(inode->i_ino));
|
2006-06-27 17:53:59 +08:00
|
|
|
} else {
|
|
|
|
struct ufs_inode *ufs_inode = (struct ufs_inode *)bh->b_data;
|
|
|
|
|
2007-04-17 13:53:24 +08:00
|
|
|
err = ufs1_read_inode(inode,
|
|
|
|
ufs_inode + ufs_inotofsbo(inode->i_ino));
|
2006-06-27 17:53:59 +08:00
|
|
|
}
|
|
|
|
|
2007-04-17 13:53:24 +08:00
|
|
|
if (err)
|
|
|
|
goto bad_inode;
|
2006-06-27 17:53:59 +08:00
|
|
|
inode->i_version++;
|
|
|
|
ufsi->i_lastfrag =
|
|
|
|
(inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift;
|
|
|
|
ufsi->i_dir_start_lookup = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
ufsi->i_osync = 0;
|
|
|
|
|
2006-06-25 20:47:21 +08:00
|
|
|
ufs_set_inode_ops(inode);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
brelse(bh);
|
|
|
|
|
2006-06-25 20:47:24 +08:00
|
|
|
UFSD("EXIT\n");
|
2008-02-07 16:15:48 +08:00
|
|
|
unlock_new_inode(inode);
|
|
|
|
return inode;
|
2006-06-27 17:53:59 +08:00
|
|
|
|
|
|
|
bad_inode:
|
2008-02-07 16:15:48 +08:00
|
|
|
iget_failed(inode);
|
|
|
|
return ERR_PTR(-EIO);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-12 16:54:31 +08:00
|
|
|
static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-12 16:54:31 +08:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode);
|
|
|
|
ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink);
|
|
|
|
|
2012-02-11 04:21:22 +08:00
|
|
|
ufs_set_inode_uid(sb, ufs_inode, i_uid_read(inode));
|
|
|
|
ufs_set_inode_gid(sb, ufs_inode, i_gid_read(inode));
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size);
|
|
|
|
ufs_inode->ui_atime.tv_sec = cpu_to_fs32(sb, inode->i_atime.tv_sec);
|
|
|
|
ufs_inode->ui_atime.tv_usec = 0;
|
|
|
|
ufs_inode->ui_ctime.tv_sec = cpu_to_fs32(sb, inode->i_ctime.tv_sec);
|
|
|
|
ufs_inode->ui_ctime.tv_usec = 0;
|
|
|
|
ufs_inode->ui_mtime.tv_sec = cpu_to_fs32(sb, inode->i_mtime.tv_sec);
|
|
|
|
ufs_inode->ui_mtime.tv_usec = 0;
|
|
|
|
ufs_inode->ui_blocks = cpu_to_fs32(sb, inode->i_blocks);
|
|
|
|
ufs_inode->ui_flags = cpu_to_fs32(sb, ufsi->i_flags);
|
2007-02-12 16:54:31 +08:00
|
|
|
ufs_inode->ui_gen = cpu_to_fs32(sb, inode->i_generation);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-12 16:54:31 +08:00
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_UID_MASK) == UFS_UID_EFT) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ufs_inode->ui_u3.ui_sun.ui_shadow = cpu_to_fs32(sb, ufsi->i_shadow);
|
|
|
|
ufs_inode->ui_u3.ui_sun.ui_oeftflag = cpu_to_fs32(sb, ufsi->i_oeftflag);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
|
|
|
|
/* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
|
|
|
|
ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.i_data[0];
|
|
|
|
} else if (inode->i_blocks) {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.i_data,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_addr));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
else {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_symlink));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!inode->i_nlink)
|
|
|
|
memset (ufs_inode, 0, sizeof(struct ufs_inode));
|
2007-02-12 16:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ufs2_update_inode(struct inode *inode, struct ufs2_inode *ufs_inode)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
|
|
|
|
|
|
|
UFSD("ENTER\n");
|
|
|
|
ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode);
|
|
|
|
ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink);
|
|
|
|
|
2012-02-11 04:21:22 +08:00
|
|
|
ufs_inode->ui_uid = cpu_to_fs32(sb, i_uid_read(inode));
|
|
|
|
ufs_inode->ui_gid = cpu_to_fs32(sb, i_gid_read(inode));
|
2007-02-12 16:54:31 +08:00
|
|
|
|
|
|
|
ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size);
|
2007-03-17 05:38:07 +08:00
|
|
|
ufs_inode->ui_atime = cpu_to_fs64(sb, inode->i_atime.tv_sec);
|
|
|
|
ufs_inode->ui_atimensec = cpu_to_fs32(sb, inode->i_atime.tv_nsec);
|
|
|
|
ufs_inode->ui_ctime = cpu_to_fs64(sb, inode->i_ctime.tv_sec);
|
|
|
|
ufs_inode->ui_ctimensec = cpu_to_fs32(sb, inode->i_ctime.tv_nsec);
|
|
|
|
ufs_inode->ui_mtime = cpu_to_fs64(sb, inode->i_mtime.tv_sec);
|
|
|
|
ufs_inode->ui_mtimensec = cpu_to_fs32(sb, inode->i_mtime.tv_nsec);
|
2007-02-12 16:54:31 +08:00
|
|
|
|
|
|
|
ufs_inode->ui_blocks = cpu_to_fs64(sb, inode->i_blocks);
|
|
|
|
ufs_inode->ui_flags = cpu_to_fs32(sb, ufsi->i_flags);
|
|
|
|
ufs_inode->ui_gen = cpu_to_fs32(sb, inode->i_generation);
|
|
|
|
|
|
|
|
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
|
|
|
|
/* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
|
|
|
|
ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.u2_i_data[0];
|
|
|
|
} else if (inode->i_blocks) {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.u2_i_data,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_addr));
|
2007-02-12 16:54:31 +08:00
|
|
|
} else {
|
2009-01-09 06:43:49 +08:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_symlink));
|
2007-02-12 16:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!inode->i_nlink)
|
|
|
|
memset (ufs_inode, 0, sizeof(struct ufs2_inode));
|
|
|
|
UFSD("EXIT\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ufs_update_inode(struct inode * inode, int do_sync)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
struct buffer_head * bh;
|
|
|
|
|
|
|
|
UFSD("ENTER, ino %lu\n", inode->i_ino);
|
|
|
|
|
|
|
|
if (inode->i_ino < UFS_ROOTINO ||
|
|
|
|
inode->i_ino > (uspi->s_ncg * uspi->s_ipg)) {
|
|
|
|
ufs_warning (sb, "ufs_read_inode", "bad inode number (%lu)\n", inode->i_ino);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bh = sb_bread(sb, ufs_inotofsba(inode->i_ino));
|
|
|
|
if (!bh) {
|
|
|
|
ufs_warning (sb, "ufs_read_inode", "unable to read inode %lu\n", inode->i_ino);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (uspi->fs_magic == UFS2_MAGIC) {
|
|
|
|
struct ufs2_inode *ufs2_inode = (struct ufs2_inode *)bh->b_data;
|
|
|
|
|
|
|
|
ufs2_update_inode(inode,
|
|
|
|
ufs2_inode + ufs_inotofsbo(inode->i_ino));
|
|
|
|
} else {
|
|
|
|
struct ufs_inode *ufs_inode = (struct ufs_inode *) bh->b_data;
|
|
|
|
|
|
|
|
ufs1_update_inode(inode, ufs_inode + ufs_inotofsbo(inode->i_ino));
|
|
|
|
}
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
if (do_sync)
|
|
|
|
sync_dirty_buffer(bh);
|
|
|
|
brelse (bh);
|
2015-06-18 00:44:14 +08:00
|
|
|
|
2006-06-25 20:47:24 +08:00
|
|
|
UFSD("EXIT\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-05 16:21:37 +08:00
|
|
|
int ufs_write_inode(struct inode *inode, struct writeback_control *wbc)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-06-16 14:35:14 +08:00
|
|
|
return ufs_update_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ufs_sync_inode (struct inode *inode)
|
|
|
|
{
|
|
|
|
return ufs_update_inode (inode, 1);
|
|
|
|
}
|
|
|
|
|
2010-06-06 07:40:56 +08:00
|
|
|
void ufs_evict_inode(struct inode * inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-06-06 07:40:56 +08:00
|
|
|
int want_delete = 0;
|
|
|
|
|
|
|
|
if (!inode->i_nlink && !is_bad_inode(inode))
|
|
|
|
want_delete = 1;
|
2006-07-01 19:36:24 +08:00
|
|
|
|
2014-04-04 05:47:49 +08:00
|
|
|
truncate_inode_pages_final(&inode->i_data);
|
2010-06-06 07:40:56 +08:00
|
|
|
if (want_delete) {
|
|
|
|
inode->i_size = 0;
|
2015-06-17 06:04:16 +08:00
|
|
|
if (inode->i_blocks)
|
|
|
|
ufs_truncate_blocks(inode);
|
2010-06-06 07:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
invalidate_inode_buffers(inode);
|
2012-05-03 20:48:02 +08:00
|
|
|
clear_inode(inode);
|
2010-06-06 07:40:56 +08:00
|
|
|
|
2015-06-16 14:35:14 +08:00
|
|
|
if (want_delete)
|
2014-09-02 15:40:17 +08:00
|
|
|
ufs_free_inode(inode);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2015-06-18 00:44:14 +08:00
|
|
|
|
|
|
|
#define DIRECT_BLOCK ((inode->i_size + uspi->s_bsize - 1) >> uspi->s_bshift)
|
|
|
|
#define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift)
|
|
|
|
|
|
|
|
static void ufs_trunc_direct(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
void *p;
|
|
|
|
u64 frag1, frag2, frag3, frag4, block1, block2;
|
|
|
|
unsigned frag_to_free, free_count;
|
|
|
|
unsigned i, tmp;
|
|
|
|
|
|
|
|
UFSD("ENTER: ino %lu\n", inode->i_ino);
|
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
|
|
|
|
frag_to_free = 0;
|
|
|
|
free_count = 0;
|
|
|
|
|
|
|
|
frag1 = DIRECT_FRAGMENT;
|
|
|
|
frag4 = min_t(u64, UFS_NDIR_FRAGMENT, ufsi->i_lastfrag);
|
|
|
|
frag2 = ((frag1 & uspi->s_fpbmask) ? ((frag1 | uspi->s_fpbmask) + 1) : frag1);
|
|
|
|
frag3 = frag4 & ~uspi->s_fpbmask;
|
|
|
|
block1 = block2 = 0;
|
|
|
|
if (frag2 > frag3) {
|
|
|
|
frag2 = frag4;
|
|
|
|
frag3 = frag4 = 0;
|
|
|
|
} else if (frag2 < frag3) {
|
|
|
|
block1 = ufs_fragstoblks (frag2);
|
|
|
|
block2 = ufs_fragstoblks (frag3);
|
|
|
|
}
|
|
|
|
|
|
|
|
UFSD("ino %lu, frag1 %llu, frag2 %llu, block1 %llu, block2 %llu,"
|
|
|
|
" frag3 %llu, frag4 %llu\n", inode->i_ino,
|
|
|
|
(unsigned long long)frag1, (unsigned long long)frag2,
|
|
|
|
(unsigned long long)block1, (unsigned long long)block2,
|
|
|
|
(unsigned long long)frag3, (unsigned long long)frag4);
|
|
|
|
|
|
|
|
if (frag1 >= frag2)
|
|
|
|
goto next1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free first free fragments
|
|
|
|
*/
|
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, ufs_fragstoblks(frag1));
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!tmp )
|
|
|
|
ufs_panic (sb, "ufs_trunc_direct", "internal error");
|
|
|
|
frag2 -= frag1;
|
|
|
|
frag1 = ufs_fragnum (frag1);
|
|
|
|
|
|
|
|
ufs_free_fragments(inode, tmp + frag1, frag2);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
frag_to_free = tmp + frag1;
|
|
|
|
|
|
|
|
next1:
|
|
|
|
/*
|
|
|
|
* Free whole blocks
|
|
|
|
*/
|
|
|
|
for (i = block1 ; i < block2; i++) {
|
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, i);
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!tmp)
|
|
|
|
continue;
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
|
|
|
|
|
|
|
if (free_count == 0) {
|
|
|
|
frag_to_free = tmp;
|
|
|
|
free_count = uspi->s_fpb;
|
|
|
|
} else if (free_count > 0 && frag_to_free == tmp - free_count)
|
|
|
|
free_count += uspi->s_fpb;
|
|
|
|
else {
|
|
|
|
ufs_free_blocks (inode, frag_to_free, free_count);
|
|
|
|
frag_to_free = tmp;
|
|
|
|
free_count = uspi->s_fpb;
|
|
|
|
}
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free_count > 0)
|
|
|
|
ufs_free_blocks (inode, frag_to_free, free_count);
|
|
|
|
|
|
|
|
if (frag3 >= frag4)
|
|
|
|
goto next3;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free last free fragments
|
|
|
|
*/
|
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, ufs_fragstoblks(frag3));
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!tmp )
|
|
|
|
ufs_panic(sb, "ufs_truncate_direct", "internal error");
|
|
|
|
frag4 = ufs_fragnum (frag4);
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
|
|
|
|
|
|
|
ufs_free_fragments (inode, tmp, frag4);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
next3:
|
|
|
|
|
|
|
|
UFSD("EXIT: ino %lu\n", inode->i_ino);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-17 13:54:58 +08:00
|
|
|
static void ufs_trunc_indirect(struct inode *inode, unsigned from, void *p)
|
2015-06-18 00:44:14 +08:00
|
|
|
{
|
2015-06-17 13:54:58 +08:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2015-06-18 00:44:14 +08:00
|
|
|
struct ufs_buffer_head * ind_ubh;
|
|
|
|
void *ind;
|
2015-06-17 13:54:58 +08:00
|
|
|
u64 tmp, frag_to_free = 0;
|
|
|
|
unsigned free_count = 0;
|
|
|
|
bool to_free = !from;
|
|
|
|
unsigned i;
|
2015-06-18 00:44:14 +08:00
|
|
|
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!tmp)
|
|
|
|
return;
|
|
|
|
ind_ubh = ubh_bread(sb, tmp, uspi->s_bsize);
|
|
|
|
if (!ind_ubh) {
|
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-17 13:54:58 +08:00
|
|
|
for (i = from; i < uspi->s_apb; i++) {
|
2015-06-18 00:44:14 +08:00
|
|
|
ind = ubh_get_data_ptr(uspi, ind_ubh, i);
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, ind);
|
|
|
|
if (!tmp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, ind);
|
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ubh_mark_buffer_dirty(ind_ubh);
|
|
|
|
if (free_count == 0) {
|
|
|
|
frag_to_free = tmp;
|
|
|
|
free_count = uspi->s_fpb;
|
|
|
|
} else if (free_count > 0 && frag_to_free == tmp - free_count)
|
|
|
|
free_count += uspi->s_fpb;
|
|
|
|
else {
|
|
|
|
ufs_free_blocks (inode, frag_to_free, free_count);
|
|
|
|
frag_to_free = tmp;
|
|
|
|
free_count = uspi->s_fpb;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free_count > 0) {
|
|
|
|
ufs_free_blocks (inode, frag_to_free, free_count);
|
|
|
|
}
|
2015-06-17 13:54:58 +08:00
|
|
|
if (to_free) {
|
2015-06-18 00:44:14 +08:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
|
|
|
|
|
|
|
ubh_bforget(ind_ubh);
|
|
|
|
ufs_free_blocks (inode, tmp, uspi->s_fpb);
|
|
|
|
mark_inode_dirty(inode);
|
2015-06-17 13:54:58 +08:00
|
|
|
return;
|
2015-06-18 00:44:14 +08:00
|
|
|
}
|
2015-06-17 13:54:58 +08:00
|
|
|
if (IS_SYNC(inode) && ubh_buffer_dirty(ind_ubh))
|
2015-06-18 00:44:14 +08:00
|
|
|
ubh_sync_block(ind_ubh);
|
|
|
|
ubh_brelse (ind_ubh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ufs_trunc_dindirect(struct inode *inode, u64 offset, void *p)
|
|
|
|
{
|
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_buffer_head *dind_bh;
|
|
|
|
u64 i, tmp, dindirect_block;
|
|
|
|
void *dind;
|
2015-06-17 13:54:58 +08:00
|
|
|
unsigned from;
|
2015-06-18 00:44:14 +08:00
|
|
|
|
|
|
|
UFSD("ENTER: ino %lu\n", inode->i_ino);
|
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
|
2015-06-17 13:54:58 +08:00
|
|
|
if (DIRECT_BLOCK <= offset) {
|
|
|
|
dindirect_block = 0;
|
|
|
|
from = 0;
|
|
|
|
} else {
|
|
|
|
dindirect_block = (DIRECT_BLOCK - offset) >> uspi->s_apbshift;
|
|
|
|
from = (DIRECT_BLOCK - offset) & uspi->s_apbmask;
|
|
|
|
}
|
2015-06-18 00:44:14 +08:00
|
|
|
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!tmp)
|
|
|
|
return;
|
|
|
|
dind_bh = ubh_bread(sb, tmp, uspi->s_bsize);
|
|
|
|
if (!dind_bh) {
|
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-17 13:54:58 +08:00
|
|
|
for (i = dindirect_block ; i < uspi->s_apb ; i++, from = 0) {
|
2015-06-18 00:44:14 +08:00
|
|
|
dind = ubh_get_data_ptr(uspi, dind_bh, i);
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, dind);
|
|
|
|
if (!tmp)
|
|
|
|
continue;
|
2015-06-17 13:54:58 +08:00
|
|
|
ufs_trunc_indirect(inode, from, dind);
|
2015-06-18 00:44:14 +08:00
|
|
|
ubh_mark_buffer_dirty(dind_bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < uspi->s_apb; i++)
|
|
|
|
if (!ufs_is_data_ptr_zero(uspi,
|
|
|
|
ubh_get_data_ptr(uspi, dind_bh, i)))
|
|
|
|
break;
|
|
|
|
if (i >= uspi->s_apb) {
|
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
|
|
|
|
|
|
|
ubh_bforget(dind_bh);
|
|
|
|
ufs_free_blocks(inode, tmp, uspi->s_fpb);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
dind_bh = NULL;
|
|
|
|
}
|
|
|
|
if (IS_SYNC(inode) && dind_bh && ubh_buffer_dirty(dind_bh))
|
|
|
|
ubh_sync_block(dind_bh);
|
|
|
|
ubh_brelse (dind_bh);
|
|
|
|
|
|
|
|
UFSD("EXIT: ino %lu\n", inode->i_ino);
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:45:07 +08:00
|
|
|
static void ufs_trunc_tindirect(struct inode *inode, u64 offset)
|
2015-06-18 00:44:14 +08:00
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
|
|
|
struct ufs_buffer_head * tind_bh;
|
2015-06-19 01:45:07 +08:00
|
|
|
u64 tmp;
|
2015-06-18 00:44:14 +08:00
|
|
|
void *tind, *p;
|
2015-06-19 01:45:07 +08:00
|
|
|
bool free_it = !offset;
|
|
|
|
unsigned tindirect_block = offset >> uspi->s_2apbshift;
|
|
|
|
unsigned i;
|
2015-06-18 00:44:14 +08:00
|
|
|
|
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, UFS_TIND_BLOCK);
|
|
|
|
if (!(tmp = ufs_data_ptr_to_cpu(sb, p)))
|
|
|
|
return;
|
|
|
|
tind_bh = ubh_bread (sb, tmp, uspi->s_bsize);
|
|
|
|
if (!tind_bh) {
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = tindirect_block ; i < uspi->s_apb ; i++) {
|
|
|
|
tind = ubh_get_data_ptr(uspi, tind_bh, i);
|
|
|
|
ufs_trunc_dindirect(inode, UFS_NDADDR +
|
|
|
|
uspi->s_apb + ((i + 1) << uspi->s_2apbshift), tind);
|
|
|
|
ubh_mark_buffer_dirty(tind_bh);
|
|
|
|
}
|
2015-06-19 01:45:07 +08:00
|
|
|
if (free_it) {
|
2015-06-18 00:44:14 +08:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
|
|
|
|
|
|
|
ubh_bforget(tind_bh);
|
|
|
|
ufs_free_blocks(inode, tmp, uspi->s_fpb);
|
|
|
|
mark_inode_dirty(inode);
|
2015-06-19 01:45:07 +08:00
|
|
|
return;
|
2015-06-18 00:44:14 +08:00
|
|
|
}
|
2015-06-19 01:45:07 +08:00
|
|
|
if (IS_SYNC(inode) && ubh_buffer_dirty(tind_bh))
|
2015-06-18 00:44:14 +08:00
|
|
|
ubh_sync_block(tind_bh);
|
|
|
|
ubh_brelse (tind_bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ufs_alloc_lastblock(struct inode *inode, loff_t size)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct address_space *mapping = inode->i_mapping;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
unsigned i, end;
|
|
|
|
sector_t lastfrag;
|
|
|
|
struct page *lastpage;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
u64 phys64;
|
|
|
|
|
|
|
|
lastfrag = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
|
|
|
|
|
|
|
|
if (!lastfrag)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
lastfrag--;
|
|
|
|
|
|
|
|
lastpage = ufs_get_locked_page(mapping, lastfrag >>
|
|
|
|
(PAGE_CACHE_SHIFT - inode->i_blkbits));
|
|
|
|
if (IS_ERR(lastpage)) {
|
|
|
|
err = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = lastfrag & ((1 << (PAGE_CACHE_SHIFT - inode->i_blkbits)) - 1);
|
|
|
|
bh = page_buffers(lastpage);
|
|
|
|
for (i = 0; i < end; ++i)
|
|
|
|
bh = bh->b_this_page;
|
|
|
|
|
|
|
|
|
|
|
|
err = ufs_getfrag_block(inode, lastfrag, bh, 1);
|
|
|
|
|
|
|
|
if (unlikely(err))
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
if (buffer_new(bh)) {
|
|
|
|
clear_buffer_new(bh);
|
|
|
|
unmap_underlying_metadata(bh->b_bdev,
|
|
|
|
bh->b_blocknr);
|
|
|
|
/*
|
|
|
|
* we do not zeroize fragment, because of
|
|
|
|
* if it maped to hole, it already contains zeroes
|
|
|
|
*/
|
|
|
|
set_buffer_uptodate(bh);
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
set_page_dirty(lastpage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastfrag >= UFS_IND_FRAGMENT) {
|
|
|
|
end = uspi->s_fpb - ufs_fragnum(lastfrag) - 1;
|
|
|
|
phys64 = bh->b_blocknr + 1;
|
|
|
|
for (i = 0; i < end; ++i) {
|
|
|
|
bh = sb_getblk(sb, i + phys64);
|
|
|
|
lock_buffer(bh);
|
|
|
|
memset(bh->b_data, 0, sb->s_blocksize);
|
|
|
|
set_buffer_uptodate(bh);
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
unlock_buffer(bh);
|
|
|
|
sync_dirty_buffer(bh);
|
|
|
|
brelse(bh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out_unlock:
|
|
|
|
ufs_put_locked_page(lastpage);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __ufs_truncate_blocks(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2015-06-17 13:54:58 +08:00
|
|
|
unsigned offsets[4] = {0,};
|
2015-06-17 13:10:03 +08:00
|
|
|
int depth = ufs_block_to_path(inode, DIRECT_BLOCK, offsets);
|
2015-06-18 00:44:14 +08:00
|
|
|
|
|
|
|
mutex_lock(&ufsi->truncate_mutex);
|
2015-06-17 13:10:03 +08:00
|
|
|
switch (depth) {
|
|
|
|
case 1:
|
|
|
|
ufs_trunc_direct(inode);
|
|
|
|
case 2:
|
2015-06-17 13:54:58 +08:00
|
|
|
ufs_trunc_indirect(inode, offsets[1],
|
2015-06-18 00:44:14 +08:00
|
|
|
ufs_get_direct_data_ptr(uspi, ufsi, UFS_IND_BLOCK));
|
2015-06-17 13:10:03 +08:00
|
|
|
case 3:
|
|
|
|
ufs_trunc_dindirect(inode, UFS_IND_BLOCK + uspi->s_apb,
|
2015-06-18 00:44:14 +08:00
|
|
|
ufs_get_direct_data_ptr(uspi, ufsi, UFS_DIND_BLOCK));
|
2015-06-19 01:45:07 +08:00
|
|
|
ufs_trunc_tindirect(inode, 0);
|
|
|
|
break;
|
2015-06-17 13:10:03 +08:00
|
|
|
case 4:
|
2015-06-19 01:45:07 +08:00
|
|
|
ufs_trunc_tindirect(inode, DIRECT_BLOCK - UFS_NDADDR - uspi->s_apb - uspi->s_2apb);
|
2015-06-17 13:10:03 +08:00
|
|
|
}
|
2015-06-18 00:44:14 +08:00
|
|
|
ufsi->i_lastfrag = DIRECT_FRAGMENT;
|
|
|
|
mutex_unlock(&ufsi->truncate_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ufs_truncate(struct inode *inode, loff_t size)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
UFSD("ENTER: ino %lu, i_size: %llu, old_i_size: %llu\n",
|
|
|
|
inode->i_ino, (unsigned long long)size,
|
|
|
|
(unsigned long long)i_size_read(inode));
|
|
|
|
|
|
|
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
|
|
|
|
S_ISLNK(inode->i_mode)))
|
|
|
|
return -EINVAL;
|
|
|
|
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
err = ufs_alloc_lastblock(inode, size);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
block_truncate_page(inode->i_mapping, size, ufs_getfrag_block);
|
|
|
|
|
|
|
|
truncate_setsize(inode, size);
|
|
|
|
|
|
|
|
__ufs_truncate_blocks(inode);
|
|
|
|
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
out:
|
|
|
|
UFSD("EXIT: err %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ufs_truncate_blocks(struct inode *inode)
|
|
|
|
{
|
|
|
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
|
|
|
|
S_ISLNK(inode->i_mode)))
|
|
|
|
return;
|
|
|
|
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
|
|
|
|
return;
|
|
|
|
__ufs_truncate_blocks(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ufs_setattr(struct dentry *dentry, struct iattr *attr)
|
|
|
|
{
|
|
|
|
struct inode *inode = d_inode(dentry);
|
|
|
|
unsigned int ia_valid = attr->ia_valid;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = inode_change_ok(inode, attr);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
|
|
|
|
error = ufs_truncate(inode, attr->ia_size);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
setattr_copy(inode, attr);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct inode_operations ufs_file_inode_operations = {
|
|
|
|
.setattr = ufs_setattr,
|
|
|
|
};
|