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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-04-04 01:23:33 +08:00
|
|
|
|
2008-07-21 04:31:56 +08:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include "ctree.h"
|
|
|
|
#include "disk-io.h"
|
|
|
|
#include "btrfs_inode.h"
|
|
|
|
#include "print-tree.h"
|
|
|
|
#include "export.h"
|
|
|
|
|
2009-01-06 10:25:51 +08:00
|
|
|
#define BTRFS_FID_SIZE_NON_CONNECTABLE (offsetof(struct btrfs_fid, \
|
|
|
|
parent_objectid) / 4)
|
|
|
|
#define BTRFS_FID_SIZE_CONNECTABLE (offsetof(struct btrfs_fid, \
|
|
|
|
parent_root_objectid) / 4)
|
|
|
|
#define BTRFS_FID_SIZE_CONNECTABLE_ROOT (sizeof(struct btrfs_fid) / 4)
|
2008-07-21 04:31:56 +08:00
|
|
|
|
2012-04-03 02:34:06 +08:00
|
|
|
static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
|
|
|
|
struct inode *parent)
|
2008-07-21 04:31:56 +08:00
|
|
|
{
|
|
|
|
struct btrfs_fid *fid = (struct btrfs_fid *)fh;
|
|
|
|
int len = *max_len;
|
|
|
|
int type;
|
|
|
|
|
2012-04-03 02:34:06 +08:00
|
|
|
if (parent && (len < BTRFS_FID_SIZE_CONNECTABLE)) {
|
2011-01-29 21:13:25 +08:00
|
|
|
*max_len = BTRFS_FID_SIZE_CONNECTABLE;
|
2013-02-17 14:48:11 +08:00
|
|
|
return FILEID_INVALID;
|
2011-01-29 21:13:25 +08:00
|
|
|
} else if (len < BTRFS_FID_SIZE_NON_CONNECTABLE) {
|
|
|
|
*max_len = BTRFS_FID_SIZE_NON_CONNECTABLE;
|
2013-02-17 14:48:11 +08:00
|
|
|
return FILEID_INVALID;
|
2011-01-29 21:13:25 +08:00
|
|
|
}
|
2008-07-21 04:31:56 +08:00
|
|
|
|
|
|
|
len = BTRFS_FID_SIZE_NON_CONNECTABLE;
|
|
|
|
type = FILEID_BTRFS_WITHOUT_PARENT;
|
|
|
|
|
2017-01-11 02:35:31 +08:00
|
|
|
fid->objectid = btrfs_ino(BTRFS_I(inode));
|
2018-08-06 13:25:24 +08:00
|
|
|
fid->root_objectid = BTRFS_I(inode)->root->root_key.objectid;
|
2008-07-21 04:31:56 +08:00
|
|
|
fid->gen = inode->i_generation;
|
|
|
|
|
2012-04-03 02:34:06 +08:00
|
|
|
if (parent) {
|
2008-07-21 04:31:56 +08:00
|
|
|
u64 parent_root_id;
|
|
|
|
|
|
|
|
fid->parent_objectid = BTRFS_I(parent)->location.objectid;
|
|
|
|
fid->parent_gen = parent->i_generation;
|
2018-08-06 13:25:24 +08:00
|
|
|
parent_root_id = BTRFS_I(parent)->root->root_key.objectid;
|
2008-07-21 04:31:56 +08:00
|
|
|
|
|
|
|
if (parent_root_id != fid->root_objectid) {
|
|
|
|
fid->parent_root_objectid = parent_root_id;
|
|
|
|
len = BTRFS_FID_SIZE_CONNECTABLE_ROOT;
|
|
|
|
type = FILEID_BTRFS_WITH_PARENT_ROOT;
|
|
|
|
} else {
|
|
|
|
len = BTRFS_FID_SIZE_CONNECTABLE;
|
|
|
|
type = FILEID_BTRFS_WITH_PARENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*max_len = len;
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2024-06-11 20:26:44 +08:00
|
|
|
struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
|
2024-06-12 13:13:20 +08:00
|
|
|
u64 root_objectid, u64 generation,
|
2024-06-11 20:26:44 +08:00
|
|
|
int check_generation)
|
2008-07-21 04:31:56 +08:00
|
|
|
{
|
2011-11-18 04:40:49 +08:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
|
2008-07-21 04:31:56 +08:00
|
|
|
struct btrfs_root *root;
|
|
|
|
struct inode *inode;
|
|
|
|
struct btrfs_key key;
|
2009-09-22 04:00:26 +08:00
|
|
|
int index;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (objectid < BTRFS_FIRST_FREE_OBJECTID)
|
|
|
|
return ERR_PTR(-ESTALE);
|
2008-07-21 04:31:56 +08:00
|
|
|
|
2008-08-20 05:20:17 +08:00
|
|
|
key.objectid = root_objectid;
|
2014-06-05 00:41:45 +08:00
|
|
|
key.type = BTRFS_ROOT_ITEM_KEY;
|
2008-08-20 05:20:17 +08:00
|
|
|
key.offset = (u64)-1;
|
|
|
|
|
2009-09-22 04:00:26 +08:00
|
|
|
index = srcu_read_lock(&fs_info->subvol_srcu);
|
|
|
|
|
|
|
|
root = btrfs_read_fs_root_no_name(fs_info, &key);
|
|
|
|
if (IS_ERR(root)) {
|
|
|
|
err = PTR_ERR(root);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-07-21 04:31:56 +08:00
|
|
|
key.objectid = objectid;
|
2014-06-05 00:41:45 +08:00
|
|
|
key.type = BTRFS_INODE_ITEM_KEY;
|
2008-07-21 04:31:56 +08:00
|
|
|
key.offset = 0;
|
|
|
|
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 01:38:27 +08:00
|
|
|
inode = btrfs_iget(sb, &key, root, NULL);
|
2009-09-22 04:00:26 +08:00
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcu_read_unlock(&fs_info->subvol_srcu, index);
|
2008-07-21 04:31:56 +08:00
|
|
|
|
2009-09-22 04:00:26 +08:00
|
|
|
if (check_generation && generation != inode->i_generation) {
|
2008-07-21 04:31:56 +08:00
|
|
|
iput(inode);
|
|
|
|
return ERR_PTR(-ESTALE);
|
|
|
|
}
|
|
|
|
|
2010-12-20 23:56:06 +08:00
|
|
|
return d_obtain_alias(inode);
|
2009-09-22 04:00:26 +08:00
|
|
|
fail:
|
|
|
|
srcu_read_unlock(&fs_info->subvol_srcu, index);
|
|
|
|
return ERR_PTR(err);
|
2008-07-21 04:31:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *btrfs_fh_to_parent(struct super_block *sb, struct fid *fh,
|
|
|
|
int fh_len, int fh_type)
|
|
|
|
{
|
|
|
|
struct btrfs_fid *fid = (struct btrfs_fid *) fh;
|
|
|
|
u64 objectid, root_objectid;
|
|
|
|
u32 generation;
|
|
|
|
|
|
|
|
if (fh_type == FILEID_BTRFS_WITH_PARENT) {
|
2015-05-08 08:16:23 +08:00
|
|
|
if (fh_len < BTRFS_FID_SIZE_CONNECTABLE)
|
2008-07-21 04:31:56 +08:00
|
|
|
return NULL;
|
|
|
|
root_objectid = fid->root_objectid;
|
|
|
|
} else if (fh_type == FILEID_BTRFS_WITH_PARENT_ROOT) {
|
2015-05-08 08:16:23 +08:00
|
|
|
if (fh_len < BTRFS_FID_SIZE_CONNECTABLE_ROOT)
|
2008-07-21 04:31:56 +08:00
|
|
|
return NULL;
|
|
|
|
root_objectid = fid->parent_root_objectid;
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
objectid = fid->parent_objectid;
|
|
|
|
generation = fid->parent_gen;
|
|
|
|
|
2009-09-22 04:00:26 +08:00
|
|
|
return btrfs_get_dentry(sb, objectid, root_objectid, generation, 1);
|
2008-07-21 04:31:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *btrfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
|
|
|
|
int fh_len, int fh_type)
|
|
|
|
{
|
|
|
|
struct btrfs_fid *fid = (struct btrfs_fid *) fh;
|
|
|
|
u64 objectid, root_objectid;
|
|
|
|
u32 generation;
|
|
|
|
|
|
|
|
if ((fh_type != FILEID_BTRFS_WITH_PARENT ||
|
2015-05-08 08:16:23 +08:00
|
|
|
fh_len < BTRFS_FID_SIZE_CONNECTABLE) &&
|
2008-07-21 04:31:56 +08:00
|
|
|
(fh_type != FILEID_BTRFS_WITH_PARENT_ROOT ||
|
2015-05-08 08:16:23 +08:00
|
|
|
fh_len < BTRFS_FID_SIZE_CONNECTABLE_ROOT) &&
|
2008-07-21 04:31:56 +08:00
|
|
|
(fh_type != FILEID_BTRFS_WITHOUT_PARENT ||
|
2015-05-08 08:16:23 +08:00
|
|
|
fh_len < BTRFS_FID_SIZE_NON_CONNECTABLE))
|
2008-07-21 04:31:56 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
objectid = fid->objectid;
|
|
|
|
root_objectid = fid->root_objectid;
|
|
|
|
generation = fid->gen;
|
|
|
|
|
2009-09-22 04:00:26 +08:00
|
|
|
return btrfs_get_dentry(sb, objectid, root_objectid, generation, 1);
|
2008-07-21 04:31:56 +08:00
|
|
|
}
|
|
|
|
|
2024-06-11 20:26:44 +08:00
|
|
|
struct dentry *btrfs_get_parent(struct dentry *child)
|
2008-07-21 04:31:56 +08:00
|
|
|
{
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *dir = d_inode(child);
|
2016-06-23 06:54:23 +08:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(dir->i_sb);
|
2008-07-21 04:31:56 +08:00
|
|
|
struct btrfs_root *root = BTRFS_I(dir)->root;
|
|
|
|
struct btrfs_path *path;
|
|
|
|
struct extent_buffer *leaf;
|
2009-09-22 04:00:26 +08:00
|
|
|
struct btrfs_root_ref *ref;
|
|
|
|
struct btrfs_key key;
|
|
|
|
struct btrfs_key found_key;
|
2008-07-21 04:31:56 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
path = btrfs_alloc_path();
|
2011-01-26 14:22:08 +08:00
|
|
|
if (!path)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2008-07-21 04:31:56 +08:00
|
|
|
|
2017-01-11 02:35:31 +08:00
|
|
|
if (btrfs_ino(BTRFS_I(dir)) == BTRFS_FIRST_FREE_OBJECTID) {
|
2009-09-22 04:00:26 +08:00
|
|
|
key.objectid = root->root_key.objectid;
|
|
|
|
key.type = BTRFS_ROOT_BACKREF_KEY;
|
|
|
|
key.offset = (u64)-1;
|
2016-06-23 06:54:23 +08:00
|
|
|
root = fs_info->tree_root;
|
2009-09-22 04:00:26 +08:00
|
|
|
} else {
|
2017-01-11 02:35:31 +08:00
|
|
|
key.objectid = btrfs_ino(BTRFS_I(dir));
|
2009-09-22 04:00:26 +08:00
|
|
|
key.type = BTRFS_INODE_REF_KEY;
|
|
|
|
key.offset = (u64)-1;
|
|
|
|
}
|
2008-07-21 04:31:56 +08:00
|
|
|
|
2008-08-19 05:50:22 +08:00
|
|
|
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
2009-09-22 04:00:26 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2012-03-12 23:03:00 +08:00
|
|
|
BUG_ON(ret == 0); /* Key with offset of -1 found */
|
2009-09-22 04:00:26 +08:00
|
|
|
if (path->slots[0] == 0) {
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto fail;
|
2008-08-20 05:33:04 +08:00
|
|
|
}
|
2009-09-22 04:00:26 +08:00
|
|
|
|
|
|
|
path->slots[0]--;
|
2008-07-21 04:31:56 +08:00
|
|
|
leaf = path->nodes[0];
|
2009-09-22 04:00:26 +08:00
|
|
|
|
|
|
|
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
|
|
|
|
if (found_key.objectid != key.objectid || found_key.type != key.type) {
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto fail;
|
2008-07-21 04:31:56 +08:00
|
|
|
}
|
|
|
|
|
2009-09-22 04:00:26 +08:00
|
|
|
if (found_key.type == BTRFS_ROOT_BACKREF_KEY) {
|
|
|
|
ref = btrfs_item_ptr(leaf, path->slots[0],
|
|
|
|
struct btrfs_root_ref);
|
|
|
|
key.objectid = btrfs_root_ref_dirid(leaf, ref);
|
|
|
|
} else {
|
|
|
|
key.objectid = found_key.offset;
|
|
|
|
}
|
2008-07-21 04:31:56 +08:00
|
|
|
btrfs_free_path(path);
|
|
|
|
|
2009-09-22 04:00:26 +08:00
|
|
|
if (found_key.type == BTRFS_ROOT_BACKREF_KEY) {
|
2016-06-23 06:54:23 +08:00
|
|
|
return btrfs_get_dentry(fs_info->sb, key.objectid,
|
2009-09-22 04:00:26 +08:00
|
|
|
found_key.offset, 0, 0);
|
|
|
|
}
|
2008-08-20 05:20:17 +08:00
|
|
|
|
2009-09-22 04:00:26 +08:00
|
|
|
key.type = BTRFS_INODE_ITEM_KEY;
|
2008-07-21 04:31:56 +08:00
|
|
|
key.offset = 0;
|
2016-06-23 06:54:23 +08:00
|
|
|
return d_obtain_alias(btrfs_iget(fs_info->sb, &key, root, NULL));
|
2009-09-22 04:00:26 +08:00
|
|
|
fail:
|
|
|
|
btrfs_free_path(path);
|
|
|
|
return ERR_PTR(ret);
|
2008-07-21 04:31:56 +08:00
|
|
|
}
|
|
|
|
|
2010-11-18 02:54:54 +08:00
|
|
|
static int btrfs_get_name(struct dentry *parent, char *name,
|
|
|
|
struct dentry *child)
|
|
|
|
{
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *inode = d_inode(child);
|
|
|
|
struct inode *dir = d_inode(parent);
|
2016-06-23 06:54:23 +08:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
|
2010-11-18 02:54:54 +08:00
|
|
|
struct btrfs_path *path;
|
|
|
|
struct btrfs_root *root = BTRFS_I(dir)->root;
|
|
|
|
struct btrfs_inode_ref *iref;
|
|
|
|
struct btrfs_root_ref *rref;
|
|
|
|
struct extent_buffer *leaf;
|
|
|
|
unsigned long name_ptr;
|
|
|
|
struct btrfs_key key;
|
|
|
|
int name_len;
|
|
|
|
int ret;
|
2011-04-20 10:31:50 +08:00
|
|
|
u64 ino;
|
2010-11-18 02:54:54 +08:00
|
|
|
|
|
|
|
if (!S_ISDIR(dir->i_mode))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-01-11 02:35:31 +08:00
|
|
|
ino = btrfs_ino(BTRFS_I(inode));
|
2011-04-20 10:31:50 +08:00
|
|
|
|
2010-11-18 02:54:54 +08:00
|
|
|
path = btrfs_alloc_path();
|
|
|
|
if (!path)
|
|
|
|
return -ENOMEM;
|
|
|
|
path->leave_spinning = 1;
|
|
|
|
|
2011-04-20 10:31:50 +08:00
|
|
|
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
|
2010-11-18 02:54:54 +08:00
|
|
|
key.objectid = BTRFS_I(inode)->root->root_key.objectid;
|
|
|
|
key.type = BTRFS_ROOT_BACKREF_KEY;
|
|
|
|
key.offset = (u64)-1;
|
2016-06-23 06:54:23 +08:00
|
|
|
root = fs_info->tree_root;
|
2010-11-18 02:54:54 +08:00
|
|
|
} else {
|
2011-04-20 10:31:50 +08:00
|
|
|
key.objectid = ino;
|
2017-01-11 02:35:31 +08:00
|
|
|
key.offset = btrfs_ino(BTRFS_I(dir));
|
2010-11-18 02:54:54 +08:00
|
|
|
key.type = BTRFS_INODE_REF_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
} else if (ret > 0) {
|
2011-04-20 10:31:50 +08:00
|
|
|
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
|
2010-11-18 02:54:54 +08:00
|
|
|
path->slots[0]--;
|
|
|
|
} else {
|
|
|
|
btrfs_free_path(path);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
leaf = path->nodes[0];
|
|
|
|
|
2011-04-20 10:31:50 +08:00
|
|
|
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
|
|
|
|
rref = btrfs_item_ptr(leaf, path->slots[0],
|
2010-11-18 02:54:54 +08:00
|
|
|
struct btrfs_root_ref);
|
2011-04-20 10:31:50 +08:00
|
|
|
name_ptr = (unsigned long)(rref + 1);
|
|
|
|
name_len = btrfs_root_ref_name_len(leaf, rref);
|
2010-11-18 02:54:54 +08:00
|
|
|
} else {
|
|
|
|
iref = btrfs_item_ptr(leaf, path->slots[0],
|
|
|
|
struct btrfs_inode_ref);
|
|
|
|
name_ptr = (unsigned long)(iref + 1);
|
|
|
|
name_len = btrfs_inode_ref_name_len(leaf, iref);
|
|
|
|
}
|
|
|
|
|
|
|
|
read_extent_buffer(leaf, name, name_ptr, name_len);
|
|
|
|
btrfs_free_path(path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* have to add the null termination to make sure that reconnect_path
|
|
|
|
* gets the right len for strlen
|
|
|
|
*/
|
|
|
|
name[name_len] = '\0';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-21 04:31:56 +08:00
|
|
|
const struct export_operations btrfs_export_ops = {
|
|
|
|
.encode_fh = btrfs_encode_fh,
|
|
|
|
.fh_to_dentry = btrfs_fh_to_dentry,
|
|
|
|
.fh_to_parent = btrfs_fh_to_parent,
|
|
|
|
.get_parent = btrfs_get_parent,
|
2010-11-18 02:54:54 +08:00
|
|
|
.get_name = btrfs_get_name,
|
2008-07-21 04:31:56 +08:00
|
|
|
};
|