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