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