License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00: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
|
|
|
|
*/
|
|
|
|
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#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>
|
2023-12-15 20:02:43 +00:00
|
|
|
#include <linux/mpage.h>
|
2010-03-05 08:21:37 +00:00
|
|
|
#include <linux/writeback.h>
|
2017-12-11 11:35:18 +00:00
|
|
|
#include <linux/iversion.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:21:31 +00:00
|
|
|
#include "ufs_fs.h"
|
2007-10-17 06:26:51 +00:00
|
|
|
#include "ufs.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "swab.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2015-06-04 18:13:14 +00:00
|
|
|
static int ufs_block_to_path(struct inode *inode, sector_t i_block, unsigned offsets[4])
|
2005-04-16 22:20:36 +00: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 12:47:24 +00:00
|
|
|
UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
|
2009-06-17 23:26:28 +00:00
|
|
|
if (i_block < direct_blocks) {
|
2005-04-16 22:20:36 +00: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-17 16:02:56 +00: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-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Returns the location of the fragment from
|
2011-03-31 01:57:33 +00:00
|
|
|
* the beginning of the filesystem.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2015-06-04 18:27:23 +00:00
|
|
|
static u64 ufs_frag_map(struct inode *inode, unsigned offsets[4], int depth)
|
2005-04-16 22:20:36 +00: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-17 16:02:56 +00:00
|
|
|
Indirect chain[4], *q = chain;
|
2015-06-04 18:27:23 +00:00
|
|
|
unsigned *p;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned flags = UFS_SB(sb)->s_flags;
|
2015-06-17 16:02:56 +00:00
|
|
|
u64 res = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-29 09:24:29 +00: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-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (depth == 0)
|
2015-06-17 16:02:56 +00:00
|
|
|
goto no_block;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-17 16:02:56 +00:00
|
|
|
again:
|
2005-04-16 22:20:36 +00:00
|
|
|
p = offsets;
|
|
|
|
|
|
|
|
if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
|
|
|
|
goto ufs2;
|
|
|
|
|
2015-06-17 16:02:56 +00:00
|
|
|
if (!grow_chain32(ufsi, NULL, &ufsi->i_u1.i_data[*p++], chain, q))
|
|
|
|
goto changed;
|
|
|
|
if (!q->key32)
|
|
|
|
goto no_block;
|
2005-04-16 22:20:36 +00:00
|
|
|
while (--depth) {
|
2015-06-17 16:02:56 +00:00
|
|
|
__fs32 *ptr;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct buffer_head *bh;
|
2015-06-04 18:13:14 +00:00
|
|
|
unsigned n = *p++;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-17 16:02:56 +00:00
|
|
|
bh = sb_bread(sb, uspi->s_sbbase +
|
|
|
|
fs32_to_cpu(sb, q->key32) + (n>>shift));
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!bh)
|
2015-06-17 16:02:56 +00: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-16 22:20:36 +00:00
|
|
|
}
|
2015-06-17 16:02:56 +00:00
|
|
|
res = fs32_to_cpu(sb, q->key32);
|
|
|
|
goto found;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-17 16:02:56 +00: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-16 22:20:36 +00:00
|
|
|
|
|
|
|
while (--depth) {
|
2015-06-17 16:02:56 +00:00
|
|
|
__fs64 *ptr;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct buffer_head *bh;
|
2015-06-04 18:13:14 +00:00
|
|
|
unsigned n = *p++;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-17 16:02:56 +00:00
|
|
|
bh = sb_bread(sb, uspi->s_sbbase +
|
|
|
|
fs64_to_cpu(sb, q->key64) + (n>>shift));
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!bh)
|
2015-06-17 16:02:56 +00: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:
|
2015-06-04 18:27:23 +00:00
|
|
|
res += uspi->s_sbbase;
|
2015-06-17 16:02:56 +00:00
|
|
|
no_block:
|
|
|
|
while (q > chain) {
|
|
|
|
brelse(q->bh);
|
|
|
|
q--;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2015-06-17 16:02:56 +00:00
|
|
|
return res;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-17 16:02:56 +00:00
|
|
|
changed:
|
|
|
|
while (q > chain) {
|
|
|
|
brelse(q->bh);
|
|
|
|
q--;
|
|
|
|
}
|
|
|
|
goto again;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 17:40:25 +00:00
|
|
|
/*
|
|
|
|
* Unpacking tails: we have a file with partial final block and
|
|
|
|
* we had been asked to extend it. If the fragment being written
|
|
|
|
* is within the same block, we need to extend the tail just to cover
|
|
|
|
* that fragment. Otherwise the tail is extended to full block.
|
|
|
|
*
|
|
|
|
* Note that we might need to create a _new_ tail, but that will
|
|
|
|
* be handled elsewhere; this is strictly for resizing old
|
|
|
|
* ones.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
ufs_extend_tail(struct inode *inode, u64 writes_to,
|
2024-10-05 18:02:05 +00:00
|
|
|
int *err, struct folio *locked_folio)
|
2015-06-19 17:40:25 +00: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;
|
|
|
|
unsigned lastfrag = ufsi->i_lastfrag; /* it's a short file, so unsigned is enough */
|
|
|
|
unsigned block = ufs_fragstoblks(lastfrag);
|
|
|
|
unsigned new_size;
|
|
|
|
void *p;
|
|
|
|
u64 tmp;
|
|
|
|
|
|
|
|
if (writes_to < (lastfrag | uspi->s_fpbmask))
|
|
|
|
new_size = (writes_to & uspi->s_fpbmask) + 1;
|
|
|
|
else
|
|
|
|
new_size = uspi->s_fpb;
|
|
|
|
|
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, block);
|
|
|
|
tmp = ufs_new_fragments(inode, p, lastfrag, ufs_data_ptr_to_cpu(sb, p),
|
2017-06-09 03:27:12 +00:00
|
|
|
new_size - (lastfrag & uspi->s_fpbmask), err,
|
2024-10-05 18:02:07 +00:00
|
|
|
locked_folio);
|
2015-06-19 17:40:25 +00:00
|
|
|
return tmp != 0;
|
|
|
|
}
|
|
|
|
|
2006-06-25 12:47:27 +00:00
|
|
|
/**
|
|
|
|
* ufs_inode_getfrag() - allocate new fragment(s)
|
2014-08-08 21:21:08 +00:00
|
|
|
* @inode: pointer to inode
|
2015-06-19 17:53:52 +00:00
|
|
|
* @index: number of block pointer within the inode's array.
|
2014-08-08 21:21:08 +00:00
|
|
|
* @new_fragment: number of new allocated fragment(s)
|
|
|
|
* @err: we set it if something wrong
|
|
|
|
* @new: we set it if we allocate new block
|
2024-10-05 18:02:07 +00:00
|
|
|
* @locked_folio: for ufs_new_fragments()
|
2006-06-25 12:47:27 +00:00
|
|
|
*/
|
2024-10-05 18:02:06 +00:00
|
|
|
static u64 ufs_inode_getfrag(struct inode *inode, unsigned index,
|
2015-06-19 17:53:52 +00:00
|
|
|
sector_t new_fragment, int *err,
|
2024-10-05 18:02:06 +00:00
|
|
|
int *new, struct folio *locked_folio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
2006-06-25 12:47:27 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2015-06-19 17:53:52 +00:00
|
|
|
u64 tmp, goal, lastfrag;
|
2015-06-19 17:40:25 +00:00
|
|
|
unsigned nfrags = uspi->s_fpb;
|
|
|
|
void *p;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-19 17:53:52 +00:00
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, index);
|
2007-02-12 08:54:32 +00:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
2015-06-19 17:40:25 +00:00
|
|
|
if (tmp)
|
|
|
|
goto out;
|
2007-02-12 08:54:32 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
lastfrag = ufsi->i_lastfrag;
|
|
|
|
|
2015-06-19 17:40:25 +00:00
|
|
|
/* will that be a new tail? */
|
|
|
|
if (new_fragment < UFS_NDIR_FRAGMENT && new_fragment >= lastfrag)
|
|
|
|
nfrags = (new_fragment & uspi->s_fpbmask) + 1;
|
|
|
|
|
|
|
|
goal = 0;
|
2015-06-19 17:53:52 +00:00
|
|
|
if (index) {
|
2015-06-19 17:40:25 +00:00
|
|
|
goal = ufs_data_ptr_to_cpu(sb,
|
2015-06-19 17:53:52 +00:00
|
|
|
ufs_get_direct_data_ptr(uspi, ufsi, index - 1));
|
2015-06-19 17:40:25 +00:00
|
|
|
if (goal)
|
|
|
|
goal += uspi->s_fpb;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2015-06-19 17:53:52 +00:00
|
|
|
tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment),
|
2024-10-05 18:02:07 +00:00
|
|
|
goal, nfrags, err, locked_folio);
|
2015-06-19 17:40:25 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!tmp) {
|
|
|
|
*err = -ENOSPC;
|
2015-06-19 04:53:06 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 18:27:10 +00:00
|
|
|
if (new)
|
2005-04-16 22:20:36 +00:00
|
|
|
*new = 1;
|
2023-07-05 19:01:45 +00:00
|
|
|
inode_set_ctime_current(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_SYNC(inode))
|
|
|
|
ufs_sync_inode (inode);
|
|
|
|
mark_inode_dirty(inode);
|
2015-06-19 04:10:00 +00:00
|
|
|
out:
|
2015-06-19 04:53:06 +00:00
|
|
|
return tmp + uspi->s_sbbase;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-06-25 12:47:27 +00:00
|
|
|
/**
|
|
|
|
* ufs_inode_getblock() - allocate new block
|
2014-08-08 21:21:08 +00:00
|
|
|
* @inode: pointer to inode
|
2015-06-19 05:23:08 +00:00
|
|
|
* @ind_block: block number of the indirect block
|
|
|
|
* @index: number of pointer within the indirect block
|
2014-08-08 21:21:08 +00:00
|
|
|
* @new_fragment: number of new allocated fragment
|
2006-06-25 12:47:27 +00:00
|
|
|
* (block will hold this fragment and also uspi->s_fpb-1)
|
2014-08-08 21:21:08 +00:00
|
|
|
* @err: see ufs_inode_getfrag()
|
|
|
|
* @new: see ufs_inode_getfrag()
|
2024-10-05 18:02:04 +00:00
|
|
|
* @locked_folio: see ufs_inode_getfrag()
|
2006-06-25 12:47:27 +00:00
|
|
|
*/
|
2024-10-05 18:02:04 +00:00
|
|
|
static u64 ufs_inode_getblock(struct inode *inode, u64 ind_block,
|
|
|
|
unsigned index, sector_t new_fragment, int *err,
|
|
|
|
int *new, struct folio *locked_folio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-06-25 12:47:27 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2015-06-19 05:23:08 +00:00
|
|
|
int shift = uspi->s_apbshift - uspi->s_fpbshift;
|
2015-06-19 05:06:21 +00:00
|
|
|
u64 tmp = 0, goal;
|
2015-06-19 05:23:08 +00:00
|
|
|
struct buffer_head *bh;
|
2007-02-12 08:54:32 +00:00
|
|
|
void *p;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-19 05:23:08 +00:00
|
|
|
if (!ind_block)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bh = sb_bread(sb, ind_block + (index >> shift));
|
2015-06-19 18:10:53 +00:00
|
|
|
if (unlikely(!bh)) {
|
|
|
|
*err = -EIO;
|
2015-06-19 05:23:08 +00:00
|
|
|
return 0;
|
2015-06-19 18:10:53 +00:00
|
|
|
}
|
2015-06-19 05:23:08 +00:00
|
|
|
|
|
|
|
index &= uspi->s_apbmask >> uspi->s_fpbshift;
|
2007-02-12 08:54:32 +00:00
|
|
|
if (uspi->fs_magic == UFS2_MAGIC)
|
2015-06-19 05:06:21 +00:00
|
|
|
p = (__fs64 *)bh->b_data + index;
|
2007-02-12 08:54:32 +00:00
|
|
|
else
|
2015-06-19 05:06:21 +00:00
|
|
|
p = (__fs32 *)bh->b_data + index;
|
2015-06-19 02:39:46 +00:00
|
|
|
|
2007-02-12 08:54:32 +00:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
2015-06-19 04:10:00 +00:00
|
|
|
if (tmp)
|
2015-06-19 02:39:46 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-06-19 05:06:21 +00:00
|
|
|
if (index && (uspi->fs_magic == UFS2_MAGIC ?
|
|
|
|
(tmp = fs64_to_cpu(sb, ((__fs64 *)bh->b_data)[index-1])) :
|
|
|
|
(tmp = fs32_to_cpu(sb, ((__fs32 *)bh->b_data)[index-1]))))
|
2005-04-16 22:20:36 +00:00
|
|
|
goal = tmp + uspi->s_fpb;
|
|
|
|
else
|
|
|
|
goal = bh->b_blocknr + uspi->s_fpb;
|
2006-06-25 12:47:20 +00:00
|
|
|
tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment), goal,
|
2024-10-05 18:02:07 +00:00
|
|
|
uspi->s_fpb, err, locked_folio);
|
2015-06-19 02:39:46 +00:00
|
|
|
if (!tmp)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
2006-06-25 12:47:19 +00:00
|
|
|
|
2015-06-19 04:10:00 +00:00
|
|
|
if (new)
|
2005-04-16 22:20:36 +00:00
|
|
|
*new = 1;
|
|
|
|
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
if (IS_SYNC(inode))
|
|
|
|
sync_dirty_buffer(bh);
|
2023-07-05 19:01:45 +00:00
|
|
|
inode_set_ctime_current(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
out:
|
|
|
|
brelse (bh);
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT\n");
|
2015-06-19 04:53:06 +00:00
|
|
|
if (tmp)
|
|
|
|
tmp += uspi->s_sbbase;
|
|
|
|
return tmp;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-06-25 12:47:27 +00:00
|
|
|
/**
|
2011-04-08 17:33:07 +00:00
|
|
|
* ufs_getfrag_block() - `get_block_t' function, interface between UFS and
|
2023-12-15 20:02:43 +00:00
|
|
|
* read_folio, writepages and so on
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2015-06-17 16:44:14 +00:00
|
|
|
static int ufs_getfrag_block(struct inode *inode, sector_t fragment, struct buffer_head *bh_result, int create)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-06-19 18:20:21 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
int err = 0, new = 0;
|
2015-06-04 18:27:23 +00:00
|
|
|
unsigned offsets[4];
|
|
|
|
int depth = ufs_block_to_path(inode, fragment >> uspi->s_fpbshift, offsets);
|
2005-04-16 22:20:36 +00:00
|
|
|
u64 phys64 = 0;
|
2015-06-19 04:53:06 +00:00
|
|
|
unsigned frag = fragment & uspi->s_fpbmask;
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2017-06-15 04:17:30 +00:00
|
|
|
phys64 = ufs_frag_map(inode, offsets, depth);
|
|
|
|
if (!create)
|
|
|
|
goto done;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-15 04:17:30 +00:00
|
|
|
if (phys64) {
|
|
|
|
if (fragment >= UFS_NDIR_FRAGMENT)
|
|
|
|
goto done;
|
|
|
|
read_seqlock_excl(&UFS_I(inode)->meta_lock);
|
|
|
|
if (fragment < UFS_I(inode)->i_lastfrag) {
|
|
|
|
read_sequnlock_excl(&UFS_I(inode)->meta_lock);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
read_sequnlock_excl(&UFS_I(inode)->meta_lock);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
/* This code entered only while writing ....? */
|
|
|
|
|
2015-06-17 16:02:56 +00:00
|
|
|
mutex_lock(&UFS_I(inode)->truncate_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
|
2015-06-19 18:20:21 +00:00
|
|
|
if (unlikely(!depth)) {
|
|
|
|
ufs_warning(sb, "ufs_get_block", "block > big");
|
|
|
|
err = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-06-19 17:40:25 +00:00
|
|
|
|
|
|
|
if (UFS_I(inode)->i_lastfrag < UFS_NDIR_FRAGMENT) {
|
|
|
|
unsigned lastfrag = UFS_I(inode)->i_lastfrag;
|
|
|
|
unsigned tailfrags = lastfrag & uspi->s_fpbmask;
|
|
|
|
if (tailfrags && fragment >= lastfrag) {
|
|
|
|
if (!ufs_extend_tail(inode, fragment,
|
2024-10-05 18:02:05 +00:00
|
|
|
&err, bh_result->b_folio))
|
2015-06-19 18:20:21 +00:00
|
|
|
goto out;
|
2015-06-19 17:40:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 18:34:43 +00:00
|
|
|
if (depth == 1) {
|
2015-06-19 17:53:52 +00:00
|
|
|
phys64 = ufs_inode_getfrag(inode, offsets[0], fragment,
|
2024-10-05 18:02:06 +00:00
|
|
|
&err, &new, bh_result->b_folio);
|
2015-06-19 18:08:16 +00:00
|
|
|
} else {
|
|
|
|
int i;
|
2015-06-19 17:53:52 +00:00
|
|
|
phys64 = ufs_inode_getfrag(inode, offsets[0], fragment,
|
2015-06-19 18:27:10 +00:00
|
|
|
&err, NULL, NULL);
|
2015-06-19 18:08:16 +00:00
|
|
|
for (i = 1; i < depth - 1; i++)
|
|
|
|
phys64 = ufs_inode_getblock(inode, phys64, offsets[i],
|
2015-06-19 18:27:10 +00:00
|
|
|
fragment, &err, NULL, NULL);
|
2015-06-19 18:08:16 +00:00
|
|
|
phys64 = ufs_inode_getblock(inode, phys64, offsets[depth - 1],
|
2024-10-05 18:02:04 +00:00
|
|
|
fragment, &err, &new, bh_result->b_folio);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2015-06-19 18:20:21 +00:00
|
|
|
out:
|
2015-06-19 04:53:06 +00:00
|
|
|
if (phys64) {
|
|
|
|
phys64 += frag;
|
2015-06-19 18:20:21 +00:00
|
|
|
map_bh(bh_result, sb, phys64);
|
|
|
|
if (new)
|
|
|
|
set_buffer_new(bh_result);
|
2015-06-19 04:53:06 +00:00
|
|
|
}
|
2015-06-17 16:02:56 +00:00
|
|
|
mutex_unlock(&UFS_I(inode)->truncate_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
2017-06-15 04:17:30 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (phys64)
|
|
|
|
map_bh(bh_result, sb, phys64 + frag);
|
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2023-12-15 20:02:43 +00:00
|
|
|
static int ufs_writepages(struct address_space *mapping,
|
|
|
|
struct writeback_control *wbc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2023-12-15 20:02:43 +00:00
|
|
|
return mpage_writepages(mapping, wbc, ufs_getfrag_block);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-10-16 08:25:19 +00:00
|
|
|
|
2022-04-29 14:40:40 +00:00
|
|
|
static int ufs_read_folio(struct file *file, struct folio *folio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2022-04-29 14:40:40 +00:00
|
|
|
return block_read_full_folio(folio, ufs_getfrag_block);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-10-16 08:25:19 +00:00
|
|
|
|
2024-07-08 21:47:06 +00:00
|
|
|
int ufs_prepare_chunk(struct folio *folio, loff_t pos, unsigned len)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2024-07-11 03:09:04 +00:00
|
|
|
return __block_write_begin(folio, pos, len, ufs_getfrag_block);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-10-16 08:25:19 +00:00
|
|
|
|
2015-06-17 16:44:14 +00:00
|
|
|
static void ufs_truncate_blocks(struct inode *);
|
|
|
|
|
2012-12-15 10:45:14 +00:00
|
|
|
static void ufs_write_failed(struct address_space *mapping, loff_t to)
|
|
|
|
{
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
2015-06-16 22:06:40 +00:00
|
|
|
if (to > inode->i_size) {
|
2013-09-12 22:13:56 +00:00
|
|
|
truncate_pagecache(inode, inode->i_size);
|
2015-06-16 22:06:40 +00:00
|
|
|
ufs_truncate_blocks(inode);
|
|
|
|
}
|
2012-12-15 10:45:14 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 08:25:19 +00:00
|
|
|
static int ufs_write_begin(struct file *file, struct address_space *mapping,
|
2022-02-22 19:31:43 +00:00
|
|
|
loff_t pos, unsigned len,
|
2024-07-15 18:24:01 +00:00
|
|
|
struct folio **foliop, void **fsdata)
|
2007-10-16 08:25:19 +00:00
|
|
|
{
|
2010-06-04 09:29:58 +00:00
|
|
|
int ret;
|
|
|
|
|
2024-07-15 18:24:01 +00:00
|
|
|
ret = block_write_begin(mapping, pos, len, foliop, ufs_getfrag_block);
|
2012-12-15 10:45:14 +00:00
|
|
|
if (unlikely(ret))
|
|
|
|
ufs_write_failed(mapping, pos + len);
|
2010-06-04 09:29:58 +00:00
|
|
|
|
|
|
|
return ret;
|
2007-10-16 08:25:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 22:06:40 +00:00
|
|
|
static int ufs_write_end(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned copied,
|
2024-07-10 19:45:32 +00:00
|
|
|
struct folio *folio, void *fsdata)
|
2015-06-16 22:06:40 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2024-07-10 19:45:32 +00:00
|
|
|
ret = generic_write_end(file, mapping, pos, len, copied, folio, fsdata);
|
2015-06-16 22:06:40 +00:00
|
|
|
if (ret < len)
|
|
|
|
ufs_write_failed(mapping, pos + len);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00: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 08:25:19 +00:00
|
|
|
|
2006-06-28 11:26:44 +00:00
|
|
|
const struct address_space_operations ufs_aops = {
|
2022-02-09 20:22:12 +00:00
|
|
|
.dirty_folio = block_dirty_folio,
|
2022-02-09 20:21:34 +00:00
|
|
|
.invalidate_folio = block_invalidate_folio,
|
2022-04-29 14:40:40 +00:00
|
|
|
.read_folio = ufs_read_folio,
|
2023-12-15 20:02:43 +00:00
|
|
|
.writepages = ufs_writepages,
|
2007-10-16 08:25:19 +00:00
|
|
|
.write_begin = ufs_write_begin,
|
2015-06-16 22:06:40 +00:00
|
|
|
.write_end = ufs_write_end,
|
2023-12-15 20:02:43 +00:00
|
|
|
.migrate_folio = buffer_migrate_folio,
|
2005-04-16 22:20:36 +00:00
|
|
|
.bmap = ufs_bmap
|
|
|
|
};
|
|
|
|
|
2006-06-25 12:47:21 +00: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 14:28:56 +00:00
|
|
|
if (!inode->i_blocks) {
|
|
|
|
inode->i_link = (char *)UFS_I(inode)->i_u1.i_symlink;
|
2015-11-15 23:24:17 +00:00
|
|
|
inode->i_op = &simple_symlink_inode_operations;
|
2015-05-02 14:28:56 +00:00
|
|
|
} else {
|
2006-06-25 12:47:21 +00:00
|
|
|
inode->i_mapping->a_ops = &ufs_aops;
|
2015-11-15 23:24:17 +00:00
|
|
|
inode->i_op = &page_symlink_inode_operations;
|
2015-11-17 06:07:57 +00:00
|
|
|
inode_nohighmem(inode);
|
2006-06-25 12:47:21 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
init_special_inode(inode, inode->i_mode,
|
|
|
|
ufs_get_inode_dev(inode->i_sb, UFS_I(inode)));
|
|
|
|
}
|
|
|
|
|
2007-04-17 05:53:24 +00:00
|
|
|
static int ufs1_read_inode(struct inode *inode, struct ufs_inode *ufs_inode)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
2006-06-27 09:53:59 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
2011-07-26 06:49:13 +00:00
|
|
|
umode_t mode;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy data to the in-core inode.
|
|
|
|
*/
|
|
|
|
inode->i_mode = mode = fs16_to_cpu(sb, ufs_inode->ui_mode);
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, fs16_to_cpu(sb, ufs_inode->ui_nlink));
|
2017-06-17 03:54:47 +00:00
|
|
|
if (inode->i_nlink == 0)
|
|
|
|
return -ESTALE;
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Linux now has 32-bit uid and gid, so we can support EFT.
|
|
|
|
*/
|
2012-02-10 20:21:22 +00: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-16 22:20:36 +00:00
|
|
|
|
|
|
|
inode->i_size = fs64_to_cpu(sb, ufs_inode->ui_size);
|
2023-10-04 18:53:00 +00:00
|
|
|
inode_set_atime(inode,
|
|
|
|
(signed)fs32_to_cpu(sb, ufs_inode->ui_atime.tv_sec),
|
|
|
|
0);
|
2023-07-05 19:01:45 +00:00
|
|
|
inode_set_ctime(inode,
|
|
|
|
(signed)fs32_to_cpu(sb, ufs_inode->ui_ctime.tv_sec),
|
|
|
|
0);
|
2023-10-04 18:53:00 +00:00
|
|
|
inode_set_mtime(inode,
|
|
|
|
(signed)fs32_to_cpu(sb, ufs_inode->ui_mtime.tv_sec),
|
|
|
|
0);
|
2005-04-16 22:20:36 +00:00
|
|
|
inode->i_blocks = fs32_to_cpu(sb, ufs_inode->ui_blocks);
|
2007-02-12 08:54:31 +00:00
|
|
|
inode->i_generation = fs32_to_cpu(sb, ufs_inode->ui_gen);
|
2005-04-16 22:20:36 +00: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 09:53:59 +00:00
|
|
|
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
|
2009-01-08 22:43:49 +00:00
|
|
|
memcpy(ufsi->i_u1.i_data, &ufs_inode->ui_u2.ui_addr,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_addr));
|
2006-06-25 12:47:25 +00:00
|
|
|
} else {
|
2009-01-08 22:43:49 +00:00
|
|
|
memcpy(ufsi->i_u1.i_symlink, ufs_inode->ui_u2.ui_symlink,
|
2009-01-08 22:43:50 +00: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-16 22:20:36 +00:00
|
|
|
}
|
2007-04-17 05:53:24 +00:00
|
|
|
return 0;
|
2006-06-27 09:53:59 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-17 05:53:24 +00:00
|
|
|
static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode)
|
2006-06-27 09:53:59 +00:00
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
|
|
|
struct super_block *sb = inode->i_sb;
|
2011-07-26 06:49:13 +00:00
|
|
|
umode_t mode;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("Reading ufs2 inode, ino %lu\n", inode->i_ino);
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copy data to the in-core inode.
|
|
|
|
*/
|
|
|
|
inode->i_mode = mode = fs16_to_cpu(sb, ufs2_inode->ui_mode);
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, fs16_to_cpu(sb, ufs2_inode->ui_nlink));
|
2017-06-17 03:54:47 +00:00
|
|
|
if (inode->i_nlink == 0)
|
|
|
|
return -ESTALE;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Linux now has 32-bit uid and gid, so we can support EFT.
|
|
|
|
*/
|
2012-02-10 20:21:22 +00: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-16 22:20:36 +00:00
|
|
|
|
|
|
|
inode->i_size = fs64_to_cpu(sb, ufs2_inode->ui_size);
|
2023-10-04 18:53:00 +00:00
|
|
|
inode_set_atime(inode, fs64_to_cpu(sb, ufs2_inode->ui_atime),
|
|
|
|
fs32_to_cpu(sb, ufs2_inode->ui_atimensec));
|
2023-07-05 19:01:45 +00:00
|
|
|
inode_set_ctime(inode, fs64_to_cpu(sb, ufs2_inode->ui_ctime),
|
|
|
|
fs32_to_cpu(sb, ufs2_inode->ui_ctimensec));
|
2023-10-04 18:53:00 +00:00
|
|
|
inode_set_mtime(inode, fs64_to_cpu(sb, ufs2_inode->ui_mtime),
|
|
|
|
fs32_to_cpu(sb, ufs2_inode->ui_mtimensec));
|
2005-04-16 22:20:36 +00:00
|
|
|
inode->i_blocks = fs64_to_cpu(sb, ufs2_inode->ui_blocks);
|
2007-02-12 08:54:31 +00:00
|
|
|
inode->i_generation = fs32_to_cpu(sb, ufs2_inode->ui_gen);
|
2005-04-16 22:20:36 +00: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-08 22:43:49 +00:00
|
|
|
memcpy(ufsi->i_u1.u2_i_data, &ufs2_inode->ui_u2.ui_addr,
|
|
|
|
sizeof(ufs2_inode->ui_u2.ui_addr));
|
2006-06-27 09:53:59 +00:00
|
|
|
} else {
|
2009-01-08 22:43:49 +00:00
|
|
|
memcpy(ufsi->i_u1.i_symlink, ufs2_inode->ui_u2.ui_symlink,
|
2009-01-08 22:43:50 +00: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-16 22:20:36 +00:00
|
|
|
}
|
2007-04-17 05:53:24 +00:00
|
|
|
return 0;
|
2006-06-27 09:53:59 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:15:48 +00:00
|
|
|
struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
|
2006-06-27 09:53:59 +00:00
|
|
|
{
|
2008-02-07 08:15:48 +00:00
|
|
|
struct ufs_inode_info *ufsi;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2006-06-27 09:53:59 +00:00
|
|
|
struct buffer_head * bh;
|
2008-02-07 08:15:48 +00:00
|
|
|
struct inode *inode;
|
2017-06-17 03:54:47 +00:00
|
|
|
int err = -EIO;
|
2006-06-27 09:53:59 +00:00
|
|
|
|
2008-02-07 08:15:48 +00:00
|
|
|
UFSD("ENTER, ino %lu\n", ino);
|
2006-06-27 09:53:59 +00:00
|
|
|
|
2008-02-07 08:15:48 +00:00
|
|
|
if (ino < UFS_ROOTINO || ino > (uspi->s_ncg * uspi->s_ipg)) {
|
2006-06-27 09:53:59 +00:00
|
|
|
ufs_warning(sb, "ufs_read_inode", "bad inode number (%lu)\n",
|
2008-02-07 08:15:48 +00:00
|
|
|
ino);
|
|
|
|
return ERR_PTR(-EIO);
|
2006-06-27 09:53:59 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:15:48 +00: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 09:53:59 +00: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 05:53:24 +00:00
|
|
|
err = ufs2_read_inode(inode,
|
|
|
|
ufs2_inode + ufs_inotofsbo(inode->i_ino));
|
2006-06-27 09:53:59 +00:00
|
|
|
} else {
|
|
|
|
struct ufs_inode *ufs_inode = (struct ufs_inode *)bh->b_data;
|
|
|
|
|
2007-04-17 05:53:24 +00:00
|
|
|
err = ufs1_read_inode(inode,
|
|
|
|
ufs_inode + ufs_inotofsbo(inode->i_ino));
|
2006-06-27 09:53:59 +00:00
|
|
|
}
|
2017-06-17 03:54:47 +00:00
|
|
|
brelse(bh);
|
2007-04-17 05:53:24 +00:00
|
|
|
if (err)
|
|
|
|
goto bad_inode;
|
2017-06-17 03:54:47 +00:00
|
|
|
|
2017-12-11 11:35:18 +00:00
|
|
|
inode_inc_iversion(inode);
|
2006-06-27 09:53:59 +00:00
|
|
|
ufsi->i_lastfrag =
|
|
|
|
(inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift;
|
|
|
|
ufsi->i_dir_start_lookup = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
ufsi->i_osync = 0;
|
|
|
|
|
2006-06-25 12:47:21 +00:00
|
|
|
ufs_set_inode_ops(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT\n");
|
2008-02-07 08:15:48 +00:00
|
|
|
unlock_new_inode(inode);
|
|
|
|
return inode;
|
2006-06-27 09:53:59 +00:00
|
|
|
|
|
|
|
bad_inode:
|
2008-02-07 08:15:48 +00:00
|
|
|
iget_failed(inode);
|
2017-06-17 03:54:47 +00:00
|
|
|
return ERR_PTR(err);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-02-12 08:54:31 +00:00
|
|
|
static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-02-12 08:54:31 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
2005-04-16 22:20:36 +00: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-10 20:21:22 +00: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-17 16:44:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size);
|
2023-10-04 18:53:00 +00:00
|
|
|
ufs_inode->ui_atime.tv_sec = cpu_to_fs32(sb,
|
|
|
|
inode_get_atime_sec(inode));
|
2005-04-16 22:20:36 +00:00
|
|
|
ufs_inode->ui_atime.tv_usec = 0;
|
2023-07-05 19:01:45 +00:00
|
|
|
ufs_inode->ui_ctime.tv_sec = cpu_to_fs32(sb,
|
2023-10-04 18:53:00 +00:00
|
|
|
inode_get_ctime_sec(inode));
|
2005-04-16 22:20:36 +00:00
|
|
|
ufs_inode->ui_ctime.tv_usec = 0;
|
2023-10-04 18:53:00 +00:00
|
|
|
ufs_inode->ui_mtime.tv_sec = cpu_to_fs32(sb,
|
|
|
|
inode_get_mtime_sec(inode));
|
2005-04-16 22:20:36 +00:00
|
|
|
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 08:54:31 +00:00
|
|
|
ufs_inode->ui_gen = cpu_to_fs32(sb, inode->i_generation);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-02-12 08:54:31 +00:00
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_UID_MASK) == UFS_UID_EFT) {
|
2005-04-16 22:20:36 +00: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-08 22:43:49 +00:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.i_data,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_addr));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-01-08 22:43:49 +00:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_symlink));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!inode->i_nlink)
|
|
|
|
memset (ufs_inode, 0, sizeof(struct ufs_inode));
|
2007-02-12 08:54:31 +00: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-10 20:21:22 +00: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 08:54:31 +00:00
|
|
|
|
|
|
|
ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size);
|
2023-10-04 18:53:00 +00:00
|
|
|
ufs_inode->ui_atime = cpu_to_fs64(sb, inode_get_atime_sec(inode));
|
|
|
|
ufs_inode->ui_atimensec = cpu_to_fs32(sb,
|
|
|
|
inode_get_atime_nsec(inode));
|
|
|
|
ufs_inode->ui_ctime = cpu_to_fs64(sb, inode_get_ctime_sec(inode));
|
2023-07-05 19:01:45 +00:00
|
|
|
ufs_inode->ui_ctimensec = cpu_to_fs32(sb,
|
2023-10-04 18:53:00 +00:00
|
|
|
inode_get_ctime_nsec(inode));
|
|
|
|
ufs_inode->ui_mtime = cpu_to_fs64(sb, inode_get_mtime_sec(inode));
|
|
|
|
ufs_inode->ui_mtimensec = cpu_to_fs32(sb,
|
|
|
|
inode_get_mtime_nsec(inode));
|
2007-02-12 08:54:31 +00: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-08 22:43:49 +00:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.u2_i_data,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_addr));
|
2007-02-12 08:54:31 +00:00
|
|
|
} else {
|
2009-01-08 22:43:49 +00:00
|
|
|
memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
|
|
|
|
sizeof(ufs_inode->ui_u2.ui_symlink));
|
2007-02-12 08:54:31 +00: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-17 16:44:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
if (do_sync)
|
|
|
|
sync_dirty_buffer(bh);
|
|
|
|
brelse (bh);
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2006-06-25 12:47:24 +00:00
|
|
|
UFSD("EXIT\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-05 08:21:37 +00:00
|
|
|
int ufs_write_inode(struct inode *inode, struct writeback_control *wbc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-06-16 06:35:14 +00:00
|
|
|
return ufs_update_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ufs_sync_inode (struct inode *inode)
|
|
|
|
{
|
|
|
|
return ufs_update_inode (inode, 1);
|
|
|
|
}
|
|
|
|
|
2010-06-05 23:40:56 +00:00
|
|
|
void ufs_evict_inode(struct inode * inode)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2010-06-05 23:40:56 +00:00
|
|
|
int want_delete = 0;
|
|
|
|
|
|
|
|
if (!inode->i_nlink && !is_bad_inode(inode))
|
|
|
|
want_delete = 1;
|
2006-07-01 11:36:24 +00:00
|
|
|
|
2014-04-03 21:47:49 +00:00
|
|
|
truncate_inode_pages_final(&inode->i_data);
|
2010-06-05 23:40:56 +00:00
|
|
|
if (want_delete) {
|
|
|
|
inode->i_size = 0;
|
2017-06-09 20:20:34 +00:00
|
|
|
if (inode->i_blocks &&
|
|
|
|
(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
|
|
|
|
S_ISLNK(inode->i_mode)))
|
2015-06-16 22:04:16 +00:00
|
|
|
ufs_truncate_blocks(inode);
|
2017-06-10 16:01:50 +00:00
|
|
|
ufs_update_inode(inode, inode_needs_sync(inode));
|
2010-06-05 23:40:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
invalidate_inode_buffers(inode);
|
2012-05-03 12:48:02 +00:00
|
|
|
clear_inode(inode);
|
2010-06-05 23:40:56 +00:00
|
|
|
|
2015-06-16 06:35:14 +00:00
|
|
|
if (want_delete)
|
2014-09-02 07:40:17 +00:00
|
|
|
ufs_free_inode(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2015-06-18 06:18:54 +00:00
|
|
|
struct to_free {
|
|
|
|
struct inode *inode;
|
|
|
|
u64 to;
|
|
|
|
unsigned count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void free_data(struct to_free *ctx, u64 from, unsigned count)
|
|
|
|
{
|
|
|
|
if (ctx->count && ctx->to != from) {
|
|
|
|
ufs_free_blocks(ctx->inode, ctx->to - ctx->count, ctx->count);
|
|
|
|
ctx->count = 0;
|
|
|
|
}
|
|
|
|
ctx->count += count;
|
|
|
|
ctx->to = from + count;
|
|
|
|
}
|
|
|
|
|
2015-06-17 16:44:14 +00:00
|
|
|
#define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift)
|
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
/*
|
|
|
|
* used only for truncation down to direct blocks.
|
|
|
|
*/
|
2015-06-17 16:44:14 +00:00
|
|
|
static void ufs_trunc_direct(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct ufs_inode_info *ufsi = UFS_I(inode);
|
2023-03-13 16:40:40 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
unsigned int new_frags, old_frags;
|
|
|
|
unsigned int old_slot, new_slot;
|
|
|
|
unsigned int old_tail, new_tail;
|
2015-06-18 06:18:54 +00:00
|
|
|
struct to_free ctx = {.inode = inode};
|
2015-06-17 16:44:14 +00:00
|
|
|
|
|
|
|
UFSD("ENTER: ino %lu\n", inode->i_ino);
|
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
new_frags = DIRECT_FRAGMENT;
|
|
|
|
// new_frags = first fragment past the new EOF
|
|
|
|
old_frags = min_t(u64, UFS_NDIR_FRAGMENT, ufsi->i_lastfrag);
|
|
|
|
// old_frags = first fragment past the old EOF or covered by indirects
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
if (new_frags >= old_frags) // expanding - nothing to free
|
|
|
|
goto done;
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
old_tail = ufs_fragnum(old_frags);
|
|
|
|
old_slot = ufs_fragstoblks(old_frags);
|
|
|
|
new_tail = ufs_fragnum(new_frags);
|
|
|
|
new_slot = ufs_fragstoblks(new_frags);
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
if (old_slot == new_slot) { // old_tail > 0
|
|
|
|
void *p = ufs_get_direct_data_ptr(uspi, ufsi, old_slot);
|
|
|
|
u64 tmp = ufs_data_ptr_to_cpu(sb, p);
|
2015-06-17 16:44:14 +00:00
|
|
|
if (!tmp)
|
2023-03-13 16:40:40 +00:00
|
|
|
ufs_panic(sb, __func__, "internal error");
|
|
|
|
if (!new_tail) {
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
|
|
|
}
|
|
|
|
ufs_free_fragments(inode, tmp + new_tail, old_tail - new_tail);
|
|
|
|
} else {
|
|
|
|
unsigned int slot = new_slot;
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
if (new_tail) {
|
|
|
|
void *p = ufs_get_direct_data_ptr(uspi, ufsi, slot++);
|
|
|
|
u64 tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!tmp)
|
|
|
|
ufs_panic(sb, __func__, "internal error");
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
ufs_free_fragments(inode, tmp + new_tail,
|
|
|
|
uspi->s_fpb - new_tail);
|
|
|
|
}
|
|
|
|
while (slot < old_slot) {
|
|
|
|
void *p = ufs_get_direct_data_ptr(uspi, ufsi, slot++);
|
|
|
|
u64 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);
|
|
|
|
|
|
|
|
free_data(&ctx, tmp, uspi->s_fpb);
|
|
|
|
}
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
free_data(&ctx, 0, 0);
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
if (old_tail) {
|
|
|
|
void *p = ufs_get_direct_data_ptr(uspi, ufsi, slot);
|
|
|
|
u64 tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!tmp)
|
|
|
|
ufs_panic(sb, __func__, "internal error");
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-03-13 16:40:40 +00:00
|
|
|
ufs_free_fragments(inode, tmp, old_tail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
2015-06-17 16:44:14 +00:00
|
|
|
UFSD("EXIT: ino %lu\n", inode->i_ino);
|
|
|
|
}
|
|
|
|
|
2015-06-19 00:07:08 +00:00
|
|
|
static void free_full_branch(struct inode *inode, u64 ind_block, int depth)
|
2015-06-18 21:11:49 +00:00
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2015-06-19 00:07:08 +00:00
|
|
|
struct ufs_buffer_head *ubh = ubh_bread(sb, ind_block, uspi->s_bsize);
|
2015-06-18 21:11:49 +00:00
|
|
|
unsigned i;
|
|
|
|
|
2015-06-19 00:07:08 +00:00
|
|
|
if (!ubh)
|
2015-06-18 21:11:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (--depth) {
|
2015-06-19 00:07:08 +00:00
|
|
|
for (i = 0; i < uspi->s_apb; i++) {
|
|
|
|
void *p = ubh_get_data_ptr(uspi, ubh, i);
|
|
|
|
u64 block = ufs_data_ptr_to_cpu(sb, p);
|
2015-06-19 00:14:02 +00:00
|
|
|
if (block)
|
2015-06-19 00:07:08 +00:00
|
|
|
free_full_branch(inode, block, depth);
|
2015-06-18 21:11:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct to_free ctx = {.inode = inode};
|
|
|
|
|
|
|
|
for (i = 0; i < uspi->s_apb; i++) {
|
2015-06-19 00:07:08 +00:00
|
|
|
void *p = ubh_get_data_ptr(uspi, ubh, i);
|
|
|
|
u64 block = ufs_data_ptr_to_cpu(sb, p);
|
2015-06-19 00:14:02 +00:00
|
|
|
if (block)
|
2015-06-19 00:07:08 +00:00
|
|
|
free_data(&ctx, block, uspi->s_fpb);
|
2015-06-18 21:11:49 +00:00
|
|
|
}
|
|
|
|
free_data(&ctx, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ubh_bforget(ubh);
|
2015-06-19 00:07:08 +00:00
|
|
|
ufs_free_blocks(inode, ind_block, uspi->s_fpb);
|
2015-06-18 21:11:49 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 23:13:02 +00:00
|
|
|
static void free_branch_tail(struct inode *inode, unsigned from, struct ufs_buffer_head *ubh, int depth)
|
2015-06-17 16:44:14 +00:00
|
|
|
{
|
2015-06-18 18:21:09 +00:00
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
unsigned i;
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2015-06-18 19:33:47 +00:00
|
|
|
if (--depth) {
|
2015-06-18 23:13:02 +00:00
|
|
|
for (i = from; i < uspi->s_apb ; i++) {
|
2015-06-19 00:07:08 +00:00
|
|
|
void *p = ubh_get_data_ptr(uspi, ubh, i);
|
|
|
|
u64 block = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (block) {
|
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ubh_mark_buffer_dirty(ubh);
|
|
|
|
free_full_branch(inode, block, depth);
|
|
|
|
}
|
2015-06-18 20:13:56 +00:00
|
|
|
}
|
2015-06-18 19:33:47 +00:00
|
|
|
} else {
|
2015-06-18 06:18:54 +00:00
|
|
|
struct to_free ctx = {.inode = inode};
|
2015-06-18 19:33:47 +00:00
|
|
|
|
|
|
|
for (i = from; i < uspi->s_apb; i++) {
|
2015-06-19 00:07:08 +00:00
|
|
|
void *p = ubh_get_data_ptr(uspi, ubh, i);
|
|
|
|
u64 block = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (block) {
|
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
|
|
|
ubh_mark_buffer_dirty(ubh);
|
|
|
|
free_data(&ctx, block, uspi->s_fpb);
|
|
|
|
}
|
2015-06-18 19:33:47 +00:00
|
|
|
}
|
2015-06-18 06:18:54 +00:00
|
|
|
free_data(&ctx, 0, 0);
|
2015-06-17 16:44:14 +00:00
|
|
|
}
|
2015-06-18 19:33:47 +00:00
|
|
|
if (IS_SYNC(inode) && ubh_buffer_dirty(ubh))
|
|
|
|
ubh_sync_block(ubh);
|
|
|
|
ubh_brelse(ubh);
|
2015-06-17 16:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2023-10-16 20:11:11 +00:00
|
|
|
struct folio *folio;
|
2015-06-17 16:44:14 +00:00
|
|
|
struct buffer_head *bh;
|
|
|
|
u64 phys64;
|
|
|
|
|
|
|
|
lastfrag = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
|
|
|
|
|
|
|
|
if (!lastfrag)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
lastfrag--;
|
|
|
|
|
2023-10-16 20:11:11 +00:00
|
|
|
folio = ufs_get_locked_folio(mapping, lastfrag >>
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
(PAGE_SHIFT - inode->i_blkbits));
|
2023-10-16 20:11:11 +00:00
|
|
|
if (IS_ERR(folio)) {
|
|
|
|
err = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-06-17 16:44:14 +00:00
|
|
|
|
2023-10-16 20:11:11 +00:00
|
|
|
end = lastfrag & ((1 << (PAGE_SHIFT - inode->i_blkbits)) - 1);
|
|
|
|
bh = folio_buffers(folio);
|
|
|
|
for (i = 0; i < end; ++i)
|
|
|
|
bh = bh->b_this_page;
|
2015-06-17 16:44:14 +00:00
|
|
|
|
|
|
|
err = ufs_getfrag_block(inode, lastfrag, bh, 1);
|
|
|
|
|
|
|
|
if (unlikely(err))
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
if (buffer_new(bh)) {
|
|
|
|
clear_buffer_new(bh);
|
2016-11-04 17:08:15 +00:00
|
|
|
clean_bdev_bh_alias(bh);
|
2015-06-17 16:44:14 +00:00
|
|
|
/*
|
|
|
|
* we do not zeroize fragment, because of
|
|
|
|
* if it maped to hole, it already contains zeroes
|
|
|
|
*/
|
|
|
|
set_buffer_uptodate(bh);
|
|
|
|
mark_buffer_dirty(bh);
|
2023-10-16 20:11:11 +00:00
|
|
|
folio_mark_dirty(folio);
|
2015-06-17 16:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2023-10-16 20:11:11 +00:00
|
|
|
ufs_put_locked_folio(folio);
|
2015-06-17 16:44:14 +00:00
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-06-09 20:20:34 +00:00
|
|
|
static void ufs_truncate_blocks(struct inode *inode)
|
2015-06-17 16:44:14 +00: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;
|
2015-06-18 18:21:09 +00:00
|
|
|
unsigned offsets[4];
|
2017-06-15 07:57:46 +00:00
|
|
|
int depth;
|
2015-06-18 18:55:50 +00:00
|
|
|
int depth2;
|
2015-06-18 19:47:17 +00:00
|
|
|
unsigned i;
|
2015-06-18 23:13:02 +00:00
|
|
|
struct ufs_buffer_head *ubh[3];
|
|
|
|
void *p;
|
|
|
|
u64 block;
|
2015-06-18 18:55:50 +00:00
|
|
|
|
2017-06-15 07:57:46 +00:00
|
|
|
if (inode->i_size) {
|
|
|
|
sector_t last = (inode->i_size - 1) >> uspi->s_bshift;
|
|
|
|
depth = ufs_block_to_path(inode, last, offsets);
|
|
|
|
if (!depth)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
depth = 1;
|
|
|
|
}
|
2015-06-18 18:55:50 +00:00
|
|
|
|
|
|
|
for (depth2 = depth - 1; depth2; depth2--)
|
2017-06-15 07:57:46 +00:00
|
|
|
if (offsets[depth2] != uspi->s_apb - 1)
|
2015-06-18 18:55:50 +00:00
|
|
|
break;
|
2015-06-17 16:44:14 +00:00
|
|
|
|
|
|
|
mutex_lock(&ufsi->truncate_mutex);
|
2015-06-18 19:47:17 +00:00
|
|
|
if (depth == 1) {
|
2015-06-17 05:10:03 +00:00
|
|
|
ufs_trunc_direct(inode);
|
2015-06-18 19:47:17 +00:00
|
|
|
offsets[0] = UFS_IND_BLOCK;
|
|
|
|
} else {
|
2015-06-18 23:13:02 +00:00
|
|
|
/* get the blocks that should be partially emptied */
|
2017-06-15 07:57:46 +00:00
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, offsets[0]++);
|
2015-06-18 23:13:02 +00:00
|
|
|
for (i = 0; i < depth2; i++) {
|
|
|
|
block = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (!block)
|
|
|
|
break;
|
|
|
|
ubh[i] = ubh_bread(sb, block, uspi->s_bsize);
|
|
|
|
if (!ubh[i]) {
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
|
|
|
break;
|
|
|
|
}
|
2017-06-15 07:57:46 +00:00
|
|
|
p = ubh_get_data_ptr(uspi, ubh[i], offsets[i + 1]++);
|
2015-06-18 23:13:02 +00:00
|
|
|
}
|
2015-06-19 00:17:32 +00:00
|
|
|
while (i--)
|
2015-06-18 23:13:02 +00:00
|
|
|
free_branch_tail(inode, offsets[i + 1], ubh[i], depth - i - 1);
|
2015-06-18 19:47:17 +00:00
|
|
|
}
|
|
|
|
for (i = offsets[0]; i <= UFS_TIND_BLOCK; i++) {
|
2015-06-19 00:07:08 +00:00
|
|
|
p = ufs_get_direct_data_ptr(uspi, ufsi, i);
|
|
|
|
block = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
if (block) {
|
|
|
|
write_seqlock(&ufsi->meta_lock);
|
|
|
|
ufs_data_ptr_clear(uspi, p);
|
|
|
|
write_sequnlock(&ufsi->meta_lock);
|
|
|
|
free_full_branch(inode, block, i - UFS_IND_BLOCK + 1);
|
|
|
|
}
|
2015-06-17 05:10:03 +00:00
|
|
|
}
|
2017-06-15 04:17:30 +00:00
|
|
|
read_seqlock_excl(&ufsi->meta_lock);
|
2015-06-17 16:44:14 +00:00
|
|
|
ufsi->i_lastfrag = DIRECT_FRAGMENT;
|
2017-06-15 04:17:30 +00:00
|
|
|
read_sequnlock_excl(&ufsi->meta_lock);
|
2015-06-19 00:09:39 +00:00
|
|
|
mark_inode_dirty(inode);
|
2015-06-17 16:44:14 +00:00
|
|
|
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);
|
|
|
|
|
2017-06-09 20:20:34 +00:00
|
|
|
ufs_truncate_blocks(inode);
|
2023-10-04 18:53:00 +00:00
|
|
|
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
|
2015-06-17 16:44:14 +00:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
out:
|
|
|
|
UFSD("EXIT: err %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-01-13 11:49:11 +00:00
|
|
|
int ufs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct iattr *attr)
|
2015-06-17 16:44:14 +00:00
|
|
|
{
|
|
|
|
struct inode *inode = d_inode(dentry);
|
|
|
|
unsigned int ia_valid = attr->ia_valid;
|
|
|
|
int error;
|
|
|
|
|
2023-01-13 11:49:11 +00:00
|
|
|
error = setattr_prepare(&nop_mnt_idmap, dentry, attr);
|
2015-06-17 16:44:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-13 11:49:11 +00:00
|
|
|
setattr_copy(&nop_mnt_idmap, inode, attr);
|
2015-06-17 16:44:14 +00:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct inode_operations ufs_file_inode_operations = {
|
|
|
|
.setattr = ufs_setattr,
|
|
|
|
};
|