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