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 |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 22 | static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, |
| 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; |
| 48 | if (!(*bh = udf_tread(dir->i_sb, block))) |
| 49 | return NULL; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 50 | } else if (*offset > dir->i_sb->s_blocksize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | ad = tmpad; |
| 52 | |
| 53 | remainder = dir->i_sb->s_blocksize - loffset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 54 | memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 56 | brelse(*bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); |
| 58 | if (!block) |
| 59 | return NULL; |
| 60 | if (!((*bh) = udf_tread(dir->i_sb, block))) |
| 61 | return NULL; |
| 62 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 63 | memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | *offset = ad_size - remainder; |
| 65 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | return ad; |
| 68 | } |
| 69 | #endif |
| 70 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 71 | struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, |
| 72 | struct udf_fileident_bh *fibh, |
| 73 | struct fileIdentDesc *cfi, |
| 74 | struct extent_position *epos, |
| 75 | kernel_lb_addr * eloc, uint32_t * elen, |
| 76 | sector_t * offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | struct fileIdentDesc *fi; |
| 79 | int i, num, block; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 80 | struct buffer_head *tmp, *bha[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | fibh->soffset = fibh->eoffset; |
| 83 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 84 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | fi = udf_get_fileident(UDF_I_DATA(dir) - |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 86 | (UDF_I_EFE(dir) ? |
| 87 | sizeof(struct extendedFileEntry) : |
| 88 | sizeof(struct fileEntry)), |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 89 | dir->i_sb->s_blocksize, &(fibh->eoffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | if (!fi) |
| 91 | return NULL; |
| 92 | |
| 93 | *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); |
| 94 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 95 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 96 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | return fi; |
| 99 | } |
| 100 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 101 | if (fibh->eoffset == dir->i_sb->s_blocksize) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 102 | int lextoffset = epos->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 104 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 105 | (EXT_RECORDED_ALLOCATED >> 30)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); |
| 109 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 110 | (*offset)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) |
| 113 | *offset = 0; |
| 114 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 115 | epos->offset = lextoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 117 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) |
| 119 | return NULL; |
| 120 | fibh->soffset = fibh->eoffset = 0; |
| 121 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 122 | if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | i = 16 >> (dir->i_sb->s_blocksize_bits - 9); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 124 | if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits)) |
| 125 | i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 126 | for (num = 0; i > 0; i--) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 127 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | tmp = udf_tgetblk(dir->i_sb, block); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 129 | if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | bha[num++] = tmp; |
| 131 | else |
| 132 | brelse(tmp); |
| 133 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 134 | if (num) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | ll_rw_block(READA, num, bha); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 136 | for (i = 0; i < num; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | brelse(bha[i]); |
| 138 | } |
| 139 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 140 | } else if (fibh->sbh != fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 141 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | fibh->sbh = fibh->ebh; |
| 143 | } |
| 144 | |
| 145 | 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] | 146 | &(fibh->eoffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | if (!fi) |
| 149 | return NULL; |
| 150 | |
| 151 | *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); |
| 152 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 153 | if (fibh->eoffset <= dir->i_sb->s_blocksize) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 154 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 155 | sizeof(struct fileIdentDesc)); |
| 156 | } else if (fibh->eoffset > dir->i_sb->s_blocksize) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 157 | int lextoffset = epos->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 159 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 160 | (EXT_RECORDED_ALLOCATED >> 30)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); |
| 164 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 165 | (*offset)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) |
| 168 | *offset = 0; |
| 169 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 170 | epos->offset = lextoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | fibh->soffset -= dir->i_sb->s_blocksize; |
| 173 | fibh->eoffset -= dir->i_sb->s_blocksize; |
| 174 | |
| 175 | if (!(fibh->ebh = udf_tread(dir->i_sb, block))) |
| 176 | return NULL; |
| 177 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 178 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | int fi_len; |
| 180 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 181 | memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); |
| 182 | memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 183 | sizeof(struct fileIdentDesc) + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 185 | fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + |
| 186 | le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 188 | *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | fibh->eoffset = fibh->soffset + fi_len; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 190 | } else { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 191 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 192 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | return fi; |
| 196 | } |
| 197 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 198 | struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | struct fileIdentDesc *fi; |
| 201 | int lengthThisIdent; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 202 | uint8_t *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | int padlen; |
| 204 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 205 | if ((!buffer) || (!offset)) { |
| 206 | udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, |
| 207 | offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | ptr = buffer; |
| 212 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 213 | if ((*offset > 0) && (*offset < bufsize)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | ptr += *offset; |
| 215 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 216 | fi = (struct fileIdentDesc *)ptr; |
| 217 | if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | udf_debug("0x%x != TAG_IDENT_FID\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 219 | le16_to_cpu(fi->descTag.tagIdent)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | udf_debug("offset: %u sizeof: %lu bufsize: %u\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 221 | *offset, (unsigned long)sizeof(struct fileIdentDesc), |
| 222 | bufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | return NULL; |
| 224 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 225 | if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | lengthThisIdent = sizeof(struct fileIdentDesc); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 227 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | lengthThisIdent = sizeof(struct fileIdentDesc) + |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 229 | fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); |
| 230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | /* we need to figure padding, too! */ |
| 233 | padlen = lengthThisIdent % UDF_NAME_PAD; |
| 234 | if (padlen) |
| 235 | lengthThisIdent += (UDF_NAME_PAD - padlen); |
| 236 | *offset = *offset + lengthThisIdent; |
| 237 | |
| 238 | return fi; |
| 239 | } |
| 240 | |
| 241 | #if 0 |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 242 | static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 244 | extent_ad *ext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | struct fileEntry *fe; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 246 | uint8_t *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 248 | if ((!buffer) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n"); |
| 250 | return NULL; |
| 251 | } |
| 252 | |
| 253 | fe = (struct fileEntry *)buffer; |
| 254 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 255 | if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | udf_debug("0x%x != TAG_IDENT_FE\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 257 | le16_to_cpu(fe->descTag.tagIdent)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | return NULL; |
| 259 | } |
| 260 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 261 | ptr = (uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 263 | if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | ptr += *offset; |
| 265 | } |
| 266 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 267 | ext = (extent_ad *)ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | *offset = *offset + sizeof(extent_ad); |
| 270 | return ext; |
| 271 | } |
| 272 | #endif |
| 273 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 274 | short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 275 | int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
| 277 | short_ad *sa; |
| 278 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 279 | if ((!ptr) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n"); |
| 281 | return NULL; |
| 282 | } |
| 283 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 284 | if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | return NULL; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 286 | else if ((sa = (short_ad *)ptr)->extLength == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return NULL; |
| 288 | |
| 289 | if (inc) |
| 290 | *offset += sizeof(short_ad); |
| 291 | return sa; |
| 292 | } |
| 293 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 294 | long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
| 296 | long_ad *la; |
| 297 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 298 | if ((!ptr) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n"); |
| 300 | return NULL; |
| 301 | } |
| 302 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 303 | if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return NULL; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 305 | else if ((la = (long_ad *)ptr)->extLength == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return NULL; |
| 307 | |
| 308 | if (inc) |
| 309 | *offset += sizeof(long_ad); |
| 310 | return la; |
| 311 | } |