2 * linux/fs/isofs/namei.c
4 * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem.
6 * (C) 1991 Linus Torvalds - minix filesystem
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
)
23 if (likely(!dentry
->d_op
))
24 return dentry
->d_name
.len
!= dlen
|| memcmp(dentry
->d_name
.name
, compare
, dlen
);
25 return dentry
->d_op
->d_compare(NULL
, NULL
, dentry
->d_name
.len
, dentry
->d_name
.name
, &qstr
);
31 * finds an entry in the specified directory with the wanted name. It
32 * returns the inode number of the found entry, or 0 on error.
35 isofs_find_entry(struct inode
*dir
, struct dentry
*dentry
,
36 unsigned long *block_rv
, unsigned long *offset_rv
,
37 char *tmpname
, struct iso_directory_record
*tmpde
)
39 unsigned long bufsize
= ISOFS_BUFFER_SIZE(dir
);
40 unsigned char bufbits
= ISOFS_BUFFER_BITS(dir
);
41 unsigned long block
, f_pos
, offset
, block_saved
, offset_saved
;
42 struct buffer_head
*bh
= NULL
;
43 struct isofs_sb_info
*sbi
= ISOFS_SB(dir
->i_sb
);
45 if (!ISOFS_I(dir
)->i_first_extent
)
52 while (f_pos
< dir
->i_size
) {
53 struct iso_directory_record
*de
;
54 int de_len
, match
, i
, dlen
;
58 bh
= isofs_bread(dir
, block
);
63 de
= (struct iso_directory_record
*) (bh
->b_data
+ offset
);
65 de_len
= *(unsigned char *) de
;
69 f_pos
= (f_pos
+ ISOFS_BLOCK_SIZE
) & ~(ISOFS_BLOCK_SIZE
- 1);
70 block
= f_pos
>> bufbits
;
75 block_saved
= bh
->b_blocknr
;
76 offset_saved
= offset
;
80 /* Make sure we have a full directory entry */
81 if (offset
>= bufsize
) {
82 int slop
= bufsize
- offset
+ de_len
;
83 memcpy(tmpde
, de
, slop
);
84 offset
&= bufsize
- 1;
89 bh
= isofs_bread(dir
, block
);
92 memcpy((void *) tmpde
+ slop
, bh
->b_data
, offset
);
97 dlen
= de
->name_len
[0];
99 /* Basic sanity check, whether name doesn't exceed dir entry */
100 if (de_len
< dlen
+ sizeof(struct iso_directory_record
)) {
101 printk(KERN_NOTICE
"iso9660: Corrupted directory entry"
102 " in block %lu of inode %lu\n", block
,
108 ((i
= get_rock_ridge_filename(de
, tmpname
, dir
)))) {
109 dlen
= i
; /* possibly -1 */
112 } else if (sbi
->s_joliet_level
) {
113 dlen
= get_joliet_filename(de
, tmpname
, dir
);
116 } else if (sbi
->s_mapping
== 'a') {
117 dlen
= get_acorn_filename(de
, tmpname
, dir
);
119 } else if (sbi
->s_mapping
== 'n') {
120 dlen
= isofs_name_translate(de
, tmpname
, dir
);
125 * Skip hidden or associated files unless hide or showassoc,
126 * respectively, is set
131 (!(de
->flags
[-sbi
->s_high_sierra
] & 1))) &&
133 (!(de
->flags
[-sbi
->s_high_sierra
] & 4)))) {
134 if (dpnt
&& (dlen
> 1 || dpnt
[0] > 1))
135 match
= (isofs_cmp(dentry
, dpnt
, dlen
) == 0);
138 isofs_normalize_block_and_offset(de
,
141 *block_rv
= block_saved
;
142 *offset_rv
= offset_saved
;
151 struct dentry
*isofs_lookup(struct inode
*dir
, struct dentry
*dentry
, unsigned int flags
)
154 unsigned long uninitialized_var(block
);
155 unsigned long uninitialized_var(offset
);
159 page
= alloc_page(GFP_USER
);
161 return ERR_PTR(-ENOMEM
);
163 found
= isofs_find_entry(dir
, dentry
,
166 1024 + page_address(page
));
169 inode
= found
? isofs_iget(dir
->i_sb
, block
, offset
) : NULL
;
171 return d_splice_alias(inode
, dentry
);