| 1 | |
| 2 | |
| 3 | * linux/fs/isofs/dir.c
|
| 4 | *
|
| 5 | * (C) 1992, 1993, 1994 Eric Youngdale Modified for ISO 9660 filesystem.
|
| 6 | *
|
| 7 | * (C) 1991 Linus Torvalds - minix filesystem
|
| 8 | *
|
| 9 | * Steve Beynon : Missing last directory entries fixed
|
| 10 | * ([email protected]) : 21st June 1996
|
| 11 | *
|
| 12 | * isofs directory handling functions
|
| 13 |
|
| 14 | #include <linux/gfp.h>
|
| 15 | #include <linux/filelock.h>
|
| 16 | #include <linux/slab.h>
|
| 17 | #include "isofs.h"
|
| 18 | #include <linux/fileattr.h>
|
| 19 |
|
| 20 | int isofs_name_translate(struct iso_directory_record *de, char *new, struct inode *inode)
|
| 21 | {
|
| 22 | char * old = de->name;
|
| 23 | int len = de->name_len[0];
|
| 24 | int i;
|
| 25 |
|
| 26 | for (i = 0; i < len; i++) {
|
| 27 | unsigned char c = old[i];
|
| 28 | if (!c)
|
| 29 | break;
|
| 30 |
|
| 31 | if (c >= 'A' && c <= 'Z')
|
| 32 | c |= 0x20;
|
| 33 |
|
| 34 |
|
| 35 | if (c == '.' && i == len - 3 && old[i + 1] == ';' && old[i + 2] == '1')
|
| 36 | break;
|
| 37 |
|
| 38 |
|
| 39 | if (c == ';' && i == len - 2 && old[i + 1] == '1')
|
| 40 | break;
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 | if (c == ';' || c == '/')
|
| 45 | c = '.';
|
| 46 |
|
| 47 | new[i] = c;
|
| 48 | }
|
| 49 | return i;
|
| 50 | }
|
| 51 |
|
| 52 |
|
| 53 | int get_acorn_filename(struct iso_directory_record *de,
|
| 54 | char *retname, struct inode *inode)
|
| 55 | {
|
| 56 | int std;
|
| 57 | unsigned char *chr;
|
| 58 | int retnamlen = isofs_name_translate(de, retname, inode);
|
| 59 |
|
| 60 | if (retnamlen == 0)
|
| 61 | return 0;
|
| 62 | std = sizeof(struct iso_directory_record) + de->name_len[0];
|
| 63 | if (std & 1)
|
| 64 | std++;
|
| 65 | if (de->length[0] - std != 32)
|
| 66 | return retnamlen;
|
| 67 | chr = ((unsigned char *) de) + std;
|
| 68 | if (strncmp(chr, "ARCHIMEDES", 10))
|
| 69 | return retnamlen;
|
| 70 | if ((*retname == '_') && ((chr[19] & 1) == 1))
|
| 71 | *retname = '!';
|
| 72 | if (((de->flags[0] & 2) == 0) && (chr[13] == 0xff)
|
| 73 | && ((chr[12] & 0xf0) == 0xf0)) {
|
| 74 | retname[retnamlen] = ',';
|
| 75 | sprintf(retname+retnamlen+1, "%3.3x",
|
| 76 | ((chr[12] & 0xf) << 8) | chr[11]);
|
| 77 | retnamlen += 4;
|
| 78 | }
|
| 79 | return retnamlen;
|
| 80 | }
|
| 81 |
|
| 82 | |
| 83 | * This should _really_ be cleaned up some day..
|
| 84 |
|
| 85 | static int do_isofs_readdir(struct inode *inode, struct file *file,
|
| 86 | struct dir_context *ctx,
|
| 87 | char *tmpname)
|
| 88 | {
|
| 89 | unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
|
| 90 | unsigned char bufbits = ISOFS_BUFFER_BITS(inode);
|
| 91 | unsigned long block, offset, block_saved, offset_saved;
|
| 92 | unsigned long inode_number = 0;
|
| 93 | struct buffer_head *bh = NULL;
|
| 94 | int len;
|
| 95 | int map;
|
| 96 | int first_de = 1;
|
| 97 | char *p = NULL;
|
| 98 | struct iso_directory_record *de;
|
| 99 | struct isofs_sb_info *sbi = ISOFS_SB(inode->i_sb);
|
| 100 |
|
| 101 | offset = ctx->pos & (bufsize - 1);
|
| 102 | block = ctx->pos >> bufbits;
|
| 103 |
|
| 104 | while (ctx->pos < inode->i_size) {
|
| 105 | int de_len;
|
| 106 |
|
| 107 | if (!bh) {
|
| 108 | bh = isofs_bread(inode, block);
|
| 109 | if (!bh)
|
| 110 | return 0;
|
| 111 | }
|
| 112 |
|
| 113 | de = (struct iso_directory_record *)(bh->b_data + offset);
|
| 114 | |
| 115 | * If we are at the end of a block (or at its zero-padded
|
| 116 | * tail), move on to the next CDROM sector. If we are at the
|
| 117 | * end of the directory, we'll abort the while loop.
|
| 118 |
|
| 119 | if (offset >= bufsize || de->length[0] == 0) {
|
| 120 | brelse(bh);
|
| 121 | bh = NULL;
|
| 122 | block++;
|
| 123 | ctx->pos = (loff_t)block << bufbits;
|
| 124 | offset = 0;
|
| 125 | continue;
|
| 126 | }
|
| 127 | de_len = de->length[0];
|
| 128 | block_saved = block;
|
| 129 | offset_saved = offset;
|
| 130 | offset += de_len;
|
| 131 |
|
| 132 | if (!isofs_dir_record_valid(de, offset_saved, bufsize)) {
|
| 133 | printk(KERN_NOTICE "iso9660: Corrupted directory entry"
|
| 134 | " in block %lu of inode %llu\n", block,
|
| 135 | inode->i_ino);
|
| 136 | brelse(bh);
|
| 137 | return -EIO;
|
| 138 | }
|
| 139 |
|
| 140 | if (first_de) {
|
| 141 | isofs_normalize_block_and_offset(de,
|
| 142 | &block_saved,
|
| 143 | &offset_saved);
|
| 144 | inode_number = isofs_get_ino(block_saved,
|
| 145 | offset_saved, bufbits);
|
| 146 | }
|
| 147 |
|
| 148 | if (de->flags[-sbi->s_high_sierra] & 0x80) {
|
| 149 | first_de = 0;
|
| 150 | ctx->pos += de_len;
|
| 151 | continue;
|
| 152 | }
|
| 153 | first_de = 1;
|
| 154 |
|
| 155 |
|
| 156 | if (de->name_len[0] == 1 && de->name[0] == 0) {
|
| 157 | if (!dir_emit_dot(file, ctx))
|
| 158 | break;
|
| 159 | ctx->pos += de_len;
|
| 160 | continue;
|
| 161 | }
|
| 162 |
|
| 163 | len = 0;
|
| 164 |
|
| 165 |
|
| 166 | if (de->name_len[0] == 1 && de->name[0] == 1) {
|
| 167 | if (!dir_emit_dotdot(file, ctx))
|
| 168 | break;
|
| 169 | ctx->pos += de_len;
|
| 170 | continue;
|
| 171 | }
|
| 172 |
|
| 173 | |
| 174 | is no Rock Ridge NM field.
|
| 175 |
|
| 176 | |
| 177 | * Do not report hidden files if so instructed, or associated
|
| 178 | * files unless instructed to do so
|
| 179 |
|
| 180 | if ((sbi->s_hide && (de->flags[-sbi->s_high_sierra] & 1)) ||
|
| 181 | (!sbi->s_showassoc &&
|
| 182 | (de->flags[-sbi->s_high_sierra] & 4))) {
|
| 183 | ctx->pos += de_len;
|
| 184 | continue;
|
| 185 | }
|
| 186 |
|
| 187 | map = 1;
|
| 188 | if (sbi->s_rock) {
|
| 189 | len = get_rock_ridge_filename(de, tmpname, NAME_MAX + 1,
|
| 190 | inode);
|
| 191 | if (len != 0) {
|
| 192 | p = tmpname;
|
| 193 | map = 0;
|
| 194 | }
|
| 195 | }
|
| 196 | if (map) {
|
| 197 | #ifdef CONFIG_JOLIET
|
| 198 | if (sbi->s_joliet_level) {
|
| 199 | len = get_joliet_filename(de, tmpname,
|
| 200 | JOLIET_NAME_MAX + 1,
|
| 201 | inode);
|
| 202 | p = tmpname;
|
| 203 | } else
|
| 204 | #endif
|
| 205 | if (sbi->s_mapping == 'a') {
|
| 206 | len = get_acorn_filename(de, tmpname, inode);
|
| 207 | p = tmpname;
|
| 208 | } else
|
| 209 | if (sbi->s_mapping == 'n') {
|
| 210 | len = isofs_name_translate(de, tmpname, inode);
|
| 211 | p = tmpname;
|
| 212 | } else {
|
| 213 | p = de->name;
|
| 214 | len = de->name_len[0];
|
| 215 | }
|
| 216 | }
|
| 217 | if (len > 0) {
|
| 218 | if (!dir_emit(ctx, p, len, inode_number, DT_UNKNOWN))
|
| 219 | break;
|
| 220 | }
|
| 221 | ctx->pos += de_len;
|
| 222 | }
|
| 223 | if (bh)
|
| 224 | brelse(bh);
|
| 225 | return 0;
|
| 226 | }
|
| 227 |
|
| 228 | |
| 229 | * Handle allocation of temporary space for name translation and
|
| 230 | * handling split directory entries.. The real work is done by
|
| 231 | * "do_isofs_readdir()".
|
| 232 |
|
| 233 | static int isofs_readdir(struct file *file, struct dir_context *ctx)
|
| 234 | {
|
| 235 | int result;
|
| 236 | char *tmpname;
|
| 237 | struct inode *inode = file_inode(file);
|
| 238 |
|
| 239 | |
| 240 | * Rockridge can produce names of NAME_MAX size, Acorn extensions at
|
| 241 | * most 227 chars.
|
| 242 |
|
| 243 | BUILD_BUG_ON(JOLIET_NAME_MAX < NAME_MAX || JOLIET_NAME_MAX < 227);
|
| 244 | tmpname = kmalloc(JOLIET_NAME_MAX + 1, GFP_KERNEL);
|
| 245 | if (tmpname == NULL)
|
| 246 | return -ENOMEM;
|
| 247 |
|
| 248 | result = do_isofs_readdir(inode, file, ctx, tmpname);
|
| 249 |
|
| 250 | kfree(tmpname);
|
| 251 | return result;
|
| 252 | }
|
| 253 |
|
| 254 | int isofs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
|
| 255 | {
|
| 256 | struct isofs_sb_info *sbi = ISOFS_SB(dentry->d_sb);
|
| 257 |
|
| 258 | if (sbi->s_check == 'r') {
|
| 259 | fa->fsx_xflags |= FS_XFLAG_CASEFOLD;
|
| 260 | fa->flags |= FS_CASEFOLD_FL;
|
| 261 | }
|
| 262 | if (!sbi->s_joliet_level && !sbi->s_rock &&
|
| 263 | (sbi->s_mapping == 'n' || sbi->s_mapping == 'a'))
|
| 264 | fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
|
| 265 | return 0;
|
| 266 | }
|
| 267 |
|
| 268 | const struct file_operations isofs_dir_operations =
|
| 269 | {
|
| 270 | .llseek = generic_file_llseek,
|
| 271 | .read = generic_read_dir,
|
| 272 | .iterate_shared = isofs_readdir,
|
| 273 | .setlease = generic_setlease,
|
| 274 | };
|
| 275 |
|
| 276 | |
| 277 | * directories can handle most operations...
|
| 278 |
|
| 279 | const struct inode_operations isofs_dir_inode_operations =
|
| 280 | {
|
| 281 | .lookup = isofs_lookup,
|
| 282 | .fileattr_get = isofs_fileattr_get,
|
| 283 | };
|
| 284 |
|