Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * directory.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Directory related functions |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * COPYRIGHT |
| 8 | * This file is distributed under the terms of the GNU General Public |
| 9 | * License (GPL). Copies of the GPL can be obtained from: |
| 10 | * ftp://prep.ai.mit.edu/pub/gnu/GPL |
| 11 | * Each contributing author retains all rights to their own work. |
| 12 | */ |
| 13 | |
| 14 | #include "udfdecl.h" |
| 15 | #include "udf_i.h" |
| 16 | |
| 17 | #include <linux/fs.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/buffer_head.h> |
| 20 | |
| 21 | #if 0 |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 22 | static uint8_t *udf_filead_read(struct inode *dir, uint8_t *tmpad, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 23 | uint8_t ad_size, kernel_lb_addr fe_loc, |
| 24 | int *pos, int *offset, struct buffer_head **bh, |
| 25 | int *error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
| 27 | int loffset = *offset; |
| 28 | int block; |
| 29 | uint8_t *ad; |
| 30 | int remainder; |
| 31 | |
| 32 | *error = 0; |
| 33 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 34 | ad = (uint8_t *)(*bh)->b_data + *offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | *offset += ad_size; |
| 36 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 37 | if (!ad) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 38 | brelse(*bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | *error = 1; |
| 40 | return NULL; |
| 41 | } |
| 42 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 43 | if (*offset == dir->i_sb->s_blocksize) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 44 | brelse(*bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); |
| 46 | if (!block) |
| 47 | return NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 48 | *bh = udf_tread(dir->i_sb, block); |
| 49 | if (!*bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | return NULL; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 51 | } else if (*offset > dir->i_sb->s_blocksize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | ad = tmpad; |
| 53 | |
| 54 | remainder = dir->i_sb->s_blocksize - loffset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 55 | memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 57 | brelse(*bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); |
| 59 | if (!block) |
| 60 | return NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 61 | (*bh) = udf_tread(dir->i_sb, block); |
| 62 | if (!*bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | return NULL; |
| 64 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 65 | memcpy((uint8_t *)ad + remainder, (*bh)->b_data, |
| 66 | ad_size - remainder); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | *offset = ad_size - remainder; |
| 68 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | return ad; |
| 71 | } |
| 72 | #endif |
| 73 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 74 | struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 75 | struct udf_fileident_bh *fibh, |
| 76 | struct fileIdentDesc *cfi, |
| 77 | struct extent_position *epos, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 78 | kernel_lb_addr *eloc, uint32_t *elen, |
| 79 | sector_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | struct fileIdentDesc *fi; |
| 82 | int i, num, block; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 83 | struct buffer_head *tmp, *bha[16]; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 84 | struct udf_inode_info *iinfo = UDF_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | fibh->soffset = fibh->eoffset; |
| 87 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 88 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 89 | fi = udf_get_fileident(iinfo->i_ext.i_data - |
| 90 | (iinfo->i_efe ? |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 91 | sizeof(struct extendedFileEntry) : |
| 92 | sizeof(struct fileEntry)), |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 93 | dir->i_sb->s_blocksize, |
| 94 | &(fibh->eoffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | if (!fi) |
| 96 | return NULL; |
| 97 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 98 | *nf_pos += fibh->eoffset - fibh->soffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 100 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 101 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | return fi; |
| 104 | } |
| 105 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 106 | if (fibh->eoffset == dir->i_sb->s_blocksize) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 107 | int lextoffset = epos->offset; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 108 | unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 110 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 111 | (EXT_RECORDED_ALLOCATED >> 30)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); |
| 115 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 116 | (*offset)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 118 | if ((*offset << blocksize_bits) >= *elen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | *offset = 0; |
| 120 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 121 | epos->offset = lextoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 123 | brelse(fibh->sbh); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 124 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 125 | if (!fibh->sbh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | return NULL; |
| 127 | fibh->soffset = fibh->eoffset = 0; |
| 128 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 129 | if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) { |
| 130 | i = 16 >> (blocksize_bits - 9); |
| 131 | if (i + *offset > (*elen >> blocksize_bits)) |
| 132 | i = (*elen >> blocksize_bits)-*offset; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 133 | for (num = 0; i > 0; i--) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 134 | block = udf_get_lb_pblock(dir->i_sb, *eloc, |
| 135 | *offset + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | tmp = udf_tgetblk(dir->i_sb, block); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 137 | if (tmp && !buffer_uptodate(tmp) && |
| 138 | !buffer_locked(tmp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | bha[num++] = tmp; |
| 140 | else |
| 141 | brelse(tmp); |
| 142 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 143 | if (num) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | ll_rw_block(READA, num, bha); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 145 | for (i = 0; i < num; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | brelse(bha[i]); |
| 147 | } |
| 148 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 149 | } else if (fibh->sbh != fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 150 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | fibh->sbh = fibh->ebh; |
| 152 | } |
| 153 | |
| 154 | fi = udf_get_fileident(fibh->sbh->b_data, dir->i_sb->s_blocksize, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 155 | &(fibh->eoffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | if (!fi) |
| 158 | return NULL; |
| 159 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 160 | *nf_pos += fibh->eoffset - fibh->soffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 162 | if (fibh->eoffset <= dir->i_sb->s_blocksize) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 163 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 164 | sizeof(struct fileIdentDesc)); |
| 165 | } else if (fibh->eoffset > dir->i_sb->s_blocksize) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 166 | int lextoffset = epos->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 168 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 169 | (EXT_RECORDED_ALLOCATED >> 30)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); |
| 173 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 174 | (*offset)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) |
| 177 | *offset = 0; |
| 178 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 179 | epos->offset = lextoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | fibh->soffset -= dir->i_sb->s_blocksize; |
| 182 | fibh->eoffset -= dir->i_sb->s_blocksize; |
| 183 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 184 | fibh->ebh = udf_tread(dir->i_sb, block); |
| 185 | if (!fibh->ebh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | return NULL; |
| 187 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 188 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | int fi_len; |
| 190 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 191 | memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 192 | memcpy((uint8_t *)cfi - fibh->soffset, |
| 193 | fibh->ebh->b_data, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 194 | sizeof(struct fileIdentDesc) + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 196 | fi_len = (sizeof(struct fileIdentDesc) + |
| 197 | cfi->lengthFileIdent + |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 198 | le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 200 | *nf_pos += fi_len - (fibh->eoffset - fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | fibh->eoffset = fibh->soffset + fi_len; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 202 | } else { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 203 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 204 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | return fi; |
| 208 | } |
| 209 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 210 | struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | struct fileIdentDesc *fi; |
| 213 | int lengthThisIdent; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 214 | uint8_t *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | int padlen; |
| 216 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 217 | if ((!buffer) || (!offset)) { |
| 218 | udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, |
| 219 | offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | return NULL; |
| 221 | } |
| 222 | |
| 223 | ptr = buffer; |
| 224 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 225 | if ((*offset > 0) && (*offset < bufsize)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | ptr += *offset; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 227 | fi = (struct fileIdentDesc *)ptr; |
Marcin Slusarz | 5e0f001 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 228 | if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | udf_debug("0x%x != TAG_IDENT_FID\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 230 | le16_to_cpu(fi->descTag.tagIdent)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | udf_debug("offset: %u sizeof: %lu bufsize: %u\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 232 | *offset, (unsigned long)sizeof(struct fileIdentDesc), |
| 233 | bufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return NULL; |
| 235 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 236 | if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | lengthThisIdent = sizeof(struct fileIdentDesc); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 238 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | lengthThisIdent = sizeof(struct fileIdentDesc) + |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 240 | fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* we need to figure padding, too! */ |
| 243 | padlen = lengthThisIdent % UDF_NAME_PAD; |
| 244 | if (padlen) |
| 245 | lengthThisIdent += (UDF_NAME_PAD - padlen); |
| 246 | *offset = *offset + lengthThisIdent; |
| 247 | |
| 248 | return fi; |
| 249 | } |
| 250 | |
| 251 | #if 0 |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 252 | static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 254 | extent_ad *ext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | struct fileEntry *fe; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 256 | uint8_t *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 258 | if ((!buffer) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n"); |
| 260 | return NULL; |
| 261 | } |
| 262 | |
| 263 | fe = (struct fileEntry *)buffer; |
| 264 | |
Marcin Slusarz | 5e0f001 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 265 | if (fe->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | udf_debug("0x%x != TAG_IDENT_FE\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 267 | le16_to_cpu(fe->descTag.tagIdent)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | return NULL; |
| 269 | } |
| 270 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 271 | ptr = (uint8_t *)(fe->extendedAttr) + |
| 272 | le32_to_cpu(fe->lengthExtendedAttr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 274 | if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | ptr += *offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 277 | ext = (extent_ad *)ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | *offset = *offset + sizeof(extent_ad); |
| 280 | return ext; |
| 281 | } |
| 282 | #endif |
| 283 | |
Marcin Slusarz | 1ed1617 | 2008-02-08 04:20:48 -0800 | [diff] [blame] | 284 | short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, uint32_t *offset, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 285 | int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
| 287 | short_ad *sa; |
| 288 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 289 | if ((!ptr) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n"); |
| 291 | return NULL; |
| 292 | } |
| 293 | |
Marcin Slusarz | 1ed1617 | 2008-02-08 04:20:48 -0800 | [diff] [blame] | 294 | if ((*offset + sizeof(short_ad)) > maxoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | return NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 296 | else { |
| 297 | sa = (short_ad *)ptr; |
| 298 | if (sa->extLength == 0) |
| 299 | return NULL; |
| 300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (inc) |
| 303 | *offset += sizeof(short_ad); |
| 304 | return sa; |
| 305 | } |
| 306 | |
Marcin Slusarz | 1ed1617 | 2008-02-08 04:20:48 -0800 | [diff] [blame] | 307 | long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, uint32_t *offset, int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | long_ad *la; |
| 310 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 311 | if ((!ptr) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n"); |
| 313 | return NULL; |
| 314 | } |
| 315 | |
Marcin Slusarz | 1ed1617 | 2008-02-08 04:20:48 -0800 | [diff] [blame] | 316 | if ((*offset + sizeof(long_ad)) > maxoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 318 | else { |
| 319 | la = (long_ad *)ptr; |
| 320 | if (la->extLength == 0) |
| 321 | return NULL; |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | if (inc) |
| 325 | *offset += sizeof(long_ad); |
| 326 | return la; |
| 327 | } |