4 * Copyright (C) 1999-2000 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Common directory handling for ADFS
15 * For future. This should probably be per-directory.
17 static DEFINE_RWLOCK(adfs_dir_lock);
20 adfs_readdir(struct file *file, struct dir_context *ctx)
22 struct inode *inode = file_inode(file);
23 struct super_block *sb = inode->i_sb;
24 struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
25 struct object_info obj;
32 ret = ops->read(sb, inode->i_ino, inode->i_size, &dir);
37 if (!dir_emit_dot(file, ctx))
42 if (!dir_emit(ctx, "..", 2, dir.parent_id, DT_DIR))
47 read_lock(&adfs_dir_lock);
49 ret = ops->setpos(&dir, ctx->pos - 2);
52 while (ops->getnext(&dir, &obj) == 0) {
53 if (!dir_emit(ctx, obj.name, obj.name_len,
54 obj.file_id, DT_UNKNOWN))
60 read_unlock(&adfs_dir_lock);
68 adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait)
71 #ifdef CONFIG_ADFS_FS_RW
72 struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
75 printk(KERN_INFO "adfs_dir_update: object %06X in dir %06X\n",
76 obj->file_id, obj->parent_id);
83 ret = ops->read(sb, obj->parent_id, 0, &dir);
87 write_lock(&adfs_dir_lock);
88 ret = ops->update(&dir, obj);
89 write_unlock(&adfs_dir_lock);
92 int err = ops->sync(&dir);
104 adfs_match(struct qstr *name, struct object_info *obj)
108 if (name->len != obj->name_len)
111 for (i = 0; i < name->len; i++) {
117 if (c1 >= 'A' && c1 <= 'Z')
119 if (c2 >= 'A' && c2 <= 'Z')
129 adfs_dir_lookup_byname(struct inode *inode, struct qstr *name, struct object_info *obj)
131 struct super_block *sb = inode->i_sb;
132 struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
136 ret = ops->read(sb, inode->i_ino, inode->i_size, &dir);
140 if (ADFS_I(inode)->parent_id != dir.parent_id) {
141 adfs_error(sb, "parent directory changed under me! (%lx but got %lx)\n",
142 ADFS_I(inode)->parent_id, dir.parent_id);
147 obj->parent_id = inode->i_ino;
150 * '.' is handled by reserved_lookup() in fs/namei.c
152 if (name->len == 2 && name->name[0] == '.' && name->name[1] == '.') {
154 * Currently unable to fill in the rest of 'obj',
155 * but this is better than nothing. We need to
156 * ascend one level to find it's parent.
159 obj->file_id = obj->parent_id;
163 read_lock(&adfs_dir_lock);
165 ret = ops->setpos(&dir, 0);
170 while (ops->getnext(&dir, obj) == 0) {
171 if (adfs_match(name, obj)) {
178 read_unlock(&adfs_dir_lock);
186 const struct file_operations adfs_dir_operations = {
187 .read = generic_read_dir,
188 .llseek = generic_file_llseek,
189 .iterate = adfs_readdir,
190 .fsync = generic_file_fsync,
194 adfs_hash(const struct dentry *parent, const struct inode *inode,
197 const unsigned int name_len = ADFS_SB(parent->d_sb)->s_namelen;
198 const unsigned char *name;
202 if (qstr->len < name_len)
206 * Truncate the name in place, avoids
207 * having to define a compare function.
209 qstr->len = i = name_len;
211 hash = init_name_hash();
216 if (c >= 'A' && c <= 'Z')
219 hash = partial_name_hash(c, hash);
221 qstr->hash = end_name_hash(hash);
227 * Compare two names, taking note of the name length
228 * requirements of the underlying filesystem.
231 adfs_compare(const struct dentry *parent, const struct inode *pinode,
232 const struct dentry *dentry, const struct inode *inode,
233 unsigned int len, const char *str, const struct qstr *name)
237 if (len != name->len)
240 for (i = 0; i < name->len; i++) {
246 if (a >= 'A' && a <= 'Z')
248 if (b >= 'A' && b <= 'Z')
257 const struct dentry_operations adfs_dentry_operations = {
259 .d_compare = adfs_compare,
262 static struct dentry *
263 adfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
265 struct inode *inode = NULL;
266 struct object_info obj;
269 error = adfs_dir_lookup_byname(dir, &dentry->d_name, &obj);
273 * This only returns NULL if get_empty_inode
276 inode = adfs_iget(dir->i_sb, &obj);
280 d_add(dentry, inode);
281 return ERR_PTR(error);
285 * directories can handle most operations...
287 const struct inode_operations adfs_dir_inode_operations = {
288 .lookup = adfs_lookup,
289 .setattr = adfs_notify_change,