| Start/ | End/ | |||
| True | False | - | Line | Source |
| 1 | /* | |||
| 2 | * linux/fs/isofs/namei.c | |||
| 3 | * | |||
| 4 | * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem. | |||
| 5 | * | |||
| 6 | * (C) 1991 Linus Torvalds - minix filesystem | |||
| 7 | */ | |||
| 8 | ||||
| 9 | #include <linux/config.h> /* Joliet? */ | |||
| 10 | #include <linux/smp_lock.h> | |||
| 11 | #include "isofs.h" | |||
| 12 | ||||
| 13 | /* | |||
| 14 | * ok, we cannot use strncmp, as the name is not in our data space. | |||
| 15 | * Thus we'll have to use isofs_match. No big problem. Match also makes | |||
| 16 | * some sanity tests. | |||
| 17 | */ | |||
| 18 | static int | |||
| 0 | 0 | - | 19 | isofs_cmp(struct dentry * dentry, const char * compare, int dlen) |
| 20 | { | |||
| 21 | struct qstr qstr; | |||
| 22 | ||||
| 0 | 0 | - | 23 | if (!compare) |
| 0 | - | 24 | return 1; | |
| 25 | ||||
| 26 | /* check special "." and ".." files */ | |||
| 0 | 0 | - | 27 | if (dlen == 1) { |
| 28 | /* "." */ | |||
| 0 | 0 | - | 29 | if (compare[0] == 0) { |
| 0 | 0 | - | 30 | if (!dentry->d_name.len) |
| 0 | - | 31 | return 0; | |
| 32 | compare = "."; | |||
| 0 | 0 | - | 33 | } else if (compare[0] == 1) { |
| 34 | compare = ".."; | |||
| 35 | dlen = 2; | |||
| 36 | } | |||
| 37 | } | |||
| 38 | ||||
| 39 | qstr.name = compare; | |||
| 40 | qstr.len = dlen; | |||
| 0 | - | 41 | return dentry->d_op->d_compare(dentry, &dentry->d_name, &qstr); | |
| 42 | } | |||
| 43 | ||||
| 44 | /* | |||
| 45 | * isofs_find_entry() | |||
| 46 | * | |||
| 47 | * finds an entry in the specified directory with the wanted name. It | |||
| 48 | * returns the inode number of the found entry, or 0 on error. | |||
| 49 | */ | |||
| 50 | static unsigned long | |||
| 0 | 0 | - | 51 | isofs_find_entry(struct inode *dir, struct dentry *dentry, |
| 52 | unsigned long *block_rv, unsigned long* offset_rv, | |||
| 53 | char * tmpname, struct iso_directory_record * tmpde) | |||
| 54 | { | |||
| 55 | unsigned long bufsize = ISOFS_BUFFER_SIZE(dir); | |||
| 56 | unsigned char bufbits = ISOFS_BUFFER_BITS(dir); | |||
| 57 | unsigned long block, f_pos, offset, block_saved, offset_saved; | |||
| 58 | struct buffer_head * bh = NULL; | |||
| 59 | struct isofs_sb_info *sbi = ISOFS_SB(dir->i_sb); | |||
| 60 | ||||
| 0 | 0 | - | 61 | if (!ISOFS_I(dir)->i_first_extent) |
| 0 | - | 62 | return 0; | |
| 63 | ||||
| 64 | f_pos = 0; | |||
| 65 | offset = 0; | |||
| 66 | block = 0; | |||
| 67 | ||||
| 0 | 0 | - | 68 | while (f_pos < dir->i_size) { |
| 69 | struct iso_directory_record * de; | |||
| 70 | int de_len, match, i, dlen; | |||
| 71 | char *dpnt; | |||
| 72 | ||||
| 0 | 0 | - | 73 | if (!bh) { |
| 74 | bh = isofs_bread(dir, block); | |||
| 0 | 0 | - | 75 | if (!bh) |
| 0 | - | 76 | return 0; | |
| 77 | } | |||
| 78 | ||||
| 79 | de = (struct iso_directory_record *) (bh->b_data + offset); | |||
| 80 | ||||
| 81 | de_len = *(unsigned char *) de; | |||
| 0 | 0 | - | 82 | if (!de_len) { |
| 83 | brelse(bh); | |||
| 84 | bh = NULL; | |||
| 85 | f_pos = (f_pos + ISOFS_BLOCK_SIZE) & ~(ISOFS_BLOCK_SIZE - 1); | |||
| 86 | block = f_pos >> bufbits; | |||
| 87 | offset = 0; | |||
| 0 | - | 88 | continue; | |
| 89 | } | |||
| 90 | ||||
| 91 | block_saved = bh->b_blocknr; | |||
| 92 | offset_saved = offset; | |||
| 93 | offset += de_len; | |||
| 94 | f_pos += de_len; | |||
| 95 | ||||
| 96 | /* Make sure we have a full directory entry */ | |||
| 0 | 0 | - | 97 | if (offset >= bufsize) { |
| 98 | int slop = bufsize - offset + de_len; | |||
| 99 | memcpy(tmpde, de, slop); | |||
| 100 | offset &= bufsize - 1; | |||
| 101 | block++; | |||
| 102 | brelse(bh); | |||
| 103 | bh = NULL; | |||
| 0 | 0 | - | 104 | if (offset) { |
| 105 | bh = isofs_bread(dir, block); | |||
| 0 | 0 | - | 106 | if (!bh) |
| 0 | - | 107 | return 0; | |
| 108 | memcpy((void *) tmpde + slop, bh->b_data, offset); | |||
| 109 | } | |||
| 110 | de = tmpde; | |||
| 111 | } | |||
| 112 | ||||
| 113 | dlen = de->name_len[0]; | |||
| 114 | dpnt = de->name; | |||
| 115 | ||||
| 116 | if (sbi->s_rock && | |||
| 0 | 0 | - | 117 | ((i = get_rock_ridge_filename(de, tmpname, dir)))) { |
| 0 | - | 117 | T && ((T)) | |
| 0 | - | 117 | T && ((F)) | |
| 0 | - | 117 | F && ((_)) | |
| 118 | dlen = i; /* possibly -1 */ | |||
| 119 | dpnt = tmpname; | |||
| 120 | #ifdef CONFIG_JOLIET | |||
| 0 | 0 | - | 121 | } else if (sbi->s_joliet_level) { |
| 122 | dlen = get_joliet_filename(de, tmpname, dir); | |||
| 123 | dpnt = tmpname; | |||
| 124 | #endif | |||
| 0 | 0 | - | 125 | } else if (sbi->s_mapping == 'a') { |
| 126 | dlen = get_acorn_filename(de, tmpname, dir); | |||
| 127 | dpnt = tmpname; | |||
| 0 | 0 | - | 128 | } else if (sbi->s_mapping == 'n') { |
| 129 | dlen = isofs_name_translate(de, tmpname, dir); | |||
| 130 | dpnt = tmpname; | |||
| 131 | } | |||
| 132 | ||||
| 133 | /* | |||
| 134 | * Skip hidden or associated files unless hide or showassoc, | |||
| 135 | * respectively, is set | |||
| 136 | */ | |||
| 137 | match = 0; | |||
| 138 | if (dlen > 0 && | |||
| 139 | (sbi->s_hide =='n' || | |||
| 140 | (!(de->flags[-sbi->s_high_sierra] & 1))) && | |||
| 141 | (sbi->s_showassoc =='y' || | |||
| 0 | 0 | - | 142 | (!(de->flags[-sbi->s_high_sierra] & 4)))) { |
| 0 | - | 142 | T && (T || (!(_))) && (T || (!(_))) | |
| 0 | - | 142 | T && (T || (!(_))) && (F || (!(F))) | |
| 0 | - | 142 | T && (F || (!(F))) && (T || (!(_))) | |
| 0 | - | 142 | T && (F || (!(F))) && (F || (!(F))) | |
| 0 | - | 142 | T && (T || (!(_))) && (F || (!(T))) | |
| 0 | - | 142 | T && (F || (!(T))) && (_ || (!(_))) | |
| 0 | - | 142 | T && (F || (!(F))) && (F || (!(T))) | |
| 0 | - | 142 | F && (_ || (!(_))) && (_ || (!(_))) | |
| 143 | match = (isofs_cmp(dentry, dpnt, dlen) == 0); | |||
| 144 | } | |||
| 0 | 0 | - | 145 | if (match) { |
| 146 | isofs_normalize_block_and_offset(de, | |||
| 147 | &block_saved, | |||
| 148 | &offset_saved); | |||
| 149 | *block_rv = block_saved; | |||
| 150 | *offset_rv = offset_saved; | |||
| 151 | brelse(bh); | |||
| 0 | - | 152 | return 1; | |
| 153 | } | |||
| 154 | } | |||
| 155 | brelse(bh); | |||
| 0 | - | 156 | return 0; | |
| 157 | } | |||
| 158 | ||||
| 0 | 0 | - | 159 | struct dentry *isofs_lookup(struct inode * dir, struct dentry * dentry, struct nameidata *nd) |
| 160 | { | |||
| 161 | int found; | |||
| 162 | unsigned long block, offset; | |||
| 163 | struct inode *inode; | |||
| 164 | struct page *page; | |||
| 165 | ||||
| 166 | dentry->d_op = dir->i_sb->s_root->d_op; | |||
| 167 | ||||
| 168 | page = alloc_page(GFP_USER); | |||
| 0 | 0 | - | 169 | if (!page) |
| 0 | - | 170 | return ERR_PTR(-ENOMEM); | |
| 171 | ||||
| 172 | lock_kernel(); | |||
| 0 | 0 | - | 172 | do-while (0) |
| 173 | found = isofs_find_entry(dir, dentry, | |||
| 174 | &block, &offset, | |||
| 175 | page_address(page), | |||
| 176 | 1024 + page_address(page)); | |||
| 177 | __free_page(page); | |||
| 178 | ||||
| 179 | inode = NULL; | |||
| 0 | 0 | - | 180 | if (found) { |
| 181 | inode = isofs_iget(dir->i_sb, block, offset); | |||
| 0 | 0 | - | 182 | if (!inode) { |
| 183 | unlock_kernel(); | |||
| 0 | 0 | - | 183 | do-while (0) |
| 0 | - | 184 | return ERR_PTR(-EACCES); | |
| 185 | } | |||
| 186 | } | |||
| 187 | unlock_kernel(); | |||
| 0 | 0 | - | 187 | do-while (0) |
| 0 | - | 188 | return d_splice_alias(inode, dentry); | |
| 189 | } | |||
| ***TER 0% (0/76) of SOURCE FILE namei.c | ||||