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 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* linux/fs/affs/namei.c
|
|
|
|
*
|
|
|
|
* (c) 1996 Hans-Joachim Widmaier - Rewritten
|
|
|
|
*
|
|
|
|
* (C) 1993 Ray Burr - Modified for Amiga FFS filesystem.
|
|
|
|
*
|
|
|
|
* (C) 1991 Linus Torvalds - minix filesystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "affs.h"
|
2017-02-28 05:27:49 +07:00
|
|
|
#include <linux/exportfs.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
typedef int (*toupper_t)(int);
|
|
|
|
|
|
|
|
/* Simple toupper() for DOS\1 */
|
|
|
|
|
|
|
|
static int
|
|
|
|
affs_toupper(int ch)
|
|
|
|
{
|
|
|
|
return ch >= 'a' && ch <= 'z' ? ch -= ('a' - 'A') : ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* International toupper() for DOS\3 ("international") */
|
|
|
|
|
|
|
|
static int
|
|
|
|
affs_intl_toupper(int ch)
|
|
|
|
{
|
|
|
|
return (ch >= 'a' && ch <= 'z') || (ch >= 0xE0
|
|
|
|
&& ch <= 0xFE && ch != 0xF7) ?
|
|
|
|
ch - ('a' - 'A') : ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline toupper_t
|
|
|
|
affs_get_toupper(struct super_block *sb)
|
|
|
|
{
|
2015-04-17 02:48:24 +07:00
|
|
|
return affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL) ?
|
|
|
|
affs_intl_toupper : affs_toupper;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: the dentry argument is the parent dentry.
|
|
|
|
*/
|
|
|
|
static inline int
|
2016-06-10 21:51:30 +07:00
|
|
|
__affs_hash_dentry(const struct dentry *dentry, struct qstr *qstr, toupper_t toupper, bool notruncate)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
const u8 *name = qstr->name;
|
|
|
|
unsigned long hash;
|
2015-02-18 04:46:20 +07:00
|
|
|
int retval;
|
|
|
|
u32 len;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-02-18 04:46:20 +07:00
|
|
|
retval = affs_check_name(qstr->name, qstr->len, notruncate);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2016-06-10 21:51:30 +07:00
|
|
|
hash = init_name_hash(dentry);
|
2015-02-18 04:46:23 +07:00
|
|
|
len = min(qstr->len, AFFSNAMEMAX);
|
2015-02-18 04:46:20 +07:00
|
|
|
for (; len > 0; name++, len--)
|
2005-04-17 05:20:36 +07:00
|
|
|
hash = partial_name_hash(toupper(*name), hash);
|
|
|
|
qstr->hash = end_name_hash(hash);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-05-22 05:22:44 +07:00
|
|
|
affs_hash_dentry(const struct dentry *dentry, struct qstr *qstr)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2016-06-10 21:51:30 +07:00
|
|
|
return __affs_hash_dentry(dentry, qstr, affs_toupper,
|
2014-04-08 05:39:01 +07:00
|
|
|
affs_nofilenametruncate(dentry));
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2014-04-08 05:39:01 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
static int
|
2013-05-22 05:22:44 +07:00
|
|
|
affs_intl_hash_dentry(const struct dentry *dentry, struct qstr *qstr)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2016-06-10 21:51:30 +07:00
|
|
|
return __affs_hash_dentry(dentry, qstr, affs_intl_toupper,
|
2014-04-08 05:39:01 +07:00
|
|
|
affs_nofilenametruncate(dentry));
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2011-01-07 13:49:27 +07:00
|
|
|
static inline int __affs_compare_dentry(unsigned int len,
|
2014-04-08 05:39:01 +07:00
|
|
|
const char *str, const struct qstr *name, toupper_t toupper,
|
|
|
|
bool notruncate)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2011-01-07 13:49:27 +07:00
|
|
|
const u8 *aname = str;
|
|
|
|
const u8 *bname = name->name;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-01-07 13:49:27 +07:00
|
|
|
/*
|
|
|
|
* 'str' is the name of an already existing dentry, so the name
|
|
|
|
* must be valid. 'name' must be validated first.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
2014-04-08 05:39:01 +07:00
|
|
|
if (affs_check_name(name->name, name->len, notruncate))
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
|
2011-01-07 13:49:27 +07:00
|
|
|
/*
|
|
|
|
* If the names are longer than the allowed 30 chars,
|
2005-04-17 05:20:36 +07:00
|
|
|
* the excess is ignored, so their length may differ.
|
|
|
|
*/
|
2015-02-18 04:46:23 +07:00
|
|
|
if (len >= AFFSNAMEMAX) {
|
|
|
|
if (name->len < AFFSNAMEMAX)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
2015-02-18 04:46:23 +07:00
|
|
|
len = AFFSNAMEMAX;
|
2011-01-07 13:49:27 +07:00
|
|
|
} else if (len != name->len)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (; len > 0; len--)
|
|
|
|
if (toupper(*aname++) != toupper(*bname++))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-08-01 03:37:25 +07:00
|
|
|
affs_compare_dentry(const struct dentry *dentry,
|
2011-01-07 13:49:27 +07:00
|
|
|
unsigned int len, const char *str, const struct qstr *name)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2014-04-08 05:39:01 +07:00
|
|
|
|
|
|
|
return __affs_compare_dentry(len, str, name, affs_toupper,
|
2016-07-30 05:22:49 +07:00
|
|
|
affs_nofilenametruncate(dentry));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2014-04-08 05:39:01 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
static int
|
2016-08-01 03:37:25 +07:00
|
|
|
affs_intl_compare_dentry(const struct dentry *dentry,
|
2011-01-07 13:49:27 +07:00
|
|
|
unsigned int len, const char *str, const struct qstr *name)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2014-04-08 05:39:01 +07:00
|
|
|
return __affs_compare_dentry(len, str, name, affs_intl_toupper,
|
2016-07-30 05:22:49 +07:00
|
|
|
affs_nofilenametruncate(dentry));
|
2014-04-08 05:39:01 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE! unlike strncmp, affs_match returns 1 for success, 0 for failure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
affs_match(struct dentry *dentry, const u8 *name2, toupper_t toupper)
|
|
|
|
{
|
|
|
|
const u8 *name = dentry->d_name.name;
|
|
|
|
int len = dentry->d_name.len;
|
|
|
|
|
2015-02-18 04:46:23 +07:00
|
|
|
if (len >= AFFSNAMEMAX) {
|
|
|
|
if (*name2 < AFFSNAMEMAX)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
2015-02-18 04:46:23 +07:00
|
|
|
len = AFFSNAMEMAX;
|
2005-04-17 05:20:36 +07:00
|
|
|
} else if (len != *name2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (name2++; len > 0; len--)
|
|
|
|
if (toupper(*name++) != toupper(*name2++))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len)
|
|
|
|
{
|
|
|
|
toupper_t toupper = affs_get_toupper(sb);
|
2015-02-18 04:46:20 +07:00
|
|
|
u32 hash;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-02-18 04:46:23 +07:00
|
|
|
hash = len = min(len, AFFSNAMEMAX);
|
2005-04-17 05:20:36 +07:00
|
|
|
for (; len > 0; len--)
|
|
|
|
hash = (hash * 13 + toupper(*name++)) & 0x7ff;
|
|
|
|
|
|
|
|
return hash % AFFS_SB(sb)->s_hashsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct buffer_head *
|
|
|
|
affs_find_entry(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
toupper_t toupper = affs_get_toupper(sb);
|
|
|
|
u32 key;
|
|
|
|
|
2014-10-22 07:11:25 +07:00
|
|
|
pr_debug("%s(\"%pd\")\n", __func__, dentry);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
bh = affs_bread(sb, dir->i_ino);
|
|
|
|
if (!bh)
|
|
|
|
return ERR_PTR(-EIO);
|
|
|
|
|
|
|
|
key = be32_to_cpu(AFFS_HEAD(bh)->table[affs_hash_name(sb, dentry->d_name.name, dentry->d_name.len)]);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
affs_brelse(bh);
|
|
|
|
if (key == 0)
|
|
|
|
return NULL;
|
|
|
|
bh = affs_bread(sb, key);
|
|
|
|
if (!bh)
|
|
|
|
return ERR_PTR(-EIO);
|
|
|
|
if (affs_match(dentry, AFFS_TAIL(sb, bh)->name, toupper))
|
|
|
|
return bh;
|
|
|
|
key = be32_to_cpu(AFFS_TAIL(sb, bh)->hash_chain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *
|
2012-06-11 04:13:09 +07:00
|
|
|
affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
struct inode *inode = NULL;
|
2018-05-06 23:20:40 +07:00
|
|
|
struct dentry *res;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-10-22 07:11:25 +07:00
|
|
|
pr_debug("%s(\"%pd\")\n", __func__, dentry);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
affs_lock_dir(dir);
|
|
|
|
bh = affs_find_entry(dir, dentry);
|
2018-05-06 23:15:20 +07:00
|
|
|
if (IS_ERR(bh)) {
|
|
|
|
affs_unlock_dir(dir);
|
2008-02-07 15:15:26 +07:00
|
|
|
return ERR_CAST(bh);
|
2018-05-06 23:15:20 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
if (bh) {
|
|
|
|
u32 ino = bh->b_blocknr;
|
|
|
|
|
|
|
|
/* store the real header ino in d_fsdata for faster lookups */
|
|
|
|
dentry->d_fsdata = (void *)(long)ino;
|
|
|
|
switch (be32_to_cpu(AFFS_TAIL(sb, bh)->stype)) {
|
|
|
|
//link to dirs disabled
|
|
|
|
//case ST_LINKDIR:
|
|
|
|
case ST_LINKFILE:
|
|
|
|
ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original);
|
|
|
|
}
|
|
|
|
affs_brelse(bh);
|
2008-02-07 15:15:29 +07:00
|
|
|
inode = affs_iget(sb, ino);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2018-05-06 23:20:40 +07:00
|
|
|
res = d_splice_alias(inode, dentry);
|
|
|
|
if (!IS_ERR_OR_NULL(res))
|
|
|
|
res->d_fsdata = dentry->d_fsdata;
|
2018-05-06 23:15:20 +07:00
|
|
|
affs_unlock_dir(dir);
|
2018-05-06 23:20:40 +07:00
|
|
|
return res;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
affs_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-02-18 04:46:10 +07:00
|
|
|
pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino,
|
2015-03-18 05:25:59 +07:00
|
|
|
d_inode(dentry)->i_ino, dentry);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return affs_remove_header(dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-11 05:05:36 +07:00
|
|
|
affs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct inode *inode;
|
|
|
|
int error;
|
|
|
|
|
2014-10-22 07:11:25 +07:00
|
|
|
pr_debug("%s(%lu,\"%pd\",0%ho)\n",
|
|
|
|
__func__, dir->i_ino, dentry, mode);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
inode = affs_new_inode(dir);
|
|
|
|
if (!inode)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
inode->i_mode = mode;
|
2017-02-28 05:27:54 +07:00
|
|
|
affs_mode_to_prot(inode);
|
2005-04-17 05:20:36 +07:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
|
|
|
|
inode->i_op = &affs_file_inode_operations;
|
|
|
|
inode->i_fop = &affs_file_operations;
|
2015-04-17 02:48:24 +07:00
|
|
|
inode->i_mapping->a_ops = affs_test_opt(AFFS_SB(sb)->s_flags, SF_OFS) ?
|
2015-04-17 02:48:15 +07:00
|
|
|
&affs_aops_ofs : &affs_aops;
|
2005-04-17 05:20:36 +07:00
|
|
|
error = affs_add_entry(dir, inode, dentry, ST_FILE);
|
|
|
|
if (error) {
|
2011-10-28 19:13:28 +07:00
|
|
|
clear_nlink(inode);
|
2005-04-17 05:20:36 +07:00
|
|
|
iput(inode);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-07-26 12:41:39 +07:00
|
|
|
affs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
int error;
|
|
|
|
|
2014-10-22 07:11:25 +07:00
|
|
|
pr_debug("%s(%lu,\"%pd\",0%ho)\n",
|
|
|
|
__func__, dir->i_ino, dentry, mode);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
inode = affs_new_inode(dir);
|
|
|
|
if (!inode)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
inode->i_mode = S_IFDIR | mode;
|
2017-02-28 05:27:54 +07:00
|
|
|
affs_mode_to_prot(inode);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
inode->i_op = &affs_dir_inode_operations;
|
|
|
|
inode->i_fop = &affs_dir_operations;
|
|
|
|
|
|
|
|
error = affs_add_entry(dir, inode, dentry, ST_USERDIR);
|
|
|
|
if (error) {
|
2011-10-28 19:13:28 +07:00
|
|
|
clear_nlink(inode);
|
2005-04-17 05:20:36 +07:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
iput(inode);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
affs_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-02-18 04:46:10 +07:00
|
|
|
pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino,
|
2015-03-18 05:25:59 +07:00
|
|
|
d_inode(dentry)->i_ino, dentry);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return affs_remove_header(dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
affs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
struct inode *inode;
|
|
|
|
char *p;
|
|
|
|
int i, maxlen, error;
|
|
|
|
char c, lc;
|
|
|
|
|
2014-10-22 07:11:25 +07:00
|
|
|
pr_debug("%s(%lu,\"%pd\" -> \"%s\")\n",
|
|
|
|
__func__, dir->i_ino, dentry, symname);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
maxlen = AFFS_SB(sb)->s_hashsize * sizeof(u32) - 1;
|
|
|
|
inode = affs_new_inode(dir);
|
|
|
|
if (!inode)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
inode->i_op = &affs_symlink_inode_operations;
|
2015-11-17 13:07:57 +07:00
|
|
|
inode_nohighmem(inode);
|
2005-04-17 05:20:36 +07:00
|
|
|
inode->i_data.a_ops = &affs_symlink_aops;
|
|
|
|
inode->i_mode = S_IFLNK | 0777;
|
2017-02-28 05:27:54 +07:00
|
|
|
affs_mode_to_prot(inode);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
error = -EIO;
|
|
|
|
bh = affs_bread(sb, inode->i_ino);
|
|
|
|
if (!bh)
|
|
|
|
goto err;
|
|
|
|
i = 0;
|
|
|
|
p = (char *)AFFS_HEAD(bh)->table;
|
|
|
|
lc = '/';
|
|
|
|
if (*symname == '/') {
|
2010-01-24 12:04:07 +07:00
|
|
|
struct affs_sb_info *sbi = AFFS_SB(sb);
|
2005-04-17 05:20:36 +07:00
|
|
|
while (*symname == '/')
|
|
|
|
symname++;
|
2010-01-24 12:04:07 +07:00
|
|
|
spin_lock(&sbi->symlink_lock);
|
|
|
|
while (sbi->s_volume[i]) /* Cannot overflow */
|
|
|
|
*p++ = sbi->s_volume[i++];
|
|
|
|
spin_unlock(&sbi->symlink_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
while (i < maxlen && (c = *symname++)) {
|
|
|
|
if (c == '.' && lc == '/' && *symname == '.' && symname[1] == '/') {
|
|
|
|
*p++ = '/';
|
|
|
|
i++;
|
|
|
|
symname += 2;
|
|
|
|
lc = '/';
|
|
|
|
} else if (c == '.' && lc == '/' && *symname == '/') {
|
|
|
|
symname++;
|
|
|
|
lc = '/';
|
|
|
|
} else {
|
|
|
|
*p++ = c;
|
|
|
|
lc = c;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (lc == '/')
|
|
|
|
while (*symname == '/')
|
|
|
|
symname++;
|
|
|
|
}
|
|
|
|
*p = 0;
|
2017-04-15 13:54:36 +07:00
|
|
|
inode->i_size = i + 1;
|
2005-04-17 05:20:36 +07:00
|
|
|
mark_buffer_dirty_inode(bh, inode);
|
|
|
|
affs_brelse(bh);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
|
|
|
|
error = affs_add_entry(dir, inode, dentry, ST_SOFTLINK);
|
|
|
|
if (error)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2011-10-28 19:13:28 +07:00
|
|
|
clear_nlink(inode);
|
2005-04-17 05:20:36 +07:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
iput(inode);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
affs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(old_dentry);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-02-18 04:46:10 +07:00
|
|
|
pr_debug("%s(%lu, %lu, \"%pd\")\n", __func__, inode->i_ino, dir->i_ino,
|
2014-10-22 07:11:25 +07:00
|
|
|
dentry);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return affs_add_entry(dir, inode, dentry, ST_LINKFILE);
|
|
|
|
}
|
|
|
|
|
2017-05-06 01:51:42 +07:00
|
|
|
static int
|
2005-04-17 05:20:36 +07:00
|
|
|
affs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
2017-05-06 01:51:42 +07:00
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct super_block *sb = old_dir->i_sb;
|
|
|
|
struct buffer_head *bh = NULL;
|
|
|
|
int retval;
|
|
|
|
|
2014-04-08 05:39:01 +07:00
|
|
|
retval = affs_check_name(new_dentry->d_name.name,
|
|
|
|
new_dentry->d_name.len,
|
|
|
|
affs_nofilenametruncate(old_dentry));
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* Unlink destination if it already exists */
|
2015-03-18 05:25:59 +07:00
|
|
|
if (d_really_is_positive(new_dentry)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
retval = affs_remove_header(new_dentry);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-03-18 05:25:59 +07:00
|
|
|
bh = affs_bread(sb, d_inode(old_dentry)->i_ino);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!bh)
|
2006-05-26 08:44:23 +07:00
|
|
|
return -EIO;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Remove header from its parent directory. */
|
|
|
|
affs_lock_dir(old_dir);
|
|
|
|
retval = affs_remove_hash(old_dir, bh);
|
|
|
|
affs_unlock_dir(old_dir);
|
|
|
|
if (retval)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* And insert it into the new directory with the new name. */
|
|
|
|
affs_copy_name(AFFS_TAIL(sb, bh)->name, new_dentry);
|
|
|
|
affs_fix_checksum(sb, bh);
|
|
|
|
affs_lock_dir(new_dir);
|
|
|
|
retval = affs_insert_hash(new_dir, bh);
|
|
|
|
affs_unlock_dir(new_dir);
|
|
|
|
/* TODO: move it back to old_dir, if error? */
|
|
|
|
|
|
|
|
done:
|
|
|
|
mark_buffer_dirty_inode(bh, retval ? old_dir : new_dir);
|
|
|
|
affs_brelse(bh);
|
|
|
|
return retval;
|
|
|
|
}
|
2017-02-28 05:27:49 +07:00
|
|
|
|
2017-05-06 01:52:07 +07:00
|
|
|
static int
|
|
|
|
affs_xrename(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct super_block *sb = old_dir->i_sb;
|
|
|
|
struct buffer_head *bh_old = NULL;
|
|
|
|
struct buffer_head *bh_new = NULL;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
bh_old = affs_bread(sb, d_inode(old_dentry)->i_ino);
|
|
|
|
if (!bh_old)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
bh_new = affs_bread(sb, d_inode(new_dentry)->i_ino);
|
|
|
|
if (!bh_new)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* Remove old header from its parent directory. */
|
|
|
|
affs_lock_dir(old_dir);
|
|
|
|
retval = affs_remove_hash(old_dir, bh_old);
|
|
|
|
affs_unlock_dir(old_dir);
|
|
|
|
if (retval)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Remove new header from its parent directory. */
|
|
|
|
affs_lock_dir(new_dir);
|
|
|
|
retval = affs_remove_hash(new_dir, bh_new);
|
|
|
|
affs_unlock_dir(new_dir);
|
|
|
|
if (retval)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Insert old into the new directory with the new name. */
|
|
|
|
affs_copy_name(AFFS_TAIL(sb, bh_old)->name, new_dentry);
|
|
|
|
affs_fix_checksum(sb, bh_old);
|
|
|
|
affs_lock_dir(new_dir);
|
|
|
|
retval = affs_insert_hash(new_dir, bh_old);
|
|
|
|
affs_unlock_dir(new_dir);
|
|
|
|
|
|
|
|
/* Insert new into the old directory with the old name. */
|
|
|
|
affs_copy_name(AFFS_TAIL(sb, bh_new)->name, old_dentry);
|
|
|
|
affs_fix_checksum(sb, bh_new);
|
|
|
|
affs_lock_dir(old_dir);
|
|
|
|
retval = affs_insert_hash(old_dir, bh_new);
|
|
|
|
affs_unlock_dir(old_dir);
|
|
|
|
done:
|
|
|
|
mark_buffer_dirty_inode(bh_old, new_dir);
|
|
|
|
mark_buffer_dirty_inode(bh_new, old_dir);
|
|
|
|
affs_brelse(bh_old);
|
|
|
|
affs_brelse(bh_new);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2017-05-06 01:51:42 +07:00
|
|
|
int affs_rename2(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
|
2017-05-06 01:52:07 +07:00
|
|
|
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
|
2017-05-06 01:51:42 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
pr_debug("%s(old=%lu,\"%pd\" to new=%lu,\"%pd\")\n", __func__,
|
|
|
|
old_dir->i_ino, old_dentry, new_dir->i_ino, new_dentry);
|
|
|
|
|
2017-05-06 01:52:07 +07:00
|
|
|
if (flags & RENAME_EXCHANGE)
|
|
|
|
return affs_xrename(old_dir, old_dentry, new_dir, new_dentry);
|
|
|
|
|
2017-05-06 01:51:42 +07:00
|
|
|
return affs_rename(old_dir, old_dentry, new_dir, new_dentry);
|
|
|
|
}
|
|
|
|
|
2017-02-28 05:28:00 +07:00
|
|
|
static struct dentry *affs_get_parent(struct dentry *child)
|
|
|
|
{
|
|
|
|
struct inode *parent;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
|
|
|
|
bh = affs_bread(child->d_sb, d_inode(child)->i_ino);
|
|
|
|
if (!bh)
|
|
|
|
return ERR_PTR(-EIO);
|
|
|
|
|
|
|
|
parent = affs_iget(child->d_sb,
|
|
|
|
be32_to_cpu(AFFS_TAIL(child->d_sb, bh)->parent));
|
|
|
|
brelse(bh);
|
|
|
|
if (IS_ERR(parent))
|
|
|
|
return ERR_CAST(parent);
|
|
|
|
|
|
|
|
return d_obtain_alias(parent);
|
|
|
|
}
|
|
|
|
|
2017-02-28 05:27:49 +07:00
|
|
|
static struct inode *affs_nfs_get_inode(struct super_block *sb, u64 ino,
|
|
|
|
u32 generation)
|
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
if (!affs_validblock(sb, ino))
|
|
|
|
return ERR_PTR(-ESTALE);
|
|
|
|
|
|
|
|
inode = affs_iget(sb, ino);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return ERR_CAST(inode);
|
|
|
|
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *affs_fh_to_dentry(struct super_block *sb, struct fid *fid,
|
|
|
|
int fh_len, int fh_type)
|
|
|
|
{
|
|
|
|
return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
|
|
|
|
affs_nfs_get_inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *affs_fh_to_parent(struct super_block *sb, struct fid *fid,
|
|
|
|
int fh_len, int fh_type)
|
|
|
|
{
|
|
|
|
return generic_fh_to_parent(sb, fid, fh_len, fh_type,
|
|
|
|
affs_nfs_get_inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct export_operations affs_export_ops = {
|
|
|
|
.fh_to_dentry = affs_fh_to_dentry,
|
|
|
|
.fh_to_parent = affs_fh_to_parent,
|
2017-02-28 05:28:00 +07:00
|
|
|
.get_parent = affs_get_parent,
|
2017-02-28 05:27:49 +07:00
|
|
|
};
|
2017-02-28 05:27:57 +07:00
|
|
|
|
|
|
|
const struct dentry_operations affs_dentry_operations = {
|
|
|
|
.d_hash = affs_hash_dentry,
|
|
|
|
.d_compare = affs_compare_dentry,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct dentry_operations affs_intl_dentry_operations = {
|
|
|
|
.d_hash = affs_intl_hash_dentry,
|
|
|
|
.d_compare = affs_intl_compare_dentry,
|
|
|
|
};
|