aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/namei.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/namei.c')
-rw-r--r--fs/udf/namei.c443
1 files changed, 255 insertions, 188 deletions
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index bec96a6b3343..112a5fb0b27b 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -43,12 +43,10 @@ static inline int udf_match(int len1, const char *name1, int len2,
43 43
44int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, 44int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
45 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, 45 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh,
46 uint8_t * impuse, uint8_t * fileident) 46 uint8_t *impuse, uint8_t *fileident)
47{ 47{
48 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); 48 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag);
49 uint16_t crc; 49 uint16_t crc;
50 uint8_t checksum = 0;
51 int i;
52 int offset; 50 int offset;
53 uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); 51 uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse);
54 uint8_t lfi = cfi->lengthFileIdent; 52 uint8_t lfi = cfi->lengthFileIdent;
@@ -56,7 +54,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
56 sizeof(struct fileIdentDesc); 54 sizeof(struct fileIdentDesc);
57 int adinicb = 0; 55 int adinicb = 0;
58 56
59 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 57 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
60 adinicb = 1; 58 adinicb = 1;
61 59
62 offset = fibh->soffset + sizeof(struct fileIdentDesc); 60 offset = fibh->soffset + sizeof(struct fileIdentDesc);
@@ -68,7 +66,8 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
68 memcpy(fibh->ebh->b_data + offset, impuse, liu); 66 memcpy(fibh->ebh->b_data + offset, impuse, liu);
69 } else { 67 } else {
70 memcpy((uint8_t *)sfi->impUse, impuse, -offset); 68 memcpy((uint8_t *)sfi->impUse, impuse, -offset);
71 memcpy(fibh->ebh->b_data, impuse - offset, liu + offset); 69 memcpy(fibh->ebh->b_data, impuse - offset,
70 liu + offset);
72 } 71 }
73 } 72 }
74 73
@@ -80,8 +79,10 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
80 } else if (offset >= 0) { 79 } else if (offset >= 0) {
81 memcpy(fibh->ebh->b_data + offset, fileident, lfi); 80 memcpy(fibh->ebh->b_data + offset, fileident, lfi);
82 } else { 81 } else {
83 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset); 82 memcpy((uint8_t *)sfi->fileIdent + liu, fileident,
84 memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset); 83 -offset);
84 memcpy(fibh->ebh->b_data, fileident - offset,
85 lfi + offset);
85 } 86 }
86 } 87 }
87 88
@@ -101,27 +102,29 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
101 102
102 if (fibh->sbh == fibh->ebh) { 103 if (fibh->sbh == fibh->ebh) {
103 crc = udf_crc((uint8_t *)sfi->impUse, 104 crc = udf_crc((uint8_t *)sfi->impUse,
104 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); 105 crclen + sizeof(tag) -
106 sizeof(struct fileIdentDesc), crc);
105 } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { 107 } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
106 crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset, 108 crc = udf_crc(fibh->ebh->b_data +
107 crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); 109 sizeof(struct fileIdentDesc) +
110 fibh->soffset,
111 crclen + sizeof(tag) -
112 sizeof(struct fileIdentDesc),
113 crc);
108 } else { 114 } else {
109 crc = udf_crc((uint8_t *)sfi->impUse, 115 crc = udf_crc((uint8_t *)sfi->impUse,
110 -fibh->soffset - sizeof(struct fileIdentDesc), crc); 116 -fibh->soffset - sizeof(struct fileIdentDesc),
117 crc);
111 crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); 118 crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
112 } 119 }
113 120
114 cfi->descTag.descCRC = cpu_to_le16(crc); 121 cfi->descTag.descCRC = cpu_to_le16(crc);
115 cfi->descTag.descCRCLength = cpu_to_le16(crclen); 122 cfi->descTag.descCRCLength = cpu_to_le16(crclen);
123 cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag);
116 124
117 for (i = 0; i < 16; i++) {
118 if (i != 4)
119 checksum += ((uint8_t *)&cfi->descTag)[i];
120 }
121
122 cfi->descTag.tagChecksum = checksum;
123 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { 125 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) {
124 memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc)); 126 memcpy((uint8_t *)sfi, (uint8_t *)cfi,
127 sizeof(struct fileIdentDesc));
125 } else { 128 } else {
126 memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); 129 memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset);
127 memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, 130 memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset,
@@ -155,26 +158,28 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
155 uint32_t elen; 158 uint32_t elen;
156 sector_t offset; 159 sector_t offset;
157 struct extent_position epos = {}; 160 struct extent_position epos = {};
161 struct udf_inode_info *dinfo = UDF_I(dir);
158 162
159 size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 163 size = udf_ext0_offset(dir) + dir->i_size;
160 f_pos = (udf_ext0_offset(dir) >> 2); 164 f_pos = udf_ext0_offset(dir);
161 165
162 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 166 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
163 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 167 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
164 fibh->sbh = fibh->ebh = NULL; 168 fibh->sbh = fibh->ebh = NULL;
165 } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 169 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
166 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { 170 &epos, &eloc, &elen, &offset) ==
171 (EXT_RECORDED_ALLOCATED >> 30)) {
167 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 172 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
168 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { 173 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
169 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 174 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
170 epos.offset -= sizeof(short_ad); 175 epos.offset -= sizeof(short_ad);
171 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 176 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
172 epos.offset -= sizeof(long_ad); 177 epos.offset -= sizeof(long_ad);
173 } else { 178 } else
174 offset = 0; 179 offset = 0;
175 }
176 180
177 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { 181 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
182 if (!fibh->sbh) {
178 brelse(epos.bh); 183 brelse(epos.bh);
179 return NULL; 184 return NULL;
180 } 185 }
@@ -183,7 +188,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
183 return NULL; 188 return NULL;
184 } 189 }
185 190
186 while ((f_pos < size)) { 191 while (f_pos < size) {
187 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 192 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
188 &elen, &offset); 193 &elen, &offset);
189 if (!fi) { 194 if (!fi) {
@@ -202,14 +207,18 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
202 } else { 207 } else {
203 int poffset; /* Unpaded ending offset */ 208 int poffset; /* Unpaded ending offset */
204 209
205 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; 210 poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
211 liu + lfi;
206 212
207 if (poffset >= lfi) { 213 if (poffset >= lfi)
208 nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi); 214 nameptr = (uint8_t *)(fibh->ebh->b_data +
209 } else { 215 poffset - lfi);
216 else {
210 nameptr = fname; 217 nameptr = fname;
211 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 218 memcpy(nameptr, fi->fileIdent + liu,
212 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); 219 lfi - poffset);
220 memcpy(nameptr + lfi - poffset,
221 fibh->ebh->b_data, poffset);
213 } 222 }
214 } 223 }
215 224
@@ -226,11 +235,11 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
226 if (!lfi) 235 if (!lfi)
227 continue; 236 continue;
228 237
229 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) { 238 flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
230 if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { 239 if (flen && udf_match(flen, fname, dentry->d_name.len,
231 brelse(epos.bh); 240 dentry->d_name.name)) {
232 return fi; 241 brelse(epos.bh);
233 } 242 return fi;
234 } 243 }
235 } 244 }
236 245
@@ -291,16 +300,16 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
291 if (!strncmp(dentry->d_name.name, ".B=", 3)) { 300 if (!strncmp(dentry->d_name.name, ".B=", 3)) {
292 kernel_lb_addr lb = { 301 kernel_lb_addr lb = {
293 .logicalBlockNum = 0, 302 .logicalBlockNum = 0,
294 .partitionReferenceNum = simple_strtoul(dentry->d_name.name + 3, 303 .partitionReferenceNum =
295 NULL, 0), 304 simple_strtoul(dentry->d_name.name + 3,
305 NULL, 0),
296 }; 306 };
297 inode = udf_iget(dir->i_sb, lb); 307 inode = udf_iget(dir->i_sb, lb);
298 if (!inode) { 308 if (!inode) {
299 unlock_kernel(); 309 unlock_kernel();
300 return ERR_PTR(-EACCES); 310 return ERR_PTR(-EACCES);
301 } 311 }
302 } 312 } else
303 else
304#endif /* UDF_RECOVERY */ 313#endif /* UDF_RECOVERY */
305 314
306 if (udf_find_entry(dir, dentry, &fibh, &cfi)) { 315 if (udf_find_entry(dir, dentry, &fibh, &cfi)) {
@@ -325,14 +334,14 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
325 struct udf_fileident_bh *fibh, 334 struct udf_fileident_bh *fibh,
326 struct fileIdentDesc *cfi, int *err) 335 struct fileIdentDesc *cfi, int *err)
327{ 336{
328 struct super_block *sb; 337 struct super_block *sb = dir->i_sb;
329 struct fileIdentDesc *fi = NULL; 338 struct fileIdentDesc *fi = NULL;
330 char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; 339 char name[UDF_NAME_LEN], fname[UDF_NAME_LEN];
331 int namelen; 340 int namelen;
332 loff_t f_pos; 341 loff_t f_pos;
333 int flen; 342 int flen;
334 char *nameptr; 343 char *nameptr;
335 loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 344 loff_t size = udf_ext0_offset(dir) + dir->i_size;
336 int nfidlen; 345 int nfidlen;
337 uint8_t lfi; 346 uint8_t lfi;
338 uint16_t liu; 347 uint16_t liu;
@@ -341,16 +350,16 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
341 uint32_t elen; 350 uint32_t elen;
342 sector_t offset; 351 sector_t offset;
343 struct extent_position epos = {}; 352 struct extent_position epos = {};
344 353 struct udf_inode_info *dinfo;
345 sb = dir->i_sb;
346 354
347 if (dentry) { 355 if (dentry) {
348 if (!dentry->d_name.len) { 356 if (!dentry->d_name.len) {
349 *err = -EINVAL; 357 *err = -EINVAL;
350 return NULL; 358 return NULL;
351 } 359 }
352 if (!(namelen = udf_put_filename(sb, dentry->d_name.name, name, 360 namelen = udf_put_filename(sb, dentry->d_name.name, name,
353 dentry->d_name.len))) { 361 dentry->d_name.len);
362 if (!namelen) {
354 *err = -ENAMETOOLONG; 363 *err = -ENAMETOOLONG;
355 return NULL; 364 return NULL;
356 } 365 }
@@ -360,39 +369,40 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
360 369
361 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; 370 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3;
362 371
363 f_pos = (udf_ext0_offset(dir) >> 2); 372 f_pos = udf_ext0_offset(dir);
364 373
365 fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 374 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
366 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 375 dinfo = UDF_I(dir);
376 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
367 fibh->sbh = fibh->ebh = NULL; 377 fibh->sbh = fibh->ebh = NULL;
368 } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 378 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
369 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { 379 &epos, &eloc, &elen, &offset) ==
380 (EXT_RECORDED_ALLOCATED >> 30)) {
370 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 381 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
371 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { 382 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
372 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 383 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
373 epos.offset -= sizeof(short_ad); 384 epos.offset -= sizeof(short_ad);
374 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 385 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
375 epos.offset -= sizeof(long_ad); 386 epos.offset -= sizeof(long_ad);
376 } else { 387 } else
377 offset = 0; 388 offset = 0;
378 }
379 389
380 if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { 390 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
391 if (!fibh->sbh) {
381 brelse(epos.bh); 392 brelse(epos.bh);
382 *err = -EIO; 393 *err = -EIO;
383 return NULL; 394 return NULL;
384 } 395 }
385 396
386 block = UDF_I_LOCATION(dir).logicalBlockNum; 397 block = dinfo->i_location.logicalBlockNum;
387
388 } else { 398 } else {
389 block = udf_get_lb_pblock(dir->i_sb, UDF_I_LOCATION(dir), 0); 399 block = udf_get_lb_pblock(dir->i_sb, dinfo->i_location, 0);
390 fibh->sbh = fibh->ebh = NULL; 400 fibh->sbh = fibh->ebh = NULL;
391 fibh->soffset = fibh->eoffset = sb->s_blocksize; 401 fibh->soffset = fibh->eoffset = sb->s_blocksize;
392 goto add; 402 goto add;
393 } 403 }
394 404
395 while ((f_pos < size)) { 405 while (f_pos < size) {
396 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 406 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
397 &elen, &offset); 407 &elen, &offset);
398 408
@@ -408,33 +418,39 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
408 liu = le16_to_cpu(cfi->lengthOfImpUse); 418 liu = le16_to_cpu(cfi->lengthOfImpUse);
409 lfi = cfi->lengthFileIdent; 419 lfi = cfi->lengthFileIdent;
410 420
411 if (fibh->sbh == fibh->ebh) { 421 if (fibh->sbh == fibh->ebh)
412 nameptr = fi->fileIdent + liu; 422 nameptr = fi->fileIdent + liu;
413 } else { 423 else {
414 int poffset; /* Unpaded ending offset */ 424 int poffset; /* Unpaded ending offset */
415 425
416 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; 426 poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
427 liu + lfi;
417 428
418 if (poffset >= lfi) { 429 if (poffset >= lfi)
419 nameptr = (char *)(fibh->ebh->b_data + poffset - lfi); 430 nameptr = (char *)(fibh->ebh->b_data +
420 } else { 431 poffset - lfi);
432 else {
421 nameptr = fname; 433 nameptr = fname;
422 memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); 434 memcpy(nameptr, fi->fileIdent + liu,
423 memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); 435 lfi - poffset);
436 memcpy(nameptr + lfi - poffset,
437 fibh->ebh->b_data, poffset);
424 } 438 }
425 } 439 }
426 440
427 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { 441 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
428 if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) { 442 if (((sizeof(struct fileIdentDesc) +
443 liu + lfi + 3) & ~3) == nfidlen) {
429 brelse(epos.bh); 444 brelse(epos.bh);
430 cfi->descTag.tagSerialNum = cpu_to_le16(1); 445 cfi->descTag.tagSerialNum = cpu_to_le16(1);
431 cfi->fileVersionNum = cpu_to_le16(1); 446 cfi->fileVersionNum = cpu_to_le16(1);
432 cfi->fileCharacteristics = 0; 447 cfi->fileCharacteristics = 0;
433 cfi->lengthFileIdent = namelen; 448 cfi->lengthFileIdent = namelen;
434 cfi->lengthOfImpUse = cpu_to_le16(0); 449 cfi->lengthOfImpUse = cpu_to_le16(0);
435 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { 450 if (!udf_write_fi(dir, cfi, fi, fibh, NULL,
451 name))
436 return fi; 452 return fi;
437 } else { 453 else {
438 *err = -EIO; 454 *err = -EIO;
439 return NULL; 455 return NULL;
440 } 456 }
@@ -444,8 +460,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
444 if (!lfi || !dentry) 460 if (!lfi || !dentry)
445 continue; 461 continue;
446 462
447 if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && 463 flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
448 udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { 464 if (flen && udf_match(flen, fname, dentry->d_name.len,
465 dentry->d_name.name)) {
449 if (fibh->sbh != fibh->ebh) 466 if (fibh->sbh != fibh->ebh)
450 brelse(fibh->ebh); 467 brelse(fibh->ebh);
451 brelse(fibh->sbh); 468 brelse(fibh->sbh);
@@ -456,29 +473,34 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
456 } 473 }
457 474
458add: 475add:
476 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
477 elen = (elen + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1);
478 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
479 epos.offset -= sizeof(short_ad);
480 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
481 epos.offset -= sizeof(long_ad);
482 udf_write_aext(dir, &epos, eloc, elen, 1);
483 }
459 f_pos += nfidlen; 484 f_pos += nfidlen;
460 485
461 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB && 486 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB &&
462 sb->s_blocksize - fibh->eoffset < nfidlen) { 487 sb->s_blocksize - fibh->eoffset < nfidlen) {
463 brelse(epos.bh); 488 brelse(epos.bh);
464 epos.bh = NULL; 489 epos.bh = NULL;
465 fibh->soffset -= udf_ext0_offset(dir); 490 fibh->soffset -= udf_ext0_offset(dir);
466 fibh->eoffset -= udf_ext0_offset(dir); 491 fibh->eoffset -= udf_ext0_offset(dir);
467 f_pos -= (udf_ext0_offset(dir) >> 2); 492 f_pos -= udf_ext0_offset(dir);
468 if (fibh->sbh != fibh->ebh) 493 if (fibh->sbh != fibh->ebh)
469 brelse(fibh->ebh); 494 brelse(fibh->ebh);
470 brelse(fibh->sbh); 495 brelse(fibh->sbh);
471 if (!(fibh->sbh = fibh->ebh = udf_expand_dir_adinicb(dir, &block, err))) 496 fibh->sbh = fibh->ebh =
497 udf_expand_dir_adinicb(dir, &block, err);
498 if (!fibh->sbh)
472 return NULL; 499 return NULL;
473 epos.block = UDF_I_LOCATION(dir); 500 epos.block = dinfo->i_location;
474 eloc.logicalBlockNum = block;
475 eloc.partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum;
476 elen = dir->i_sb->s_blocksize;
477 epos.offset = udf_file_entry_alloc_offset(dir); 501 epos.offset = udf_file_entry_alloc_offset(dir);
478 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 502 /* Load extent udf_expand_dir_adinicb() has created */
479 epos.offset += sizeof(short_ad); 503 udf_current_aext(dir, &epos, &eloc, &elen, 1);
480 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
481 epos.offset += sizeof(long_ad);
482 } 504 }
483 505
484 if (sb->s_blocksize - fibh->eoffset >= nfidlen) { 506 if (sb->s_blocksize - fibh->eoffset >= nfidlen) {
@@ -489,15 +511,19 @@ add:
489 fibh->sbh = fibh->ebh; 511 fibh->sbh = fibh->ebh;
490 } 512 }
491 513
492 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 514 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
493 block = UDF_I_LOCATION(dir).logicalBlockNum; 515 block = dinfo->i_location.logicalBlockNum;
494 fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset - 516 fi = (struct fileIdentDesc *)
495 udf_ext0_offset(dir) + 517 (dinfo->i_ext.i_data +
496 UDF_I_LENEATTR(dir)); 518 fibh->soffset -
519 udf_ext0_offset(dir) +
520 dinfo->i_lenEAttr);
497 } else { 521 } else {
498 block = eloc.logicalBlockNum + ((elen - 1) >> 522 block = eloc.logicalBlockNum +
499 dir->i_sb->s_blocksize_bits); 523 ((elen - 1) >>
500 fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset); 524 dir->i_sb->s_blocksize_bits);
525 fi = (struct fileIdentDesc *)
526 (fibh->sbh->b_data + fibh->soffset);
501 } 527 }
502 } else { 528 } else {
503 fibh->soffset = fibh->eoffset - sb->s_blocksize; 529 fibh->soffset = fibh->eoffset - sb->s_blocksize;
@@ -509,7 +535,8 @@ add:
509 535
510 block = eloc.logicalBlockNum + ((elen - 1) >> 536 block = eloc.logicalBlockNum + ((elen - 1) >>
511 dir->i_sb->s_blocksize_bits); 537 dir->i_sb->s_blocksize_bits);
512 fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err); 538 fibh->ebh = udf_bread(dir,
539 f_pos >> dir->i_sb->s_blocksize_bits, 1, err);
513 if (!fibh->ebh) { 540 if (!fibh->ebh) {
514 brelse(epos.bh); 541 brelse(epos.bh);
515 brelse(fibh->sbh); 542 brelse(fibh->sbh);
@@ -521,32 +548,34 @@ add:
521 (EXT_RECORDED_ALLOCATED >> 30)) { 548 (EXT_RECORDED_ALLOCATED >> 30)) {
522 block = eloc.logicalBlockNum + ((elen - 1) >> 549 block = eloc.logicalBlockNum + ((elen - 1) >>
523 dir->i_sb->s_blocksize_bits); 550 dir->i_sb->s_blocksize_bits);
524 } else { 551 } else
525 block++; 552 block++;
526 }
527 553
528 brelse(fibh->sbh); 554 brelse(fibh->sbh);
529 fibh->sbh = fibh->ebh; 555 fibh->sbh = fibh->ebh;
530 fi = (struct fileIdentDesc *)(fibh->sbh->b_data); 556 fi = (struct fileIdentDesc *)(fibh->sbh->b_data);
531 } else { 557 } else {
532 fi = (struct fileIdentDesc *) 558 fi = (struct fileIdentDesc *)
533 (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset); 559 (fibh->sbh->b_data + sb->s_blocksize +
560 fibh->soffset);
534 } 561 }
535 } 562 }
536 563
537 memset(cfi, 0, sizeof(struct fileIdentDesc)); 564 memset(cfi, 0, sizeof(struct fileIdentDesc));
538 if (UDF_SB_UDFREV(sb) >= 0x0200) 565 if (UDF_SB(sb)->s_udfrev >= 0x0200)
539 udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, sizeof(tag)); 566 udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block,
567 sizeof(tag));
540 else 568 else
541 udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, sizeof(tag)); 569 udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block,
570 sizeof(tag));
542 cfi->fileVersionNum = cpu_to_le16(1); 571 cfi->fileVersionNum = cpu_to_le16(1);
543 cfi->lengthFileIdent = namelen; 572 cfi->lengthFileIdent = namelen;
544 cfi->lengthOfImpUse = cpu_to_le16(0); 573 cfi->lengthOfImpUse = cpu_to_le16(0);
545 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { 574 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
546 brelse(epos.bh); 575 brelse(epos.bh);
547 dir->i_size += nfidlen; 576 dir->i_size += nfidlen;
548 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) 577 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
549 UDF_I_LENALLOC(dir) += nfidlen; 578 dinfo->i_lenAlloc += nfidlen;
550 mark_inode_dirty(dir); 579 mark_inode_dirty(dir);
551 return fi; 580 return fi;
552 } else { 581 } else {
@@ -578,6 +607,7 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
578 struct inode *inode; 607 struct inode *inode;
579 struct fileIdentDesc cfi, *fi; 608 struct fileIdentDesc cfi, *fi;
580 int err; 609 int err;
610 struct udf_inode_info *iinfo;
581 611
582 lock_kernel(); 612 lock_kernel();
583 inode = udf_new_inode(dir, mode, &err); 613 inode = udf_new_inode(dir, mode, &err);
@@ -586,7 +616,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
586 return err; 616 return err;
587 } 617 }
588 618
589 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 619 iinfo = UDF_I(inode);
620 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
590 inode->i_data.a_ops = &udf_adinicb_aops; 621 inode->i_data.a_ops = &udf_adinicb_aops;
591 else 622 else
592 inode->i_data.a_ops = &udf_aops; 623 inode->i_data.a_ops = &udf_aops;
@@ -595,7 +626,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
595 inode->i_mode = mode; 626 inode->i_mode = mode;
596 mark_inode_dirty(inode); 627 mark_inode_dirty(inode);
597 628
598 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { 629 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
630 if (!fi) {
599 inode->i_nlink--; 631 inode->i_nlink--;
600 mark_inode_dirty(inode); 632 mark_inode_dirty(inode);
601 iput(inode); 633 iput(inode);
@@ -603,13 +635,12 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
603 return err; 635 return err;
604 } 636 }
605 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 637 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
606 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 638 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
607 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 639 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
608 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 640 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
609 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 641 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
610 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 642 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
611 mark_inode_dirty(dir); 643 mark_inode_dirty(dir);
612 }
613 if (fibh.sbh != fibh.ebh) 644 if (fibh.sbh != fibh.ebh)
614 brelse(fibh.ebh); 645 brelse(fibh.ebh);
615 brelse(fibh.sbh); 646 brelse(fibh.sbh);
@@ -626,6 +657,7 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
626 struct udf_fileident_bh fibh; 657 struct udf_fileident_bh fibh;
627 struct fileIdentDesc cfi, *fi; 658 struct fileIdentDesc cfi, *fi;
628 int err; 659 int err;
660 struct udf_inode_info *iinfo;
629 661
630 if (!old_valid_dev(rdev)) 662 if (!old_valid_dev(rdev))
631 return -EINVAL; 663 return -EINVAL;
@@ -636,9 +668,11 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
636 if (!inode) 668 if (!inode)
637 goto out; 669 goto out;
638 670
671 iinfo = UDF_I(inode);
639 inode->i_uid = current->fsuid; 672 inode->i_uid = current->fsuid;
640 init_special_inode(inode, mode, rdev); 673 init_special_inode(inode, mode, rdev);
641 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { 674 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
675 if (!fi) {
642 inode->i_nlink--; 676 inode->i_nlink--;
643 mark_inode_dirty(inode); 677 mark_inode_dirty(inode);
644 iput(inode); 678 iput(inode);
@@ -646,13 +680,12 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
646 return err; 680 return err;
647 } 681 }
648 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 682 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
649 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 683 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
650 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 684 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
651 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 685 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
652 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 686 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
653 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 687 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
654 mark_inode_dirty(dir); 688 mark_inode_dirty(dir);
655 }
656 mark_inode_dirty(inode); 689 mark_inode_dirty(inode);
657 690
658 if (fibh.sbh != fibh.ebh) 691 if (fibh.sbh != fibh.ebh)
@@ -672,6 +705,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
672 struct udf_fileident_bh fibh; 705 struct udf_fileident_bh fibh;
673 struct fileIdentDesc cfi, *fi; 706 struct fileIdentDesc cfi, *fi;
674 int err; 707 int err;
708 struct udf_inode_info *dinfo = UDF_I(dir);
709 struct udf_inode_info *iinfo;
675 710
676 lock_kernel(); 711 lock_kernel();
677 err = -EMLINK; 712 err = -EMLINK;
@@ -683,9 +718,11 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
683 if (!inode) 718 if (!inode)
684 goto out; 719 goto out;
685 720
721 iinfo = UDF_I(inode);
686 inode->i_op = &udf_dir_inode_operations; 722 inode->i_op = &udf_dir_inode_operations;
687 inode->i_fop = &udf_dir_operations; 723 inode->i_fop = &udf_dir_operations;
688 if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) { 724 fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err);
725 if (!fi) {
689 inode->i_nlink--; 726 inode->i_nlink--;
690 mark_inode_dirty(inode); 727 mark_inode_dirty(inode);
691 iput(inode); 728 iput(inode);
@@ -693,10 +730,11 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
693 } 730 }
694 inode->i_nlink = 2; 731 inode->i_nlink = 2;
695 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 732 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
696 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); 733 cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location);
697 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 734 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
698 cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); 735 cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL);
699 cfi.fileCharacteristics = FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; 736 cfi.fileCharacteristics =
737 FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT;
700 udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); 738 udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL);
701 brelse(fibh.sbh); 739 brelse(fibh.sbh);
702 inode->i_mode = S_IFDIR | mode; 740 inode->i_mode = S_IFDIR | mode;
@@ -704,16 +742,17 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
704 inode->i_mode |= S_ISGID; 742 inode->i_mode |= S_ISGID;
705 mark_inode_dirty(inode); 743 mark_inode_dirty(inode);
706 744
707 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { 745 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
746 if (!fi) {
708 inode->i_nlink = 0; 747 inode->i_nlink = 0;
709 mark_inode_dirty(inode); 748 mark_inode_dirty(inode);
710 iput(inode); 749 iput(inode);
711 goto out; 750 goto out;
712 } 751 }
713 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 752 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
714 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 753 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
715 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 754 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
716 cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); 755 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
717 cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; 756 cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY;
718 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 757 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
719 inc_nlink(dir); 758 inc_nlink(dir);
@@ -734,32 +773,33 @@ static int empty_dir(struct inode *dir)
734 struct fileIdentDesc *fi, cfi; 773 struct fileIdentDesc *fi, cfi;
735 struct udf_fileident_bh fibh; 774 struct udf_fileident_bh fibh;
736 loff_t f_pos; 775 loff_t f_pos;
737 loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 776 loff_t size = udf_ext0_offset(dir) + dir->i_size;
738 int block; 777 int block;
739 kernel_lb_addr eloc; 778 kernel_lb_addr eloc;
740 uint32_t elen; 779 uint32_t elen;
741 sector_t offset; 780 sector_t offset;
742 struct extent_position epos = {}; 781 struct extent_position epos = {};
782 struct udf_inode_info *dinfo = UDF_I(dir);
743 783
744 f_pos = (udf_ext0_offset(dir) >> 2); 784 f_pos = udf_ext0_offset(dir);
785 fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
745 786
746 fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; 787 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
747
748 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
749 fibh.sbh = fibh.ebh = NULL; 788 fibh.sbh = fibh.ebh = NULL;
750 } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 789 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
751 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { 790 &epos, &eloc, &elen, &offset) ==
791 (EXT_RECORDED_ALLOCATED >> 30)) {
752 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 792 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
753 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { 793 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
754 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) 794 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
755 epos.offset -= sizeof(short_ad); 795 epos.offset -= sizeof(short_ad);
756 else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) 796 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
757 epos.offset -= sizeof(long_ad); 797 epos.offset -= sizeof(long_ad);
758 } else { 798 } else
759 offset = 0; 799 offset = 0;
760 }
761 800
762 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { 801 fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block);
802 if (!fibh.sbh) {
763 brelse(epos.bh); 803 brelse(epos.bh);
764 return 0; 804 return 0;
765 } 805 }
@@ -768,7 +808,7 @@ static int empty_dir(struct inode *dir)
768 return 0; 808 return 0;
769 } 809 }
770 810
771 while ((f_pos < size)) { 811 while (f_pos < size) {
772 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, 812 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc,
773 &elen, &offset); 813 &elen, &offset);
774 if (!fi) { 814 if (!fi) {
@@ -828,7 +868,8 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
828 clear_nlink(inode); 868 clear_nlink(inode);
829 inode->i_size = 0; 869 inode->i_size = 0;
830 inode_dec_link_count(dir); 870 inode_dec_link_count(dir);
831 inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); 871 inode->i_ctime = dir->i_ctime = dir->i_mtime =
872 current_fs_time(dir->i_sb);
832 mark_inode_dirty(dir); 873 mark_inode_dirty(dir);
833 874
834end_rmdir: 875end_rmdir:
@@ -901,36 +942,42 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
901 int block; 942 int block;
902 char name[UDF_NAME_LEN]; 943 char name[UDF_NAME_LEN];
903 int namelen; 944 int namelen;
945 struct buffer_head *bh;
946 struct udf_inode_info *iinfo;
904 947
905 lock_kernel(); 948 lock_kernel();
906 if (!(inode = udf_new_inode(dir, S_IFLNK, &err))) 949 inode = udf_new_inode(dir, S_IFLNK, &err);
950 if (!inode)
907 goto out; 951 goto out;
908 952
953 iinfo = UDF_I(inode);
909 inode->i_mode = S_IFLNK | S_IRWXUGO; 954 inode->i_mode = S_IFLNK | S_IRWXUGO;
910 inode->i_data.a_ops = &udf_symlink_aops; 955 inode->i_data.a_ops = &udf_symlink_aops;
911 inode->i_op = &page_symlink_inode_operations; 956 inode->i_op = &page_symlink_inode_operations;
912 957
913 if (UDF_I_ALLOCTYPE(inode) != ICBTAG_FLAG_AD_IN_ICB) { 958 if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
914 kernel_lb_addr eloc; 959 kernel_lb_addr eloc;
915 uint32_t elen; 960 uint32_t elen;
916 961
917 block = udf_new_block(inode->i_sb, inode, 962 block = udf_new_block(inode->i_sb, inode,
918 UDF_I_LOCATION(inode).partitionReferenceNum, 963 iinfo->i_location.partitionReferenceNum,
919 UDF_I_LOCATION(inode).logicalBlockNum, &err); 964 iinfo->i_location.logicalBlockNum, &err);
920 if (!block) 965 if (!block)
921 goto out_no_entry; 966 goto out_no_entry;
922 epos.block = UDF_I_LOCATION(inode); 967 epos.block = iinfo->i_location;
923 epos.offset = udf_file_entry_alloc_offset(inode); 968 epos.offset = udf_file_entry_alloc_offset(inode);
924 epos.bh = NULL; 969 epos.bh = NULL;
925 eloc.logicalBlockNum = block; 970 eloc.logicalBlockNum = block;
926 eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; 971 eloc.partitionReferenceNum =
972 iinfo->i_location.partitionReferenceNum;
927 elen = inode->i_sb->s_blocksize; 973 elen = inode->i_sb->s_blocksize;
928 UDF_I_LENEXTENTS(inode) = elen; 974 iinfo->i_lenExtents = elen;
929 udf_add_aext(inode, &epos, eloc, elen, 0); 975 udf_add_aext(inode, &epos, eloc, elen, 0);
930 brelse(epos.bh); 976 brelse(epos.bh);
931 977
932 block = udf_get_pblock(inode->i_sb, block, 978 block = udf_get_pblock(inode->i_sb, block,
933 UDF_I_LOCATION(inode).partitionReferenceNum, 0); 979 iinfo->i_location.partitionReferenceNum,
980 0);
934 epos.bh = udf_tread(inode->i_sb, block); 981 epos.bh = udf_tread(inode->i_sb, block);
935 lock_buffer(epos.bh); 982 lock_buffer(epos.bh);
936 memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); 983 memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize);
@@ -938,9 +985,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
938 unlock_buffer(epos.bh); 985 unlock_buffer(epos.bh);
939 mark_buffer_dirty_inode(epos.bh, inode); 986 mark_buffer_dirty_inode(epos.bh, inode);
940 ea = epos.bh->b_data + udf_ext0_offset(inode); 987 ea = epos.bh->b_data + udf_ext0_offset(inode);
941 } else { 988 } else
942 ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); 989 ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
943 }
944 990
945 eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); 991 eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode);
946 pc = (struct pathComponent *)ea; 992 pc = (struct pathComponent *)ea;
@@ -977,7 +1023,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
977 if (compstart[0] == '.') { 1023 if (compstart[0] == '.') {
978 if ((symname - compstart) == 1) 1024 if ((symname - compstart) == 1)
979 pc->componentType = 4; 1025 pc->componentType = 4;
980 else if ((symname - compstart) == 2 && compstart[1] == '.') 1026 else if ((symname - compstart) == 2 &&
1027 compstart[1] == '.')
981 pc->componentType = 3; 1028 pc->componentType = 3;
982 } 1029 }
983 1030
@@ -987,7 +1034,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
987 if (!namelen) 1034 if (!namelen)
988 goto out_no_entry; 1035 goto out_no_entry;
989 1036
990 if (elen + sizeof(struct pathComponent) + namelen > eoffset) 1037 if (elen + sizeof(struct pathComponent) + namelen >
1038 eoffset)
991 goto out_no_entry; 1039 goto out_no_entry;
992 else 1040 else
993 pc->lengthComponentIdent = namelen; 1041 pc->lengthComponentIdent = namelen;
@@ -1006,30 +1054,34 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
1006 1054
1007 brelse(epos.bh); 1055 brelse(epos.bh);
1008 inode->i_size = elen; 1056 inode->i_size = elen;
1009 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1057 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1010 UDF_I_LENALLOC(inode) = inode->i_size; 1058 iinfo->i_lenAlloc = inode->i_size;
1011 mark_inode_dirty(inode); 1059 mark_inode_dirty(inode);
1012 1060
1013 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) 1061 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
1062 if (!fi)
1014 goto out_no_entry; 1063 goto out_no_entry;
1015 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 1064 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
1016 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 1065 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
1017 if (UDF_SB_LVIDBH(inode->i_sb)) { 1066 bh = UDF_SB(inode->i_sb)->s_lvid_bh;
1067 if (bh) {
1068 struct logicalVolIntegrityDesc *lvid =
1069 (struct logicalVolIntegrityDesc *)bh->b_data;
1018 struct logicalVolHeaderDesc *lvhd; 1070 struct logicalVolHeaderDesc *lvhd;
1019 uint64_t uniqueID; 1071 uint64_t uniqueID;
1020 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); 1072 lvhd = (struct logicalVolHeaderDesc *)
1073 lvid->logicalVolContentsUse;
1021 uniqueID = le64_to_cpu(lvhd->uniqueID); 1074 uniqueID = le64_to_cpu(lvhd->uniqueID);
1022 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 1075 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
1023 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); 1076 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
1024 if (!(++uniqueID & 0x00000000FFFFFFFFUL)) 1077 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
1025 uniqueID += 16; 1078 uniqueID += 16;
1026 lvhd->uniqueID = cpu_to_le64(uniqueID); 1079 lvhd->uniqueID = cpu_to_le64(uniqueID);
1027 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); 1080 mark_buffer_dirty(bh);
1028 } 1081 }
1029 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 1082 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
1030 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 1083 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1031 mark_inode_dirty(dir); 1084 mark_inode_dirty(dir);
1032 }
1033 if (fibh.sbh != fibh.ebh) 1085 if (fibh.sbh != fibh.ebh)
1034 brelse(fibh.ebh); 1086 brelse(fibh.ebh);
1035 brelse(fibh.sbh); 1087 brelse(fibh.sbh);
@@ -1053,6 +1105,7 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
1053 struct udf_fileident_bh fibh; 1105 struct udf_fileident_bh fibh;
1054 struct fileIdentDesc cfi, *fi; 1106 struct fileIdentDesc cfi, *fi;
1055 int err; 1107 int err;
1108 struct buffer_head *bh;
1056 1109
1057 lock_kernel(); 1110 lock_kernel();
1058 if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) { 1111 if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
@@ -1060,28 +1113,32 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
1060 return -EMLINK; 1113 return -EMLINK;
1061 } 1114 }
1062 1115
1063 if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) { 1116 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
1117 if (!fi) {
1064 unlock_kernel(); 1118 unlock_kernel();
1065 return err; 1119 return err;
1066 } 1120 }
1067 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 1121 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
1068 cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); 1122 cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location);
1069 if (UDF_SB_LVIDBH(inode->i_sb)) { 1123 bh = UDF_SB(inode->i_sb)->s_lvid_bh;
1124 if (bh) {
1125 struct logicalVolIntegrityDesc *lvid =
1126 (struct logicalVolIntegrityDesc *)bh->b_data;
1070 struct logicalVolHeaderDesc *lvhd; 1127 struct logicalVolHeaderDesc *lvhd;
1071 uint64_t uniqueID; 1128 uint64_t uniqueID;
1072 lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); 1129 lvhd = (struct logicalVolHeaderDesc *)
1130 (lvid->logicalVolContentsUse);
1073 uniqueID = le64_to_cpu(lvhd->uniqueID); 1131 uniqueID = le64_to_cpu(lvhd->uniqueID);
1074 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 1132 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
1075 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); 1133 cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
1076 if (!(++uniqueID & 0x00000000FFFFFFFFUL)) 1134 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
1077 uniqueID += 16; 1135 uniqueID += 16;
1078 lvhd->uniqueID = cpu_to_le64(uniqueID); 1136 lvhd->uniqueID = cpu_to_le64(uniqueID);
1079 mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb)); 1137 mark_buffer_dirty(bh);
1080 } 1138 }
1081 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 1139 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
1082 if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { 1140 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1083 mark_inode_dirty(dir); 1141 mark_inode_dirty(dir);
1084 }
1085 1142
1086 if (fibh.sbh != fibh.ebh) 1143 if (fibh.sbh != fibh.ebh)
1087 brelse(fibh.ebh); 1144 brelse(fibh.ebh);
@@ -1105,13 +1162,16 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1105 struct inode *old_inode = old_dentry->d_inode; 1162 struct inode *old_inode = old_dentry->d_inode;
1106 struct inode *new_inode = new_dentry->d_inode; 1163 struct inode *new_inode = new_dentry->d_inode;
1107 struct udf_fileident_bh ofibh, nfibh; 1164 struct udf_fileident_bh ofibh, nfibh;
1108 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi; 1165 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL;
1166 struct fileIdentDesc ocfi, ncfi;
1109 struct buffer_head *dir_bh = NULL; 1167 struct buffer_head *dir_bh = NULL;
1110 int retval = -ENOENT; 1168 int retval = -ENOENT;
1111 kernel_lb_addr tloc; 1169 kernel_lb_addr tloc;
1170 struct udf_inode_info *old_iinfo = UDF_I(old_inode);
1112 1171
1113 lock_kernel(); 1172 lock_kernel();
1114 if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) { 1173 ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi);
1174 if (ofi) {
1115 if (ofibh.sbh != ofibh.ebh) 1175 if (ofibh.sbh != ofibh.ebh)
1116 brelse(ofibh.ebh); 1176 brelse(ofibh.ebh);
1117 brelse(ofibh.sbh); 1177 brelse(ofibh.sbh);
@@ -1131,7 +1191,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1131 } 1191 }
1132 } 1192 }
1133 if (S_ISDIR(old_inode->i_mode)) { 1193 if (S_ISDIR(old_inode->i_mode)) {
1134 uint32_t offset = udf_ext0_offset(old_inode); 1194 int offset = udf_ext0_offset(old_inode);
1135 1195
1136 if (new_inode) { 1196 if (new_inode) {
1137 retval = -ENOTEMPTY; 1197 retval = -ENOTEMPTY;
@@ -1139,30 +1199,36 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1139 goto end_rename; 1199 goto end_rename;
1140 } 1200 }
1141 retval = -EIO; 1201 retval = -EIO;
1142 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { 1202 if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1143 dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - 1203 dir_fi = udf_get_fileident(
1144 (UDF_I_EFE(old_inode) ? 1204 old_iinfo->i_ext.i_data -
1145 sizeof(struct extendedFileEntry) : 1205 (old_iinfo->i_efe ?
1146 sizeof(struct fileEntry)), 1206 sizeof(struct extendedFileEntry) :
1147 old_inode->i_sb->s_blocksize, &offset); 1207 sizeof(struct fileEntry)),
1208 old_inode->i_sb->s_blocksize, &offset);
1148 } else { 1209 } else {
1149 dir_bh = udf_bread(old_inode, 0, 0, &retval); 1210 dir_bh = udf_bread(old_inode, 0, 0, &retval);
1150 if (!dir_bh) 1211 if (!dir_bh)
1151 goto end_rename; 1212 goto end_rename;
1152 dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset); 1213 dir_fi = udf_get_fileident(dir_bh->b_data,
1214 old_inode->i_sb->s_blocksize, &offset);
1153 } 1215 }
1154 if (!dir_fi) 1216 if (!dir_fi)
1155 goto end_rename; 1217 goto end_rename;
1156 tloc = lelb_to_cpu(dir_fi->icb.extLocation); 1218 tloc = lelb_to_cpu(dir_fi->icb.extLocation);
1157 if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != old_dir->i_ino) 1219 if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) !=
1220 old_dir->i_ino)
1158 goto end_rename; 1221 goto end_rename;
1159 1222
1160 retval = -EMLINK; 1223 retval = -EMLINK;
1161 if (!new_inode && new_dir->i_nlink >= (256 << sizeof(new_dir->i_nlink)) - 1) 1224 if (!new_inode &&
1225 new_dir->i_nlink >=
1226 (256 << sizeof(new_dir->i_nlink)) - 1)
1162 goto end_rename; 1227 goto end_rename;
1163 } 1228 }
1164 if (!nfi) { 1229 if (!nfi) {
1165 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); 1230 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi,
1231 &retval);
1166 if (!nfi) 1232 if (!nfi)
1167 goto end_rename; 1233 goto end_rename;
1168 } 1234 }
@@ -1194,18 +1260,19 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1194 mark_inode_dirty(old_dir); 1260 mark_inode_dirty(old_dir);
1195 1261
1196 if (dir_fi) { 1262 if (dir_fi) {
1197 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); 1263 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location);
1198 udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + 1264 udf_update_tag((char *)dir_fi,
1199 le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); 1265 (sizeof(struct fileIdentDesc) +
1200 if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { 1266 le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3);
1267 if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1201 mark_inode_dirty(old_inode); 1268 mark_inode_dirty(old_inode);
1202 } else { 1269 else
1203 mark_buffer_dirty_inode(dir_bh, old_inode); 1270 mark_buffer_dirty_inode(dir_bh, old_inode);
1204 } 1271
1205 inode_dec_link_count(old_dir); 1272 inode_dec_link_count(old_dir);
1206 if (new_inode) { 1273 if (new_inode)
1207 inode_dec_link_count(new_inode); 1274 inode_dec_link_count(new_inode);
1208 } else { 1275 else {
1209 inc_nlink(new_dir); 1276 inc_nlink(new_dir);
1210 mark_inode_dirty(new_dir); 1277 mark_inode_dirty(new_dir);
1211 } 1278 }