Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
master
Documentation
arch
block
certs
crypto
drivers
firmware
fs
9p
adfs
Kconfig
Makefile
adfs.h
dir.c
dir_f.c
dir_f.h
dir_fplus.c
dir_fplus.h
file.c
inode.c
map.c
super.c
affs
afs
autofs4
befs
bfs
btrfs
cachefiles
ceph
cifs
coda
configfs
cramfs
crypto
debugfs
devpts
dlm
ecryptfs
efivarfs
efs
exofs
exportfs
ext2
ext4
f2fs
fat
freevxfs
fscache
fuse
gfs2
hfs
hfsplus
hostfs
hpfs
hugetlbfs
isofs
jbd2
jffs2
jfs
kernfs
lockd
logfs
minix
ncpfs
nfs
nfs_common
nfsd
nilfs2
nls
notify
ntfs
ocfs2
omfs
openpromfs
orangefs
overlayfs
proc
pstore
qnx4
qnx6
quota
ramfs
reiserfs
romfs
squashfs
sysfs
sysv
tracefs
ubifs
udf
ufs
xfs
Kconfig
Kconfig.binfmt
Makefile
aio.c
anon_inodes.c
attr.c
bad_inode.c
binfmt_aout.c
binfmt_elf.c
binfmt_elf_fdpic.c
binfmt_em86.c
binfmt_flat.c
binfmt_misc.c
binfmt_script.c
block_dev.c
buffer.c
char_dev.c
compat.c
compat_binfmt_elf.c
compat_ioctl.c
coredump.c
dax.c
dcache.c
dcookies.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c
fcntl.c
fhandle.c
file.c
file_table.c
filesystems.c
fs-writeback.c
fs_pin.c
fs_struct.c
inode.c
internal.h
ioctl.c
libfs.c
locks.c
mbcache.c
mount.h
mpage.c
namei.c
namespace.c
no-block.c
nsfs.c
open.c
pipe.c
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
select.c
seq_file.c
signalfd.c
splice.c
stack.c
stat.c
statfs.c
super.c
sync.c
timerfd.c
userfaultfd.c
utimes.c
xattr.c
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.get_maintainer.ignore
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
fs
/
adfs
/
dir.c
Blame
Blame
Latest commit
History
History
288 lines (239 loc) · 5.43 KB
Breadcrumbs
linux
/
fs
/
adfs
/
dir.c
Top
File metadata and controls
Code
Blame
288 lines (239 loc) · 5.43 KB
Raw
/* * linux/fs/adfs/dir.c * * Copyright (C) 1999-2000 Russell King * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Common directory handling for ADFS */ #include "adfs.h" /* * For future. This should probably be per-directory. */ static DEFINE_RWLOCK(adfs_dir_lock); static int adfs_readdir(struct file *file, struct dir_context *ctx) { struct inode *inode = file_inode(file); struct super_block *sb = inode->i_sb; const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir; struct object_info obj; struct adfs_dir dir; int ret = 0; if (ctx->pos >> 32) return 0; ret = ops->read(sb, inode->i_ino, inode->i_size, &dir); if (ret) return ret; if (ctx->pos == 0) { if (!dir_emit_dot(file, ctx)) goto free_out; ctx->pos = 1; } if (ctx->pos == 1) { if (!dir_emit(ctx, "..", 2, dir.parent_id, DT_DIR)) goto free_out; ctx->pos = 2; } read_lock(&adfs_dir_lock); ret = ops->setpos(&dir, ctx->pos - 2); if (ret) goto unlock_out; while (ops->getnext(&dir, &obj) == 0) { if (!dir_emit(ctx, obj.name, obj.name_len, obj.file_id, DT_UNKNOWN)) break; ctx->pos++; } unlock_out: read_unlock(&adfs_dir_lock); free_out: ops->free(&dir); return ret; } int adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait) { int ret = -EINVAL; #ifdef CONFIG_ADFS_FS_RW const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir; struct adfs_dir dir; printk(KERN_INFO "adfs_dir_update: object %06X in dir %06X\n", obj->file_id, obj->parent_id); if (!ops->update) { ret = -EINVAL; goto out; } ret = ops->read(sb, obj->parent_id, 0, &dir); if (ret) goto out; write_lock(&adfs_dir_lock); ret = ops->update(&dir, obj); write_unlock(&adfs_dir_lock); if (wait) { int err = ops->sync(&dir); if (!ret) ret = err; } ops->free(&dir); out: #endif return ret; } static int adfs_match(struct qstr *name, struct object_info *obj) { int i; if (name->len != obj->name_len) return 0; for (i = 0; i < name->len; i++) { char c1, c2; c1 = name->name[i]; c2 = obj->name[i]; if (c1 >= 'A' && c1 <= 'Z') c1 += 'a' - 'A'; if (c2 >= 'A' && c2 <= 'Z') c2 += 'a' - 'A'; if (c1 != c2) return 0; } return 1; } static int adfs_dir_lookup_byname(struct inode *inode, struct qstr *name, struct object_info *obj) { struct super_block *sb = inode->i_sb; const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir; struct adfs_dir dir; int ret; ret = ops->read(sb, inode->i_ino, inode->i_size, &dir); if (ret) goto out; if (ADFS_I(inode)->parent_id != dir.parent_id) { adfs_error(sb, "parent directory changed under me! (%lx but got %x)\n", ADFS_I(inode)->parent_id, dir.parent_id); ret = -EIO; goto free_out; } obj->parent_id = inode->i_ino; /* * '.' is handled by reserved_lookup() in fs/namei.c */ if (name->len == 2 && name->name[0] == '.' && name->name[1] == '.') { /* * Currently unable to fill in the rest of 'obj', * but this is better than nothing. We need to * ascend one level to find it's parent. */ obj->name_len = 0; obj->file_id = obj->parent_id; goto free_out; } read_lock(&adfs_dir_lock); ret = ops->setpos(&dir, 0); if (ret) goto unlock_out; ret = -ENOENT; while (ops->getnext(&dir, obj) == 0) { if (adfs_match(name, obj)) { ret = 0; break; } } unlock_out: read_unlock(&adfs_dir_lock); free_out: ops->free(&dir); out: return ret; } const struct file_operations adfs_dir_operations = { .read = generic_read_dir, .llseek = generic_file_llseek, .iterate = adfs_readdir, .fsync = generic_file_fsync, }; static int adfs_hash(const struct dentry *parent, struct qstr *qstr) { const unsigned int name_len = ADFS_SB(parent->d_sb)->s_namelen; const unsigned char *name; unsigned long hash; int i; if (qstr->len < name_len) return 0; /* * Truncate the name in place, avoids * having to define a compare function. */ qstr->len = i = name_len; name = qstr->name; hash = init_name_hash(); while (i--) { char c; c = *name++; if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; hash = partial_name_hash(c, hash); } qstr->hash = end_name_hash(hash); return 0; } /* * Compare two names, taking note of the name length * requirements of the underlying filesystem. */ static int adfs_compare(const struct dentry *parent, const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) { int i; if (len != name->len) return 1; for (i = 0; i < name->len; i++) { char a, b; a = str[i]; b = name->name[i]; if (a >= 'A' && a <= 'Z') a += 'a' - 'A'; if (b >= 'A' && b <= 'Z') b += 'a' - 'A'; if (a != b) return 1; } return 0; } const struct dentry_operations adfs_dentry_operations = { .d_hash = adfs_hash, .d_compare = adfs_compare, }; static struct dentry * adfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) { struct inode *inode = NULL; struct object_info obj; int error; error = adfs_dir_lookup_byname(dir, &dentry->d_name, &obj); if (error == 0) { error = -EACCES; /* * This only returns NULL if get_empty_inode * fails. */ inode = adfs_iget(dir->i_sb, &obj); if (inode) error = 0; } d_add(dentry, inode); return ERR_PTR(error); } /* * directories can handle most operations... */ const struct inode_operations adfs_dir_inode_operations = { .lookup = adfs_lookup, .setattr = adfs_notify_change, };
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
89
90
91
92
93
94
95
96
97
98
99
100
101
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
You can’t perform that action at this time.