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