aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/directory.c')
-rw-r--r--fs/udf/directory.c102
1 files changed, 59 insertions, 43 deletions
diff --git a/fs/udf/directory.c b/fs/udf/directory.c
index ff8c08fd7bf5..2820f8fcf4cc 100644
--- a/fs/udf/directory.c
+++ b/fs/udf/directory.c
@@ -19,7 +19,7 @@
19#include <linux/buffer_head.h> 19#include <linux/buffer_head.h>
20 20
21#if 0 21#if 0
22static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad, 22static uint8_t *udf_filead_read(struct inode *dir, uint8_t *tmpad,
23 uint8_t ad_size, kernel_lb_addr fe_loc, 23 uint8_t ad_size, kernel_lb_addr fe_loc,
24 int *pos, int *offset, struct buffer_head **bh, 24 int *pos, int *offset, struct buffer_head **bh,
25 int *error) 25 int *error)
@@ -45,7 +45,8 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
45 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); 45 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
46 if (!block) 46 if (!block)
47 return NULL; 47 return NULL;
48 if (!(*bh = udf_tread(dir->i_sb, block))) 48 *bh = udf_tread(dir->i_sb, block);
49 if (!*bh)
49 return NULL; 50 return NULL;
50 } else if (*offset > dir->i_sb->s_blocksize) { 51 } else if (*offset > dir->i_sb->s_blocksize) {
51 ad = tmpad; 52 ad = tmpad;
@@ -57,10 +58,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
57 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos); 58 block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
58 if (!block) 59 if (!block)
59 return NULL; 60 return NULL;
60 if (!((*bh) = udf_tread(dir->i_sb, block))) 61 (*bh) = udf_tread(dir->i_sb, block);
62 if (!*bh)
61 return NULL; 63 return NULL;
62 64
63 memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder); 65 memcpy((uint8_t *)ad + remainder, (*bh)->b_data,
66 ad_size - remainder);
64 *offset = ad_size - remainder; 67 *offset = ad_size - remainder;
65 } 68 }
66 69
@@ -68,29 +71,31 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
68} 71}
69#endif 72#endif
70 73
71struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos, 74struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
72 struct udf_fileident_bh *fibh, 75 struct udf_fileident_bh *fibh,
73 struct fileIdentDesc *cfi, 76 struct fileIdentDesc *cfi,
74 struct extent_position *epos, 77 struct extent_position *epos,
75 kernel_lb_addr * eloc, uint32_t * elen, 78 kernel_lb_addr *eloc, uint32_t *elen,
76 sector_t * offset) 79 sector_t *offset)
77{ 80{
78 struct fileIdentDesc *fi; 81 struct fileIdentDesc *fi;
79 int i, num, block; 82 int i, num, block;
80 struct buffer_head *tmp, *bha[16]; 83 struct buffer_head *tmp, *bha[16];
84 struct udf_inode_info *iinfo = UDF_I(dir);
81 85
82 fibh->soffset = fibh->eoffset; 86 fibh->soffset = fibh->eoffset;
83 87
84 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 88 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
85 fi = udf_get_fileident(UDF_I_DATA(dir) - 89 fi = udf_get_fileident(iinfo->i_ext.i_data -
86 (UDF_I_EFE(dir) ? 90 (iinfo->i_efe ?
87 sizeof(struct extendedFileEntry) : 91 sizeof(struct extendedFileEntry) :
88 sizeof(struct fileEntry)), 92 sizeof(struct fileEntry)),
89 dir->i_sb->s_blocksize, &(fibh->eoffset)); 93 dir->i_sb->s_blocksize,
94 &(fibh->eoffset));
90 if (!fi) 95 if (!fi)
91 return NULL; 96 return NULL;
92 97
93 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 98 *nf_pos += fibh->eoffset - fibh->soffset;
94 99
95 memcpy((uint8_t *)cfi, (uint8_t *)fi, 100 memcpy((uint8_t *)cfi, (uint8_t *)fi,
96 sizeof(struct fileIdentDesc)); 101 sizeof(struct fileIdentDesc));
@@ -100,6 +105,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
100 105
101 if (fibh->eoffset == dir->i_sb->s_blocksize) { 106 if (fibh->eoffset == dir->i_sb->s_blocksize) {
102 int lextoffset = epos->offset; 107 int lextoffset = epos->offset;
108 unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits;
103 109
104 if (udf_next_aext(dir, epos, eloc, elen, 1) != 110 if (udf_next_aext(dir, epos, eloc, elen, 1) !=
105 (EXT_RECORDED_ALLOCATED >> 30)) 111 (EXT_RECORDED_ALLOCATED >> 30))
@@ -109,24 +115,27 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
109 115
110 (*offset)++; 116 (*offset)++;
111 117
112 if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen) 118 if ((*offset << blocksize_bits) >= *elen)
113 *offset = 0; 119 *offset = 0;
114 else 120 else
115 epos->offset = lextoffset; 121 epos->offset = lextoffset;
116 122
117 brelse(fibh->sbh); 123 brelse(fibh->sbh);
118 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) 124 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
125 if (!fibh->sbh)
119 return NULL; 126 return NULL;
120 fibh->soffset = fibh->eoffset = 0; 127 fibh->soffset = fibh->eoffset = 0;
121 128
122 if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { 129 if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) {
123 i = 16 >> (dir->i_sb->s_blocksize_bits - 9); 130 i = 16 >> (blocksize_bits - 9);
124 if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits)) 131 if (i + *offset > (*elen >> blocksize_bits))
125 i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset; 132 i = (*elen >> blocksize_bits)-*offset;
126 for (num = 0; i > 0; i--) { 133 for (num = 0; i > 0; i--) {
127 block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i); 134 block = udf_get_lb_pblock(dir->i_sb, *eloc,
135 *offset + i);
128 tmp = udf_tgetblk(dir->i_sb, block); 136 tmp = udf_tgetblk(dir->i_sb, block);
129 if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) 137 if (tmp && !buffer_uptodate(tmp) &&
138 !buffer_locked(tmp))
130 bha[num++] = tmp; 139 bha[num++] = tmp;
131 else 140 else
132 brelse(tmp); 141 brelse(tmp);
@@ -148,7 +157,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
148 if (!fi) 157 if (!fi)
149 return NULL; 158 return NULL;
150 159
151 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 160 *nf_pos += fibh->eoffset - fibh->soffset;
152 161
153 if (fibh->eoffset <= dir->i_sb->s_blocksize) { 162 if (fibh->eoffset <= dir->i_sb->s_blocksize) {
154 memcpy((uint8_t *)cfi, (uint8_t *)fi, 163 memcpy((uint8_t *)cfi, (uint8_t *)fi,
@@ -172,20 +181,23 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
172 fibh->soffset -= dir->i_sb->s_blocksize; 181 fibh->soffset -= dir->i_sb->s_blocksize;
173 fibh->eoffset -= dir->i_sb->s_blocksize; 182 fibh->eoffset -= dir->i_sb->s_blocksize;
174 183
175 if (!(fibh->ebh = udf_tread(dir->i_sb, block))) 184 fibh->ebh = udf_tread(dir->i_sb, block);
185 if (!fibh->ebh)
176 return NULL; 186 return NULL;
177 187
178 if (sizeof(struct fileIdentDesc) > -fibh->soffset) { 188 if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
179 int fi_len; 189 int fi_len;
180 190
181 memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset); 191 memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset);
182 memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data, 192 memcpy((uint8_t *)cfi - fibh->soffset,
193 fibh->ebh->b_data,
183 sizeof(struct fileIdentDesc) + fibh->soffset); 194 sizeof(struct fileIdentDesc) + fibh->soffset);
184 195
185 fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent + 196 fi_len = (sizeof(struct fileIdentDesc) +
197 cfi->lengthFileIdent +
186 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; 198 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
187 199
188 *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2); 200 *nf_pos += fi_len - (fibh->eoffset - fibh->soffset);
189 fibh->eoffset = fibh->soffset + fi_len; 201 fibh->eoffset = fibh->soffset + fi_len;
190 } else { 202 } else {
191 memcpy((uint8_t *)cfi, (uint8_t *)fi, 203 memcpy((uint8_t *)cfi, (uint8_t *)fi,
@@ -210,11 +222,10 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
210 222
211 ptr = buffer; 223 ptr = buffer;
212 224
213 if ((*offset > 0) && (*offset < bufsize)) { 225 if ((*offset > 0) && (*offset < bufsize))
214 ptr += *offset; 226 ptr += *offset;
215 }
216 fi = (struct fileIdentDesc *)ptr; 227 fi = (struct fileIdentDesc *)ptr;
217 if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) { 228 if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) {
218 udf_debug("0x%x != TAG_IDENT_FID\n", 229 udf_debug("0x%x != TAG_IDENT_FID\n",
219 le16_to_cpu(fi->descTag.tagIdent)); 230 le16_to_cpu(fi->descTag.tagIdent));
220 udf_debug("offset: %u sizeof: %lu bufsize: %u\n", 231 udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
@@ -222,12 +233,11 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
222 bufsize); 233 bufsize);
223 return NULL; 234 return NULL;
224 } 235 }
225 if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) { 236 if ((*offset + sizeof(struct fileIdentDesc)) > bufsize)
226 lengthThisIdent = sizeof(struct fileIdentDesc); 237 lengthThisIdent = sizeof(struct fileIdentDesc);
227 } else { 238 else
228 lengthThisIdent = sizeof(struct fileIdentDesc) + 239 lengthThisIdent = sizeof(struct fileIdentDesc) +
229 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse); 240 fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
230 }
231 241
232 /* we need to figure padding, too! */ 242 /* we need to figure padding, too! */
233 padlen = lengthThisIdent % UDF_NAME_PAD; 243 padlen = lengthThisIdent % UDF_NAME_PAD;
@@ -252,17 +262,17 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
252 262
253 fe = (struct fileEntry *)buffer; 263 fe = (struct fileEntry *)buffer;
254 264
255 if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) { 265 if (fe->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FE)) {
256 udf_debug("0x%x != TAG_IDENT_FE\n", 266 udf_debug("0x%x != TAG_IDENT_FE\n",
257 le16_to_cpu(fe->descTag.tagIdent)); 267 le16_to_cpu(fe->descTag.tagIdent));
258 return NULL; 268 return NULL;
259 } 269 }
260 270
261 ptr = (uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr); 271 ptr = (uint8_t *)(fe->extendedAttr) +
272 le32_to_cpu(fe->lengthExtendedAttr);
262 273
263 if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) { 274 if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)))
264 ptr += *offset; 275 ptr += *offset;
265 }
266 276
267 ext = (extent_ad *)ptr; 277 ext = (extent_ad *)ptr;
268 278
@@ -271,7 +281,7 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
271} 281}
272#endif 282#endif
273 283
274short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset, 284short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, uint32_t *offset,
275 int inc) 285 int inc)
276{ 286{
277 short_ad *sa; 287 short_ad *sa;
@@ -281,17 +291,20 @@ short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset,
281 return NULL; 291 return NULL;
282 } 292 }
283 293
284 if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset)) 294 if ((*offset + sizeof(short_ad)) > maxoffset)
285 return NULL;
286 else if ((sa = (short_ad *)ptr)->extLength == 0)
287 return NULL; 295 return NULL;
296 else {
297 sa = (short_ad *)ptr;
298 if (sa->extLength == 0)
299 return NULL;
300 }
288 301
289 if (inc) 302 if (inc)
290 *offset += sizeof(short_ad); 303 *offset += sizeof(short_ad);
291 return sa; 304 return sa;
292} 305}
293 306
294long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc) 307long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, uint32_t *offset, int inc)
295{ 308{
296 long_ad *la; 309 long_ad *la;
297 310
@@ -300,10 +313,13 @@ long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc)
300 return NULL; 313 return NULL;
301 } 314 }
302 315
303 if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset)) 316 if ((*offset + sizeof(long_ad)) > maxoffset)
304 return NULL;
305 else if ((la = (long_ad *)ptr)->extLength == 0)
306 return NULL; 317 return NULL;
318 else {
319 la = (long_ad *)ptr;
320 if (la->extLength == 0)
321 return NULL;
322 }
307 323
308 if (inc) 324 if (inc)
309 *offset += sizeof(long_ad); 325 *offset += sizeof(long_ad);