Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * namei.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Inode name handling routines for the OSTA-UDF(tm) filesystem. |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
| 13 | * (C) 1998-2004 Ben Fennema |
| 14 | * (C) 1999-2000 Stelias Computing Inc |
| 15 | * |
| 16 | * HISTORY |
| 17 | * |
| 18 | * 12/12/98 blf Created. Split out the lookup code from dir.c |
| 19 | * 04/19/99 blf link, mknod, symlink support |
| 20 | */ |
| 21 | |
| 22 | #include "udfdecl.h" |
| 23 | |
| 24 | #include "udf_i.h" |
| 25 | #include "udf_sb.h" |
| 26 | #include <linux/string.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/quotaops.h> |
| 31 | #include <linux/smp_lock.h> |
| 32 | #include <linux/buffer_head.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 33 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 35 | static inline int udf_match(int len1, const char *name1, int len2, |
| 36 | const char *name2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 38 | if (len1 != len2) |
| 39 | return 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | return !memcmp(name1, name2, len1); |
| 42 | } |
| 43 | |
| 44 | int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 45 | struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 46 | uint8_t *impuse, uint8_t *fileident) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag); |
| 49 | uint16_t crc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | int offset; |
| 51 | uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 52 | uint8_t lfi = cfi->lengthFileIdent; |
| 53 | int padlen = fibh->eoffset - fibh->soffset - liu - lfi - |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 54 | sizeof(struct fileIdentDesc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | int adinicb = 0; |
| 56 | |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 57 | if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | adinicb = 1; |
| 59 | |
| 60 | offset = fibh->soffset + sizeof(struct fileIdentDesc); |
| 61 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 62 | if (impuse) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 63 | if (adinicb || (offset + liu < 0)) { |
| 64 | memcpy((uint8_t *)sfi->impUse, impuse, liu); |
| 65 | } else if (offset >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | memcpy(fibh->ebh->b_data + offset, impuse, liu); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 67 | } else { |
| 68 | memcpy((uint8_t *)sfi->impUse, impuse, -offset); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 69 | memcpy(fibh->ebh->b_data, impuse - offset, |
| 70 | liu + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | offset += liu; |
| 75 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 76 | if (fileident) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 77 | if (adinicb || (offset + lfi < 0)) { |
| 78 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi); |
| 79 | } else if (offset >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 81 | } else { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 82 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, |
| 83 | -offset); |
| 84 | memcpy(fibh->ebh->b_data, fileident - offset, |
| 85 | lfi + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | offset += lfi; |
| 90 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 91 | if (adinicb || (offset + padlen < 0)) { |
| 92 | memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen); |
| 93 | } else if (offset >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | memset(fibh->ebh->b_data + offset, 0x00, padlen); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 95 | } else { |
| 96 | memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | memset(fibh->ebh->b_data, 0x00, padlen + offset); |
| 98 | } |
| 99 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 100 | crc = udf_crc((uint8_t *)cfi + sizeof(tag), |
| 101 | sizeof(struct fileIdentDesc) - sizeof(tag), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 103 | if (fibh->sbh == fibh->ebh) { |
| 104 | crc = udf_crc((uint8_t *)sfi->impUse, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 105 | crclen + sizeof(tag) - |
| 106 | sizeof(struct fileIdentDesc), crc); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 107 | } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 108 | crc = udf_crc(fibh->ebh->b_data + |
| 109 | sizeof(struct fileIdentDesc) + |
| 110 | fibh->soffset, |
| 111 | crclen + sizeof(tag) - |
| 112 | sizeof(struct fileIdentDesc), |
| 113 | crc); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 114 | } else { |
| 115 | crc = udf_crc((uint8_t *)sfi->impUse, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 116 | -fibh->soffset - sizeof(struct fileIdentDesc), |
| 117 | crc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); |
| 119 | } |
| 120 | |
| 121 | cfi->descTag.descCRC = cpu_to_le16(crc); |
| 122 | cfi->descTag.descCRCLength = cpu_to_le16(crclen); |
Marcin Slusarz | 3f2587b | 2008-02-08 04:20:39 -0800 | [diff] [blame] | 123 | cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 125 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 126 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, |
| 127 | sizeof(struct fileIdentDesc)); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 128 | } else { |
| 129 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); |
| 130 | memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 131 | sizeof(struct fileIdentDesc) + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 134 | if (adinicb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | mark_inode_dirty(inode); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 136 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | if (fibh->sbh != fibh->ebh) |
| 138 | mark_buffer_dirty_inode(fibh->ebh, inode); |
| 139 | mark_buffer_dirty_inode(fibh->sbh, inode); |
| 140 | } |
| 141 | return 0; |
| 142 | } |
| 143 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 144 | static struct fileIdentDesc *udf_find_entry(struct inode *dir, |
| 145 | struct dentry *dentry, |
| 146 | struct udf_fileident_bh *fibh, |
| 147 | struct fileIdentDesc *cfi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 149 | struct fileIdentDesc *fi = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | loff_t f_pos; |
| 151 | int block, flen; |
| 152 | char fname[UDF_NAME_LEN]; |
| 153 | char *nameptr; |
| 154 | uint8_t lfi; |
| 155 | uint16_t liu; |
KAMBAROV, ZAUR | ec471dc | 2005-06-28 20:45:10 -0700 | [diff] [blame] | 156 | loff_t size; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 157 | kernel_lb_addr eloc; |
| 158 | uint32_t elen; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 159 | sector_t offset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 160 | struct extent_position epos = {}; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 161 | struct udf_inode_info *dinfo = UDF_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 163 | size = udf_ext0_offset(dir) + dir->i_size; |
| 164 | f_pos = udf_ext0_offset(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 166 | fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 167 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | fibh->sbh = fibh->ebh = NULL; |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 169 | else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 170 | &epos, &eloc, &elen, &offset) == |
| 171 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 173 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 174 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 175 | epos.offset -= sizeof(short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 176 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 177 | epos.offset -= sizeof(long_ad); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 178 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | offset = 0; |
| 180 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 181 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 182 | if (!fibh->sbh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 183 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return NULL; |
| 185 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 186 | } else { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 187 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | return NULL; |
| 189 | } |
| 190 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 191 | while (f_pos < size) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 192 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, |
| 193 | &elen, &offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 194 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 196 | brelse(fibh->ebh); |
| 197 | brelse(fibh->sbh); |
| 198 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return NULL; |
| 200 | } |
| 201 | |
| 202 | liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 203 | lfi = cfi->lengthFileIdent; |
| 204 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 205 | if (fibh->sbh == fibh->ebh) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | nameptr = fi->fileIdent + liu; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 207 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | int poffset; /* Unpaded ending offset */ |
| 209 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 210 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
| 211 | liu + lfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 213 | if (poffset >= lfi) |
| 214 | nameptr = (uint8_t *)(fibh->ebh->b_data + |
| 215 | poffset - lfi); |
| 216 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | nameptr = fname; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 218 | memcpy(nameptr, fi->fileIdent + liu, |
| 219 | lfi - poffset); |
| 220 | memcpy(nameptr + lfi - poffset, |
| 221 | fibh->ebh->b_data, poffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 225 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
| 226 | if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | continue; |
| 228 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 229 | |
| 230 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) { |
| 231 | if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | continue; |
| 233 | } |
| 234 | |
| 235 | if (!lfi) |
| 236 | continue; |
| 237 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 238 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
| 239 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
| 240 | dentry->d_name.name)) { |
| 241 | brelse(epos.bh); |
| 242 | return fi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 247 | brelse(fibh->ebh); |
| 248 | brelse(fibh->sbh); |
| 249 | brelse(epos.bh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | return NULL; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * udf_lookup |
| 256 | * |
| 257 | * PURPOSE |
| 258 | * Look-up the inode for a given name. |
| 259 | * |
| 260 | * DESCRIPTION |
| 261 | * Required - lookup_dentry() will return -ENOTDIR if this routine is not |
| 262 | * available for a directory. The filesystem is useless if this routine is |
| 263 | * not available for at least the filesystem's root directory. |
| 264 | * |
| 265 | * This routine is passed an incomplete dentry - it must be completed by |
| 266 | * calling d_add(dentry, inode). If the name does not exist, then the |
| 267 | * specified inode must be set to null. An error should only be returned |
| 268 | * when the lookup fails for a reason other than the name not existing. |
| 269 | * Note that the directory inode semaphore is held during the call. |
| 270 | * |
| 271 | * Refer to lookup_dentry() in fs/namei.c |
| 272 | * lookup_dentry() -> lookup() -> real_lookup() -> . |
| 273 | * |
| 274 | * PRE-CONDITIONS |
| 275 | * dir Pointer to inode of parent directory. |
| 276 | * dentry Pointer to dentry to complete. |
| 277 | * nd Pointer to lookup nameidata |
| 278 | * |
| 279 | * POST-CONDITIONS |
| 280 | * <return> Zero on success. |
| 281 | * |
| 282 | * HISTORY |
| 283 | * July 1, 1997 - Andrew E. Mileski |
| 284 | * Written, tested, and released. |
| 285 | */ |
| 286 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 287 | static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, |
| 288 | struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { |
| 290 | struct inode *inode = NULL; |
Jayachandran C | db9a369 | 2006-02-03 03:04:50 -0800 | [diff] [blame] | 291 | struct fileIdentDesc cfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | struct udf_fileident_bh fibh; |
| 293 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 294 | if (dentry->d_name.len > UDF_NAME_LEN - 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | return ERR_PTR(-ENAMETOOLONG); |
| 296 | |
| 297 | lock_kernel(); |
| 298 | #ifdef UDF_RECOVERY |
| 299 | /* temporary shorthand for specifying files by inode number */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 300 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 301 | kernel_lb_addr lb = { |
| 302 | .logicalBlockNum = 0, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 303 | .partitionReferenceNum = |
| 304 | simple_strtoul(dentry->d_name.name + 3, |
| 305 | NULL, 0), |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 306 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | inode = udf_iget(dir->i_sb, lb); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 308 | if (!inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | unlock_kernel(); |
| 310 | return ERR_PTR(-EACCES); |
| 311 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 312 | } else |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 313 | #endif /* UDF_RECOVERY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 315 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 317 | brelse(fibh.ebh); |
| 318 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | inode = udf_iget(dir->i_sb, lelb_to_cpu(cfi.icb.extLocation)); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 321 | if (!inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | unlock_kernel(); |
| 323 | return ERR_PTR(-EACCES); |
| 324 | } |
| 325 | } |
| 326 | unlock_kernel(); |
| 327 | d_add(dentry, inode); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return NULL; |
| 330 | } |
| 331 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 332 | static struct fileIdentDesc *udf_add_entry(struct inode *dir, |
| 333 | struct dentry *dentry, |
| 334 | struct udf_fileident_bh *fibh, |
| 335 | struct fileIdentDesc *cfi, int *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 337 | struct super_block *sb = dir->i_sb; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 338 | struct fileIdentDesc *fi = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; |
| 340 | int namelen; |
| 341 | loff_t f_pos; |
| 342 | int flen; |
| 343 | char *nameptr; |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 344 | loff_t size = udf_ext0_offset(dir) + dir->i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | int nfidlen; |
| 346 | uint8_t lfi; |
| 347 | uint16_t liu; |
| 348 | int block; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 349 | kernel_lb_addr eloc; |
| 350 | uint32_t elen; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 351 | sector_t offset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 352 | struct extent_position epos = {}; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 353 | struct udf_inode_info *dinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 355 | if (dentry) { |
| 356 | if (!dentry->d_name.len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | *err = -EINVAL; |
| 358 | return NULL; |
| 359 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 360 | namelen = udf_put_filename(sb, dentry->d_name.name, name, |
| 361 | dentry->d_name.len); |
| 362 | if (!namelen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | *err = -ENAMETOOLONG; |
| 364 | return NULL; |
| 365 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 366 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | namelen = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; |
| 371 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 372 | f_pos = udf_ext0_offset(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 374 | fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 375 | dinfo = UDF_I(dir); |
| 376 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | fibh->sbh = fibh->ebh = NULL; |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 378 | else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 379 | &epos, &eloc, &elen, &offset) == |
| 380 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 382 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 383 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 384 | epos.offset -= sizeof(short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 385 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 386 | epos.offset -= sizeof(long_ad); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 387 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | offset = 0; |
| 389 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 390 | fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); |
| 391 | if (!fibh->sbh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 392 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | *err = -EIO; |
| 394 | return NULL; |
| 395 | } |
| 396 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 397 | block = dinfo->i_location.logicalBlockNum; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 398 | } else { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 399 | block = udf_get_lb_pblock(dir->i_sb, dinfo->i_location, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | fibh->sbh = fibh->ebh = NULL; |
| 401 | fibh->soffset = fibh->eoffset = sb->s_blocksize; |
| 402 | goto add; |
| 403 | } |
| 404 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 405 | while (f_pos < size) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 406 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, |
| 407 | &elen, &offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 409 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 411 | brelse(fibh->ebh); |
| 412 | brelse(fibh->sbh); |
| 413 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | *err = -EIO; |
| 415 | return NULL; |
| 416 | } |
| 417 | |
| 418 | liu = le16_to_cpu(cfi->lengthOfImpUse); |
| 419 | lfi = cfi->lengthFileIdent; |
| 420 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 421 | if (fibh->sbh == fibh->ebh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | nameptr = fi->fileIdent + liu; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 423 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | int poffset; /* Unpaded ending offset */ |
| 425 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 426 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + |
| 427 | liu + lfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 429 | if (poffset >= lfi) |
| 430 | nameptr = (char *)(fibh->ebh->b_data + |
| 431 | poffset - lfi); |
| 432 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | nameptr = fname; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 434 | memcpy(nameptr, fi->fileIdent + liu, |
| 435 | lfi - poffset); |
| 436 | memcpy(nameptr + lfi - poffset, |
| 437 | fibh->ebh->b_data, poffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 441 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 442 | if (((sizeof(struct fileIdentDesc) + |
| 443 | liu + lfi + 3) & ~3) == nfidlen) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 444 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | cfi->descTag.tagSerialNum = cpu_to_le16(1); |
| 446 | cfi->fileVersionNum = cpu_to_le16(1); |
| 447 | cfi->fileCharacteristics = 0; |
| 448 | cfi->lengthFileIdent = namelen; |
| 449 | cfi->lengthOfImpUse = cpu_to_le16(0); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 450 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, |
| 451 | name)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return fi; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 453 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | *err = -EIO; |
| 455 | return NULL; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | if (!lfi || !dentry) |
| 461 | continue; |
| 462 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 463 | flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); |
| 464 | if (flen && udf_match(flen, fname, dentry->d_name.len, |
| 465 | dentry->d_name.name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 467 | brelse(fibh->ebh); |
| 468 | brelse(fibh->sbh); |
| 469 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | *err = -EEXIST; |
| 471 | return NULL; |
| 472 | } |
| 473 | } |
| 474 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 475 | add: |
Jan Kara | 05343c4 | 2008-02-08 04:20:51 -0800 | [diff] [blame] | 476 | if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { |
| 477 | elen = (elen + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1); |
| 478 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
| 479 | epos.offset -= sizeof(short_ad); |
| 480 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
| 481 | epos.offset -= sizeof(long_ad); |
| 482 | udf_write_aext(dir, &epos, eloc, elen, 1); |
| 483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | f_pos += nfidlen; |
| 485 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 486 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 487 | sb->s_blocksize - fibh->eoffset < nfidlen) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 488 | brelse(epos.bh); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 489 | epos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | fibh->soffset -= udf_ext0_offset(dir); |
| 491 | fibh->eoffset -= udf_ext0_offset(dir); |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 492 | f_pos -= udf_ext0_offset(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 494 | brelse(fibh->ebh); |
| 495 | brelse(fibh->sbh); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 496 | fibh->sbh = fibh->ebh = |
| 497 | udf_expand_dir_adinicb(dir, &block, err); |
| 498 | if (!fibh->sbh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | return NULL; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 500 | epos.block = dinfo->i_location; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 501 | epos.offset = udf_file_entry_alloc_offset(dir); |
Jan Kara | 05343c4 | 2008-02-08 04:20:51 -0800 | [diff] [blame] | 502 | /* Load extent udf_expand_dir_adinicb() has created */ |
| 503 | udf_current_aext(dir, &epos, &eloc, &elen, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 506 | if (sb->s_blocksize - fibh->eoffset >= nfidlen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | fibh->soffset = fibh->eoffset; |
| 508 | fibh->eoffset += nfidlen; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 509 | if (fibh->sbh != fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 510 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | fibh->sbh = fibh->ebh; |
| 512 | } |
| 513 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 514 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
| 515 | block = dinfo->i_location.logicalBlockNum; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 516 | fi = (struct fileIdentDesc *) |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 517 | (dinfo->i_ext.i_data + |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 518 | fibh->soffset - |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 519 | udf_ext0_offset(dir) + |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 520 | dinfo->i_lenEAttr); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 521 | } else { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 522 | block = eloc.logicalBlockNum + |
| 523 | ((elen - 1) >> |
| 524 | dir->i_sb->s_blocksize_bits); |
| 525 | fi = (struct fileIdentDesc *) |
| 526 | (fibh->sbh->b_data + fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 528 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | fibh->soffset = fibh->eoffset - sb->s_blocksize; |
| 530 | fibh->eoffset += nfidlen - sb->s_blocksize; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 531 | if (fibh->sbh != fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 532 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | fibh->sbh = fibh->ebh; |
| 534 | } |
| 535 | |
| 536 | block = eloc.logicalBlockNum + ((elen - 1) >> |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 537 | dir->i_sb->s_blocksize_bits); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 538 | fibh->ebh = udf_bread(dir, |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 539 | f_pos >> dir->i_sb->s_blocksize_bits, 1, err); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 540 | if (!fibh->ebh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 541 | brelse(epos.bh); |
| 542 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | return NULL; |
| 544 | } |
| 545 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 546 | if (!fibh->soffset) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 547 | if (udf_next_aext(dir, &epos, &eloc, &elen, 1) == |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 548 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | block = eloc.logicalBlockNum + ((elen - 1) >> |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 550 | dir->i_sb->s_blocksize_bits); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 551 | } else |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 552 | block++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 554 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | fibh->sbh = fibh->ebh; |
| 556 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 557 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | fi = (struct fileIdentDesc *) |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 559 | (fibh->sbh->b_data + sb->s_blocksize + |
| 560 | fibh->soffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
| 564 | memset(cfi, 0, sizeof(struct fileIdentDesc)); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 565 | if (UDF_SB(sb)->s_udfrev >= 0x0200) |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 566 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, |
| 567 | sizeof(tag)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | else |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 569 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, |
| 570 | sizeof(tag)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | cfi->fileVersionNum = cpu_to_le16(1); |
| 572 | cfi->lengthFileIdent = namelen; |
| 573 | cfi->lengthOfImpUse = cpu_to_le16(0); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 574 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 575 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | dir->i_size += nfidlen; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 577 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 578 | dinfo->i_lenAlloc += nfidlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | mark_inode_dirty(dir); |
| 580 | return fi; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 581 | } else { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 582 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | if (fibh->sbh != fibh->ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 584 | brelse(fibh->ebh); |
| 585 | brelse(fibh->sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | *err = -EIO; |
| 587 | return NULL; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 592 | struct udf_fileident_bh *fibh, |
| 593 | struct fileIdentDesc *cfi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
| 595 | cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) |
| 598 | memset(&(cfi->icb), 0x00, sizeof(long_ad)); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); |
| 601 | } |
| 602 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 603 | static int udf_create(struct inode *dir, struct dentry *dentry, int mode, |
| 604 | struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
| 606 | struct udf_fileident_bh fibh; |
| 607 | struct inode *inode; |
| 608 | struct fileIdentDesc cfi, *fi; |
| 609 | int err; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 610 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | lock_kernel(); |
| 613 | inode = udf_new_inode(dir, mode, &err); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 614 | if (!inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | unlock_kernel(); |
| 616 | return err; |
| 617 | } |
| 618 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 619 | iinfo = UDF_I(inode); |
| 620 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | inode->i_data.a_ops = &udf_adinicb_aops; |
| 622 | else |
| 623 | inode->i_data.a_ops = &udf_aops; |
| 624 | inode->i_op = &udf_file_inode_operations; |
| 625 | inode->i_fop = &udf_file_operations; |
| 626 | inode->i_mode = mode; |
| 627 | mark_inode_dirty(inode); |
| 628 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 629 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 630 | if (!fi) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 631 | inode->i_nlink--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | mark_inode_dirty(inode); |
| 633 | iput(inode); |
| 634 | unlock_kernel(); |
| 635 | return err; |
| 636 | } |
| 637 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 638 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 639 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 640 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 642 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | mark_inode_dirty(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 645 | brelse(fibh.ebh); |
| 646 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | unlock_kernel(); |
| 648 | d_instantiate(dentry, inode); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | return 0; |
| 651 | } |
| 652 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 653 | static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, |
| 654 | dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 656 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | struct udf_fileident_bh fibh; |
| 658 | struct fileIdentDesc cfi, *fi; |
| 659 | int err; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 660 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
| 662 | if (!old_valid_dev(rdev)) |
| 663 | return -EINVAL; |
| 664 | |
| 665 | lock_kernel(); |
| 666 | err = -EIO; |
| 667 | inode = udf_new_inode(dir, mode, &err); |
| 668 | if (!inode) |
| 669 | goto out; |
| 670 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 671 | iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | inode->i_uid = current->fsuid; |
| 673 | init_special_inode(inode, mode, rdev); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 674 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 675 | if (!fi) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 676 | inode->i_nlink--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | mark_inode_dirty(inode); |
| 678 | iput(inode); |
| 679 | unlock_kernel(); |
| 680 | return err; |
| 681 | } |
| 682 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 683 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 684 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 685 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 687 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | mark_inode_dirty(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | mark_inode_dirty(inode); |
| 690 | |
| 691 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 692 | brelse(fibh.ebh); |
| 693 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | d_instantiate(dentry, inode); |
| 695 | err = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 696 | |
| 697 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | unlock_kernel(); |
| 699 | return err; |
| 700 | } |
| 701 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 702 | static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 704 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | struct udf_fileident_bh fibh; |
| 706 | struct fileIdentDesc cfi, *fi; |
| 707 | int err; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 708 | struct udf_inode_info *dinfo = UDF_I(dir); |
| 709 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
| 711 | lock_kernel(); |
| 712 | err = -EMLINK; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 713 | if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | goto out; |
| 715 | |
| 716 | err = -EIO; |
| 717 | inode = udf_new_inode(dir, S_IFDIR, &err); |
| 718 | if (!inode) |
| 719 | goto out; |
| 720 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 721 | iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | inode->i_op = &udf_dir_inode_operations; |
| 723 | inode->i_fop = &udf_dir_operations; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 724 | fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err); |
| 725 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | inode->i_nlink--; |
| 727 | mark_inode_dirty(inode); |
| 728 | iput(inode); |
| 729 | goto out; |
| 730 | } |
| 731 | inode->i_nlink = 2; |
| 732 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 733 | cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 734 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 735 | cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 736 | cfi.fileCharacteristics = |
| 737 | FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 739 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | inode->i_mode = S_IFDIR | mode; |
| 741 | if (dir->i_mode & S_ISGID) |
| 742 | inode->i_mode |= S_ISGID; |
| 743 | mark_inode_dirty(inode); |
| 744 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 745 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 746 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | inode->i_nlink = 0; |
| 748 | mark_inode_dirty(inode); |
| 749 | iput(inode); |
| 750 | goto out; |
| 751 | } |
| 752 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 753 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 754 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 755 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; |
| 757 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 758 | inc_nlink(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | mark_inode_dirty(dir); |
| 760 | d_instantiate(dentry, inode); |
| 761 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 762 | brelse(fibh.ebh); |
| 763 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | err = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 765 | |
| 766 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | unlock_kernel(); |
| 768 | return err; |
| 769 | } |
| 770 | |
| 771 | static int empty_dir(struct inode *dir) |
| 772 | { |
| 773 | struct fileIdentDesc *fi, cfi; |
| 774 | struct udf_fileident_bh fibh; |
| 775 | loff_t f_pos; |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 776 | loff_t size = udf_ext0_offset(dir) + dir->i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | int block; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 778 | kernel_lb_addr eloc; |
| 779 | uint32_t elen; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 780 | sector_t offset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 781 | struct extent_position epos = {}; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 782 | struct udf_inode_info *dinfo = UDF_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 784 | f_pos = udf_ext0_offset(dir); |
| 785 | fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 787 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | fibh.sbh = fibh.ebh = NULL; |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 789 | else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 790 | &epos, &eloc, &elen, &offset) == |
| 791 | (EXT_RECORDED_ALLOCATED >> 30)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 793 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 794 | if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 795 | epos.offset -= sizeof(short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 796 | else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 797 | epos.offset -= sizeof(long_ad); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 798 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | offset = 0; |
| 800 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 801 | fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block); |
| 802 | if (!fibh.sbh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 803 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return 0; |
| 805 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 806 | } else { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 807 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | return 0; |
| 809 | } |
| 810 | |
Jan Kara | af79329 | 2008-02-08 04:20:50 -0800 | [diff] [blame] | 811 | while (f_pos < size) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 812 | fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, |
| 813 | &elen, &offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 814 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 816 | brelse(fibh.ebh); |
| 817 | brelse(fibh.sbh); |
| 818 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 822 | if (cfi.lengthFileIdent && |
| 823 | (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 825 | brelse(fibh.ebh); |
| 826 | brelse(fibh.sbh); |
| 827 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | return 0; |
| 829 | } |
| 830 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 833 | brelse(fibh.ebh); |
| 834 | brelse(fibh.sbh); |
| 835 | brelse(epos.bh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | return 1; |
| 838 | } |
| 839 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 840 | static int udf_rmdir(struct inode *dir, struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
| 842 | int retval; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 843 | struct inode *inode = dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | struct udf_fileident_bh fibh; |
| 845 | struct fileIdentDesc *fi, cfi; |
| 846 | kernel_lb_addr tloc; |
| 847 | |
| 848 | retval = -ENOENT; |
| 849 | lock_kernel(); |
| 850 | fi = udf_find_entry(dir, dentry, &fibh, &cfi); |
| 851 | if (!fi) |
| 852 | goto out; |
| 853 | |
| 854 | retval = -EIO; |
| 855 | tloc = lelb_to_cpu(cfi.icb.extLocation); |
| 856 | if (udf_get_lb_pblock(dir->i_sb, tloc, 0) != inode->i_ino) |
| 857 | goto end_rmdir; |
| 858 | retval = -ENOTEMPTY; |
| 859 | if (!empty_dir(inode)) |
| 860 | goto end_rmdir; |
| 861 | retval = udf_delete_entry(dir, fi, &fibh, &cfi); |
| 862 | if (retval) |
| 863 | goto end_rmdir; |
| 864 | if (inode->i_nlink != 2) |
| 865 | udf_warning(inode->i_sb, "udf_rmdir", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 866 | "empty directory has nlink != 2 (%d)", |
| 867 | inode->i_nlink); |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 868 | clear_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | inode->i_size = 0; |
Stephen Mollett | c007c06 | 2007-05-08 00:31:31 -0700 | [diff] [blame] | 870 | inode_dec_link_count(dir); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 871 | inode->i_ctime = dir->i_ctime = dir->i_mtime = |
| 872 | current_fs_time(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | mark_inode_dirty(dir); |
| 874 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 875 | end_rmdir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 877 | brelse(fibh.ebh); |
| 878 | brelse(fibh.sbh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 879 | |
| 880 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | unlock_kernel(); |
| 882 | return retval; |
| 883 | } |
| 884 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 885 | static int udf_unlink(struct inode *dir, struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
| 887 | int retval; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 888 | struct inode *inode = dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | struct udf_fileident_bh fibh; |
| 890 | struct fileIdentDesc *fi; |
| 891 | struct fileIdentDesc cfi; |
| 892 | kernel_lb_addr tloc; |
| 893 | |
| 894 | retval = -ENOENT; |
| 895 | lock_kernel(); |
| 896 | fi = udf_find_entry(dir, dentry, &fibh, &cfi); |
| 897 | if (!fi) |
| 898 | goto out; |
| 899 | |
| 900 | retval = -EIO; |
| 901 | tloc = lelb_to_cpu(cfi.icb.extLocation); |
| 902 | if (udf_get_lb_pblock(dir->i_sb, tloc, 0) != inode->i_ino) |
| 903 | goto end_unlink; |
| 904 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 905 | if (!inode->i_nlink) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | udf_debug("Deleting nonexistent file (%lu), %d\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 907 | inode->i_ino, inode->i_nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | inode->i_nlink = 1; |
| 909 | } |
| 910 | retval = udf_delete_entry(dir, fi, &fibh, &cfi); |
| 911 | if (retval) |
| 912 | goto end_unlink; |
| 913 | dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); |
| 914 | mark_inode_dirty(dir); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 915 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | inode->i_ctime = dir->i_ctime; |
| 917 | retval = 0; |
| 918 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 919 | end_unlink: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 921 | brelse(fibh.ebh); |
| 922 | brelse(fibh.sbh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 923 | |
| 924 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | unlock_kernel(); |
| 926 | return retval; |
| 927 | } |
| 928 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 929 | static int udf_symlink(struct inode *dir, struct dentry *dentry, |
| 930 | const char *symname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 932 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | struct pathComponent *pc; |
| 934 | char *compstart; |
| 935 | struct udf_fileident_bh fibh; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 936 | struct extent_position epos = {}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | int eoffset, elen = 0; |
| 938 | struct fileIdentDesc *fi; |
| 939 | struct fileIdentDesc cfi; |
| 940 | char *ea; |
| 941 | int err; |
| 942 | int block; |
| 943 | char name[UDF_NAME_LEN]; |
| 944 | int namelen; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 945 | struct buffer_head *bh; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 946 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
| 948 | lock_kernel(); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 949 | inode = udf_new_inode(dir, S_IFLNK, &err); |
| 950 | if (!inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | goto out; |
| 952 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 953 | iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | inode->i_mode = S_IFLNK | S_IRWXUGO; |
| 955 | inode->i_data.a_ops = &udf_symlink_aops; |
| 956 | inode->i_op = &page_symlink_inode_operations; |
| 957 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 958 | if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 959 | kernel_lb_addr eloc; |
| 960 | uint32_t elen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | block = udf_new_block(inode->i_sb, inode, |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 963 | iinfo->i_location.partitionReferenceNum, |
| 964 | iinfo->i_location.logicalBlockNum, &err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | if (!block) |
| 966 | goto out_no_entry; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 967 | epos.block = iinfo->i_location; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 968 | epos.offset = udf_file_entry_alloc_offset(inode); |
| 969 | epos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | eloc.logicalBlockNum = block; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 971 | eloc.partitionReferenceNum = |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 972 | iinfo->i_location.partitionReferenceNum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | elen = inode->i_sb->s_blocksize; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 974 | iinfo->i_lenExtents = elen; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 975 | udf_add_aext(inode, &epos, eloc, elen, 0); |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 976 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | block = udf_get_pblock(inode->i_sb, block, |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 979 | iinfo->i_location.partitionReferenceNum, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 980 | 0); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 981 | epos.bh = udf_tread(inode->i_sb, block); |
| 982 | lock_buffer(epos.bh); |
| 983 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); |
| 984 | set_buffer_uptodate(epos.bh); |
| 985 | unlock_buffer(epos.bh); |
| 986 | mark_buffer_dirty_inode(epos.bh, inode); |
| 987 | ea = epos.bh->b_data + udf_ext0_offset(inode); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 988 | } else |
| 989 | ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
| 991 | eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); |
| 992 | pc = (struct pathComponent *)ea; |
| 993 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 994 | if (*symname == '/') { |
| 995 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | symname++; |
| 997 | } while (*symname == '/'); |
| 998 | |
| 999 | pc->componentType = 1; |
| 1000 | pc->lengthComponentIdent = 0; |
| 1001 | pc->componentFileVersionNum = 0; |
| 1002 | pc += sizeof(struct pathComponent); |
| 1003 | elen += sizeof(struct pathComponent); |
| 1004 | } |
| 1005 | |
| 1006 | err = -ENAMETOOLONG; |
| 1007 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1008 | while (*symname) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | if (elen + sizeof(struct pathComponent) > eoffset) |
| 1010 | goto out_no_entry; |
| 1011 | |
| 1012 | pc = (struct pathComponent *)(ea + elen); |
| 1013 | |
| 1014 | compstart = (char *)symname; |
| 1015 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1016 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | symname++; |
| 1018 | } while (*symname && *symname != '/'); |
| 1019 | |
| 1020 | pc->componentType = 5; |
| 1021 | pc->lengthComponentIdent = 0; |
| 1022 | pc->componentFileVersionNum = 0; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1023 | if (compstart[0] == '.') { |
| 1024 | if ((symname - compstart) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | pc->componentType = 4; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1026 | else if ((symname - compstart) == 2 && |
| 1027 | compstart[1] == '.') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | pc->componentType = 3; |
| 1029 | } |
| 1030 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1031 | if (pc->componentType == 5) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1032 | namelen = udf_put_filename(inode->i_sb, compstart, name, |
| 1033 | symname - compstart); |
| 1034 | if (!namelen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | goto out_no_entry; |
| 1036 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1037 | if (elen + sizeof(struct pathComponent) + namelen > |
| 1038 | eoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | goto out_no_entry; |
| 1040 | else |
| 1041 | pc->lengthComponentIdent = namelen; |
| 1042 | |
| 1043 | memcpy(pc->componentIdent, name, namelen); |
| 1044 | } |
| 1045 | |
| 1046 | elen += sizeof(struct pathComponent) + pc->lengthComponentIdent; |
| 1047 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1048 | if (*symname) { |
| 1049 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | symname++; |
| 1051 | } while (*symname == '/'); |
| 1052 | } |
| 1053 | } |
| 1054 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1055 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | inode->i_size = elen; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1057 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
| 1058 | iinfo->i_lenAlloc = inode->i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | mark_inode_dirty(inode); |
| 1060 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1061 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 1062 | if (!fi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | goto out_no_entry; |
| 1064 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1065 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1066 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
| 1067 | if (bh) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1068 | struct logicalVolIntegrityDesc *lvid = |
| 1069 | (struct logicalVolIntegrityDesc *)bh->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | struct logicalVolHeaderDesc *lvhd; |
| 1071 | uint64_t uniqueID; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1072 | lvhd = (struct logicalVolHeaderDesc *) |
| 1073 | lvid->logicalVolContentsUse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1075 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 1076 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
| 1078 | uniqueID += 16; |
| 1079 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1080 | mark_buffer_dirty(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | } |
| 1082 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1083 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | mark_inode_dirty(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1086 | brelse(fibh.ebh); |
| 1087 | brelse(fibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | d_instantiate(dentry, inode); |
| 1089 | err = 0; |
| 1090 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1091 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | unlock_kernel(); |
| 1093 | return err; |
| 1094 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1095 | out_no_entry: |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1096 | inode_dec_link_count(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | iput(inode); |
| 1098 | goto out; |
| 1099 | } |
| 1100 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1101 | static int udf_link(struct dentry *old_dentry, struct inode *dir, |
| 1102 | struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | { |
| 1104 | struct inode *inode = old_dentry->d_inode; |
| 1105 | struct udf_fileident_bh fibh; |
| 1106 | struct fileIdentDesc cfi, *fi; |
| 1107 | int err; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1108 | struct buffer_head *bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
| 1110 | lock_kernel(); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1111 | if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | unlock_kernel(); |
| 1113 | return -EMLINK; |
| 1114 | } |
| 1115 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1116 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
| 1117 | if (!fi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | unlock_kernel(); |
| 1119 | return err; |
| 1120 | } |
| 1121 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1122 | cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1123 | bh = UDF_SB(inode->i_sb)->s_lvid_bh; |
| 1124 | if (bh) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1125 | struct logicalVolIntegrityDesc *lvid = |
| 1126 | (struct logicalVolIntegrityDesc *)bh->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | struct logicalVolHeaderDesc *lvhd; |
| 1128 | uint64_t uniqueID; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1129 | lvhd = (struct logicalVolHeaderDesc *) |
| 1130 | (lvid->logicalVolContentsUse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1132 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
| 1133 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
| 1135 | uniqueID += 16; |
| 1136 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1137 | mark_buffer_dirty(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | } |
| 1139 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1140 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | mark_inode_dirty(dir); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | if (fibh.sbh != fibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1144 | brelse(fibh.ebh); |
| 1145 | brelse(fibh.sbh); |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1146 | inc_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | inode->i_ctime = current_fs_time(inode->i_sb); |
| 1148 | mark_inode_dirty(inode); |
| 1149 | atomic_inc(&inode->i_count); |
| 1150 | d_instantiate(dentry, inode); |
| 1151 | unlock_kernel(); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | /* Anybody can rename anything with this: the permission checks are left to the |
| 1157 | * higher-level routines. |
| 1158 | */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1159 | static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 1160 | struct inode *new_dir, struct dentry *new_dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1162 | struct inode *old_inode = old_dentry->d_inode; |
| 1163 | struct inode *new_inode = new_dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | struct udf_fileident_bh ofibh, nfibh; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1165 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL; |
| 1166 | struct fileIdentDesc ocfi, ncfi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | struct buffer_head *dir_bh = NULL; |
| 1168 | int retval = -ENOENT; |
| 1169 | kernel_lb_addr tloc; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1170 | struct udf_inode_info *old_iinfo = UDF_I(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
| 1172 | lock_kernel(); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1173 | ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); |
| 1174 | if (ofi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | if (ofibh.sbh != ofibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1176 | brelse(ofibh.ebh); |
| 1177 | brelse(ofibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | tloc = lelb_to_cpu(ocfi.icb.extLocation); |
| 1180 | if (!ofi || udf_get_lb_pblock(old_dir->i_sb, tloc, 0) |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1181 | != old_inode->i_ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | goto end_rename; |
| 1183 | |
| 1184 | nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1185 | if (nfi) { |
| 1186 | if (!new_inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | if (nfibh.sbh != nfibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1188 | brelse(nfibh.ebh); |
| 1189 | brelse(nfibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | nfi = NULL; |
| 1191 | } |
| 1192 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1193 | if (S_ISDIR(old_inode->i_mode)) { |
Marcin Slusarz | 7f3fbd0 | 2008-02-08 04:20:49 -0800 | [diff] [blame] | 1194 | int offset = udf_ext0_offset(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1196 | if (new_inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | retval = -ENOTEMPTY; |
| 1198 | if (!empty_dir(new_inode)) |
| 1199 | goto end_rename; |
| 1200 | } |
| 1201 | retval = -EIO; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1202 | if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1203 | dir_fi = udf_get_fileident( |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1204 | old_iinfo->i_ext.i_data - |
| 1205 | (old_iinfo->i_efe ? |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1206 | sizeof(struct extendedFileEntry) : |
| 1207 | sizeof(struct fileEntry)), |
| 1208 | old_inode->i_sb->s_blocksize, &offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1209 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | dir_bh = udf_bread(old_inode, 0, 0, &retval); |
| 1211 | if (!dir_bh) |
| 1212 | goto end_rename; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1213 | dir_fi = udf_get_fileident(dir_bh->b_data, |
| 1214 | old_inode->i_sb->s_blocksize, &offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | } |
| 1216 | if (!dir_fi) |
| 1217 | goto end_rename; |
| 1218 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1219 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != |
| 1220 | old_dir->i_ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | goto end_rename; |
| 1222 | |
| 1223 | retval = -EMLINK; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1224 | if (!new_inode && |
| 1225 | new_dir->i_nlink >= |
| 1226 | (256 << sizeof(new_dir->i_nlink)) - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | goto end_rename; |
| 1228 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1229 | if (!nfi) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1230 | nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, |
| 1231 | &retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | if (!nfi) |
| 1233 | goto end_rename; |
| 1234 | } |
| 1235 | |
| 1236 | /* |
| 1237 | * Like most other Unix systems, set the ctime for inodes on a |
| 1238 | * rename. |
| 1239 | */ |
| 1240 | old_inode->i_ctime = current_fs_time(old_inode->i_sb); |
| 1241 | mark_inode_dirty(old_inode); |
| 1242 | |
| 1243 | /* |
| 1244 | * ok, that's it |
| 1245 | */ |
| 1246 | ncfi.fileVersionNum = ocfi.fileVersionNum; |
| 1247 | ncfi.fileCharacteristics = ocfi.fileCharacteristics; |
| 1248 | memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(long_ad)); |
| 1249 | udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL); |
| 1250 | |
| 1251 | /* The old fid may have moved - find it again */ |
| 1252 | ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); |
| 1253 | udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); |
| 1254 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1255 | if (new_inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | new_inode->i_ctime = current_fs_time(new_inode->i_sb); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1257 | inode_dec_link_count(new_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | } |
| 1259 | old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb); |
| 1260 | mark_inode_dirty(old_dir); |
| 1261 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1262 | if (dir_fi) { |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 1263 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1264 | udf_update_tag((char *)dir_fi, |
| 1265 | (sizeof(struct fileIdentDesc) + |
| 1266 | le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 1267 | if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | mark_inode_dirty(old_inode); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1269 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | mark_buffer_dirty_inode(dir_bh, old_inode); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1271 | |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1272 | inode_dec_link_count(old_dir); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1273 | if (new_inode) |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1274 | inode_dec_link_count(new_inode); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1275 | else { |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1276 | inc_nlink(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | mark_inode_dirty(new_dir); |
| 1278 | } |
| 1279 | } |
| 1280 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1281 | if (ofi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | if (ofibh.sbh != ofibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1283 | brelse(ofibh.ebh); |
| 1284 | brelse(ofibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | retval = 0; |
| 1288 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1289 | end_rename: |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1290 | brelse(dir_bh); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1291 | if (nfi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | if (nfibh.sbh != nfibh.ebh) |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1293 | brelse(nfibh.ebh); |
| 1294 | brelse(nfibh.sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | } |
| 1296 | unlock_kernel(); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | return retval; |
| 1299 | } |
| 1300 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1301 | const struct inode_operations udf_dir_inode_operations = { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1302 | .lookup = udf_lookup, |
| 1303 | .create = udf_create, |
| 1304 | .link = udf_link, |
| 1305 | .unlink = udf_unlink, |
| 1306 | .symlink = udf_symlink, |
| 1307 | .mkdir = udf_mkdir, |
| 1308 | .rmdir = udf_rmdir, |
| 1309 | .mknod = udf_mknod, |
| 1310 | .rename = udf_rename, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | }; |