| 1 |
|
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
#include <linux/namei.h> |
| 7 |
#include "apfs.h" |
| 8 |
#include "unicode.h" |
| 9 |
|
| 10 |
static struct dentry *apfs_lookup(struct inode *dir, struct dentry *dentry, |
| 11 |
unsigned int flags) |
| 12 |
{ |
| 13 |
struct inode *inode = NULL; |
| 14 |
u64 ino = 0; |
| 15 |
int err; |
| 16 |
|
| 17 |
if (dentry->d_name.len > APFS_NAME_LEN) |
| 18 |
return ERR_PTR(-ENAMETOOLONG); |
| 19 |
|
| 20 |
err = apfs_inode_by_name(dir, &dentry->d_name, &ino); |
| 21 |
if (err && err != -ENODATA) { |
| 22 |
apfs_err(dir->i_sb, "inode lookup by name failed"); |
| 23 |
return ERR_PTR(err); |
| 24 |
} |
| 25 |
|
| 26 |
if (!err) { |
| 27 |
inode = apfs_iget(dir->i_sb, ino); |
| 28 |
if (IS_ERR(inode)) { |
| 29 |
apfs_err(dir->i_sb, "iget failed"); |
| 30 |
return ERR_CAST(inode); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
return d_splice_alias(inode, dentry); |
| 35 |
} |
| 36 |
|
| 37 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) |
| 38 |
static int apfs_symlink(struct inode *dir, struct dentry *dentry, |
| 39 |
const char *symname) |
| 40 |
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) && !RHEL_VERSION_GE(9, 6) |
| 41 |
static int apfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, |
| 42 |
struct dentry *dentry, const char *symname) |
| 43 |
#else |
| 44 |
static int apfs_symlink(struct mnt_idmap *idmap, struct inode *dir, |
| 45 |
struct dentry *dentry, const char *symname) |
| 46 |
#endif |
| 47 |
{ |
| 48 |
|
| 49 |
return apfs_mkany(dir, dentry, S_IFLNK | 0x1ed, 0 , symname); |
| 50 |
} |
| 51 |
|
| 52 |
const struct inode_operations apfs_dir_inode_operations = { |
| 53 |
.create = apfs_create, |
| 54 |
.lookup = apfs_lookup, |
| 55 |
.link = apfs_link, |
| 56 |
.unlink = apfs_unlink, |
| 57 |
.symlink = apfs_symlink, |
| 58 |
.mkdir = apfs_mkdir, |
| 59 |
.rmdir = apfs_rmdir, |
| 60 |
.mknod = apfs_mknod, |
| 61 |
.rename = apfs_rename, |
| 62 |
.getattr = apfs_getattr, |
| 63 |
.listxattr = apfs_listxattr, |
| 64 |
.setattr = apfs_setattr, |
| 65 |
.update_time = apfs_update_time, |
| 66 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 13, 0) |
| 67 |
.fileattr_get = apfs_fileattr_get, |
| 68 |
.fileattr_set = apfs_fileattr_set, |
| 69 |
#endif |
| 70 |
}; |
| 71 |
|
| 72 |
const struct inode_operations apfs_special_inode_operations = { |
| 73 |
.getattr = apfs_getattr, |
| 74 |
.listxattr = apfs_listxattr, |
| 75 |
.setattr = apfs_setattr, |
| 76 |
.update_time = apfs_update_time, |
| 77 |
}; |
| 78 |
|
| 79 |
static int apfs_dentry_hash(const struct dentry *dir, struct qstr *child) |
| 80 |
{ |
| 81 |
struct apfs_unicursor cursor; |
| 82 |
unsigned long hash; |
| 83 |
bool case_fold = apfs_is_case_insensitive(dir->d_sb); |
| 84 |
|
| 85 |
if (!apfs_is_normalization_insensitive(dir->d_sb)) |
| 86 |
return 0; |
| 87 |
|
| 88 |
apfs_init_unicursor(&cursor, child->name, child->len); |
| 89 |
hash = init_name_hash(dir); |
| 90 |
|
| 91 |
while (1) { |
| 92 |
int i; |
| 93 |
unicode_t utf32; |
| 94 |
|
| 95 |
utf32 = apfs_normalize_next(&cursor, case_fold); |
| 96 |
if (!utf32) |
| 97 |
break; |
| 98 |
|
| 99 |
|
| 100 |
for (i = 0; i < 4; ++i) { |
| 101 |
hash = partial_name_hash((u8)utf32, hash); |
| 102 |
utf32 = utf32 >> 8; |
| 103 |
} |
| 104 |
} |
| 105 |
child->hash = end_name_hash(hash); |
| 106 |
|
| 107 |
|
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
static int apfs_dentry_compare(const struct dentry *dentry, unsigned int len, |
| 112 |
const char *str, const struct qstr *name) |
| 113 |
{ |
| 114 |
return apfs_filename_cmp(dentry->d_sb, name->name, name->len, str, len); |
| 115 |
} |
| 116 |
|
| 117 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 14, 0) |
| 118 |
static int apfs_dentry_revalidate(struct dentry *dentry, unsigned int flags) |
| 119 |
#else |
| 120 |
static int apfs_dentry_revalidate(struct inode *dir, const struct qstr *name, struct dentry *dentry, unsigned int flags) |
| 121 |
#endif |
| 122 |
{ |
| 123 |
struct super_block *sb = dentry->d_sb; |
| 124 |
|
| 125 |
if (flags & LOOKUP_RCU) |
| 126 |
return -ECHILD; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
if (d_really_is_positive(dentry)) |
| 134 |
return 1; |
| 135 |
if (!apfs_is_case_insensitive(sb) && !apfs_is_normalization_insensitive(sb)) |
| 136 |
return 1; |
| 137 |
if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) |
| 138 |
return 0; |
| 139 |
return 1; |
| 140 |
} |
| 141 |
|
| 142 |
const struct dentry_operations apfs_dentry_operations = { |
| 143 |
.d_revalidate = apfs_dentry_revalidate, |
| 144 |
.d_hash = apfs_dentry_hash, |
| 145 |
.d_compare = apfs_dentry_compare, |
| 146 |
}; |