diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/affs/dir.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'fs/affs/dir.c')
-rw-r--r-- | fs/affs/dir.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/fs/affs/dir.c b/fs/affs/dir.c new file mode 100644 index 000000000000..548efd0ee98c --- /dev/null +++ b/fs/affs/dir.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | * linux/fs/affs/dir.c | ||
3 | * | ||
4 | * (c) 1996 Hans-Joachim Widmaier - Rewritten | ||
5 | * | ||
6 | * (C) 1993 Ray Burr - Modified for Amiga FFS filesystem. | ||
7 | * | ||
8 | * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem. | ||
9 | * | ||
10 | * (C) 1991 Linus Torvalds - minix filesystem | ||
11 | * | ||
12 | * affs directory handling functions | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include "affs.h" | ||
17 | |||
18 | static int affs_readdir(struct file *, void *, filldir_t); | ||
19 | |||
20 | struct file_operations affs_dir_operations = { | ||
21 | .read = generic_read_dir, | ||
22 | .readdir = affs_readdir, | ||
23 | .fsync = file_fsync, | ||
24 | }; | ||
25 | |||
26 | /* | ||
27 | * directories can handle most operations... | ||
28 | */ | ||
29 | struct inode_operations affs_dir_inode_operations = { | ||
30 | .create = affs_create, | ||
31 | .lookup = affs_lookup, | ||
32 | .link = affs_link, | ||
33 | .unlink = affs_unlink, | ||
34 | .symlink = affs_symlink, | ||
35 | .mkdir = affs_mkdir, | ||
36 | .rmdir = affs_rmdir, | ||
37 | .rename = affs_rename, | ||
38 | .setattr = affs_notify_change, | ||
39 | }; | ||
40 | |||
41 | static int | ||
42 | affs_readdir(struct file *filp, void *dirent, filldir_t filldir) | ||
43 | { | ||
44 | struct inode *inode = filp->f_dentry->d_inode; | ||
45 | struct super_block *sb = inode->i_sb; | ||
46 | struct buffer_head *dir_bh; | ||
47 | struct buffer_head *fh_bh; | ||
48 | unsigned char *name; | ||
49 | int namelen; | ||
50 | u32 i; | ||
51 | int hash_pos; | ||
52 | int chain_pos; | ||
53 | u32 f_pos; | ||
54 | u32 ino; | ||
55 | int stored; | ||
56 | int res; | ||
57 | |||
58 | pr_debug("AFFS: readdir(ino=%lu,f_pos=%lx)\n",inode->i_ino,(unsigned long)filp->f_pos); | ||
59 | |||
60 | stored = 0; | ||
61 | res = -EIO; | ||
62 | dir_bh = NULL; | ||
63 | fh_bh = NULL; | ||
64 | f_pos = filp->f_pos; | ||
65 | |||
66 | if (f_pos == 0) { | ||
67 | filp->private_data = (void *)0; | ||
68 | if (filldir(dirent, ".", 1, f_pos, inode->i_ino, DT_DIR) < 0) | ||
69 | return 0; | ||
70 | filp->f_pos = f_pos = 1; | ||
71 | stored++; | ||
72 | } | ||
73 | if (f_pos == 1) { | ||
74 | if (filldir(dirent, "..", 2, f_pos, parent_ino(filp->f_dentry), DT_DIR) < 0) | ||
75 | return stored; | ||
76 | filp->f_pos = f_pos = 2; | ||
77 | stored++; | ||
78 | } | ||
79 | |||
80 | affs_lock_dir(inode); | ||
81 | chain_pos = (f_pos - 2) & 0xffff; | ||
82 | hash_pos = (f_pos - 2) >> 16; | ||
83 | if (chain_pos == 0xffff) { | ||
84 | affs_warning(sb, "readdir", "More than 65535 entries in chain"); | ||
85 | chain_pos = 0; | ||
86 | hash_pos++; | ||
87 | filp->f_pos = ((hash_pos << 16) | chain_pos) + 2; | ||
88 | } | ||
89 | dir_bh = affs_bread(sb, inode->i_ino); | ||
90 | if (!dir_bh) | ||
91 | goto readdir_out; | ||
92 | |||
93 | /* If the directory hasn't changed since the last call to readdir(), | ||
94 | * we can jump directly to where we left off. | ||
95 | */ | ||
96 | ino = (u32)(long)filp->private_data; | ||
97 | if (ino && filp->f_version == inode->i_version) { | ||
98 | pr_debug("AFFS: readdir() left off=%d\n", ino); | ||
99 | goto inside; | ||
100 | } | ||
101 | |||
102 | ino = be32_to_cpu(AFFS_HEAD(dir_bh)->table[hash_pos]); | ||
103 | for (i = 0; ino && i < chain_pos; i++) { | ||
104 | fh_bh = affs_bread(sb, ino); | ||
105 | if (!fh_bh) { | ||
106 | affs_error(sb, "readdir","Cannot read block %d", i); | ||
107 | goto readdir_out; | ||
108 | } | ||
109 | ino = be32_to_cpu(AFFS_TAIL(sb, fh_bh)->hash_chain); | ||
110 | affs_brelse(fh_bh); | ||
111 | fh_bh = NULL; | ||
112 | } | ||
113 | if (ino) | ||
114 | goto inside; | ||
115 | hash_pos++; | ||
116 | |||
117 | for (; hash_pos < AFFS_SB(sb)->s_hashsize; hash_pos++) { | ||
118 | ino = be32_to_cpu(AFFS_HEAD(dir_bh)->table[hash_pos]); | ||
119 | if (!ino) | ||
120 | continue; | ||
121 | f_pos = (hash_pos << 16) + 2; | ||
122 | inside: | ||
123 | do { | ||
124 | fh_bh = affs_bread(sb, ino); | ||
125 | if (!fh_bh) { | ||
126 | affs_error(sb, "readdir","Cannot read block %d", ino); | ||
127 | goto readdir_done; | ||
128 | } | ||
129 | |||
130 | namelen = min(AFFS_TAIL(sb, fh_bh)->name[0], (u8)30); | ||
131 | name = AFFS_TAIL(sb, fh_bh)->name + 1; | ||
132 | pr_debug("AFFS: readdir(): filldir(\"%.*s\", ino=%u), hash=%d, f_pos=%x\n", | ||
133 | namelen, name, ino, hash_pos, f_pos); | ||
134 | if (filldir(dirent, name, namelen, f_pos, ino, DT_UNKNOWN) < 0) | ||
135 | goto readdir_done; | ||
136 | stored++; | ||
137 | f_pos++; | ||
138 | ino = be32_to_cpu(AFFS_TAIL(sb, fh_bh)->hash_chain); | ||
139 | affs_brelse(fh_bh); | ||
140 | fh_bh = NULL; | ||
141 | } while (ino); | ||
142 | } | ||
143 | readdir_done: | ||
144 | filp->f_pos = f_pos; | ||
145 | filp->f_version = inode->i_version; | ||
146 | filp->private_data = (void *)(long)ino; | ||
147 | res = stored; | ||
148 | |||
149 | readdir_out: | ||
150 | affs_brelse(dir_bh); | ||
151 | affs_brelse(fh_bh); | ||
152 | affs_unlock_dir(inode); | ||
153 | pr_debug("AFFS: readdir()=%d\n", stored); | ||
154 | return res; | ||
155 | } | ||