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 | cb00ea3 | 2007-07-19 01:47:43 -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 | cb00ea3 | 2007-07-19 01:47:43 -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 | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 63 | memcpy((uint8_t *) ad + remainder, (*bh)->b_data, |
| 64 | ad_size - remainder); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | *offset = ad_size - remainder; |
| 66 | } |
| 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)), |
| 89 | dir->i_sb->s_blocksize, |
| 90 | &(fibh->eoffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | if (!fi) |
| 93 | return NULL; |
| 94 | |
| 95 | *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); |
| 96 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 97 | memcpy((uint8_t *) cfi, (uint8_t *) fi, |
| 98 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | return fi; |
| 101 | } |
| 102 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 103 | if (fibh->eoffset == dir->i_sb->s_blocksize) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 104 | int lextoffset = epos->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 106 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 107 | (EXT_RECORDED_ALLOCATED >> 30)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset); |
| 111 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 112 | (*offset)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) |
| 115 | *offset = 0; |
| 116 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 117 | epos->offset = lextoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 119 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) |
| 121 | return NULL; |
| 122 | fibh->soffset = fibh->eoffset = 0; |
| 123 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 124 | if (! |
| 125 | (*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | i = 16 >> (dir->i_sb->s_blocksize_bits - 9); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 128 | if (i + *offset > |
| 129 | (*elen >> dir->i_sb->s_blocksize_bits)) |
| 130 | i = (*elen >> dir->i_sb->s_blocksize_bits) - |
| 131 | *offset; |
| 132 | for (num = 0; i > 0; i--) { |
| 133 | block = |
| 134 | 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); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [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 | |
| 160 | *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); |
| 161 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 162 | if (fibh->eoffset <= dir->i_sb->s_blocksize) { |
| 163 | memcpy((uint8_t *) cfi, (uint8_t *) fi, |
| 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 | |
| 184 | if (!(fibh->ebh = udf_tread(dir->i_sb, block))) |
| 185 | return NULL; |
| 186 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 187 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | int fi_len; |
| 189 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 190 | memcpy((uint8_t *) cfi, (uint8_t *) fi, -fibh->soffset); |
| 191 | memcpy((uint8_t *) cfi - fibh->soffset, |
| 192 | fibh->ebh->b_data, |
| 193 | sizeof(struct fileIdentDesc) + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 195 | fi_len = |
| 196 | (sizeof(struct fileIdentDesc) + |
| 197 | cfi->lengthFileIdent + |
| 198 | le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 200 | *nf_pos += |
| 201 | ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | fibh->eoffset = fibh->soffset + fi_len; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 203 | } else { |
| 204 | memcpy((uint8_t *) cfi, (uint8_t *) fi, |
| 205 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | return fi; |
| 209 | } |
| 210 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 211 | struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
| 213 | struct fileIdentDesc *fi; |
| 214 | int lengthThisIdent; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 215 | uint8_t *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | int padlen; |
| 217 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 218 | if ((!buffer) || (!offset)) { |
| 219 | udf_debug("invalidparms\n, buffer=%p, offset=%p\n", buffer, |
| 220 | offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | return NULL; |
| 222 | } |
| 223 | |
| 224 | ptr = buffer; |
| 225 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 226 | if ((*offset > 0) && (*offset < bufsize)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | ptr += *offset; |
| 228 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 229 | fi = (struct fileIdentDesc *)ptr; |
| 230 | if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | udf_debug("0x%x != TAG_IDENT_FID\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 232 | le16_to_cpu(fi->descTag.tagIdent)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | udf_debug("offset: %u sizeof: %lu bufsize: %u\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 234 | *offset, (unsigned long)sizeof(struct fileIdentDesc), |
| 235 | bufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return NULL; |
| 237 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 238 | if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | lengthThisIdent = sizeof(struct fileIdentDesc); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 240 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | lengthThisIdent = sizeof(struct fileIdentDesc) + |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 242 | fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | /* we need to figure padding, too! */ |
| 245 | padlen = lengthThisIdent % UDF_NAME_PAD; |
| 246 | if (padlen) |
| 247 | lengthThisIdent += (UDF_NAME_PAD - padlen); |
| 248 | *offset = *offset + lengthThisIdent; |
| 249 | |
| 250 | return fi; |
| 251 | } |
| 252 | |
| 253 | #if 0 |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 254 | static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 256 | extent_ad *ext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | struct fileEntry *fe; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 258 | uint8_t *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 260 | if ((!buffer) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | printk(KERN_ERR "udf: udf_get_fileextent() invalidparms\n"); |
| 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | fe = (struct fileEntry *)buffer; |
| 266 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 267 | if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | udf_debug("0x%x != TAG_IDENT_FE\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 269 | le16_to_cpu(fe->descTag.tagIdent)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return NULL; |
| 271 | } |
| 272 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 273 | ptr = |
| 274 | (uint8_t *) (fe->extendedAttr) + |
| 275 | le32_to_cpu(fe->lengthExtendedAttr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 277 | if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | ptr += *offset; |
| 279 | } |
| 280 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 281 | ext = (extent_ad *) ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | *offset = *offset + sizeof(extent_ad); |
| 284 | return ext; |
| 285 | } |
| 286 | #endif |
| 287 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 288 | short_ad *udf_get_fileshortad(uint8_t * ptr, int maxoffset, int *offset, |
| 289 | int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
| 291 | short_ad *sa; |
| 292 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 293 | if ((!ptr) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | printk(KERN_ERR "udf: udf_get_fileshortad() invalidparms\n"); |
| 295 | return NULL; |
| 296 | } |
| 297 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 298 | if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | return NULL; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 300 | else if ((sa = (short_ad *) ptr)->extLength == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | return NULL; |
| 302 | |
| 303 | if (inc) |
| 304 | *offset += sizeof(short_ad); |
| 305 | return sa; |
| 306 | } |
| 307 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 308 | 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] | 309 | { |
| 310 | long_ad *la; |
| 311 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 312 | if ((!ptr) || (!offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | printk(KERN_ERR "udf: udf_get_filelongad() invalidparms\n"); |
| 314 | return NULL; |
| 315 | } |
| 316 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 317 | if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return NULL; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 319 | else if ((la = (long_ad *) ptr)->extLength == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return NULL; |
| 321 | |
| 322 | if (inc) |
| 323 | *offset += sizeof(long_ad); |
| 324 | return la; |
| 325 | } |