2 * linux/fs/isofs/namei.c
4 * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem.
6 * (C) 1991 Linus Torvalds - minix filesystem
9 #include <linux/smp_lock.h>
13 * ok, we cannot use strncmp, as the name is not in our data space.
14 * Thus we'll have to use isofs_match. No big problem. Match also makes
18 isofs_cmp(struct dentry *dentry, const char *compare, int dlen)
25 /* check special "." and ".." files */
28 if (compare[0] == 0) {
29 if (!dentry->d_name.len)
32 } else if (compare[0] == 1) {
40 return dentry->d_op->d_compare(dentry, &dentry->d_name, &qstr);
46 * finds an entry in the specified directory with the wanted name. It
47 * returns the inode number of the found entry, or 0 on error.
50 isofs_find_entry(struct inode *dir, struct dentry *dentry,
51 unsigned long *block_rv, unsigned long *offset_rv,
52 char *tmpname, struct iso_directory_record *tmpde)
54 unsigned long bufsize = ISOFS_BUFFER_SIZE(dir);
55 unsigned char bufbits = ISOFS_BUFFER_BITS(dir);
56 unsigned long block, f_pos, offset, block_saved, offset_saved;
57 struct buffer_head *bh = NULL;
58 struct isofs_sb_info *sbi = ISOFS_SB(dir->i_sb);
60 if (!ISOFS_I(dir)->i_first_extent)
67 while (f_pos < dir->i_size) {
68 struct iso_directory_record *de;
69 int de_len, match, i, dlen;
73 bh = isofs_bread(dir, block);
78 de = (struct iso_directory_record *) (bh->b_data + offset);
80 de_len = *(unsigned char *) de;
84 f_pos = (f_pos + ISOFS_BLOCK_SIZE) & ~(ISOFS_BLOCK_SIZE - 1);
85 block = f_pos >> bufbits;
90 block_saved = bh->b_blocknr;
91 offset_saved = offset;
95 /* Make sure we have a full directory entry */
96 if (offset >= bufsize) {
97 int slop = bufsize - offset + de_len;
98 memcpy(tmpde, de, slop);
99 offset &= bufsize - 1;
104 bh = isofs_bread(dir, block);
107 memcpy((void *) tmpde + slop, bh->b_data, offset);
112 dlen = de->name_len[0];
114 /* Basic sanity check, whether name doesn't exceed dir entry */
115 if (de_len < dlen + sizeof(struct iso_directory_record)) {
116 printk(KERN_NOTICE "iso9660: Corrupted directory entry"
117 " in block %lu of inode %lu\n", block,
123 ((i = get_rock_ridge_filename(de, tmpname, dir)))) {
124 dlen = i; /* possibly -1 */
127 } else if (sbi->s_joliet_level) {
128 dlen = get_joliet_filename(de, tmpname, dir);
131 } else if (sbi->s_mapping == 'a') {
132 dlen = get_acorn_filename(de, tmpname, dir);
134 } else if (sbi->s_mapping == 'n') {
135 dlen = isofs_name_translate(de, tmpname, dir);
140 * Skip hidden or associated files unless hide or showassoc,
141 * respectively, is set
145 (sbi->s_hide =='n' ||
146 (!(de->flags[-sbi->s_high_sierra] & 1))) &&
147 (sbi->s_showassoc =='y' ||
148 (!(de->flags[-sbi->s_high_sierra] & 4)))) {
149 match = (isofs_cmp(dentry, dpnt, dlen) == 0);
152 isofs_normalize_block_and_offset(de,
155 *block_rv = block_saved;
156 *offset_rv = offset_saved;
165 struct dentry *isofs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
168 unsigned long uninitialized_var(block);
169 unsigned long uninitialized_var(offset);
173 dentry->d_op = dir->i_sb->s_root->d_op;
175 page = alloc_page(GFP_USER);
177 return ERR_PTR(-ENOMEM);
180 found = isofs_find_entry(dir, dentry,
183 1024 + page_address(page));
188 inode = isofs_iget(dir->i_sb, block, offset);
191 return ERR_CAST(inode);
195 return d_splice_alias(inode, dentry);