~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/udf/namei.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/udf/namei.c (Version linux-6.11.5) and /fs/udf/namei.c (Version linux-4.16.18)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php