This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnamei.c
88 lines (72 loc) · 1.97 KB
/
namei.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: GPL-2.0
/*
* linux/fs/apfs/namei.c
*
* Copyright (C) 2018 Ernesto A. Fernández <[email protected]>
*/
#include "apfs.h"
#include "dir.h"
#include "inode.h"
#include "key.h"
#include "super.h"
#include "unicode.h"
#include "xattr.h"
static struct dentry *apfs_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags)
{
struct inode *inode = NULL;
u64 ino = 0;
int err;
if (dentry->d_name.len > APFS_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG);
err = apfs_inode_by_name(dir, &dentry->d_name, &ino);
if (err && err != -ENODATA)
return ERR_PTR(err);
if (!err) {
inode = apfs_iget(dir->i_sb, ino);
if (IS_ERR(inode))
return ERR_CAST(inode);
}
return d_splice_alias(inode, dentry);
}
const struct inode_operations apfs_dir_inode_operations = {
.lookup = apfs_lookup,
.getattr = apfs_getattr,
.listxattr = apfs_listxattr,
};
const struct inode_operations apfs_special_inode_operations = {
.getattr = apfs_getattr,
.listxattr = apfs_listxattr,
};
static int apfs_dentry_hash(const struct dentry *dir, struct qstr *child)
{
struct apfs_unicursor cursor;
unsigned long hash;
bool case_fold = apfs_is_case_insensitive(dir->d_sb);
apfs_init_unicursor(&cursor, child->name);
hash = init_name_hash(dir);
while (1) {
int i;
unicode_t utf32;
utf32 = apfs_normalize_next(&cursor, case_fold);
if (!utf32)
break;
/* Hash the unicode character one byte at a time */
for (i = 0; i < 4; ++i) {
hash = partial_name_hash((u8)utf32, hash);
utf32 = utf32 >> 8;
}
}
child->hash = end_name_hash(hash);
/* TODO: return error instead of truncating invalid UTF-8? */
return 0;
}
static int apfs_dentry_compare(const struct dentry *dentry, unsigned int len,
const char *str, const struct qstr *name)
{
return apfs_filename_cmp(dentry->d_sb, name->name, str);
}
const struct dentry_operations apfs_dentry_operations = {
.d_hash = apfs_dentry_hash,
.d_compare = apfs_dentry_compare,
};