diff options
Diffstat (limited to 'fs/udf/namei.c')
-rw-r--r-- | fs/udf/namei.c | 410 |
1 files changed, 181 insertions, 229 deletions
diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 334d363a0903..bec96a6b3343 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c | |||
@@ -37,6 +37,7 @@ static inline int udf_match(int len1, const char *name1, int len2, | |||
37 | { | 37 | { |
38 | if (len1 != len2) | 38 | if (len1 != len2) |
39 | return 0; | 39 | return 0; |
40 | |||
40 | return !memcmp(name1, name2, len1); | 41 | return !memcmp(name1, name2, len1); |
41 | } | 42 | } |
42 | 43 | ||
@@ -52,7 +53,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
52 | uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); | 53 | uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse); |
53 | uint8_t lfi = cfi->lengthFileIdent; | 54 | uint8_t lfi = cfi->lengthFileIdent; |
54 | int padlen = fibh->eoffset - fibh->soffset - liu - lfi - | 55 | int padlen = fibh->eoffset - fibh->soffset - liu - lfi - |
55 | sizeof(struct fileIdentDesc); | 56 | sizeof(struct fileIdentDesc); |
56 | int adinicb = 0; | 57 | int adinicb = 0; |
57 | 58 | ||
58 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) | 59 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) |
@@ -61,85 +62,75 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, | |||
61 | offset = fibh->soffset + sizeof(struct fileIdentDesc); | 62 | offset = fibh->soffset + sizeof(struct fileIdentDesc); |
62 | 63 | ||
63 | if (impuse) { | 64 | if (impuse) { |
64 | if (adinicb || (offset + liu < 0)) | 65 | if (adinicb || (offset + liu < 0)) { |
65 | memcpy((uint8_t *) sfi->impUse, impuse, liu); | 66 | memcpy((uint8_t *)sfi->impUse, impuse, liu); |
66 | else if (offset >= 0) | 67 | } else if (offset >= 0) { |
67 | memcpy(fibh->ebh->b_data + offset, impuse, liu); | 68 | memcpy(fibh->ebh->b_data + offset, impuse, liu); |
68 | else { | 69 | } else { |
69 | memcpy((uint8_t *) sfi->impUse, impuse, -offset); | 70 | memcpy((uint8_t *)sfi->impUse, impuse, -offset); |
70 | memcpy(fibh->ebh->b_data, impuse - offset, | 71 | memcpy(fibh->ebh->b_data, impuse - offset, liu + offset); |
71 | liu + offset); | ||
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | offset += liu; | 75 | offset += liu; |
76 | 76 | ||
77 | if (fileident) { | 77 | if (fileident) { |
78 | if (adinicb || (offset + lfi < 0)) | 78 | if (adinicb || (offset + lfi < 0)) { |
79 | memcpy((uint8_t *) sfi->fileIdent + liu, fileident, | 79 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi); |
80 | lfi); | 80 | } else if (offset >= 0) { |
81 | else if (offset >= 0) | ||
82 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); | 81 | memcpy(fibh->ebh->b_data + offset, fileident, lfi); |
83 | else { | 82 | } else { |
84 | memcpy((uint8_t *) sfi->fileIdent + liu, fileident, | 83 | memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset); |
85 | -offset); | 84 | memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset); |
86 | memcpy(fibh->ebh->b_data, fileident - offset, | ||
87 | lfi + offset); | ||
88 | } | 85 | } |
89 | } | 86 | } |
90 | 87 | ||
91 | offset += lfi; | 88 | offset += lfi; |
92 | 89 | ||
93 | if (adinicb || (offset + padlen < 0)) | 90 | if (adinicb || (offset + padlen < 0)) { |
94 | memset((uint8_t *) sfi->padding + liu + lfi, 0x00, padlen); | 91 | memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen); |
95 | else if (offset >= 0) | 92 | } else if (offset >= 0) { |
96 | memset(fibh->ebh->b_data + offset, 0x00, padlen); | 93 | memset(fibh->ebh->b_data + offset, 0x00, padlen); |
97 | else { | 94 | } else { |
98 | memset((uint8_t *) sfi->padding + liu + lfi, 0x00, -offset); | 95 | memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset); |
99 | memset(fibh->ebh->b_data, 0x00, padlen + offset); | 96 | memset(fibh->ebh->b_data, 0x00, padlen + offset); |
100 | } | 97 | } |
101 | 98 | ||
102 | crc = | 99 | crc = udf_crc((uint8_t *)cfi + sizeof(tag), |
103 | udf_crc((uint8_t *) cfi + sizeof(tag), | 100 | sizeof(struct fileIdentDesc) - sizeof(tag), 0); |
104 | sizeof(struct fileIdentDesc) - sizeof(tag), 0); | 101 | |
105 | 102 | if (fibh->sbh == fibh->ebh) { | |
106 | if (fibh->sbh == fibh->ebh) | 103 | crc = udf_crc((uint8_t *)sfi->impUse, |
107 | crc = udf_crc((uint8_t *) sfi->impUse, | 104 | crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); |
108 | crclen + sizeof(tag) - | 105 | } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { |
109 | sizeof(struct fileIdentDesc), crc); | 106 | crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset, |
110 | else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) | 107 | crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc); |
111 | crc = | 108 | } else { |
112 | udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + | 109 | crc = udf_crc((uint8_t *)sfi->impUse, |
113 | fibh->soffset, | 110 | -fibh->soffset - sizeof(struct fileIdentDesc), crc); |
114 | crclen + sizeof(tag) - sizeof(struct fileIdentDesc), | ||
115 | crc); | ||
116 | else { | ||
117 | crc = udf_crc((uint8_t *) sfi->impUse, | ||
118 | -fibh->soffset - sizeof(struct fileIdentDesc), | ||
119 | crc); | ||
120 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); | 111 | crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); |
121 | } | 112 | } |
122 | 113 | ||
123 | cfi->descTag.descCRC = cpu_to_le16(crc); | 114 | cfi->descTag.descCRC = cpu_to_le16(crc); |
124 | cfi->descTag.descCRCLength = cpu_to_le16(crclen); | 115 | cfi->descTag.descCRCLength = cpu_to_le16(crclen); |
125 | 116 | ||
126 | for (i = 0; i < 16; i++) | 117 | for (i = 0; i < 16; i++) { |
127 | if (i != 4) | 118 | if (i != 4) |
128 | checksum += ((uint8_t *) & cfi->descTag)[i]; | 119 | checksum += ((uint8_t *)&cfi->descTag)[i]; |
120 | } | ||
129 | 121 | ||
130 | cfi->descTag.tagChecksum = checksum; | 122 | cfi->descTag.tagChecksum = checksum; |
131 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) | 123 | if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) { |
132 | memcpy((uint8_t *) sfi, (uint8_t *) cfi, | 124 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc)); |
133 | sizeof(struct fileIdentDesc)); | 125 | } else { |
134 | else { | 126 | memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset); |
135 | memcpy((uint8_t *) sfi, (uint8_t *) cfi, -fibh->soffset); | 127 | memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset, |
136 | memcpy(fibh->ebh->b_data, (uint8_t *) cfi - fibh->soffset, | ||
137 | sizeof(struct fileIdentDesc) + fibh->soffset); | 128 | sizeof(struct fileIdentDesc) + fibh->soffset); |
138 | } | 129 | } |
139 | 130 | ||
140 | if (adinicb) | 131 | if (adinicb) { |
141 | mark_inode_dirty(inode); | 132 | mark_inode_dirty(inode); |
142 | else { | 133 | } else { |
143 | if (fibh->sbh != fibh->ebh) | 134 | if (fibh->sbh != fibh->ebh) |
144 | mark_buffer_dirty_inode(fibh->ebh, inode); | 135 | mark_buffer_dirty_inode(fibh->ebh, inode); |
145 | mark_buffer_dirty_inode(fibh->sbh, inode); | 136 | mark_buffer_dirty_inode(fibh->sbh, inode); |
@@ -163,26 +154,25 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
163 | kernel_lb_addr eloc; | 154 | kernel_lb_addr eloc; |
164 | uint32_t elen; | 155 | uint32_t elen; |
165 | sector_t offset; | 156 | sector_t offset; |
166 | struct extent_position epos = { NULL, 0, {0, 0} }; | 157 | struct extent_position epos = {}; |
167 | 158 | ||
168 | size = (udf_ext0_offset(dir) + dir->i_size) >> 2; | 159 | size = (udf_ext0_offset(dir) + dir->i_size) >> 2; |
169 | f_pos = (udf_ext0_offset(dir) >> 2); | 160 | f_pos = (udf_ext0_offset(dir) >> 2); |
170 | 161 | ||
171 | fibh->soffset = fibh->eoffset = | 162 | fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
172 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 163 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
173 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) | ||
174 | fibh->sbh = fibh->ebh = NULL; | 164 | fibh->sbh = fibh->ebh = NULL; |
175 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 165 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
176 | &epos, &eloc, &elen, | 166 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { |
177 | &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | ||
178 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 167 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
179 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 168 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
180 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 169 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
181 | epos.offset -= sizeof(short_ad); | 170 | epos.offset -= sizeof(short_ad); |
182 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 171 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) |
183 | epos.offset -= sizeof(long_ad); | 172 | epos.offset -= sizeof(long_ad); |
184 | } else | 173 | } else { |
185 | offset = 0; | 174 | offset = 0; |
175 | } | ||
186 | 176 | ||
187 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { | 177 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { |
188 | brelse(epos.bh); | 178 | brelse(epos.bh); |
@@ -196,7 +186,6 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
196 | while ((f_pos < size)) { | 186 | while ((f_pos < size)) { |
197 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, | 187 | fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, |
198 | &elen, &offset); | 188 | &elen, &offset); |
199 | |||
200 | if (!fi) { | 189 | if (!fi) { |
201 | if (fibh->sbh != fibh->ebh) | 190 | if (fibh->sbh != fibh->ebh) |
202 | brelse(fibh->ebh); | 191 | brelse(fibh->ebh); |
@@ -213,20 +202,14 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
213 | } else { | 202 | } else { |
214 | int poffset; /* Unpaded ending offset */ | 203 | int poffset; /* Unpaded ending offset */ |
215 | 204 | ||
216 | poffset = | 205 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; |
217 | fibh->soffset + sizeof(struct fileIdentDesc) + liu + | ||
218 | lfi; | ||
219 | 206 | ||
220 | if (poffset >= lfi) | 207 | if (poffset >= lfi) { |
221 | nameptr = | 208 | nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi); |
222 | (uint8_t *) (fibh->ebh->b_data + poffset - | 209 | } else { |
223 | lfi); | ||
224 | else { | ||
225 | nameptr = fname; | 210 | nameptr = fname; |
226 | memcpy(nameptr, fi->fileIdent + liu, | 211 | memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); |
227 | lfi - poffset); | 212 | memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); |
228 | memcpy(nameptr + lfi - poffset, | ||
229 | fibh->ebh->b_data, poffset); | ||
230 | } | 213 | } |
231 | } | 214 | } |
232 | 215 | ||
@@ -244,18 +227,18 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, | |||
244 | continue; | 227 | continue; |
245 | 228 | ||
246 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) { | 229 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) { |
247 | if (udf_match | 230 | if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { |
248 | (flen, fname, dentry->d_name.len, | ||
249 | dentry->d_name.name)) { | ||
250 | brelse(epos.bh); | 231 | brelse(epos.bh); |
251 | return fi; | 232 | return fi; |
252 | } | 233 | } |
253 | } | 234 | } |
254 | } | 235 | } |
236 | |||
255 | if (fibh->sbh != fibh->ebh) | 237 | if (fibh->sbh != fibh->ebh) |
256 | brelse(fibh->ebh); | 238 | brelse(fibh->ebh); |
257 | brelse(fibh->sbh); | 239 | brelse(fibh->sbh); |
258 | brelse(epos.bh); | 240 | brelse(epos.bh); |
241 | |||
259 | return NULL; | 242 | return NULL; |
260 | } | 243 | } |
261 | 244 | ||
@@ -306,15 +289,19 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, | |||
306 | #ifdef UDF_RECOVERY | 289 | #ifdef UDF_RECOVERY |
307 | /* temporary shorthand for specifying files by inode number */ | 290 | /* temporary shorthand for specifying files by inode number */ |
308 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { | 291 | if (!strncmp(dentry->d_name.name, ".B=", 3)) { |
309 | kernel_lb_addr lb = | 292 | kernel_lb_addr lb = { |
310 | { 0, simple_strtoul(dentry->d_name.name + 3, NULL, 0) }; | 293 | .logicalBlockNum = 0, |
294 | .partitionReferenceNum = simple_strtoul(dentry->d_name.name + 3, | ||
295 | NULL, 0), | ||
296 | }; | ||
311 | inode = udf_iget(dir->i_sb, lb); | 297 | inode = udf_iget(dir->i_sb, lb); |
312 | if (!inode) { | 298 | if (!inode) { |
313 | unlock_kernel(); | 299 | unlock_kernel(); |
314 | return ERR_PTR(-EACCES); | 300 | return ERR_PTR(-EACCES); |
315 | } | 301 | } |
316 | } else | 302 | } |
317 | #endif /* UDF_RECOVERY */ | 303 | else |
304 | #endif /* UDF_RECOVERY */ | ||
318 | 305 | ||
319 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { | 306 | if (udf_find_entry(dir, dentry, &fibh, &cfi)) { |
320 | if (fibh.sbh != fibh.ebh) | 307 | if (fibh.sbh != fibh.ebh) |
@@ -329,6 +316,7 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, | |||
329 | } | 316 | } |
330 | unlock_kernel(); | 317 | unlock_kernel(); |
331 | d_add(dentry, inode); | 318 | d_add(dentry, inode); |
319 | |||
332 | return NULL; | 320 | return NULL; |
333 | } | 321 | } |
334 | 322 | ||
@@ -352,7 +340,7 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
352 | kernel_lb_addr eloc; | 340 | kernel_lb_addr eloc; |
353 | uint32_t elen; | 341 | uint32_t elen; |
354 | sector_t offset; | 342 | sector_t offset; |
355 | struct extent_position epos = { NULL, 0, {0, 0} }; | 343 | struct extent_position epos = {}; |
356 | 344 | ||
357 | sb = dir->i_sb; | 345 | sb = dir->i_sb; |
358 | 346 | ||
@@ -361,36 +349,33 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
361 | *err = -EINVAL; | 349 | *err = -EINVAL; |
362 | return NULL; | 350 | return NULL; |
363 | } | 351 | } |
364 | 352 | if (!(namelen = udf_put_filename(sb, dentry->d_name.name, name, | |
365 | if (! | 353 | dentry->d_name.len))) { |
366 | (namelen = | ||
367 | udf_put_filename(sb, dentry->d_name.name, name, | ||
368 | dentry->d_name.len))) { | ||
369 | *err = -ENAMETOOLONG; | 354 | *err = -ENAMETOOLONG; |
370 | return NULL; | 355 | return NULL; |
371 | } | 356 | } |
372 | } else | 357 | } else { |
373 | namelen = 0; | 358 | namelen = 0; |
359 | } | ||
374 | 360 | ||
375 | nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; | 361 | nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; |
376 | 362 | ||
377 | f_pos = (udf_ext0_offset(dir) >> 2); | 363 | f_pos = (udf_ext0_offset(dir) >> 2); |
378 | 364 | ||
379 | fibh->soffset = fibh->eoffset = | 365 | fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
380 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | 366 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
381 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) | ||
382 | fibh->sbh = fibh->ebh = NULL; | 367 | fibh->sbh = fibh->ebh = NULL; |
383 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 368 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
384 | &epos, &eloc, &elen, | 369 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { |
385 | &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | ||
386 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 370 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
387 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 371 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
388 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 372 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
389 | epos.offset -= sizeof(short_ad); | 373 | epos.offset -= sizeof(short_ad); |
390 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 374 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) |
391 | epos.offset -= sizeof(long_ad); | 375 | epos.offset -= sizeof(long_ad); |
392 | } else | 376 | } else { |
393 | offset = 0; | 377 | offset = 0; |
378 | } | ||
394 | 379 | ||
395 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { | 380 | if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) { |
396 | brelse(epos.bh); | 381 | brelse(epos.bh); |
@@ -423,40 +408,33 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
423 | liu = le16_to_cpu(cfi->lengthOfImpUse); | 408 | liu = le16_to_cpu(cfi->lengthOfImpUse); |
424 | lfi = cfi->lengthFileIdent; | 409 | lfi = cfi->lengthFileIdent; |
425 | 410 | ||
426 | if (fibh->sbh == fibh->ebh) | 411 | if (fibh->sbh == fibh->ebh) { |
427 | nameptr = fi->fileIdent + liu; | 412 | nameptr = fi->fileIdent + liu; |
428 | else { | 413 | } else { |
429 | int poffset; /* Unpaded ending offset */ | 414 | int poffset; /* Unpaded ending offset */ |
430 | 415 | ||
431 | poffset = | 416 | poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi; |
432 | fibh->soffset + sizeof(struct fileIdentDesc) + liu + | ||
433 | lfi; | ||
434 | 417 | ||
435 | if (poffset >= lfi) | 418 | if (poffset >= lfi) { |
436 | nameptr = | 419 | nameptr = (char *)(fibh->ebh->b_data + poffset - lfi); |
437 | (char *)(fibh->ebh->b_data + poffset - lfi); | 420 | } else { |
438 | else { | ||
439 | nameptr = fname; | 421 | nameptr = fname; |
440 | memcpy(nameptr, fi->fileIdent + liu, | 422 | memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); |
441 | lfi - poffset); | 423 | memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset); |
442 | memcpy(nameptr + lfi - poffset, | ||
443 | fibh->ebh->b_data, poffset); | ||
444 | } | 424 | } |
445 | } | 425 | } |
446 | 426 | ||
447 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { | 427 | if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
448 | if (((sizeof(struct fileIdentDesc) + liu + lfi + | 428 | if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) { |
449 | 3) & ~3) == nfidlen) { | ||
450 | brelse(epos.bh); | 429 | brelse(epos.bh); |
451 | cfi->descTag.tagSerialNum = cpu_to_le16(1); | 430 | cfi->descTag.tagSerialNum = cpu_to_le16(1); |
452 | cfi->fileVersionNum = cpu_to_le16(1); | 431 | cfi->fileVersionNum = cpu_to_le16(1); |
453 | cfi->fileCharacteristics = 0; | 432 | cfi->fileCharacteristics = 0; |
454 | cfi->lengthFileIdent = namelen; | 433 | cfi->lengthFileIdent = namelen; |
455 | cfi->lengthOfImpUse = cpu_to_le16(0); | 434 | cfi->lengthOfImpUse = cpu_to_le16(0); |
456 | if (!udf_write_fi | 435 | if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { |
457 | (dir, cfi, fi, fibh, NULL, name)) | ||
458 | return fi; | 436 | return fi; |
459 | else { | 437 | } else { |
460 | *err = -EIO; | 438 | *err = -EIO; |
461 | return NULL; | 439 | return NULL; |
462 | } | 440 | } |
@@ -467,8 +445,7 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
467 | continue; | 445 | continue; |
468 | 446 | ||
469 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && | 447 | if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) && |
470 | udf_match(flen, fname, dentry->d_name.len, | 448 | udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) { |
471 | dentry->d_name.name)) { | ||
472 | if (fibh->sbh != fibh->ebh) | 449 | if (fibh->sbh != fibh->ebh) |
473 | brelse(fibh->ebh); | 450 | brelse(fibh->ebh); |
474 | brelse(fibh->sbh); | 451 | brelse(fibh->sbh); |
@@ -478,7 +455,7 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
478 | } | 455 | } |
479 | } | 456 | } |
480 | 457 | ||
481 | add: | 458 | add: |
482 | f_pos += nfidlen; | 459 | f_pos += nfidlen; |
483 | 460 | ||
484 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB && | 461 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB && |
@@ -491,14 +468,11 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
491 | if (fibh->sbh != fibh->ebh) | 468 | if (fibh->sbh != fibh->ebh) |
492 | brelse(fibh->ebh); | 469 | brelse(fibh->ebh); |
493 | brelse(fibh->sbh); | 470 | brelse(fibh->sbh); |
494 | if (! | 471 | if (!(fibh->sbh = fibh->ebh = udf_expand_dir_adinicb(dir, &block, err))) |
495 | (fibh->sbh = fibh->ebh = | ||
496 | udf_expand_dir_adinicb(dir, &block, err))) | ||
497 | return NULL; | 472 | return NULL; |
498 | epos.block = UDF_I_LOCATION(dir); | 473 | epos.block = UDF_I_LOCATION(dir); |
499 | eloc.logicalBlockNum = block; | 474 | eloc.logicalBlockNum = block; |
500 | eloc.partitionReferenceNum = | 475 | eloc.partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum; |
501 | UDF_I_LOCATION(dir).partitionReferenceNum; | ||
502 | elen = dir->i_sb->s_blocksize; | 476 | elen = dir->i_sb->s_blocksize; |
503 | epos.offset = udf_file_entry_alloc_offset(dir); | 477 | epos.offset = udf_file_entry_alloc_offset(dir); |
504 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 478 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
@@ -517,16 +491,13 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
517 | 491 | ||
518 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 492 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
519 | block = UDF_I_LOCATION(dir).logicalBlockNum; | 493 | block = UDF_I_LOCATION(dir).logicalBlockNum; |
520 | fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + | 494 | fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset - |
521 | fibh->soffset - | ||
522 | udf_ext0_offset(dir) + | 495 | udf_ext0_offset(dir) + |
523 | UDF_I_LENEATTR(dir)); | 496 | UDF_I_LENEATTR(dir)); |
524 | } else { | 497 | } else { |
525 | block = eloc.logicalBlockNum + ((elen - 1) >> | 498 | block = eloc.logicalBlockNum + ((elen - 1) >> |
526 | dir->i_sb-> | 499 | dir->i_sb->s_blocksize_bits); |
527 | s_blocksize_bits); | 500 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset); |
528 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data + | ||
529 | fibh->soffset); | ||
530 | } | 501 | } |
531 | } else { | 502 | } else { |
532 | fibh->soffset = fibh->eoffset - sb->s_blocksize; | 503 | fibh->soffset = fibh->eoffset - sb->s_blocksize; |
@@ -538,42 +509,36 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir, | |||
538 | 509 | ||
539 | block = eloc.logicalBlockNum + ((elen - 1) >> | 510 | block = eloc.logicalBlockNum + ((elen - 1) >> |
540 | dir->i_sb->s_blocksize_bits); | 511 | dir->i_sb->s_blocksize_bits); |
541 | 512 | fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err); | |
542 | if (! | 513 | if (!fibh->ebh) { |
543 | (fibh->ebh = | ||
544 | udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | ||
545 | 1, err))) { | ||
546 | brelse(epos.bh); | 514 | brelse(epos.bh); |
547 | brelse(fibh->sbh); | 515 | brelse(fibh->sbh); |
548 | return NULL; | 516 | return NULL; |
549 | } | 517 | } |
550 | 518 | ||
551 | if (!(fibh->soffset)) { | 519 | if (!fibh->soffset) { |
552 | if (udf_next_aext(dir, &epos, &eloc, &elen, 1) == | 520 | if (udf_next_aext(dir, &epos, &eloc, &elen, 1) == |
553 | (EXT_RECORDED_ALLOCATED >> 30)) { | 521 | (EXT_RECORDED_ALLOCATED >> 30)) { |
554 | block = eloc.logicalBlockNum + ((elen - 1) >> | 522 | block = eloc.logicalBlockNum + ((elen - 1) >> |
555 | dir->i_sb-> | 523 | dir->i_sb->s_blocksize_bits); |
556 | s_blocksize_bits); | 524 | } else { |
557 | } else | ||
558 | block++; | 525 | block++; |
526 | } | ||
559 | 527 | ||
560 | brelse(fibh->sbh); | 528 | brelse(fibh->sbh); |
561 | fibh->sbh = fibh->ebh; | 529 | fibh->sbh = fibh->ebh; |
562 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); | 530 | fi = (struct fileIdentDesc *)(fibh->sbh->b_data); |
563 | } else { | 531 | } else { |
564 | fi = (struct fileIdentDesc *) | 532 | fi = (struct fileIdentDesc *) |
565 | (fibh->sbh->b_data + sb->s_blocksize + | 533 | (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset); |
566 | fibh->soffset); | ||
567 | } | 534 | } |
568 | } | 535 | } |
569 | 536 | ||
570 | memset(cfi, 0, sizeof(struct fileIdentDesc)); | 537 | memset(cfi, 0, sizeof(struct fileIdentDesc)); |
571 | if (UDF_SB_UDFREV(sb) >= 0x0200) | 538 | if (UDF_SB_UDFREV(sb) >= 0x0200) |
572 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, | 539 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, sizeof(tag)); |
573 | sizeof(tag)); | ||
574 | else | 540 | else |
575 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, | 541 | udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, sizeof(tag)); |
576 | sizeof(tag)); | ||
577 | cfi->fileVersionNum = cpu_to_le16(1); | 542 | cfi->fileVersionNum = cpu_to_le16(1); |
578 | cfi->lengthFileIdent = namelen; | 543 | cfi->lengthFileIdent = namelen; |
579 | cfi->lengthOfImpUse = cpu_to_le16(0); | 544 | cfi->lengthOfImpUse = cpu_to_le16(0); |
@@ -599,8 +564,10 @@ static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, | |||
599 | struct fileIdentDesc *cfi) | 564 | struct fileIdentDesc *cfi) |
600 | { | 565 | { |
601 | cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED; | 566 | cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED; |
567 | |||
602 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) | 568 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) |
603 | memset(&(cfi->icb), 0x00, sizeof(long_ad)); | 569 | memset(&(cfi->icb), 0x00, sizeof(long_ad)); |
570 | |||
604 | return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); | 571 | return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); |
605 | } | 572 | } |
606 | 573 | ||
@@ -637,8 +604,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
637 | } | 604 | } |
638 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 605 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
639 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 606 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); |
640 | *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 607 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
641 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 608 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); |
642 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 609 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
643 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 610 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
644 | mark_inode_dirty(dir); | 611 | mark_inode_dirty(dir); |
@@ -648,6 +615,7 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode, | |||
648 | brelse(fibh.sbh); | 615 | brelse(fibh.sbh); |
649 | unlock_kernel(); | 616 | unlock_kernel(); |
650 | d_instantiate(dentry, inode); | 617 | d_instantiate(dentry, inode); |
618 | |||
651 | return 0; | 619 | return 0; |
652 | } | 620 | } |
653 | 621 | ||
@@ -679,8 +647,8 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, | |||
679 | } | 647 | } |
680 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 648 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
681 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 649 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); |
682 | *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 650 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
683 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 651 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); |
684 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 652 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
685 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 653 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
686 | mark_inode_dirty(dir); | 654 | mark_inode_dirty(dir); |
@@ -692,7 +660,8 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode, | |||
692 | brelse(fibh.sbh); | 660 | brelse(fibh.sbh); |
693 | d_instantiate(dentry, inode); | 661 | d_instantiate(dentry, inode); |
694 | err = 0; | 662 | err = 0; |
695 | out: | 663 | |
664 | out: | ||
696 | unlock_kernel(); | 665 | unlock_kernel(); |
697 | return err; | 666 | return err; |
698 | } | 667 | } |
@@ -725,10 +694,9 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
725 | inode->i_nlink = 2; | 694 | inode->i_nlink = 2; |
726 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 695 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
727 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); | 696 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir)); |
728 | *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 697 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
729 | cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); | 698 | cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL); |
730 | cfi.fileCharacteristics = | 699 | cfi.fileCharacteristics = FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; |
731 | FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT; | ||
732 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); | 700 | udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL); |
733 | brelse(fibh.sbh); | 701 | brelse(fibh.sbh); |
734 | inode->i_mode = S_IFDIR | mode; | 702 | inode->i_mode = S_IFDIR | mode; |
@@ -744,8 +712,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
744 | } | 712 | } |
745 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | 713 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); |
746 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); | 714 | cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode)); |
747 | *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 715 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
748 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); | 716 | cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL); |
749 | cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; | 717 | cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY; |
750 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 718 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
751 | inc_nlink(dir); | 719 | inc_nlink(dir); |
@@ -755,7 +723,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
755 | brelse(fibh.ebh); | 723 | brelse(fibh.ebh); |
756 | brelse(fibh.sbh); | 724 | brelse(fibh.sbh); |
757 | err = 0; | 725 | err = 0; |
758 | out: | 726 | |
727 | out: | ||
759 | unlock_kernel(); | 728 | unlock_kernel(); |
760 | return err; | 729 | return err; |
761 | } | 730 | } |
@@ -770,26 +739,25 @@ static int empty_dir(struct inode *dir) | |||
770 | kernel_lb_addr eloc; | 739 | kernel_lb_addr eloc; |
771 | uint32_t elen; | 740 | uint32_t elen; |
772 | sector_t offset; | 741 | sector_t offset; |
773 | struct extent_position epos = { NULL, 0, {0, 0} }; | 742 | struct extent_position epos = {}; |
774 | 743 | ||
775 | f_pos = (udf_ext0_offset(dir) >> 2); | 744 | f_pos = (udf_ext0_offset(dir) >> 2); |
776 | 745 | ||
777 | fibh.soffset = fibh.eoffset = | 746 | fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; |
778 | (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; | ||
779 | 747 | ||
780 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) | 748 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
781 | fibh.sbh = fibh.ebh = NULL; | 749 | fibh.sbh = fibh.ebh = NULL; |
782 | else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), | 750 | } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), |
783 | &epos, &eloc, &elen, | 751 | &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { |
784 | &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { | ||
785 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); | 752 | block = udf_get_lb_pblock(dir->i_sb, eloc, offset); |
786 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { | 753 | if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { |
787 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) | 754 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) |
788 | epos.offset -= sizeof(short_ad); | 755 | epos.offset -= sizeof(short_ad); |
789 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) | 756 | else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) |
790 | epos.offset -= sizeof(long_ad); | 757 | epos.offset -= sizeof(long_ad); |
791 | } else | 758 | } else { |
792 | offset = 0; | 759 | offset = 0; |
760 | } | ||
793 | 761 | ||
794 | if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { | 762 | if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { |
795 | brelse(epos.bh); | 763 | brelse(epos.bh); |
@@ -803,7 +771,6 @@ static int empty_dir(struct inode *dir) | |||
803 | while ((f_pos < size)) { | 771 | while ((f_pos < size)) { |
804 | fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, | 772 | fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, |
805 | &elen, &offset); | 773 | &elen, &offset); |
806 | |||
807 | if (!fi) { | 774 | if (!fi) { |
808 | if (fibh.sbh != fibh.ebh) | 775 | if (fibh.sbh != fibh.ebh) |
809 | brelse(fibh.ebh); | 776 | brelse(fibh.ebh); |
@@ -812,8 +779,8 @@ static int empty_dir(struct inode *dir) | |||
812 | return 0; | 779 | return 0; |
813 | } | 780 | } |
814 | 781 | ||
815 | if (cfi.lengthFileIdent | 782 | if (cfi.lengthFileIdent && |
816 | && (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) { | 783 | (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) { |
817 | if (fibh.sbh != fibh.ebh) | 784 | if (fibh.sbh != fibh.ebh) |
818 | brelse(fibh.ebh); | 785 | brelse(fibh.ebh); |
819 | brelse(fibh.sbh); | 786 | brelse(fibh.sbh); |
@@ -821,10 +788,12 @@ static int empty_dir(struct inode *dir) | |||
821 | return 0; | 788 | return 0; |
822 | } | 789 | } |
823 | } | 790 | } |
791 | |||
824 | if (fibh.sbh != fibh.ebh) | 792 | if (fibh.sbh != fibh.ebh) |
825 | brelse(fibh.ebh); | 793 | brelse(fibh.ebh); |
826 | brelse(fibh.sbh); | 794 | brelse(fibh.sbh); |
827 | brelse(epos.bh); | 795 | brelse(epos.bh); |
796 | |||
828 | return 1; | 797 | return 1; |
829 | } | 798 | } |
830 | 799 | ||
@@ -859,15 +828,15 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry) | |||
859 | clear_nlink(inode); | 828 | clear_nlink(inode); |
860 | inode->i_size = 0; | 829 | inode->i_size = 0; |
861 | inode_dec_link_count(dir); | 830 | inode_dec_link_count(dir); |
862 | inode->i_ctime = dir->i_ctime = dir->i_mtime = | 831 | inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb); |
863 | current_fs_time(dir->i_sb); | ||
864 | mark_inode_dirty(dir); | 832 | mark_inode_dirty(dir); |
865 | 833 | ||
866 | end_rmdir: | 834 | end_rmdir: |
867 | if (fibh.sbh != fibh.ebh) | 835 | if (fibh.sbh != fibh.ebh) |
868 | brelse(fibh.ebh); | 836 | brelse(fibh.ebh); |
869 | brelse(fibh.sbh); | 837 | brelse(fibh.sbh); |
870 | out: | 838 | |
839 | out: | ||
871 | unlock_kernel(); | 840 | unlock_kernel(); |
872 | return retval; | 841 | return retval; |
873 | } | 842 | } |
@@ -906,11 +875,12 @@ static int udf_unlink(struct inode *dir, struct dentry *dentry) | |||
906 | inode->i_ctime = dir->i_ctime; | 875 | inode->i_ctime = dir->i_ctime; |
907 | retval = 0; | 876 | retval = 0; |
908 | 877 | ||
909 | end_unlink: | 878 | end_unlink: |
910 | if (fibh.sbh != fibh.ebh) | 879 | if (fibh.sbh != fibh.ebh) |
911 | brelse(fibh.ebh); | 880 | brelse(fibh.ebh); |
912 | brelse(fibh.sbh); | 881 | brelse(fibh.sbh); |
913 | out: | 882 | |
883 | out: | ||
914 | unlock_kernel(); | 884 | unlock_kernel(); |
915 | return retval; | 885 | return retval; |
916 | } | 886 | } |
@@ -922,7 +892,7 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
922 | struct pathComponent *pc; | 892 | struct pathComponent *pc; |
923 | char *compstart; | 893 | char *compstart; |
924 | struct udf_fileident_bh fibh; | 894 | struct udf_fileident_bh fibh; |
925 | struct extent_position epos = { NULL, 0, {0, 0} }; | 895 | struct extent_position epos = {}; |
926 | int eoffset, elen = 0; | 896 | int eoffset, elen = 0; |
927 | struct fileIdentDesc *fi; | 897 | struct fileIdentDesc *fi; |
928 | struct fileIdentDesc cfi; | 898 | struct fileIdentDesc cfi; |
@@ -945,26 +915,22 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
945 | uint32_t elen; | 915 | uint32_t elen; |
946 | 916 | ||
947 | block = udf_new_block(inode->i_sb, inode, | 917 | block = udf_new_block(inode->i_sb, inode, |
948 | UDF_I_LOCATION(inode). | 918 | UDF_I_LOCATION(inode).partitionReferenceNum, |
949 | partitionReferenceNum, | 919 | UDF_I_LOCATION(inode).logicalBlockNum, &err); |
950 | UDF_I_LOCATION(inode).logicalBlockNum, | ||
951 | &err); | ||
952 | if (!block) | 920 | if (!block) |
953 | goto out_no_entry; | 921 | goto out_no_entry; |
954 | epos.block = UDF_I_LOCATION(inode); | 922 | epos.block = UDF_I_LOCATION(inode); |
955 | epos.offset = udf_file_entry_alloc_offset(inode); | 923 | epos.offset = udf_file_entry_alloc_offset(inode); |
956 | epos.bh = NULL; | 924 | epos.bh = NULL; |
957 | eloc.logicalBlockNum = block; | 925 | eloc.logicalBlockNum = block; |
958 | eloc.partitionReferenceNum = | 926 | eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; |
959 | UDF_I_LOCATION(inode).partitionReferenceNum; | ||
960 | elen = inode->i_sb->s_blocksize; | 927 | elen = inode->i_sb->s_blocksize; |
961 | UDF_I_LENEXTENTS(inode) = elen; | 928 | UDF_I_LENEXTENTS(inode) = elen; |
962 | udf_add_aext(inode, &epos, eloc, elen, 0); | 929 | udf_add_aext(inode, &epos, eloc, elen, 0); |
963 | brelse(epos.bh); | 930 | brelse(epos.bh); |
964 | 931 | ||
965 | block = udf_get_pblock(inode->i_sb, block, | 932 | block = udf_get_pblock(inode->i_sb, block, |
966 | UDF_I_LOCATION(inode). | 933 | UDF_I_LOCATION(inode).partitionReferenceNum, 0); |
967 | partitionReferenceNum, 0); | ||
968 | epos.bh = udf_tread(inode->i_sb, block); | 934 | epos.bh = udf_tread(inode->i_sb, block); |
969 | lock_buffer(epos.bh); | 935 | lock_buffer(epos.bh); |
970 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); | 936 | memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize); |
@@ -972,8 +938,9 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
972 | unlock_buffer(epos.bh); | 938 | unlock_buffer(epos.bh); |
973 | mark_buffer_dirty_inode(epos.bh, inode); | 939 | mark_buffer_dirty_inode(epos.bh, inode); |
974 | ea = epos.bh->b_data + udf_ext0_offset(inode); | 940 | ea = epos.bh->b_data + udf_ext0_offset(inode); |
975 | } else | 941 | } else { |
976 | ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); | 942 | ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode); |
943 | } | ||
977 | 944 | ||
978 | eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); | 945 | eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode); |
979 | pc = (struct pathComponent *)ea; | 946 | pc = (struct pathComponent *)ea; |
@@ -1010,20 +977,17 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
1010 | if (compstart[0] == '.') { | 977 | if (compstart[0] == '.') { |
1011 | if ((symname - compstart) == 1) | 978 | if ((symname - compstart) == 1) |
1012 | pc->componentType = 4; | 979 | pc->componentType = 4; |
1013 | else if ((symname - compstart) == 2 | 980 | else if ((symname - compstart) == 2 && compstart[1] == '.') |
1014 | && compstart[1] == '.') | ||
1015 | pc->componentType = 3; | 981 | pc->componentType = 3; |
1016 | } | 982 | } |
1017 | 983 | ||
1018 | if (pc->componentType == 5) { | 984 | if (pc->componentType == 5) { |
1019 | if (! | 985 | namelen = udf_put_filename(inode->i_sb, compstart, name, |
1020 | (namelen = | 986 | symname - compstart); |
1021 | udf_put_filename(inode->i_sb, compstart, name, | 987 | if (!namelen) |
1022 | symname - compstart))) | ||
1023 | goto out_no_entry; | 988 | goto out_no_entry; |
1024 | 989 | ||
1025 | if (elen + sizeof(struct pathComponent) + namelen > | 990 | if (elen + sizeof(struct pathComponent) + namelen > eoffset) |
1026 | eoffset) | ||
1027 | goto out_no_entry; | 991 | goto out_no_entry; |
1028 | else | 992 | else |
1029 | pc->lengthComponentIdent = namelen; | 993 | pc->lengthComponentIdent = namelen; |
@@ -1053,12 +1017,10 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
1053 | if (UDF_SB_LVIDBH(inode->i_sb)) { | 1017 | if (UDF_SB_LVIDBH(inode->i_sb)) { |
1054 | struct logicalVolHeaderDesc *lvhd; | 1018 | struct logicalVolHeaderDesc *lvhd; |
1055 | uint64_t uniqueID; | 1019 | uint64_t uniqueID; |
1056 | lvhd = | 1020 | lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); |
1057 | (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)-> | ||
1058 | logicalVolContentsUse); | ||
1059 | uniqueID = le64_to_cpu(lvhd->uniqueID); | 1021 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
1060 | *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 1022 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
1061 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); | 1023 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
1062 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) | 1024 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
1063 | uniqueID += 16; | 1025 | uniqueID += 16; |
1064 | lvhd->uniqueID = cpu_to_le64(uniqueID); | 1026 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
@@ -1074,11 +1036,11 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
1074 | d_instantiate(dentry, inode); | 1036 | d_instantiate(dentry, inode); |
1075 | err = 0; | 1037 | err = 0; |
1076 | 1038 | ||
1077 | out: | 1039 | out: |
1078 | unlock_kernel(); | 1040 | unlock_kernel(); |
1079 | return err; | 1041 | return err; |
1080 | 1042 | ||
1081 | out_no_entry: | 1043 | out_no_entry: |
1082 | inode_dec_link_count(inode); | 1044 | inode_dec_link_count(inode); |
1083 | iput(inode); | 1045 | iput(inode); |
1084 | goto out; | 1046 | goto out; |
@@ -1107,12 +1069,10 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
1107 | if (UDF_SB_LVIDBH(inode->i_sb)) { | 1069 | if (UDF_SB_LVIDBH(inode->i_sb)) { |
1108 | struct logicalVolHeaderDesc *lvhd; | 1070 | struct logicalVolHeaderDesc *lvhd; |
1109 | uint64_t uniqueID; | 1071 | uint64_t uniqueID; |
1110 | lvhd = | 1072 | lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse); |
1111 | (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)-> | ||
1112 | logicalVolContentsUse); | ||
1113 | uniqueID = le64_to_cpu(lvhd->uniqueID); | 1073 | uniqueID = le64_to_cpu(lvhd->uniqueID); |
1114 | *(__le32 *) ((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | 1074 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = |
1115 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); | 1075 | cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL); |
1116 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) | 1076 | if (!(++uniqueID & 0x00000000FFFFFFFFUL)) |
1117 | uniqueID += 16; | 1077 | uniqueID += 16; |
1118 | lvhd->uniqueID = cpu_to_le64(uniqueID); | 1078 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
@@ -1122,6 +1082,7 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
1122 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { | 1082 | if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) { |
1123 | mark_inode_dirty(dir); | 1083 | mark_inode_dirty(dir); |
1124 | } | 1084 | } |
1085 | |||
1125 | if (fibh.sbh != fibh.ebh) | 1086 | if (fibh.sbh != fibh.ebh) |
1126 | brelse(fibh.ebh); | 1087 | brelse(fibh.ebh); |
1127 | brelse(fibh.sbh); | 1088 | brelse(fibh.sbh); |
@@ -1131,6 +1092,7 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir, | |||
1131 | atomic_inc(&inode->i_count); | 1092 | atomic_inc(&inode->i_count); |
1132 | d_instantiate(dentry, inode); | 1093 | d_instantiate(dentry, inode); |
1133 | unlock_kernel(); | 1094 | unlock_kernel(); |
1095 | |||
1134 | return 0; | 1096 | return 0; |
1135 | } | 1097 | } |
1136 | 1098 | ||
@@ -1143,8 +1105,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1143 | struct inode *old_inode = old_dentry->d_inode; | 1105 | struct inode *old_inode = old_dentry->d_inode; |
1144 | struct inode *new_inode = new_dentry->d_inode; | 1106 | struct inode *new_inode = new_dentry->d_inode; |
1145 | struct udf_fileident_bh ofibh, nfibh; | 1107 | struct udf_fileident_bh ofibh, nfibh; |
1146 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = | 1108 | struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi; |
1147 | NULL, ocfi, ncfi; | ||
1148 | struct buffer_head *dir_bh = NULL; | 1109 | struct buffer_head *dir_bh = NULL; |
1149 | int retval = -ENOENT; | 1110 | int retval = -ENOENT; |
1150 | kernel_lb_addr tloc; | 1111 | kernel_lb_addr tloc; |
@@ -1181,36 +1142,27 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1181 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1142 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { |
1182 | dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - | 1143 | dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) - |
1183 | (UDF_I_EFE(old_inode) ? | 1144 | (UDF_I_EFE(old_inode) ? |
1184 | sizeof(struct | 1145 | sizeof(struct extendedFileEntry) : |
1185 | extendedFileEntry) : | ||
1186 | sizeof(struct fileEntry)), | 1146 | sizeof(struct fileEntry)), |
1187 | old_inode->i_sb->s_blocksize, | 1147 | old_inode->i_sb->s_blocksize, &offset); |
1188 | &offset); | ||
1189 | } else { | 1148 | } else { |
1190 | dir_bh = udf_bread(old_inode, 0, 0, &retval); | 1149 | dir_bh = udf_bread(old_inode, 0, 0, &retval); |
1191 | if (!dir_bh) | 1150 | if (!dir_bh) |
1192 | goto end_rename; | 1151 | goto end_rename; |
1193 | dir_fi = | 1152 | dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset); |
1194 | udf_get_fileident(dir_bh->b_data, | ||
1195 | old_inode->i_sb->s_blocksize, | ||
1196 | &offset); | ||
1197 | } | 1153 | } |
1198 | if (!dir_fi) | 1154 | if (!dir_fi) |
1199 | goto end_rename; | 1155 | goto end_rename; |
1200 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); | 1156 | tloc = lelb_to_cpu(dir_fi->icb.extLocation); |
1201 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) | 1157 | if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != old_dir->i_ino) |
1202 | != old_dir->i_ino) | ||
1203 | goto end_rename; | 1158 | goto end_rename; |
1204 | 1159 | ||
1205 | retval = -EMLINK; | 1160 | retval = -EMLINK; |
1206 | if (!new_inode | 1161 | if (!new_inode && new_dir->i_nlink >= (256 << sizeof(new_dir->i_nlink)) - 1) |
1207 | && new_dir->i_nlink >= | ||
1208 | (256 << sizeof(new_dir->i_nlink)) - 1) | ||
1209 | goto end_rename; | 1162 | goto end_rename; |
1210 | } | 1163 | } |
1211 | if (!nfi) { | 1164 | if (!nfi) { |
1212 | nfi = | 1165 | nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); |
1213 | udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval); | ||
1214 | if (!nfi) | 1166 | if (!nfi) |
1215 | goto end_rename; | 1167 | goto end_rename; |
1216 | } | 1168 | } |
@@ -1244,13 +1196,12 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1244 | if (dir_fi) { | 1196 | if (dir_fi) { |
1245 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); | 1197 | dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir)); |
1246 | udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + | 1198 | udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) + |
1247 | le16_to_cpu(dir_fi-> | 1199 | le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3); |
1248 | lengthOfImpUse) + | ||
1249 | 3) & ~3); | ||
1250 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { | 1200 | if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) { |
1251 | mark_inode_dirty(old_inode); | 1201 | mark_inode_dirty(old_inode); |
1252 | } else | 1202 | } else { |
1253 | mark_buffer_dirty_inode(dir_bh, old_inode); | 1203 | mark_buffer_dirty_inode(dir_bh, old_inode); |
1204 | } | ||
1254 | inode_dec_link_count(old_dir); | 1205 | inode_dec_link_count(old_dir); |
1255 | if (new_inode) { | 1206 | if (new_inode) { |
1256 | inode_dec_link_count(new_inode); | 1207 | inode_dec_link_count(new_inode); |
@@ -1268,7 +1219,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1268 | 1219 | ||
1269 | retval = 0; | 1220 | retval = 0; |
1270 | 1221 | ||
1271 | end_rename: | 1222 | end_rename: |
1272 | brelse(dir_bh); | 1223 | brelse(dir_bh); |
1273 | if (nfi) { | 1224 | if (nfi) { |
1274 | if (nfibh.sbh != nfibh.ebh) | 1225 | if (nfibh.sbh != nfibh.ebh) |
@@ -1276,17 +1227,18 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1276 | brelse(nfibh.sbh); | 1227 | brelse(nfibh.sbh); |
1277 | } | 1228 | } |
1278 | unlock_kernel(); | 1229 | unlock_kernel(); |
1230 | |||
1279 | return retval; | 1231 | return retval; |
1280 | } | 1232 | } |
1281 | 1233 | ||
1282 | const struct inode_operations udf_dir_inode_operations = { | 1234 | const struct inode_operations udf_dir_inode_operations = { |
1283 | .lookup = udf_lookup, | 1235 | .lookup = udf_lookup, |
1284 | .create = udf_create, | 1236 | .create = udf_create, |
1285 | .link = udf_link, | 1237 | .link = udf_link, |
1286 | .unlink = udf_unlink, | 1238 | .unlink = udf_unlink, |
1287 | .symlink = udf_symlink, | 1239 | .symlink = udf_symlink, |
1288 | .mkdir = udf_mkdir, | 1240 | .mkdir = udf_mkdir, |
1289 | .rmdir = udf_rmdir, | 1241 | .rmdir = udf_rmdir, |
1290 | .mknod = udf_mknod, | 1242 | .mknod = udf_mknod, |
1291 | .rename = udf_rename, | 1243 | .rename = udf_rename, |
1292 | }; | 1244 | }; |