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> |
Christoph Hellwig | 2f8b544 | 2016-11-01 07:40:13 -0600 | [diff] [blame] | 19 | #include <linux/bio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 21 | struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 22 | struct udf_fileident_bh *fibh, |
| 23 | struct fileIdentDesc *cfi, |
| 24 | struct extent_position *epos, |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 25 | struct kernel_lb_addr *eloc, uint32_t *elen, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 26 | sector_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
| 28 | struct fileIdentDesc *fi; |
Steve Magnani | b490bdd | 2017-10-12 08:48:40 -0500 | [diff] [blame] | 29 | int i, num; |
| 30 | udf_pblk_t block; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 31 | struct buffer_head *tmp, *bha[16]; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 32 | struct udf_inode_info *iinfo = UDF_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | fibh->soffset = fibh->eoffset; |
| 35 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 36 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 37 | fi = udf_get_fileident(iinfo->i_ext.i_data - |
| 38 | (iinfo->i_efe ? |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 39 | sizeof(struct extendedFileEntry) : |
| 40 | sizeof(struct fileEntry)), |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 41 | dir->i_sb->s_blocksize, |
| 42 | &(fibh->eoffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | if (!fi) |
| 44 | return NULL; |
| 45 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 46 | *nf_pos += fibh->eoffset - fibh->soffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 48 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 49 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | return fi; |
| 52 | } |
| 53 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 54 | if (fibh->eoffset == dir->i_sb->s_blocksize) { |
Steve Magnani | 89a4d97 | 2017-10-12 08:48:42 -0500 | [diff] [blame] | 55 | uint32_t lextoffset = epos->offset; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 56 | unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 58 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 59 | (EXT_RECORDED_ALLOCATED >> 30)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 62 | block = udf_get_lb_pblock(dir->i_sb, eloc, *offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 64 | (*offset)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 66 | if ((*offset << blocksize_bits) >= *elen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | *offset = 0; |
| 68 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 69 | epos->offset = lextoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 71 | brelse(fibh->sbh); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 72 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 73 | if (!fibh->sbh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return NULL; |
| 75 | fibh->soffset = fibh->eoffset = 0; |
| 76 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 77 | if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) { |
| 78 | i = 16 >> (blocksize_bits - 9); |
| 79 | if (i + *offset > (*elen >> blocksize_bits)) |
| 80 | i = (*elen >> blocksize_bits)-*offset; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 81 | for (num = 0; i > 0; i--) { |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 82 | block = udf_get_lb_pblock(dir->i_sb, eloc, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 83 | *offset + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | tmp = udf_tgetblk(dir->i_sb, block); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 85 | if (tmp && !buffer_uptodate(tmp) && |
| 86 | !buffer_locked(tmp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | bha[num++] = tmp; |
| 88 | else |
| 89 | brelse(tmp); |
| 90 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 91 | if (num) { |
Christoph Hellwig | 7024628 | 2016-07-19 11:28:41 +0200 | [diff] [blame] | 92 | ll_rw_block(REQ_OP_READ, REQ_RAHEAD, num, bha); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 93 | for (i = 0; i < num; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | brelse(bha[i]); |
| 95 | } |
| 96 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 97 | } else if (fibh->sbh != fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 98 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | fibh->sbh = fibh->ebh; |
| 100 | } |
| 101 | |
| 102 | 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] | 103 | &(fibh->eoffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | if (!fi) |
| 106 | return NULL; |
| 107 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 108 | *nf_pos += fibh->eoffset - fibh->soffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 110 | if (fibh->eoffset <= dir->i_sb->s_blocksize) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 111 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 112 | sizeof(struct fileIdentDesc)); |
| 113 | } else if (fibh->eoffset > dir->i_sb->s_blocksize) { |
Steve Magnani | 89a4d97 | 2017-10-12 08:48:42 -0500 | [diff] [blame] | 114 | uint32_t lextoffset = epos->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 116 | if (udf_next_aext(dir, epos, eloc, elen, 1) != |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 117 | (EXT_RECORDED_ALLOCATED >> 30)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 120 | block = udf_get_lb_pblock(dir->i_sb, eloc, *offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 122 | (*offset)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) |
| 125 | *offset = 0; |
| 126 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 127 | epos->offset = lextoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | fibh->soffset -= dir->i_sb->s_blocksize; |
| 130 | fibh->eoffset -= dir->i_sb->s_blocksize; |
| 131 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 132 | fibh->ebh = udf_tread(dir->i_sb, block); |
| 133 | if (!fibh->ebh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return NULL; |
| 135 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 136 | if (sizeof(struct fileIdentDesc) > -fibh->soffset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | int fi_len; |
| 138 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 139 | memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 140 | memcpy((uint8_t *)cfi - fibh->soffset, |
| 141 | fibh->ebh->b_data, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 142 | sizeof(struct fileIdentDesc) + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Jan Kara | f2e8334 | 2018-06-13 17:30:14 +0200 | [diff] [blame] | 144 | fi_len = udf_dir_entry_len(cfi); |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 145 | *nf_pos += fi_len - (fibh->eoffset - fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | fibh->eoffset = fibh->soffset + fi_len; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 147 | } else { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 148 | memcpy((uint8_t *)cfi, (uint8_t *)fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 149 | sizeof(struct fileIdentDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
Jan Kara | fa65653 | 2018-06-13 12:09:22 +0200 | [diff] [blame] | 152 | /* Got last entry outside of dir size - fs is corrupted! */ |
| 153 | if (*nf_pos > dir->i_size) |
| 154 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | return fi; |
| 156 | } |
| 157 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 158 | struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
| 160 | struct fileIdentDesc *fi; |
| 161 | int lengthThisIdent; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 162 | uint8_t *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | int padlen; |
| 164 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 165 | if ((!buffer) || (!offset)) { |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 166 | udf_debug("invalidparms, buffer=%p, offset=%p\n", |
| 167 | buffer, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return NULL; |
| 169 | } |
| 170 | |
| 171 | ptr = buffer; |
| 172 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 173 | if ((*offset > 0) && (*offset < bufsize)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | ptr += *offset; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 175 | fi = (struct fileIdentDesc *)ptr; |
Marcin Slusarz | 5e0f001 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 176 | if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | udf_debug("0x%x != TAG_IDENT_FID\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 178 | le16_to_cpu(fi->descTag.tagIdent)); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 179 | udf_debug("offset: %d sizeof: %lu bufsize: %d\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 180 | *offset, (unsigned long)sizeof(struct fileIdentDesc), |
| 181 | bufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return NULL; |
| 183 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 184 | if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | lengthThisIdent = sizeof(struct fileIdentDesc); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 186 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | lengthThisIdent = sizeof(struct fileIdentDesc) + |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 188 | fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* we need to figure padding, too! */ |
| 191 | padlen = lengthThisIdent % UDF_NAME_PAD; |
| 192 | if (padlen) |
| 193 | lengthThisIdent += (UDF_NAME_PAD - padlen); |
| 194 | *offset = *offset + lengthThisIdent; |
| 195 | |
| 196 | return fi; |
| 197 | } |
| 198 | |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 199 | struct 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] | 200 | int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 202 | struct short_ad *sa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 204 | if ((!ptr) || (!offset)) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 205 | pr_err("%s: invalidparms\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return NULL; |
| 207 | } |
| 208 | |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 209 | if ((*offset + sizeof(struct short_ad)) > maxoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | return NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 211 | else { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 212 | sa = (struct short_ad *)ptr; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 213 | if (sa->extLength == 0) |
| 214 | return NULL; |
| 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | if (inc) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 218 | *offset += sizeof(struct short_ad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return sa; |
| 220 | } |
| 221 | |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 222 | struct 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] | 223 | { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 224 | struct long_ad *la; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 226 | if ((!ptr) || (!offset)) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 227 | pr_err("%s: invalidparms\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
| 230 | |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 231 | if ((*offset + sizeof(struct long_ad)) > maxoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 233 | else { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 234 | la = (struct long_ad *)ptr; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 235 | if (la->extLength == 0) |
| 236 | return NULL; |
| 237 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | if (inc) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 240 | *offset += sizeof(struct long_ad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | return la; |
| 242 | } |