1 // SPDX-License-Identifier: GPL-2.0-only << 2 /* 1 /* 3 * namei.c 2 * namei.c 4 * 3 * 5 * PURPOSE 4 * PURPOSE 6 * Inode name handling routines for the O 5 * Inode name handling routines for the OSTA-UDF(tm) filesystem. 7 * 6 * 8 * COPYRIGHT 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 * 9 * (C) 1998-2004 Ben Fennema 13 * (C) 1998-2004 Ben Fennema 10 * (C) 1999-2000 Stelias Computing Inc 14 * (C) 1999-2000 Stelias Computing Inc 11 * 15 * 12 * HISTORY 16 * HISTORY 13 * 17 * 14 * 12/12/98 blf Created. Split out the looku 18 * 12/12/98 blf Created. Split out the lookup code from dir.c 15 * 04/19/99 blf link, mknod, symlink support 19 * 04/19/99 blf link, mknod, symlink support 16 */ 20 */ 17 21 18 #include "udfdecl.h" 22 #include "udfdecl.h" 19 23 20 #include "udf_i.h" 24 #include "udf_i.h" 21 #include "udf_sb.h" 25 #include "udf_sb.h" 22 #include <linux/string.h> 26 #include <linux/string.h> 23 #include <linux/errno.h> 27 #include <linux/errno.h> 24 #include <linux/mm.h> 28 #include <linux/mm.h> 25 #include <linux/slab.h> 29 #include <linux/slab.h> 26 #include <linux/sched.h> 30 #include <linux/sched.h> 27 #include <linux/crc-itu-t.h> 31 #include <linux/crc-itu-t.h> 28 #include <linux/exportfs.h> 32 #include <linux/exportfs.h> 29 #include <linux/iversion.h> << 30 33 31 static inline int udf_match(int len1, const un 34 static inline int udf_match(int len1, const unsigned char *name1, int len2, 32 const unsigned cha 35 const unsigned char *name2) 33 { 36 { 34 if (len1 != len2) 37 if (len1 != len2) 35 return 0; 38 return 0; 36 39 37 return !memcmp(name1, name2, len1); 40 return !memcmp(name1, name2, len1); 38 } 41 } 39 42 >> 43 int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, >> 44 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, >> 45 uint8_t *impuse, uint8_t *fileident) >> 46 { >> 47 uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(struct tag); >> 48 uint16_t crc; >> 49 int offset; >> 50 uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); >> 51 uint8_t lfi = cfi->lengthFileIdent; >> 52 int padlen = fibh->eoffset - fibh->soffset - liu - lfi - >> 53 sizeof(struct fileIdentDesc); >> 54 int adinicb = 0; >> 55 >> 56 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) >> 57 adinicb = 1; >> 58 >> 59 offset = fibh->soffset + sizeof(struct fileIdentDesc); >> 60 >> 61 if (impuse) { >> 62 if (adinicb || (offset + liu < 0)) { >> 63 memcpy((uint8_t *)sfi->impUse, impuse, liu); >> 64 } else if (offset >= 0) { >> 65 memcpy(fibh->ebh->b_data + offset, impuse, liu); >> 66 } else { >> 67 memcpy((uint8_t *)sfi->impUse, impuse, -offset); >> 68 memcpy(fibh->ebh->b_data, impuse - offset, >> 69 liu + offset); >> 70 } >> 71 } >> 72 >> 73 offset += liu; >> 74 >> 75 if (fileident) { >> 76 if (adinicb || (offset + lfi < 0)) { >> 77 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi); >> 78 } else if (offset >= 0) { >> 79 memcpy(fibh->ebh->b_data + offset, fileident, lfi); >> 80 } else { >> 81 memcpy((uint8_t *)sfi->fileIdent + liu, fileident, >> 82 -offset); >> 83 memcpy(fibh->ebh->b_data, fileident - offset, >> 84 lfi + offset); >> 85 } >> 86 } >> 87 >> 88 offset += lfi; >> 89 >> 90 if (adinicb || (offset + padlen < 0)) { >> 91 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen); >> 92 } else if (offset >= 0) { >> 93 memset(fibh->ebh->b_data + offset, 0x00, padlen); >> 94 } else { >> 95 memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset); >> 96 memset(fibh->ebh->b_data, 0x00, padlen + offset); >> 97 } >> 98 >> 99 crc = crc_itu_t(0, (uint8_t *)cfi + sizeof(struct tag), >> 100 sizeof(struct fileIdentDesc) - sizeof(struct tag)); >> 101 >> 102 if (fibh->sbh == fibh->ebh) { >> 103 crc = crc_itu_t(crc, (uint8_t *)sfi->impUse, >> 104 crclen + sizeof(struct tag) - >> 105 sizeof(struct fileIdentDesc)); >> 106 } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { >> 107 crc = crc_itu_t(crc, fibh->ebh->b_data + >> 108 sizeof(struct fileIdentDesc) + >> 109 fibh->soffset, >> 110 crclen + sizeof(struct tag) - >> 111 sizeof(struct fileIdentDesc)); >> 112 } else { >> 113 crc = crc_itu_t(crc, (uint8_t *)sfi->impUse, >> 114 -fibh->soffset - sizeof(struct fileIdentDesc)); >> 115 crc = crc_itu_t(crc, fibh->ebh->b_data, fibh->eoffset); >> 116 } >> 117 >> 118 cfi->descTag.descCRC = cpu_to_le16(crc); >> 119 cfi->descTag.descCRCLength = cpu_to_le16(crclen); >> 120 cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag); >> 121 >> 122 if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { >> 123 memcpy((uint8_t *)sfi, (uint8_t *)cfi, >> 124 sizeof(struct fileIdentDesc)); >> 125 } else { >> 126 memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); >> 127 memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, >> 128 sizeof(struct fileIdentDesc) + fibh->soffset); >> 129 } >> 130 >> 131 if (adinicb) { >> 132 mark_inode_dirty(inode); >> 133 } else { >> 134 if (fibh->sbh != fibh->ebh) >> 135 mark_buffer_dirty_inode(fibh->ebh, inode); >> 136 mark_buffer_dirty_inode(fibh->sbh, inode); >> 137 } >> 138 return 0; >> 139 } >> 140 40 /** 141 /** 41 * udf_fiiter_find_entry - find entry in given !! 142 * udf_find_entry - find entry in given directory. 42 * 143 * 43 * @dir: directory inode to search in 144 * @dir: directory inode to search in 44 * @child: qstr of the name 145 * @child: qstr of the name 45 * @iter: iter to use for searching !! 146 * @fibh: buffer head / inode with file identifier descriptor we found >> 147 * @cfi: found file identifier descriptor with given name 46 * 148 * 47 * This function searches in the directory @di 149 * This function searches in the directory @dir for a file name @child. When 48 * found, @iter points to the position in the !! 150 * found, @fibh points to the buffer head(s) (bh is NULL for in ICB >> 151 * directories) containing the file identifier descriptor (FID). In that case >> 152 * the function returns pointer to the FID in the buffer or inode - but note >> 153 * that FID may be split among two buffers (blocks) so accessing it via that >> 154 * pointer isn't easily possible. This pointer can be used only as an iterator >> 155 * for other directory manipulation functions. For inspection of the FID @cfi >> 156 * can be used - the found FID is copied there. 49 * 157 * 50 * Returns 0 on success, < 0 on error (includi !! 158 * Returns pointer to FID, NULL when nothing found, or error code. 51 */ 159 */ 52 static int udf_fiiter_find_entry(struct inode !! 160 static struct fileIdentDesc *udf_find_entry(struct inode *dir, 53 struct udf_fi !! 161 const struct qstr *child, >> 162 struct udf_fileident_bh *fibh, >> 163 struct fileIdentDesc *cfi) 54 { 164 { >> 165 struct fileIdentDesc *fi = NULL; >> 166 loff_t f_pos; >> 167 udf_pblk_t block; 55 int flen; 168 int flen; 56 unsigned char *fname = NULL; !! 169 unsigned char *fname = NULL, *copy_name = NULL; 57 struct super_block *sb = dir->i_sb; !! 170 unsigned char *nameptr; >> 171 uint8_t lfi; >> 172 uint16_t liu; >> 173 loff_t size; >> 174 struct kernel_lb_addr eloc; >> 175 uint32_t elen; >> 176 sector_t offset; >> 177 struct extent_position epos = {}; >> 178 struct udf_inode_info *dinfo = UDF_I(dir); 58 int isdotdot = child->len == 2 && 179 int isdotdot = child->len == 2 && 59 child->name[0] == '.' && child 180 child->name[0] == '.' && child->name[1] == '.'; 60 int ret; !! 181 struct super_block *sb = dir->i_sb; >> 182 >> 183 size = udf_ext0_offset(dir) + dir->i_size; >> 184 f_pos = udf_ext0_offset(dir); >> 185 >> 186 fibh->sbh = fibh->ebh = NULL; >> 187 fibh->soffset = fibh->eoffset = f_pos & (sb->s_blocksize - 1); >> 188 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { >> 189 if (inode_bmap(dir, f_pos >> sb->s_blocksize_bits, &epos, >> 190 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) { >> 191 fi = ERR_PTR(-EIO); >> 192 goto out_err; >> 193 } >> 194 >> 195 block = udf_get_lb_pblock(sb, &eloc, offset); >> 196 if ((++offset << sb->s_blocksize_bits) < elen) { >> 197 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) >> 198 epos.offset -= sizeof(struct short_ad); >> 199 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) >> 200 epos.offset -= sizeof(struct long_ad); >> 201 } else >> 202 offset = 0; >> 203 >> 204 fibh->sbh = fibh->ebh = udf_tread(sb, block); >> 205 if (!fibh->sbh) { >> 206 fi = ERR_PTR(-EIO); >> 207 goto out_err; >> 208 } >> 209 } >> 210 >> 211 fname = kmalloc(UDF_NAME_LEN, GFP_NOFS); >> 212 if (!fname) { >> 213 fi = ERR_PTR(-ENOMEM); >> 214 goto out_err; >> 215 } 61 216 62 fname = kmalloc(UDF_NAME_LEN, GFP_KERN !! 217 while (f_pos < size) { 63 if (!fname) !! 218 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 64 return -ENOMEM; !! 219 &elen, &offset); 65 !! 220 if (!fi) { 66 for (ret = udf_fiiter_init(iter, dir, !! 221 fi = ERR_PTR(-EIO); 67 !ret && iter->pos < dir->i_size; !! 222 goto out_err; 68 ret = udf_fiiter_advance(iter)) { !! 223 } 69 if (iter->fi.fileCharacteristi !! 224 >> 225 liu = le16_to_cpu(cfi->lengthOfImpUse); >> 226 lfi = cfi->lengthFileIdent; >> 227 >> 228 if (fibh->sbh == fibh->ebh) { >> 229 nameptr = fi->fileIdent + liu; >> 230 } else { >> 231 int poffset; /* Unpaded ending offset */ >> 232 >> 233 poffset = fibh->soffset + sizeof(struct fileIdentDesc) + >> 234 liu + lfi; >> 235 >> 236 if (poffset >= lfi) >> 237 nameptr = (uint8_t *)(fibh->ebh->b_data + >> 238 poffset - lfi); >> 239 else { >> 240 if (!copy_name) { >> 241 copy_name = kmalloc(UDF_NAME_LEN, >> 242 GFP_NOFS); >> 243 if (!copy_name) { >> 244 fi = ERR_PTR(-ENOMEM); >> 245 goto out_err; >> 246 } >> 247 } >> 248 nameptr = copy_name; >> 249 memcpy(nameptr, fi->fileIdent + liu, >> 250 lfi - poffset); >> 251 memcpy(nameptr + lfi - poffset, >> 252 fibh->ebh->b_data, poffset); >> 253 } >> 254 } >> 255 >> 256 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { 70 if (!UDF_QUERY_FLAG(sb 257 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE)) 71 continue; 258 continue; 72 } 259 } 73 260 74 if (iter->fi.fileCharacteristi !! 261 if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) { 75 if (!UDF_QUERY_FLAG(sb 262 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE)) 76 continue; 263 continue; 77 } 264 } 78 265 79 if ((iter->fi.fileCharacterist !! 266 if ((cfi->fileCharacteristics & FID_FILE_CHAR_PARENT) && 80 isdotdot) 267 isdotdot) 81 goto out_ok; 268 goto out_ok; 82 269 83 if (!iter->fi.lengthFileIdent) !! 270 if (!lfi) 84 continue; 271 continue; 85 272 86 flen = udf_get_filename(sb, it !! 273 flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); 87 iter->fi.lengt << 88 if (flen < 0) { 274 if (flen < 0) { 89 ret = flen; !! 275 fi = ERR_PTR(flen); 90 goto out_err; 276 goto out_err; 91 } 277 } 92 278 93 if (udf_match(flen, fname, chi 279 if (udf_match(flen, fname, child->len, child->name)) 94 goto out_ok; 280 goto out_ok; 95 } 281 } 96 if (!ret) << 97 ret = -ENOENT; << 98 282 >> 283 fi = NULL; 99 out_err: 284 out_err: 100 udf_fiiter_release(iter); !! 285 if (fibh->sbh != fibh->ebh) >> 286 brelse(fibh->ebh); >> 287 brelse(fibh->sbh); 101 out_ok: 288 out_ok: >> 289 brelse(epos.bh); 102 kfree(fname); 290 kfree(fname); >> 291 kfree(copy_name); 103 292 104 return ret; !! 293 return fi; 105 } 294 } 106 295 107 static struct dentry *udf_lookup(struct inode 296 static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, 108 unsigned int 297 unsigned int flags) 109 { 298 { 110 struct inode *inode = NULL; 299 struct inode *inode = NULL; 111 struct udf_fileident_iter iter; !! 300 struct fileIdentDesc cfi; 112 int err; !! 301 struct udf_fileident_bh fibh; >> 302 struct fileIdentDesc *fi; 113 303 114 if (dentry->d_name.len > UDF_NAME_LEN) 304 if (dentry->d_name.len > UDF_NAME_LEN) 115 return ERR_PTR(-ENAMETOOLONG); 305 return ERR_PTR(-ENAMETOOLONG); 116 306 117 err = udf_fiiter_find_entry(dir, &dent !! 307 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); 118 if (err < 0 && err != -ENOENT) !! 308 if (IS_ERR(fi)) 119 return ERR_PTR(err); !! 309 return ERR_CAST(fi); 120 310 121 if (err == 0) { !! 311 if (fi) { 122 struct kernel_lb_addr loc; 312 struct kernel_lb_addr loc; 123 313 124 loc = lelb_to_cpu(iter.fi.icb. !! 314 if (fibh.sbh != fibh.ebh) 125 udf_fiiter_release(&iter); !! 315 brelse(fibh.ebh); >> 316 brelse(fibh.sbh); 126 317 >> 318 loc = lelb_to_cpu(cfi.icb.extLocation); 127 inode = udf_iget(dir->i_sb, &l 319 inode = udf_iget(dir->i_sb, &loc); >> 320 if (IS_ERR(inode)) >> 321 return ERR_CAST(inode); 128 } 322 } 129 323 130 return d_splice_alias(inode, dentry); 324 return d_splice_alias(inode, dentry); 131 } 325 } 132 326 133 static int udf_expand_dir_adinicb(struct inode !! 327 static struct fileIdentDesc *udf_add_entry(struct inode *dir, >> 328 struct dentry *dentry, >> 329 struct udf_fileident_bh *fibh, >> 330 struct fileIdentDesc *cfi, int *err) 134 { 331 { 135 udf_pblk_t newblock; !! 332 struct super_block *sb = dir->i_sb; 136 struct buffer_head *dbh = NULL; !! 333 struct fileIdentDesc *fi = NULL; >> 334 unsigned char *name = NULL; >> 335 int namelen; >> 336 loff_t f_pos; >> 337 loff_t size = udf_ext0_offset(dir) + dir->i_size; >> 338 int nfidlen; >> 339 udf_pblk_t block; 137 struct kernel_lb_addr eloc; 340 struct kernel_lb_addr eloc; 138 struct extent_position epos; !! 341 uint32_t elen = 0; 139 uint8_t alloctype; !! 342 sector_t offset; 140 struct udf_inode_info *iinfo = UDF_I(i !! 343 struct extent_position epos = {}; 141 struct udf_fileident_iter iter; !! 344 struct udf_inode_info *dinfo; 142 uint8_t *impuse; << 143 int ret; << 144 << 145 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FL << 146 alloctype = ICBTAG_FLAG_AD_SHO << 147 else << 148 alloctype = ICBTAG_FLAG_AD_LON << 149 345 150 if (!inode->i_size) { !! 346 fibh->sbh = fibh->ebh = NULL; 151 iinfo->i_alloc_type = alloctyp !! 347 name = kmalloc(UDF_NAME_LEN_CS0, GFP_NOFS); 152 mark_inode_dirty(inode); !! 348 if (!name) { 153 return 0; !! 349 *err = -ENOMEM; >> 350 goto out_err; 154 } 351 } 155 352 156 /* alloc block, and copy data to it */ !! 353 if (dentry) { 157 *block = udf_new_block(inode->i_sb, in !! 354 if (!dentry->d_name.len) { 158 iinfo->i_locati !! 355 *err = -EINVAL; 159 iinfo->i_locati !! 356 goto out_err; 160 if (!(*block)) !! 357 } 161 return ret; !! 358 namelen = udf_put_filename(sb, dentry->d_name.name, 162 newblock = udf_get_pblock(inode->i_sb, !! 359 dentry->d_name.len, 163 iinfo->i_loc !! 360 name, UDF_NAME_LEN_CS0); 164 0); !! 361 if (!namelen) { 165 if (newblock == 0xffffffff) !! 362 *err = -ENAMETOOLONG; 166 return -EFSCORRUPTED; !! 363 goto out_err; 167 dbh = sb_getblk(inode->i_sb, newblock) !! 364 } 168 if (!dbh) !! 365 } else { 169 return -ENOMEM; !! 366 namelen = 0; 170 lock_buffer(dbh); << 171 memcpy(dbh->b_data, iinfo->i_data, ino << 172 memset(dbh->b_data + inode->i_size, 0, << 173 inode->i_sb->s_blocksize - inod << 174 set_buffer_uptodate(dbh); << 175 unlock_buffer(dbh); << 176 << 177 /* Drop inline data, add block instead << 178 iinfo->i_alloc_type = alloctype; << 179 memset(iinfo->i_data + iinfo->i_lenEAt << 180 iinfo->i_lenAlloc = 0; << 181 eloc.logicalBlockNum = *block; << 182 eloc.partitionReferenceNum = << 183 iinfo->i_locat << 184 iinfo->i_lenExtents = inode->i_size; << 185 epos.bh = NULL; << 186 epos.block = iinfo->i_location; << 187 epos.offset = udf_file_entry_alloc_off << 188 ret = udf_add_aext(inode, &epos, &eloc << 189 brelse(epos.bh); << 190 if (ret < 0) { << 191 brelse(dbh); << 192 udf_free_blocks(inode->i_sb, i << 193 return ret; << 194 } 367 } 195 mark_inode_dirty(inode); << 196 368 197 /* Now fixup tags in moved directory e !! 369 nfidlen = ALIGN(sizeof(struct fileIdentDesc) + namelen, UDF_NAME_PAD); 198 for (ret = udf_fiiter_init(&iter, inod << 199 !ret && iter.pos < inode->i_size; << 200 ret = udf_fiiter_advance(&iter)) << 201 iter.fi.descTag.tagLocation = << 202 if (iter.fi.lengthOfImpUse != << 203 impuse = dbh->b_data + << 204 << 205 else << 206 impuse = NULL; << 207 udf_fiiter_write_fi(&iter, imp << 208 } << 209 brelse(dbh); << 210 /* << 211 * We don't expect the iteration to fa << 212 * already verified to be correct << 213 */ << 214 WARN_ON_ONCE(ret); << 215 udf_fiiter_release(&iter); << 216 370 217 return 0; !! 371 f_pos = udf_ext0_offset(dir); 218 } << 219 372 220 static int udf_fiiter_add_entry(struct inode * !! 373 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1); 221 struct udf_fil !! 374 dinfo = UDF_I(dir); 222 { !! 375 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { 223 struct udf_inode_info *dinfo = UDF_I(d !! 376 if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos, 224 int nfidlen, namelen = 0; !! 377 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) { 225 int ret; !! 378 block = udf_get_lb_pblock(dir->i_sb, 226 int off, blksize = 1 << dir->i_blkbits !! 379 &dinfo->i_location, 0); 227 udf_pblk_t block; !! 380 fibh->soffset = fibh->eoffset = sb->s_blocksize; 228 char name[UDF_NAME_LEN_CS0]; !! 381 goto add; >> 382 } >> 383 block = udf_get_lb_pblock(dir->i_sb, &eloc, offset); >> 384 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { >> 385 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) >> 386 epos.offset -= sizeof(struct short_ad); >> 387 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) >> 388 epos.offset -= sizeof(struct long_ad); >> 389 } else >> 390 offset = 0; >> 391 >> 392 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); >> 393 if (!fibh->sbh) { >> 394 *err = -EIO; >> 395 goto out_err; >> 396 } 229 397 230 if (dentry) { !! 398 block = dinfo->i_location.logicalBlockNum; 231 namelen = udf_put_filename(dir << 232 den << 233 nam << 234 if (!namelen) << 235 return -ENAMETOOLONG; << 236 } 399 } 237 nfidlen = ALIGN(sizeof(struct fileIden << 238 400 239 for (ret = udf_fiiter_init(iter, dir, !! 401 while (f_pos < size) { 240 !ret && iter->pos < dir->i_size; !! 402 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 241 ret = udf_fiiter_advance(iter)) { !! 403 &elen, &offset); 242 if (iter->fi.fileCharacteristi !! 404 243 if (udf_dir_entry_len( !! 405 if (!fi) { 244 iter->fi.descT !! 406 *err = -EIO; 245 iter->fi.fileV !! 407 goto out_err; 246 iter->fi.fileC !! 408 } 247 iter->fi.lengt !! 409 248 iter->fi.lengt !! 410 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { 249 memcpy(iter->n !! 411 if (udf_dir_entry_len(cfi) == nfidlen) { 250 iter->name = i !! 412 cfi->descTag.tagSerialNum = cpu_to_le16(1); 251 return 0; !! 413 cfi->fileVersionNum = cpu_to_le16(1); >> 414 cfi->fileCharacteristics = 0; >> 415 cfi->lengthFileIdent = namelen; >> 416 cfi->lengthOfImpUse = cpu_to_le16(0); >> 417 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, >> 418 name)) >> 419 goto out_ok; >> 420 else { >> 421 *err = -EIO; >> 422 goto out_err; >> 423 } 252 } 424 } 253 } 425 } 254 } 426 } 255 if (ret) { !! 427 256 udf_fiiter_release(iter); !! 428 add: 257 return ret; !! 429 f_pos += nfidlen; 258 } !! 430 259 if (dinfo->i_alloc_type == ICBTAG_FLAG 431 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && 260 blksize - udf_ext0_offset(dir) - i !! 432 sb->s_blocksize - fibh->eoffset < nfidlen) { 261 udf_fiiter_release(iter); !! 433 brelse(epos.bh); 262 ret = udf_expand_dir_adinicb(d !! 434 epos.bh = NULL; 263 if (ret) !! 435 fibh->soffset -= udf_ext0_offset(dir); 264 return ret; !! 436 fibh->eoffset -= udf_ext0_offset(dir); 265 ret = udf_fiiter_init(iter, di !! 437 f_pos -= udf_ext0_offset(dir); 266 if (ret < 0) !! 438 if (fibh->sbh != fibh->ebh) 267 return ret; !! 439 brelse(fibh->ebh); >> 440 brelse(fibh->sbh); >> 441 fibh->sbh = fibh->ebh = >> 442 udf_expand_dir_adinicb(dir, &block, err); >> 443 if (!fibh->sbh) >> 444 goto out_err; >> 445 epos.block = dinfo->i_location; >> 446 epos.offset = udf_file_entry_alloc_offset(dir); >> 447 /* Load extent udf_expand_dir_adinicb() has created */ >> 448 udf_current_aext(dir, &epos, &eloc, &elen, 1); 268 } 449 } 269 450 270 /* Get blocknumber to use for entry ta !! 451 /* Entry fits into current block? */ 271 if (dinfo->i_alloc_type == ICBTAG_FLAG !! 452 if (sb->s_blocksize - fibh->eoffset >= nfidlen) { 272 block = dinfo->i_location.logi !! 453 fibh->soffset = fibh->eoffset; >> 454 fibh->eoffset += nfidlen; >> 455 if (fibh->sbh != fibh->ebh) { >> 456 brelse(fibh->sbh); >> 457 fibh->sbh = fibh->ebh; >> 458 } >> 459 >> 460 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { >> 461 block = dinfo->i_location.logicalBlockNum; >> 462 fi = (struct fileIdentDesc *) >> 463 (dinfo->i_ext.i_data + >> 464 fibh->soffset - >> 465 udf_ext0_offset(dir) + >> 466 dinfo->i_lenEAttr); >> 467 } else { >> 468 block = eloc.logicalBlockNum + >> 469 ((elen - 1) >> >> 470 dir->i_sb->s_blocksize_bits); >> 471 fi = (struct fileIdentDesc *) >> 472 (fibh->sbh->b_data + fibh->soffset); >> 473 } 273 } else { 474 } else { 274 block = iter->eloc.logicalBloc !! 475 /* Round up last extent in the file */ 275 ((iter->elen - !! 476 elen = (elen + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1); >> 477 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) >> 478 epos.offset -= sizeof(struct short_ad); >> 479 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) >> 480 epos.offset -= sizeof(struct long_ad); >> 481 udf_write_aext(dir, &epos, &eloc, elen, 1); >> 482 dinfo->i_lenExtents = (dinfo->i_lenExtents + sb->s_blocksize >> 483 - 1) & ~(sb->s_blocksize - 1); >> 484 >> 485 fibh->soffset = fibh->eoffset - sb->s_blocksize; >> 486 fibh->eoffset += nfidlen - sb->s_blocksize; >> 487 if (fibh->sbh != fibh->ebh) { >> 488 brelse(fibh->sbh); >> 489 fibh->sbh = fibh->ebh; >> 490 } >> 491 >> 492 block = eloc.logicalBlockNum + ((elen - 1) >> >> 493 dir->i_sb->s_blocksize_bits); >> 494 fibh->ebh = udf_bread(dir, >> 495 f_pos >> dir->i_sb->s_blocksize_bits, 1, err); >> 496 if (!fibh->ebh) >> 497 goto out_err; >> 498 /* Extents could have been merged, invalidate our position */ >> 499 brelse(epos.bh); >> 500 epos.bh = NULL; >> 501 epos.block = dinfo->i_location; >> 502 epos.offset = udf_file_entry_alloc_offset(dir); >> 503 >> 504 if (!fibh->soffset) { >> 505 /* Find the freshly allocated block */ >> 506 while (udf_next_aext(dir, &epos, &eloc, &elen, 1) == >> 507 (EXT_RECORDED_ALLOCATED >> 30)) >> 508 ; >> 509 block = eloc.logicalBlockNum + ((elen - 1) >> >> 510 dir->i_sb->s_blocksize_bits); >> 511 brelse(fibh->sbh); >> 512 fibh->sbh = fibh->ebh; >> 513 fi = (struct fileIdentDesc *)(fibh->sbh->b_data); >> 514 } else { >> 515 fi = (struct fileIdentDesc *) >> 516 (fibh->sbh->b_data + sb->s_blocksize + >> 517 fibh->soffset); >> 518 } 276 } 519 } 277 off = iter->pos & (blksize - 1); << 278 if (!off) << 279 off = blksize; << 280 /* Entry fits into current block? */ << 281 if (blksize - udf_ext0_offset(dir) - o << 282 goto store_fi; << 283 520 284 ret = udf_fiiter_append_blk(iter); !! 521 memset(cfi, 0, sizeof(struct fileIdentDesc)); 285 if (ret) { !! 522 if (UDF_SB(sb)->s_udfrev >= 0x0200) 286 udf_fiiter_release(iter); !! 523 udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, 287 return ret; << 288 } << 289 << 290 /* Entry will be completely in the new << 291 if (!(iter->pos & (blksize - 1))) << 292 block = iter->eloc.logicalBloc << 293 ((iter->elen - << 294 store_fi: << 295 memset(&iter->fi, 0, sizeof(struct fil << 296 if (UDF_SB(dir->i_sb)->s_udfrev >= 0x0 << 297 udf_new_tag((char *)(&iter->fi << 298 sizeof(struct tag) 524 sizeof(struct tag)); 299 else 525 else 300 udf_new_tag((char *)(&iter->fi !! 526 udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, 301 sizeof(struct tag) 527 sizeof(struct tag)); 302 iter->fi.fileVersionNum = cpu_to_le16( !! 528 cfi->fileVersionNum = cpu_to_le16(1); 303 iter->fi.lengthFileIdent = namelen; !! 529 cfi->lengthFileIdent = namelen; 304 iter->fi.lengthOfImpUse = cpu_to_le16( !! 530 cfi->lengthOfImpUse = cpu_to_le16(0); 305 memcpy(iter->namebuf, name, namelen); !! 531 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { 306 iter->name = iter->namebuf; !! 532 dir->i_size += nfidlen; 307 !! 533 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 308 dir->i_size += nfidlen; !! 534 dinfo->i_lenAlloc += nfidlen; 309 if (dinfo->i_alloc_type == ICBTAG_FLAG !! 535 else { 310 dinfo->i_lenAlloc += nfidlen; !! 536 /* Find the last extent and truncate it to proper size */ >> 537 while (udf_next_aext(dir, &epos, &eloc, &elen, 1) == >> 538 (EXT_RECORDED_ALLOCATED >> 30)) >> 539 ; >> 540 elen -= dinfo->i_lenExtents - dir->i_size; >> 541 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) >> 542 epos.offset -= sizeof(struct short_ad); >> 543 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) >> 544 epos.offset -= sizeof(struct long_ad); >> 545 udf_write_aext(dir, &epos, &eloc, elen, 1); >> 546 dinfo->i_lenExtents = dir->i_size; >> 547 } >> 548 >> 549 mark_inode_dirty(dir); >> 550 goto out_ok; 311 } else { 551 } else { 312 /* Truncate last extent to pro !! 552 *err = -EIO; 313 udf_fiiter_update_elen(iter, i !! 553 goto out_err; 314 (dinfo << 315 } 554 } 316 mark_inode_dirty(dir); << 317 555 318 return 0; !! 556 out_err: >> 557 fi = NULL; >> 558 if (fibh->sbh != fibh->ebh) >> 559 brelse(fibh->ebh); >> 560 brelse(fibh->sbh); >> 561 out_ok: >> 562 brelse(epos.bh); >> 563 kfree(name); >> 564 return fi; 319 } 565 } 320 566 321 static void udf_fiiter_delete_entry(struct udf !! 567 static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, >> 568 struct udf_fileident_bh *fibh, >> 569 struct fileIdentDesc *cfi) 322 { 570 { 323 iter->fi.fileCharacteristics |= FID_FI !! 571 cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED; 324 572 325 if (UDF_QUERY_FLAG(iter->dir->i_sb, UD !! 573 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) 326 memset(&iter->fi.icb, 0x00, si !! 574 memset(&(cfi->icb), 0x00, sizeof(struct long_ad)); 327 575 328 udf_fiiter_write_fi(iter, NULL); !! 576 return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); 329 } << 330 << 331 static void udf_add_fid_counter(struct super_b << 332 { << 333 struct logicalVolIntegrityDescImpUse * << 334 << 335 if (!lvidiu) << 336 return; << 337 mutex_lock(&UDF_SB(sb)->s_alloc_mutex) << 338 if (dir) << 339 le32_add_cpu(&lvidiu->numDirs, << 340 else << 341 le32_add_cpu(&lvidiu->numFiles << 342 udf_updated_lvid(sb); << 343 mutex_unlock(&UDF_SB(sb)->s_alloc_mute << 344 } 577 } 345 578 346 static int udf_add_nondir(struct dentry *dentr 579 static int udf_add_nondir(struct dentry *dentry, struct inode *inode) 347 { 580 { 348 struct udf_inode_info *iinfo = UDF_I(i 581 struct udf_inode_info *iinfo = UDF_I(inode); 349 struct inode *dir = d_inode(dentry->d_ 582 struct inode *dir = d_inode(dentry->d_parent); 350 struct udf_fileident_iter iter; !! 583 struct udf_fileident_bh fibh; >> 584 struct fileIdentDesc cfi, *fi; 351 int err; 585 int err; 352 586 353 err = udf_fiiter_add_entry(dir, dentry !! 587 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); 354 if (err) { !! 588 if (unlikely(!fi)) { 355 inode_dec_link_count(inode); 589 inode_dec_link_count(inode); 356 discard_new_inode(inode); 590 discard_new_inode(inode); 357 return err; 591 return err; 358 } 592 } 359 iter.fi.icb.extLength = cpu_to_le32(in !! 593 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 360 iter.fi.icb.extLocation = cpu_to_lelb( !! 594 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); 361 *(__le32 *)((struct allocDescImpUse *) !! 595 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 362 cpu_to_le32(iinfo->i_unique & 596 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); 363 udf_fiiter_write_fi(&iter, NULL); !! 597 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 364 inode_set_mtime_to_ts(dir, inode_set_c !! 598 dir->i_ctime = dir->i_mtime = current_time(dir); 365 mark_inode_dirty(dir); 599 mark_inode_dirty(dir); 366 udf_fiiter_release(&iter); !! 600 if (fibh.sbh != fibh.ebh) 367 udf_add_fid_counter(dir->i_sb, false, !! 601 brelse(fibh.ebh); >> 602 brelse(fibh.sbh); 368 d_instantiate_new(dentry, inode); 603 d_instantiate_new(dentry, inode); 369 604 370 return 0; 605 return 0; 371 } 606 } 372 607 373 static int udf_create(struct mnt_idmap *idmap, !! 608 static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode, 374 struct dentry *dentry, u !! 609 bool excl) 375 { 610 { 376 struct inode *inode = udf_new_inode(di 611 struct inode *inode = udf_new_inode(dir, mode); 377 612 378 if (IS_ERR(inode)) 613 if (IS_ERR(inode)) 379 return PTR_ERR(inode); 614 return PTR_ERR(inode); 380 615 381 inode->i_data.a_ops = &udf_aops; !! 616 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) >> 617 inode->i_data.a_ops = &udf_adinicb_aops; >> 618 else >> 619 inode->i_data.a_ops = &udf_aops; 382 inode->i_op = &udf_file_inode_operatio 620 inode->i_op = &udf_file_inode_operations; 383 inode->i_fop = &udf_file_operations; 621 inode->i_fop = &udf_file_operations; 384 mark_inode_dirty(inode); 622 mark_inode_dirty(inode); 385 623 386 return udf_add_nondir(dentry, inode); 624 return udf_add_nondir(dentry, inode); 387 } 625 } 388 626 389 static int udf_tmpfile(struct mnt_idmap *idmap !! 627 static int udf_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) 390 struct file *file, umod << 391 { 628 { 392 struct inode *inode = udf_new_inode(di 629 struct inode *inode = udf_new_inode(dir, mode); 393 630 394 if (IS_ERR(inode)) 631 if (IS_ERR(inode)) 395 return PTR_ERR(inode); 632 return PTR_ERR(inode); 396 633 397 inode->i_data.a_ops = &udf_aops; !! 634 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) >> 635 inode->i_data.a_ops = &udf_adinicb_aops; >> 636 else >> 637 inode->i_data.a_ops = &udf_aops; 398 inode->i_op = &udf_file_inode_operatio 638 inode->i_op = &udf_file_inode_operations; 399 inode->i_fop = &udf_file_operations; 639 inode->i_fop = &udf_file_operations; 400 mark_inode_dirty(inode); 640 mark_inode_dirty(inode); 401 d_tmpfile(file, inode); !! 641 d_tmpfile(dentry, inode); 402 unlock_new_inode(inode); 642 unlock_new_inode(inode); 403 return finish_open_simple(file, 0); !! 643 return 0; 404 } 644 } 405 645 406 static int udf_mknod(struct mnt_idmap *idmap, !! 646 static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, 407 struct dentry *dentry, um !! 647 dev_t rdev) 408 { 648 { 409 struct inode *inode; 649 struct inode *inode; 410 650 411 if (!old_valid_dev(rdev)) 651 if (!old_valid_dev(rdev)) 412 return -EINVAL; 652 return -EINVAL; 413 653 414 inode = udf_new_inode(dir, mode); 654 inode = udf_new_inode(dir, mode); 415 if (IS_ERR(inode)) 655 if (IS_ERR(inode)) 416 return PTR_ERR(inode); 656 return PTR_ERR(inode); 417 657 418 init_special_inode(inode, mode, rdev); 658 init_special_inode(inode, mode, rdev); 419 return udf_add_nondir(dentry, inode); 659 return udf_add_nondir(dentry, inode); 420 } 660 } 421 661 422 static int udf_mkdir(struct mnt_idmap *idmap, !! 662 static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 423 struct dentry *dentry, um << 424 { 663 { 425 struct inode *inode; 664 struct inode *inode; 426 struct udf_fileident_iter iter; !! 665 struct udf_fileident_bh fibh; >> 666 struct fileIdentDesc cfi, *fi; 427 int err; 667 int err; 428 struct udf_inode_info *dinfo = UDF_I(d 668 struct udf_inode_info *dinfo = UDF_I(dir); 429 struct udf_inode_info *iinfo; 669 struct udf_inode_info *iinfo; 430 670 431 inode = udf_new_inode(dir, S_IFDIR | m 671 inode = udf_new_inode(dir, S_IFDIR | mode); 432 if (IS_ERR(inode)) 672 if (IS_ERR(inode)) 433 return PTR_ERR(inode); 673 return PTR_ERR(inode); 434 674 435 iinfo = UDF_I(inode); 675 iinfo = UDF_I(inode); 436 inode->i_op = &udf_dir_inode_operation 676 inode->i_op = &udf_dir_inode_operations; 437 inode->i_fop = &udf_dir_operations; 677 inode->i_fop = &udf_dir_operations; 438 err = udf_fiiter_add_entry(inode, NULL !! 678 fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err); 439 if (err) { !! 679 if (!fi) { 440 clear_nlink(inode); !! 680 inode_dec_link_count(inode); 441 discard_new_inode(inode); 681 discard_new_inode(inode); 442 return err; !! 682 goto out; 443 } 683 } 444 set_nlink(inode, 2); 684 set_nlink(inode, 2); 445 iter.fi.icb.extLength = cpu_to_le32(in !! 685 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 446 iter.fi.icb.extLocation = cpu_to_lelb( !! 686 cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location); 447 *(__le32 *)((struct allocDescImpUse *) !! 687 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 448 cpu_to_le32(dinfo->i_unique & 688 cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL); 449 iter.fi.fileCharacteristics = !! 689 cfi.fileCharacteristics = 450 FID_FILE_CHAR_DIRECTOR 690 FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; 451 udf_fiiter_write_fi(&iter, NULL); !! 691 udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); 452 udf_fiiter_release(&iter); !! 692 brelse(fibh.sbh); 453 mark_inode_dirty(inode); 693 mark_inode_dirty(inode); 454 694 455 err = udf_fiiter_add_entry(dir, dentry !! 695 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); 456 if (err) { !! 696 if (!fi) { 457 clear_nlink(inode); 697 clear_nlink(inode); >> 698 mark_inode_dirty(inode); 458 discard_new_inode(inode); 699 discard_new_inode(inode); 459 return err; !! 700 goto out; 460 } 701 } 461 iter.fi.icb.extLength = cpu_to_le32(in !! 702 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 462 iter.fi.icb.extLocation = cpu_to_lelb( !! 703 cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); 463 *(__le32 *)((struct allocDescImpUse *) !! 704 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 464 cpu_to_le32(iinfo->i_unique & 705 cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); 465 iter.fi.fileCharacteristics |= FID_FIL !! 706 cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; 466 udf_fiiter_write_fi(&iter, NULL); !! 707 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 467 udf_fiiter_release(&iter); << 468 udf_add_fid_counter(dir->i_sb, true, 1 << 469 inc_nlink(dir); 708 inc_nlink(dir); 470 inode_set_mtime_to_ts(dir, inode_set_c !! 709 dir->i_ctime = dir->i_mtime = current_time(dir); 471 mark_inode_dirty(dir); 710 mark_inode_dirty(dir); 472 d_instantiate_new(dentry, inode); 711 d_instantiate_new(dentry, inode); >> 712 if (fibh.sbh != fibh.ebh) >> 713 brelse(fibh.ebh); >> 714 brelse(fibh.sbh); >> 715 err = 0; 473 716 474 return 0; !! 717 out: >> 718 return err; 475 } 719 } 476 720 477 static int empty_dir(struct inode *dir) 721 static int empty_dir(struct inode *dir) 478 { 722 { 479 struct udf_fileident_iter iter; !! 723 struct fileIdentDesc *fi, cfi; 480 int ret; !! 724 struct udf_fileident_bh fibh; >> 725 loff_t f_pos; >> 726 loff_t size = udf_ext0_offset(dir) + dir->i_size; >> 727 udf_pblk_t block; >> 728 struct kernel_lb_addr eloc; >> 729 uint32_t elen; >> 730 sector_t offset; >> 731 struct extent_position epos = {}; >> 732 struct udf_inode_info *dinfo = UDF_I(dir); >> 733 >> 734 f_pos = udf_ext0_offset(dir); >> 735 fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1); 481 736 482 for (ret = udf_fiiter_init(&iter, dir, !! 737 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 483 !ret && iter.pos < dir->i_size; !! 738 fibh.sbh = fibh.ebh = NULL; 484 ret = udf_fiiter_advance(&iter)) !! 739 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, 485 if (iter.fi.lengthFileIdent && !! 740 &epos, &eloc, &elen, &offset) == 486 !(iter.fi.fileCharacterist !! 741 (EXT_RECORDED_ALLOCATED >> 30)) { 487 udf_fiiter_release(&it !! 742 block = udf_get_lb_pblock(dir->i_sb, &eloc, offset); >> 743 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { >> 744 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) >> 745 epos.offset -= sizeof(struct short_ad); >> 746 else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) >> 747 epos.offset -= sizeof(struct long_ad); >> 748 } else >> 749 offset = 0; >> 750 >> 751 fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block); >> 752 if (!fibh.sbh) { >> 753 brelse(epos.bh); 488 return 0; 754 return 0; 489 } 755 } >> 756 } else { >> 757 brelse(epos.bh); >> 758 return 0; 490 } 759 } 491 udf_fiiter_release(&iter); !! 760 >> 761 while (f_pos < size) { >> 762 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, >> 763 &elen, &offset); >> 764 if (!fi) { >> 765 if (fibh.sbh != fibh.ebh) >> 766 brelse(fibh.ebh); >> 767 brelse(fibh.sbh); >> 768 brelse(epos.bh); >> 769 return 0; >> 770 } >> 771 >> 772 if (cfi.lengthFileIdent && >> 773 (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) { >> 774 if (fibh.sbh != fibh.ebh) >> 775 brelse(fibh.ebh); >> 776 brelse(fibh.sbh); >> 777 brelse(epos.bh); >> 778 return 0; >> 779 } >> 780 } >> 781 >> 782 if (fibh.sbh != fibh.ebh) >> 783 brelse(fibh.ebh); >> 784 brelse(fibh.sbh); >> 785 brelse(epos.bh); 492 786 493 return 1; 787 return 1; 494 } 788 } 495 789 496 static int udf_rmdir(struct inode *dir, struct 790 static int udf_rmdir(struct inode *dir, struct dentry *dentry) 497 { 791 { 498 int ret; !! 792 int retval; 499 struct inode *inode = d_inode(dentry); 793 struct inode *inode = d_inode(dentry); 500 struct udf_fileident_iter iter; !! 794 struct udf_fileident_bh fibh; >> 795 struct fileIdentDesc *fi, cfi; 501 struct kernel_lb_addr tloc; 796 struct kernel_lb_addr tloc; 502 797 503 ret = udf_fiiter_find_entry(dir, &dent !! 798 retval = -ENOENT; 504 if (ret) !! 799 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); >> 800 if (IS_ERR_OR_NULL(fi)) { >> 801 if (fi) >> 802 retval = PTR_ERR(fi); 505 goto out; 803 goto out; >> 804 } 506 805 507 ret = -EFSCORRUPTED; !! 806 retval = -EIO; 508 tloc = lelb_to_cpu(iter.fi.icb.extLoca !! 807 tloc = lelb_to_cpu(cfi.icb.extLocation); 509 if (udf_get_lb_pblock(dir->i_sb, &tloc 808 if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino) 510 goto end_rmdir; 809 goto end_rmdir; 511 ret = -ENOTEMPTY; !! 810 retval = -ENOTEMPTY; 512 if (!empty_dir(inode)) 811 if (!empty_dir(inode)) 513 goto end_rmdir; 812 goto end_rmdir; 514 udf_fiiter_delete_entry(&iter); !! 813 retval = udf_delete_entry(dir, fi, &fibh, &cfi); >> 814 if (retval) >> 815 goto end_rmdir; 515 if (inode->i_nlink != 2) 816 if (inode->i_nlink != 2) 516 udf_warn(inode->i_sb, "empty d 817 udf_warn(inode->i_sb, "empty directory has nlink != 2 (%u)\n", 517 inode->i_nlink); 818 inode->i_nlink); 518 clear_nlink(inode); 819 clear_nlink(inode); 519 inode->i_size = 0; 820 inode->i_size = 0; 520 inode_dec_link_count(dir); 821 inode_dec_link_count(dir); 521 udf_add_fid_counter(dir->i_sb, true, - !! 822 inode->i_ctime = dir->i_ctime = dir->i_mtime = 522 inode_set_mtime_to_ts(dir, !! 823 current_time(inode); 523 inode_set_ctime_ << 524 mark_inode_dirty(dir); 824 mark_inode_dirty(dir); 525 ret = 0; !! 825 526 end_rmdir: 826 end_rmdir: 527 udf_fiiter_release(&iter); !! 827 if (fibh.sbh != fibh.ebh) >> 828 brelse(fibh.ebh); >> 829 brelse(fibh.sbh); >> 830 528 out: 831 out: 529 return ret; !! 832 return retval; 530 } 833 } 531 834 532 static int udf_unlink(struct inode *dir, struc 835 static int udf_unlink(struct inode *dir, struct dentry *dentry) 533 { 836 { 534 int ret; !! 837 int retval; 535 struct inode *inode = d_inode(dentry); 838 struct inode *inode = d_inode(dentry); 536 struct udf_fileident_iter iter; !! 839 struct udf_fileident_bh fibh; >> 840 struct fileIdentDesc *fi; >> 841 struct fileIdentDesc cfi; 537 struct kernel_lb_addr tloc; 842 struct kernel_lb_addr tloc; 538 843 539 ret = udf_fiiter_find_entry(dir, &dent !! 844 retval = -ENOENT; 540 if (ret) !! 845 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); >> 846 >> 847 if (IS_ERR_OR_NULL(fi)) { >> 848 if (fi) >> 849 retval = PTR_ERR(fi); 541 goto out; 850 goto out; >> 851 } 542 852 543 ret = -EFSCORRUPTED; !! 853 retval = -EIO; 544 tloc = lelb_to_cpu(iter.fi.icb.extLoca !! 854 tloc = lelb_to_cpu(cfi.icb.extLocation); 545 if (udf_get_lb_pblock(dir->i_sb, &tloc 855 if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino) 546 goto end_unlink; 856 goto end_unlink; 547 857 548 if (!inode->i_nlink) { 858 if (!inode->i_nlink) { 549 udf_debug("Deleting nonexisten 859 udf_debug("Deleting nonexistent file (%lu), %u\n", 550 inode->i_ino, inode- 860 inode->i_ino, inode->i_nlink); 551 set_nlink(inode, 1); 861 set_nlink(inode, 1); 552 } 862 } 553 udf_fiiter_delete_entry(&iter); !! 863 retval = udf_delete_entry(dir, fi, &fibh, &cfi); 554 inode_set_mtime_to_ts(dir, inode_set_c !! 864 if (retval) >> 865 goto end_unlink; >> 866 dir->i_ctime = dir->i_mtime = current_time(dir); 555 mark_inode_dirty(dir); 867 mark_inode_dirty(dir); 556 inode_dec_link_count(inode); 868 inode_dec_link_count(inode); 557 udf_add_fid_counter(dir->i_sb, false, !! 869 inode->i_ctime = dir->i_ctime; 558 inode_set_ctime_to_ts(inode, inode_get !! 870 retval = 0; 559 ret = 0; !! 871 560 end_unlink: 872 end_unlink: 561 udf_fiiter_release(&iter); !! 873 if (fibh.sbh != fibh.ebh) >> 874 brelse(fibh.ebh); >> 875 brelse(fibh.sbh); >> 876 562 out: 877 out: 563 return ret; !! 878 return retval; 564 } 879 } 565 880 566 static int udf_symlink(struct mnt_idmap *idmap !! 881 static int udf_symlink(struct inode *dir, struct dentry *dentry, 567 struct dentry *dentry, !! 882 const char *symname) 568 { 883 { 569 struct inode *inode; !! 884 struct inode *inode = udf_new_inode(dir, S_IFLNK | 0777); 570 struct pathComponent *pc; 885 struct pathComponent *pc; 571 const char *compstart; 886 const char *compstart; 572 struct extent_position epos = {}; 887 struct extent_position epos = {}; 573 int eoffset, elen = 0; 888 int eoffset, elen = 0; 574 uint8_t *ea; 889 uint8_t *ea; 575 int err; 890 int err; 576 udf_pblk_t block; 891 udf_pblk_t block; 577 unsigned char *name = NULL; 892 unsigned char *name = NULL; 578 int namelen; 893 int namelen; 579 struct udf_inode_info *iinfo; 894 struct udf_inode_info *iinfo; 580 struct super_block *sb = dir->i_sb; 895 struct super_block *sb = dir->i_sb; 581 896 582 name = kmalloc(UDF_NAME_LEN_CS0, GFP_K !! 897 if (IS_ERR(inode)) >> 898 return PTR_ERR(inode); >> 899 >> 900 iinfo = UDF_I(inode); >> 901 down_write(&iinfo->i_data_sem); >> 902 name = kmalloc(UDF_NAME_LEN_CS0, GFP_NOFS); 583 if (!name) { 903 if (!name) { 584 err = -ENOMEM; 904 err = -ENOMEM; 585 goto out; !! 905 goto out_no_entry; 586 } << 587 << 588 inode = udf_new_inode(dir, S_IFLNK | 0 << 589 if (IS_ERR(inode)) { << 590 err = PTR_ERR(inode); << 591 goto out; << 592 } 906 } 593 907 594 iinfo = UDF_I(inode); << 595 down_write(&iinfo->i_data_sem); << 596 inode->i_data.a_ops = &udf_symlink_aop 908 inode->i_data.a_ops = &udf_symlink_aops; 597 inode->i_op = &udf_symlink_inode_opera 909 inode->i_op = &udf_symlink_inode_operations; 598 inode_nohighmem(inode); 910 inode_nohighmem(inode); 599 911 600 if (iinfo->i_alloc_type != ICBTAG_FLAG 912 if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { 601 struct kernel_lb_addr eloc; 913 struct kernel_lb_addr eloc; 602 uint32_t bsize; 914 uint32_t bsize; 603 915 604 block = udf_new_block(sb, inod 916 block = udf_new_block(sb, inode, 605 iinfo->i_locat 917 iinfo->i_location.partitionReferenceNum, 606 iinfo->i_locat 918 iinfo->i_location.logicalBlockNum, &err); 607 if (!block) 919 if (!block) 608 goto out_no_entry; 920 goto out_no_entry; 609 epos.block = iinfo->i_location 921 epos.block = iinfo->i_location; 610 epos.offset = udf_file_entry_a 922 epos.offset = udf_file_entry_alloc_offset(inode); 611 epos.bh = NULL; 923 epos.bh = NULL; 612 eloc.logicalBlockNum = block; 924 eloc.logicalBlockNum = block; 613 eloc.partitionReferenceNum = 925 eloc.partitionReferenceNum = 614 iinfo->i_locat 926 iinfo->i_location.partitionReferenceNum; 615 bsize = sb->s_blocksize; 927 bsize = sb->s_blocksize; 616 iinfo->i_lenExtents = bsize; 928 iinfo->i_lenExtents = bsize; 617 err = udf_add_aext(inode, &epo !! 929 udf_add_aext(inode, &epos, &eloc, bsize, 0); 618 brelse(epos.bh); 930 brelse(epos.bh); 619 if (err < 0) { << 620 udf_free_blocks(sb, in << 621 goto out_no_entry; << 622 } << 623 931 624 block = udf_get_pblock(sb, blo 932 block = udf_get_pblock(sb, block, 625 iinfo->i_locat 933 iinfo->i_location.partitionReferenceNum, 626 0); 934 0); 627 epos.bh = sb_getblk(sb, block) !! 935 epos.bh = udf_tgetblk(sb, block); 628 if (unlikely(!epos.bh)) { << 629 err = -ENOMEM; << 630 udf_free_blocks(sb, in << 631 goto out_no_entry; << 632 } << 633 lock_buffer(epos.bh); 936 lock_buffer(epos.bh); 634 memset(epos.bh->b_data, 0x00, 937 memset(epos.bh->b_data, 0x00, bsize); 635 set_buffer_uptodate(epos.bh); 938 set_buffer_uptodate(epos.bh); 636 unlock_buffer(epos.bh); 939 unlock_buffer(epos.bh); 637 mark_buffer_dirty_inode(epos.b 940 mark_buffer_dirty_inode(epos.bh, inode); 638 ea = epos.bh->b_data + udf_ext 941 ea = epos.bh->b_data + udf_ext0_offset(inode); 639 } else 942 } else 640 ea = iinfo->i_data + iinfo->i_ !! 943 ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr; 641 944 642 eoffset = sb->s_blocksize - udf_ext0_o 945 eoffset = sb->s_blocksize - udf_ext0_offset(inode); 643 pc = (struct pathComponent *)ea; 946 pc = (struct pathComponent *)ea; 644 947 645 if (*symname == '/') { 948 if (*symname == '/') { 646 do { 949 do { 647 symname++; 950 symname++; 648 } while (*symname == '/'); 951 } while (*symname == '/'); 649 952 650 pc->componentType = 1; 953 pc->componentType = 1; 651 pc->lengthComponentIdent = 0; 954 pc->lengthComponentIdent = 0; 652 pc->componentFileVersionNum = 955 pc->componentFileVersionNum = 0; 653 elen += sizeof(struct pathComp 956 elen += sizeof(struct pathComponent); 654 } 957 } 655 958 656 err = -ENAMETOOLONG; 959 err = -ENAMETOOLONG; 657 960 658 while (*symname) { 961 while (*symname) { 659 if (elen + sizeof(struct pathC 962 if (elen + sizeof(struct pathComponent) > eoffset) 660 goto out_no_entry; 963 goto out_no_entry; 661 964 662 pc = (struct pathComponent *)( 965 pc = (struct pathComponent *)(ea + elen); 663 966 664 compstart = symname; 967 compstart = symname; 665 968 666 do { 969 do { 667 symname++; 970 symname++; 668 } while (*symname && *symname 971 } while (*symname && *symname != '/'); 669 972 670 pc->componentType = 5; 973 pc->componentType = 5; 671 pc->lengthComponentIdent = 0; 974 pc->lengthComponentIdent = 0; 672 pc->componentFileVersionNum = 975 pc->componentFileVersionNum = 0; 673 if (compstart[0] == '.') { 976 if (compstart[0] == '.') { 674 if ((symname - compsta 977 if ((symname - compstart) == 1) 675 pc->componentT 978 pc->componentType = 4; 676 else if ((symname - co 979 else if ((symname - compstart) == 2 && 677 compst 980 compstart[1] == '.') 678 pc->componentT 981 pc->componentType = 3; 679 } 982 } 680 983 681 if (pc->componentType == 5) { 984 if (pc->componentType == 5) { 682 namelen = udf_put_file 985 namelen = udf_put_filename(sb, compstart, 683 986 symname - compstart, 684 987 name, UDF_NAME_LEN_CS0); 685 if (!namelen) 988 if (!namelen) 686 goto out_no_en 989 goto out_no_entry; 687 990 688 if (elen + sizeof(stru 991 if (elen + sizeof(struct pathComponent) + namelen > 689 eoffse 992 eoffset) 690 goto out_no_en 993 goto out_no_entry; 691 else 994 else 692 pc->lengthComp 995 pc->lengthComponentIdent = namelen; 693 996 694 memcpy(pc->componentId 997 memcpy(pc->componentIdent, name, namelen); 695 } 998 } 696 999 697 elen += sizeof(struct pathComp 1000 elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; 698 1001 699 if (*symname) { 1002 if (*symname) { 700 do { 1003 do { 701 symname++; 1004 symname++; 702 } while (*symname == ' 1005 } while (*symname == '/'); 703 } 1006 } 704 } 1007 } 705 1008 706 brelse(epos.bh); 1009 brelse(epos.bh); 707 inode->i_size = elen; 1010 inode->i_size = elen; 708 if (iinfo->i_alloc_type == ICBTAG_FLAG 1011 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 709 iinfo->i_lenAlloc = inode->i_s 1012 iinfo->i_lenAlloc = inode->i_size; 710 else 1013 else 711 udf_truncate_tail_extent(inode 1014 udf_truncate_tail_extent(inode); 712 mark_inode_dirty(inode); 1015 mark_inode_dirty(inode); 713 up_write(&iinfo->i_data_sem); 1016 up_write(&iinfo->i_data_sem); 714 1017 715 err = udf_add_nondir(dentry, inode); 1018 err = udf_add_nondir(dentry, inode); 716 out: 1019 out: 717 kfree(name); 1020 kfree(name); 718 return err; 1021 return err; 719 1022 720 out_no_entry: 1023 out_no_entry: 721 up_write(&iinfo->i_data_sem); 1024 up_write(&iinfo->i_data_sem); 722 inode_dec_link_count(inode); 1025 inode_dec_link_count(inode); 723 discard_new_inode(inode); 1026 discard_new_inode(inode); 724 goto out; 1027 goto out; 725 } 1028 } 726 1029 727 static int udf_link(struct dentry *old_dentry, 1030 static int udf_link(struct dentry *old_dentry, struct inode *dir, 728 struct dentry *dentry) 1031 struct dentry *dentry) 729 { 1032 { 730 struct inode *inode = d_inode(old_dent 1033 struct inode *inode = d_inode(old_dentry); 731 struct udf_fileident_iter iter; !! 1034 struct udf_fileident_bh fibh; >> 1035 struct fileIdentDesc cfi, *fi; 732 int err; 1036 int err; 733 1037 734 err = udf_fiiter_add_entry(dir, dentry !! 1038 fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); 735 if (err) !! 1039 if (!fi) { 736 return err; 1040 return err; 737 iter.fi.icb.extLength = cpu_to_le32(in !! 1041 } 738 iter.fi.icb.extLocation = cpu_to_lelb( !! 1042 cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); >> 1043 cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location); 739 if (UDF_SB(inode->i_sb)->s_lvid_bh) { 1044 if (UDF_SB(inode->i_sb)->s_lvid_bh) { 740 *(__le32 *)((struct allocDescI !! 1045 *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = 741 cpu_to_le32(lvid_get_u 1046 cpu_to_le32(lvid_get_unique_id(inode->i_sb)); 742 } 1047 } 743 udf_fiiter_write_fi(&iter, NULL); !! 1048 udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); 744 udf_fiiter_release(&iter); !! 1049 if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 745 !! 1050 mark_inode_dirty(dir); >> 1051 >> 1052 if (fibh.sbh != fibh.ebh) >> 1053 brelse(fibh.ebh); >> 1054 brelse(fibh.sbh); 746 inc_nlink(inode); 1055 inc_nlink(inode); 747 udf_add_fid_counter(dir->i_sb, false, !! 1056 inode->i_ctime = current_time(inode); 748 inode_set_ctime_current(inode); << 749 mark_inode_dirty(inode); 1057 mark_inode_dirty(inode); 750 inode_set_mtime_to_ts(dir, inode_set_c !! 1058 dir->i_ctime = dir->i_mtime = current_time(dir); 751 mark_inode_dirty(dir); 1059 mark_inode_dirty(dir); 752 ihold(inode); 1060 ihold(inode); 753 d_instantiate(dentry, inode); 1061 d_instantiate(dentry, inode); 754 1062 755 return 0; 1063 return 0; 756 } 1064 } 757 1065 758 /* Anybody can rename anything with this: the 1066 /* Anybody can rename anything with this: the permission checks are left to the 759 * higher-level routines. 1067 * higher-level routines. 760 */ 1068 */ 761 static int udf_rename(struct mnt_idmap *idmap, !! 1069 static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, 762 struct dentry *old_dentr !! 1070 struct inode *new_dir, struct dentry *new_dentry, 763 struct dentry *new_dentr !! 1071 unsigned int flags) 764 { 1072 { 765 struct inode *old_inode = d_inode(old_ 1073 struct inode *old_inode = d_inode(old_dentry); 766 struct inode *new_inode = d_inode(new_ 1074 struct inode *new_inode = d_inode(new_dentry); 767 struct udf_fileident_iter oiter, niter !! 1075 struct udf_fileident_bh ofibh, nfibh; 768 bool has_diriter = false, is_dir = fal !! 1076 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL; 769 int retval; !! 1077 struct fileIdentDesc ocfi, ncfi; >> 1078 struct buffer_head *dir_bh = NULL; >> 1079 int retval = -ENOENT; 770 struct kernel_lb_addr tloc; 1080 struct kernel_lb_addr tloc; >> 1081 struct udf_inode_info *old_iinfo = UDF_I(old_inode); 771 1082 772 if (flags & ~RENAME_NOREPLACE) 1083 if (flags & ~RENAME_NOREPLACE) 773 return -EINVAL; 1084 return -EINVAL; 774 1085 775 retval = udf_fiiter_find_entry(old_dir !! 1086 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi); 776 if (retval) !! 1087 if (IS_ERR(ofi)) { 777 return retval; !! 1088 retval = PTR_ERR(ofi); 778 !! 1089 goto end_rename; 779 tloc = lelb_to_cpu(oiter.fi.icb.extLoc !! 1090 } 780 if (udf_get_lb_pblock(old_dir->i_sb, & !! 1091 781 retval = -ENOENT; !! 1092 if (ofibh.sbh != ofibh.ebh) 782 goto out_oiter; !! 1093 brelse(ofibh.ebh); >> 1094 >> 1095 brelse(ofibh.sbh); >> 1096 tloc = lelb_to_cpu(ocfi.icb.extLocation); >> 1097 if (!ofi || udf_get_lb_pblock(old_dir->i_sb, &tloc, 0) >> 1098 != old_inode->i_ino) >> 1099 goto end_rename; >> 1100 >> 1101 nfi = udf_find_entry(new_dir, &new_dentry->d_name, &nfibh, &ncfi); >> 1102 if (IS_ERR(nfi)) { >> 1103 retval = PTR_ERR(nfi); >> 1104 goto end_rename; >> 1105 } >> 1106 if (nfi && !new_inode) { >> 1107 if (nfibh.sbh != nfibh.ebh) >> 1108 brelse(nfibh.ebh); >> 1109 brelse(nfibh.sbh); >> 1110 nfi = NULL; 783 } 1111 } 784 << 785 if (S_ISDIR(old_inode->i_mode)) { 1112 if (S_ISDIR(old_inode->i_mode)) { >> 1113 int offset = udf_ext0_offset(old_inode); >> 1114 786 if (new_inode) { 1115 if (new_inode) { 787 retval = -ENOTEMPTY; 1116 retval = -ENOTEMPTY; 788 if (!empty_dir(new_ino 1117 if (!empty_dir(new_inode)) 789 goto out_oiter !! 1118 goto end_rename; 790 } 1119 } 791 is_dir = true; !! 1120 retval = -EIO; 792 } !! 1121 if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { 793 if (is_dir && old_dir != new_dir) { !! 1122 dir_fi = udf_get_fileident( 794 retval = udf_fiiter_find_entry !! 1123 old_iinfo->i_ext.i_data - 795 !! 1124 (old_iinfo->i_efe ? 796 if (retval == -ENOENT) { !! 1125 sizeof(struct extendedFileEntry) : 797 udf_err(old_inode->i_s !! 1126 sizeof(struct fileEntry)), 798 "directory (in !! 1127 old_inode->i_sb->s_blocksize, &offset); 799 old_inode->i_i !! 1128 } else { 800 retval = -EFSCORRUPTED !! 1129 dir_bh = udf_bread(old_inode, 0, 0, &retval); 801 } !! 1130 if (!dir_bh) 802 if (retval) !! 1131 goto end_rename; 803 goto out_oiter; !! 1132 dir_fi = udf_get_fileident(dir_bh->b_data, 804 has_diriter = true; !! 1133 old_inode->i_sb->s_blocksize, &offset); 805 tloc = lelb_to_cpu(diriter.fi. << 806 if (udf_get_lb_pblock(old_inod << 807 old_dir->i_ino << 808 retval = -EFSCORRUPTED << 809 udf_err(old_inode->i_s << 810 "directory (in << 811 old_inode->i_i << 812 udf_get_lb_pbl << 813 goto out_oiter; << 814 } 1134 } >> 1135 if (!dir_fi) >> 1136 goto end_rename; >> 1137 tloc = lelb_to_cpu(dir_fi->icb.extLocation); >> 1138 if (udf_get_lb_pblock(old_inode->i_sb, &tloc, 0) != >> 1139 old_dir->i_ino) >> 1140 goto end_rename; 815 } 1141 } 816 !! 1142 if (!nfi) { 817 retval = udf_fiiter_find_entry(new_dir !! 1143 nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, 818 if (retval && retval != -ENOENT) !! 1144 &retval); 819 goto out_oiter; !! 1145 if (!nfi) 820 /* Entry found but not passed by VFS? !! 1146 goto end_rename; 821 if (!retval && !new_inode) { << 822 retval = -EFSCORRUPTED; << 823 udf_fiiter_release(&niter); << 824 goto out_oiter; << 825 } << 826 /* Entry not found? Need to add one... << 827 if (retval) { << 828 udf_fiiter_release(&niter); << 829 retval = udf_fiiter_add_entry( << 830 if (retval) << 831 goto out_oiter; << 832 } 1147 } 833 1148 834 /* 1149 /* 835 * Like most other Unix systems, set t 1150 * Like most other Unix systems, set the ctime for inodes on a 836 * rename. 1151 * rename. 837 */ 1152 */ 838 inode_set_ctime_current(old_inode); !! 1153 old_inode->i_ctime = current_time(old_inode); 839 mark_inode_dirty(old_inode); 1154 mark_inode_dirty(old_inode); 840 1155 841 /* 1156 /* 842 * ok, that's it 1157 * ok, that's it 843 */ 1158 */ 844 niter.fi.fileVersionNum = oiter.fi.fil !! 1159 ncfi.fileVersionNum = ocfi.fileVersionNum; 845 niter.fi.fileCharacteristics = oiter.f !! 1160 ncfi.fileCharacteristics = ocfi.fileCharacteristics; 846 memcpy(&(niter.fi.icb), &(oiter.fi.icb !! 1161 memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(ocfi.icb)); 847 udf_fiiter_write_fi(&niter, NULL); !! 1162 udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL); 848 udf_fiiter_release(&niter); !! 1163 849 !! 1164 /* The old fid may have moved - find it again */ 850 /* !! 1165 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi); 851 * The old entry may have moved due to !! 1166 udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); 852 * again. << 853 */ << 854 udf_fiiter_release(&oiter); << 855 retval = udf_fiiter_find_entry(old_dir << 856 if (retval) { << 857 udf_err(old_dir->i_sb, << 858 "failed to find rename << 859 old_dir->i_ino); << 860 } else { << 861 udf_fiiter_delete_entry(&oiter << 862 udf_fiiter_release(&oiter); << 863 } << 864 1167 865 if (new_inode) { 1168 if (new_inode) { 866 inode_set_ctime_current(new_in !! 1169 new_inode->i_ctime = current_time(new_inode); 867 inode_dec_link_count(new_inode 1170 inode_dec_link_count(new_inode); 868 udf_add_fid_counter(old_dir->i << 869 -1); << 870 } 1171 } 871 inode_set_mtime_to_ts(old_dir, inode_s !! 1172 old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir); 872 inode_set_mtime_to_ts(new_dir, inode_s !! 1173 new_dir->i_ctime = new_dir->i_mtime = current_time(new_dir); 873 mark_inode_dirty(old_dir); 1174 mark_inode_dirty(old_dir); 874 mark_inode_dirty(new_dir); 1175 mark_inode_dirty(new_dir); 875 1176 876 if (has_diriter) { !! 1177 if (dir_fi) { 877 diriter.fi.icb.extLocation = !! 1178 dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location); 878 cpu_to !! 1179 udf_update_tag((char *)dir_fi, udf_dir_entry_len(dir_fi)); 879 udf_fiiter_write_fi(&diriter, !! 1180 if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 880 udf_fiiter_release(&diriter); !! 1181 mark_inode_dirty(old_inode); 881 } !! 1182 else >> 1183 mark_buffer_dirty_inode(dir_bh, old_inode); 882 1184 883 if (is_dir) { << 884 inode_dec_link_count(old_dir); 1185 inode_dec_link_count(old_dir); 885 if (new_inode) 1186 if (new_inode) 886 inode_dec_link_count(n 1187 inode_dec_link_count(new_inode); 887 else { 1188 else { 888 inc_nlink(new_dir); 1189 inc_nlink(new_dir); 889 mark_inode_dirty(new_d 1190 mark_inode_dirty(new_dir); 890 } 1191 } 891 } 1192 } 892 return 0; !! 1193 893 out_oiter: !! 1194 if (ofi) { 894 if (has_diriter) !! 1195 if (ofibh.sbh != ofibh.ebh) 895 udf_fiiter_release(&diriter); !! 1196 brelse(ofibh.ebh); 896 udf_fiiter_release(&oiter); !! 1197 brelse(ofibh.sbh); >> 1198 } >> 1199 >> 1200 retval = 0; >> 1201 >> 1202 end_rename: >> 1203 brelse(dir_bh); >> 1204 if (nfi) { >> 1205 if (nfibh.sbh != nfibh.ebh) >> 1206 brelse(nfibh.ebh); >> 1207 brelse(nfibh.sbh); >> 1208 } 897 1209 898 return retval; 1210 return retval; 899 } 1211 } 900 1212 901 static struct dentry *udf_get_parent(struct de 1213 static struct dentry *udf_get_parent(struct dentry *child) 902 { 1214 { 903 struct kernel_lb_addr tloc; 1215 struct kernel_lb_addr tloc; 904 struct udf_fileident_iter iter; !! 1216 struct inode *inode = NULL; 905 int err; !! 1217 struct qstr dotdot = QSTR_INIT("..", 2); >> 1218 struct fileIdentDesc cfi; >> 1219 struct udf_fileident_bh fibh; >> 1220 >> 1221 if (!udf_find_entry(d_inode(child), &dotdot, &fibh, &cfi)) >> 1222 return ERR_PTR(-EACCES); >> 1223 >> 1224 if (fibh.sbh != fibh.ebh) >> 1225 brelse(fibh.ebh); >> 1226 brelse(fibh.sbh); >> 1227 >> 1228 tloc = lelb_to_cpu(cfi.icb.extLocation); >> 1229 inode = udf_iget(child->d_sb, &tloc); >> 1230 if (IS_ERR(inode)) >> 1231 return ERR_CAST(inode); 906 1232 907 err = udf_fiiter_find_entry(d_inode(ch !! 1233 return d_obtain_alias(inode); 908 if (err) << 909 return ERR_PTR(err); << 910 << 911 tloc = lelb_to_cpu(iter.fi.icb.extLoca << 912 udf_fiiter_release(&iter); << 913 return d_obtain_alias(udf_iget(child-> << 914 } 1234 } 915 1235 916 1236 917 static struct dentry *udf_nfs_get_inode(struct 1237 static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block, 918 u16 pa 1238 u16 partref, __u32 generation) 919 { 1239 { 920 struct inode *inode; 1240 struct inode *inode; 921 struct kernel_lb_addr loc; 1241 struct kernel_lb_addr loc; 922 1242 923 if (block == 0) 1243 if (block == 0) 924 return ERR_PTR(-ESTALE); 1244 return ERR_PTR(-ESTALE); 925 1245 926 loc.logicalBlockNum = block; 1246 loc.logicalBlockNum = block; 927 loc.partitionReferenceNum = partref; 1247 loc.partitionReferenceNum = partref; 928 inode = udf_iget(sb, &loc); 1248 inode = udf_iget(sb, &loc); 929 1249 930 if (IS_ERR(inode)) 1250 if (IS_ERR(inode)) 931 return ERR_CAST(inode); 1251 return ERR_CAST(inode); 932 1252 933 if (generation && inode->i_generation 1253 if (generation && inode->i_generation != generation) { 934 iput(inode); 1254 iput(inode); 935 return ERR_PTR(-ESTALE); 1255 return ERR_PTR(-ESTALE); 936 } 1256 } 937 return d_obtain_alias(inode); 1257 return d_obtain_alias(inode); 938 } 1258 } 939 1259 940 static struct dentry *udf_fh_to_dentry(struct 1260 static struct dentry *udf_fh_to_dentry(struct super_block *sb, 941 struct 1261 struct fid *fid, int fh_len, int fh_type) 942 { 1262 { 943 if (fh_len < 3 || 1263 if (fh_len < 3 || 944 (fh_type != FILEID_UDF_WITH_PARENT 1264 (fh_type != FILEID_UDF_WITH_PARENT && 945 fh_type != FILEID_UDF_WITHOUT_PAR 1265 fh_type != FILEID_UDF_WITHOUT_PARENT)) 946 return NULL; 1266 return NULL; 947 1267 948 return udf_nfs_get_inode(sb, fid->udf. 1268 return udf_nfs_get_inode(sb, fid->udf.block, fid->udf.partref, 949 fid->udf.generation); 1269 fid->udf.generation); 950 } 1270 } 951 1271 952 static struct dentry *udf_fh_to_parent(struct 1272 static struct dentry *udf_fh_to_parent(struct super_block *sb, 953 struct 1273 struct fid *fid, int fh_len, int fh_type) 954 { 1274 { 955 if (fh_len < 5 || fh_type != FILEID_UD 1275 if (fh_len < 5 || fh_type != FILEID_UDF_WITH_PARENT) 956 return NULL; 1276 return NULL; 957 1277 958 return udf_nfs_get_inode(sb, fid->udf. 1278 return udf_nfs_get_inode(sb, fid->udf.parent_block, 959 fid->udf.pare 1279 fid->udf.parent_partref, 960 fid->udf.pare 1280 fid->udf.parent_generation); 961 } 1281 } 962 static int udf_encode_fh(struct inode *inode, 1282 static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp, 963 struct inode *parent) 1283 struct inode *parent) 964 { 1284 { 965 int len = *lenp; 1285 int len = *lenp; 966 struct kernel_lb_addr location = UDF_I 1286 struct kernel_lb_addr location = UDF_I(inode)->i_location; 967 struct fid *fid = (struct fid *)fh; 1287 struct fid *fid = (struct fid *)fh; 968 int type = FILEID_UDF_WITHOUT_PARENT; 1288 int type = FILEID_UDF_WITHOUT_PARENT; 969 1289 970 if (parent && (len < 5)) { 1290 if (parent && (len < 5)) { 971 *lenp = 5; 1291 *lenp = 5; 972 return FILEID_INVALID; 1292 return FILEID_INVALID; 973 } else if (len < 3) { 1293 } else if (len < 3) { 974 *lenp = 3; 1294 *lenp = 3; 975 return FILEID_INVALID; 1295 return FILEID_INVALID; 976 } 1296 } 977 1297 978 *lenp = 3; 1298 *lenp = 3; 979 fid->udf.block = location.logicalBlock 1299 fid->udf.block = location.logicalBlockNum; 980 fid->udf.partref = location.partitionR 1300 fid->udf.partref = location.partitionReferenceNum; 981 fid->udf.parent_partref = 0; 1301 fid->udf.parent_partref = 0; 982 fid->udf.generation = inode->i_generat 1302 fid->udf.generation = inode->i_generation; 983 1303 984 if (parent) { 1304 if (parent) { 985 location = UDF_I(parent)->i_lo 1305 location = UDF_I(parent)->i_location; 986 fid->udf.parent_block = locati 1306 fid->udf.parent_block = location.logicalBlockNum; 987 fid->udf.parent_partref = loca 1307 fid->udf.parent_partref = location.partitionReferenceNum; 988 fid->udf.parent_generation = i 1308 fid->udf.parent_generation = inode->i_generation; 989 *lenp = 5; 1309 *lenp = 5; 990 type = FILEID_UDF_WITH_PARENT; 1310 type = FILEID_UDF_WITH_PARENT; 991 } 1311 } 992 1312 993 return type; 1313 return type; 994 } 1314 } 995 1315 996 const struct export_operations udf_export_ops 1316 const struct export_operations udf_export_ops = { 997 .encode_fh = udf_encode_fh, 1317 .encode_fh = udf_encode_fh, 998 .fh_to_dentry = udf_fh_to_dentry, 1318 .fh_to_dentry = udf_fh_to_dentry, 999 .fh_to_parent = udf_fh_to_parent, 1319 .fh_to_parent = udf_fh_to_parent, 1000 .get_parent = udf_get_parent, 1320 .get_parent = udf_get_parent, 1001 }; 1321 }; 1002 1322 1003 const struct inode_operations udf_dir_inode_o 1323 const struct inode_operations udf_dir_inode_operations = { 1004 .lookup = udf 1324 .lookup = udf_lookup, 1005 .create = udf 1325 .create = udf_create, 1006 .link = udf 1326 .link = udf_link, 1007 .unlink = udf 1327 .unlink = udf_unlink, 1008 .symlink = udf 1328 .symlink = udf_symlink, 1009 .mkdir = udf 1329 .mkdir = udf_mkdir, 1010 .rmdir = udf 1330 .rmdir = udf_rmdir, 1011 .mknod = udf 1331 .mknod = udf_mknod, 1012 .rename = udf 1332 .rename = udf_rename, 1013 .tmpfile = udf 1333 .tmpfile = udf_tmpfile, 1014 }; 1334 }; 1015 1335
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.