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
|
|
|
/*
|
|
|
|
* fs/bfs/dir.c
|
|
|
|
* BFS directory operations.
|
|
|
|
* Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com>
|
2005-09-09 20:02:04 +00:00
|
|
|
* Made endianness-clean by Andrew Stribblehill <ads@wompom.org> 2005
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include "bfs.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define dprintf(x...) printf(x)
|
|
|
|
#else
|
|
|
|
#define dprintf(x...)
|
|
|
|
#endif
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static int bfs_add_entry(struct inode *dir, const unsigned char *name,
|
|
|
|
int namelen, int ino);
|
|
|
|
static struct buffer_head *bfs_find_entry(struct inode *dir,
|
|
|
|
const unsigned char *name, int namelen,
|
|
|
|
struct bfs_dirent **res_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-05-16 17:41:48 +00:00
|
|
|
static int bfs_readdir(struct file *f, struct dir_context *ctx)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *dir = file_inode(f);
|
2007-11-15 00:59:47 +00:00
|
|
|
struct buffer_head *bh;
|
|
|
|
struct bfs_dirent *de;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int offset;
|
|
|
|
int block;
|
|
|
|
|
2013-05-16 17:41:48 +00:00
|
|
|
if (ctx->pos & (BFS_DIRENT_SIZE - 1)) {
|
2007-11-15 00:59:47 +00:00
|
|
|
printf("Bad f_pos=%08lx for %s:%08lx\n",
|
2013-05-16 17:41:48 +00:00
|
|
|
(unsigned long)ctx->pos,
|
2007-11-15 00:59:47 +00:00
|
|
|
dir->i_sb->s_id, dir->i_ino);
|
2013-05-16 17:41:48 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 17:41:48 +00:00
|
|
|
while (ctx->pos < dir->i_size) {
|
|
|
|
offset = ctx->pos & (BFS_BSIZE - 1);
|
|
|
|
block = BFS_I(dir)->i_sblock + (ctx->pos >> BFS_BSIZE_BITS);
|
2005-04-16 22:20:36 +00:00
|
|
|
bh = sb_bread(dir->i_sb, block);
|
|
|
|
if (!bh) {
|
2013-05-16 17:41:48 +00:00
|
|
|
ctx->pos += BFS_BSIZE - offset;
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
de = (struct bfs_dirent *)(bh->b_data + offset);
|
|
|
|
if (de->ino) {
|
|
|
|
int size = strnlen(de->name, BFS_NAMELEN);
|
2013-05-16 17:41:48 +00:00
|
|
|
if (!dir_emit(ctx, de->name, size,
|
2007-11-15 00:59:47 +00:00
|
|
|
le16_to_cpu(de->ino),
|
2013-05-16 17:41:48 +00:00
|
|
|
DT_UNKNOWN)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
brelse(bh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += BFS_DIRENT_SIZE;
|
2013-05-16 17:41:48 +00:00
|
|
|
ctx->pos += BFS_DIRENT_SIZE;
|
|
|
|
} while ((offset < BFS_BSIZE) && (ctx->pos < dir->i_size));
|
2005-04-16 22:20:36 +00:00
|
|
|
brelse(bh);
|
|
|
|
}
|
2013-05-16 17:41:48 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-28 09:56:42 +00:00
|
|
|
const struct file_operations bfs_dir_operations = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.read = generic_read_dir,
|
2016-05-01 02:37:34 +00:00
|
|
|
.iterate_shared = bfs_readdir,
|
2010-05-26 15:53:41 +00:00
|
|
|
.fsync = generic_file_fsync,
|
2008-09-03 19:53:01 +00:00
|
|
|
.llseek = generic_file_llseek,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2011-07-26 05:42:34 +00:00
|
|
|
static int bfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
2012-06-10 22:05:36 +00:00
|
|
|
bool excl)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int err;
|
2007-11-15 00:59:47 +00:00
|
|
|
struct inode *inode;
|
|
|
|
struct super_block *s = dir->i_sb;
|
|
|
|
struct bfs_sb_info *info = BFS_SB(s);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long ino;
|
|
|
|
|
|
|
|
inode = new_inode(s);
|
|
|
|
if (!inode)
|
2015-04-16 19:48:32 +00:00
|
|
|
return -ENOMEM;
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_lock(&info->bfs_lock);
|
2011-03-21 12:32:53 +00:00
|
|
|
ino = find_first_zero_bit(info->si_imap, info->si_lasti + 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ino > info->si_lasti) {
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
iput(inode);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
2007-11-15 00:59:47 +00:00
|
|
|
set_bit(ino, info->si_imap);
|
2005-04-16 22:20:36 +00:00
|
|
|
info->si_freei--;
|
2010-03-04 14:31:46 +00:00
|
|
|
inode_init_owner(inode, dir, mode);
|
2016-09-14 14:48:05 +00:00
|
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
2006-09-27 08:50:49 +00:00
|
|
|
inode->i_blocks = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
inode->i_op = &bfs_file_inops;
|
|
|
|
inode->i_fop = &bfs_file_operations;
|
|
|
|
inode->i_mapping->a_ops = &bfs_aops;
|
|
|
|
inode->i_ino = ino;
|
2005-10-04 16:43:06 +00:00
|
|
|
BFS_I(inode)->i_dsk_ino = ino;
|
2005-04-16 22:20:36 +00:00
|
|
|
BFS_I(inode)->i_sblock = 0;
|
|
|
|
BFS_I(inode)->i_eblock = 0;
|
|
|
|
insert_inode_hash(inode);
|
|
|
|
mark_inode_dirty(inode);
|
2014-08-08 21:22:29 +00:00
|
|
|
bfs_dump_imap("create", s);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
err = bfs_add_entry(dir, dentry->d_name.name, dentry->d_name.len,
|
|
|
|
inode->i_ino);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err) {
|
2006-10-01 06:29:03 +00:00
|
|
|
inode_dec_link_count(inode);
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2008-09-13 09:33:12 +00:00
|
|
|
iput(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static struct dentry *bfs_lookup(struct inode *dir, struct dentry *dentry,
|
2012-06-10 21:13:09 +00:00
|
|
|
unsigned int flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-11-15 00:59:47 +00:00
|
|
|
struct inode *inode = NULL;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
struct bfs_dirent *de;
|
2008-07-26 02:44:54 +00:00
|
|
|
struct bfs_sb_info *info = BFS_SB(dir->i_sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (dentry->d_name.len > BFS_NAMELEN)
|
|
|
|
return ERR_PTR(-ENAMETOOLONG);
|
|
|
|
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_lock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
|
|
|
|
if (bh) {
|
2005-09-09 20:02:04 +00:00
|
|
|
unsigned long ino = (unsigned long)le16_to_cpu(de->ino);
|
2005-04-16 22:20:36 +00:00
|
|
|
brelse(bh);
|
2008-02-07 08:15:32 +00:00
|
|
|
inode = bfs_iget(dir->i_sb, ino);
|
|
|
|
if (IS_ERR(inode)) {
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2008-02-07 08:15:32 +00:00
|
|
|
return ERR_CAST(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
d_add(dentry, inode);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static int bfs_link(struct dentry *old, struct inode *dir,
|
|
|
|
struct dentry *new)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-03-17 22:25:59 +00:00
|
|
|
struct inode *inode = d_inode(old);
|
2008-07-26 02:44:54 +00:00
|
|
|
struct bfs_sb_info *info = BFS_SB(inode->i_sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
int err;
|
|
|
|
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_lock(&info->bfs_lock);
|
2007-11-15 00:59:47 +00:00
|
|
|
err = bfs_add_entry(dir, new->d_name.name, new->d_name.len,
|
|
|
|
inode->i_ino);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err) {
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
2006-10-01 06:29:04 +00:00
|
|
|
inc_nlink(inode);
|
2016-09-14 14:48:05 +00:00
|
|
|
inode->i_ctime = current_time(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
mark_inode_dirty(inode);
|
2010-10-23 15:11:40 +00:00
|
|
|
ihold(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
d_instantiate(new, inode);
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static int bfs_unlink(struct inode *dir, struct dentry *dentry)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int error = -ENOENT;
|
2015-03-17 22:25:59 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2007-11-15 00:59:47 +00:00
|
|
|
struct buffer_head *bh;
|
|
|
|
struct bfs_dirent *de;
|
2008-07-26 02:44:54 +00:00
|
|
|
struct bfs_sb_info *info = BFS_SB(inode->i_sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_lock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
|
2007-11-15 00:59:47 +00:00
|
|
|
if (!bh || (le16_to_cpu(de->ino) != inode->i_ino))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out_brelse;
|
|
|
|
|
|
|
|
if (!inode->i_nlink) {
|
2007-11-15 00:59:47 +00:00
|
|
|
printf("unlinking non-existent file %s:%lu (nlink=%d)\n",
|
|
|
|
inode->i_sb->s_id, inode->i_ino,
|
|
|
|
inode->i_nlink);
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
de->ino = 0;
|
2009-06-08 05:15:58 +00:00
|
|
|
mark_buffer_dirty_inode(bh, dir);
|
2016-09-14 14:48:05 +00:00
|
|
|
dir->i_ctime = dir->i_mtime = current_time(dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
mark_inode_dirty(dir);
|
|
|
|
inode->i_ctime = dir->i_ctime;
|
2006-10-01 06:29:03 +00:00
|
|
|
inode_dec_link_count(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
error = 0;
|
|
|
|
|
|
|
|
out_brelse:
|
|
|
|
brelse(bh);
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static int bfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
fs: support RENAME_NOREPLACE for local filesystems
This is trivial to do:
- add flags argument to foo_rename()
- check if flags doesn't have any other than RENAME_NOREPLACE
- assign foo_rename() to .rename2 instead of .rename
Filesystems converted:
affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos,
nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: Boaz Harrosh <ooo@electrozaur.com>
Acked-by: Richard Weinberger <richard@nod.at>
Acked-by: Bob Copeland <me@bobcopeland.com>
Acked-by: Jan Kara <jack@suse.cz>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dave Kleikamp <shaggy@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Christoph Hellwig <hch@infradead.org>
2016-09-27 09:03:57 +00:00
|
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-11-15 00:59:47 +00:00
|
|
|
struct inode *old_inode, *new_inode;
|
|
|
|
struct buffer_head *old_bh, *new_bh;
|
|
|
|
struct bfs_dirent *old_de, *new_de;
|
2008-07-26 02:44:54 +00:00
|
|
|
struct bfs_sb_info *info;
|
2005-04-16 22:20:36 +00:00
|
|
|
int error = -ENOENT;
|
|
|
|
|
fs: support RENAME_NOREPLACE for local filesystems
This is trivial to do:
- add flags argument to foo_rename()
- check if flags doesn't have any other than RENAME_NOREPLACE
- assign foo_rename() to .rename2 instead of .rename
Filesystems converted:
affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos,
nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: Boaz Harrosh <ooo@electrozaur.com>
Acked-by: Richard Weinberger <richard@nod.at>
Acked-by: Bob Copeland <me@bobcopeland.com>
Acked-by: Jan Kara <jack@suse.cz>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dave Kleikamp <shaggy@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Christoph Hellwig <hch@infradead.org>
2016-09-27 09:03:57 +00:00
|
|
|
if (flags & ~RENAME_NOREPLACE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
old_bh = new_bh = NULL;
|
2015-03-17 22:25:59 +00:00
|
|
|
old_inode = d_inode(old_dentry);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (S_ISDIR(old_inode->i_mode))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-07-26 02:44:54 +00:00
|
|
|
info = BFS_SB(old_inode->i_sb);
|
|
|
|
|
|
|
|
mutex_lock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
old_bh = bfs_find_entry(old_dir,
|
|
|
|
old_dentry->d_name.name,
|
|
|
|
old_dentry->d_name.len, &old_de);
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
if (!old_bh || (le16_to_cpu(old_de->ino) != old_inode->i_ino))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto end_rename;
|
|
|
|
|
|
|
|
error = -EPERM;
|
2015-03-17 22:25:59 +00:00
|
|
|
new_inode = d_inode(new_dentry);
|
2005-04-16 22:20:36 +00:00
|
|
|
new_bh = bfs_find_entry(new_dir,
|
|
|
|
new_dentry->d_name.name,
|
|
|
|
new_dentry->d_name.len, &new_de);
|
|
|
|
|
|
|
|
if (new_bh && !new_inode) {
|
|
|
|
brelse(new_bh);
|
|
|
|
new_bh = NULL;
|
|
|
|
}
|
|
|
|
if (!new_bh) {
|
|
|
|
error = bfs_add_entry(new_dir,
|
|
|
|
new_dentry->d_name.name,
|
2007-11-15 00:59:47 +00:00
|
|
|
new_dentry->d_name.len,
|
|
|
|
old_inode->i_ino);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (error)
|
|
|
|
goto end_rename;
|
|
|
|
}
|
|
|
|
old_de->ino = 0;
|
2016-09-14 14:48:05 +00:00
|
|
|
old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
mark_inode_dirty(old_dir);
|
|
|
|
if (new_inode) {
|
2016-09-14 14:48:05 +00:00
|
|
|
new_inode->i_ctime = current_time(new_inode);
|
2006-10-01 06:29:03 +00:00
|
|
|
inode_dec_link_count(new_inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-06-08 05:15:58 +00:00
|
|
|
mark_buffer_dirty_inode(old_bh, old_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
error = 0;
|
|
|
|
|
|
|
|
end_rename:
|
2008-07-26 02:44:54 +00:00
|
|
|
mutex_unlock(&info->bfs_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
brelse(old_bh);
|
|
|
|
brelse(new_bh);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-02-12 08:55:38 +00:00
|
|
|
const struct inode_operations bfs_dir_inops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.create = bfs_create,
|
|
|
|
.lookup = bfs_lookup,
|
|
|
|
.link = bfs_link,
|
|
|
|
.unlink = bfs_unlink,
|
|
|
|
.rename = bfs_rename,
|
|
|
|
};
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static int bfs_add_entry(struct inode *dir, const unsigned char *name,
|
|
|
|
int namelen, int ino)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-11-15 00:59:47 +00:00
|
|
|
struct buffer_head *bh;
|
|
|
|
struct bfs_dirent *de;
|
|
|
|
int block, sblock, eblock, off, pos;
|
2005-04-16 22:20:36 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
dprintf("name=%s, namelen=%d\n", name, namelen);
|
|
|
|
|
|
|
|
if (!namelen)
|
|
|
|
return -ENOENT;
|
|
|
|
if (namelen > BFS_NAMELEN)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
sblock = BFS_I(dir)->i_sblock;
|
|
|
|
eblock = BFS_I(dir)->i_eblock;
|
2007-11-15 00:59:47 +00:00
|
|
|
for (block = sblock; block <= eblock; block++) {
|
2005-04-16 22:20:36 +00:00
|
|
|
bh = sb_bread(dir->i_sb, block);
|
2007-11-15 00:59:47 +00:00
|
|
|
if (!bh)
|
2015-04-16 19:48:32 +00:00
|
|
|
return -EIO;
|
2007-11-15 00:59:47 +00:00
|
|
|
for (off = 0; off < BFS_BSIZE; off += BFS_DIRENT_SIZE) {
|
2005-04-16 22:20:36 +00:00
|
|
|
de = (struct bfs_dirent *)(bh->b_data + off);
|
|
|
|
if (!de->ino) {
|
2007-11-15 00:59:47 +00:00
|
|
|
pos = (block - sblock) * BFS_BSIZE + off;
|
|
|
|
if (pos >= dir->i_size) {
|
2005-04-16 22:20:36 +00:00
|
|
|
dir->i_size += BFS_DIRENT_SIZE;
|
2016-09-14 14:48:05 +00:00
|
|
|
dir->i_ctime = current_time(dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2016-09-14 14:48:05 +00:00
|
|
|
dir->i_mtime = current_time(dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
mark_inode_dirty(dir);
|
2005-09-09 20:02:04 +00:00
|
|
|
de->ino = cpu_to_le16((u16)ino);
|
2007-11-15 00:59:47 +00:00
|
|
|
for (i = 0; i < BFS_NAMELEN; i++)
|
|
|
|
de->name[i] =
|
|
|
|
(i < namelen) ? name[i] : 0;
|
2009-06-08 05:15:58 +00:00
|
|
|
mark_buffer_dirty_inode(bh, dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
brelse(bh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
brelse(bh);
|
|
|
|
}
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static inline int bfs_namecmp(int len, const unsigned char *name,
|
|
|
|
const char *buffer)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-11-15 00:59:47 +00:00
|
|
|
if ((len < BFS_NAMELEN) && buffer[len])
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
return !memcmp(name, buffer, len);
|
|
|
|
}
|
|
|
|
|
2007-11-15 00:59:47 +00:00
|
|
|
static struct buffer_head *bfs_find_entry(struct inode *dir,
|
|
|
|
const unsigned char *name, int namelen,
|
|
|
|
struct bfs_dirent **res_dir)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-11-15 00:59:47 +00:00
|
|
|
unsigned long block = 0, offset = 0;
|
|
|
|
struct buffer_head *bh = NULL;
|
|
|
|
struct bfs_dirent *de;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*res_dir = NULL;
|
|
|
|
if (namelen > BFS_NAMELEN)
|
|
|
|
return NULL;
|
2007-11-15 00:59:47 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
while (block * BFS_BSIZE + offset < dir->i_size) {
|
|
|
|
if (!bh) {
|
|
|
|
bh = sb_bread(dir->i_sb, BFS_I(dir)->i_sblock + block);
|
|
|
|
if (!bh) {
|
|
|
|
block++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
de = (struct bfs_dirent *)(bh->b_data + offset);
|
|
|
|
offset += BFS_DIRENT_SIZE;
|
2007-11-15 00:59:47 +00:00
|
|
|
if (le16_to_cpu(de->ino) &&
|
|
|
|
bfs_namecmp(namelen, name, de->name)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
*res_dir = de;
|
|
|
|
return bh;
|
|
|
|
}
|
|
|
|
if (offset < bh->b_size)
|
|
|
|
continue;
|
|
|
|
brelse(bh);
|
|
|
|
bh = NULL;
|
|
|
|
offset = 0;
|
|
|
|
block++;
|
|
|
|
}
|
|
|
|
brelse(bh);
|
|
|
|
return NULL;
|
|
|
|
}
|