Blame view

fs/udf/namei.c 33.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
  /*
   * namei.c
   *
   * PURPOSE
   *      Inode name handling routines for the OSTA-UDF(tm) filesystem.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
   * COPYRIGHT
   *      This file is distributed under the terms of the GNU General Public
   *      License (GPL). Copies of the GPL can be obtained from:
   *              ftp://prep.ai.mit.edu/pub/gnu/GPL
   *      Each contributing author retains all rights to their own work.
   *
   *  (C) 1998-2004 Ben Fennema
   *  (C) 1999-2000 Stelias Computing Inc
   *
   * HISTORY
   *
   *  12/12/98 blf  Created. Split out the lookup code from dir.c
   *  04/19/99 blf  link, mknod, symlink support
   */
  
  #include "udfdecl.h"
  
  #include "udf_i.h"
  #include "udf_sb.h"
  #include <linux/string.h>
  #include <linux/errno.h>
  #include <linux/mm.h>
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  #include <linux/buffer_head.h>
e8edc6e03   Alexey Dobriyan   Detach sched.h fr...
31
  #include <linux/sched.h>
f845fced9   Bob Copeland   udf: use crc_itu_...
32
  #include <linux/crc-itu-t.h>
221e583a7   Rasmus Rohde   udf: Make udf exp...
33
  #include <linux/exportfs.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34

391e8bbd3   Al Viro   sanitize const/si...
35
36
  static inline int udf_match(int len1, const unsigned char *name1, int len2,
  			    const unsigned char *name2)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
  {
  	if (len1 != len2)
  		return 0;
28de7948a   Cyrill Gorcunov   UDF: coding style...
40

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
43
44
  	return !memcmp(name1, name2, len1);
  }
  
  int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
cb00ea352   Cyrill Gorcunov   UDF: coding style...
45
  		 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh,
4b11111ab   Marcin Slusarz   udf: fix coding s...
46
  		 uint8_t *impuse, uint8_t *fileident)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
  {
5ca4e4be8   Pekka Enberg   Remove struct typ...
48
  	uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(struct tag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  	uint16_t crc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
52
53
  	int offset;
  	uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse);
  	uint8_t lfi = cfi->lengthFileIdent;
  	int padlen = fibh->eoffset - fibh->soffset - liu - lfi -
28de7948a   Cyrill Gorcunov   UDF: coding style...
54
  		sizeof(struct fileIdentDesc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  	int adinicb = 0;
c0b344385   Marcin Slusarz   udf: remove UDF_I...
56
  	if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
59
  		adinicb = 1;
  
  	offset = fibh->soffset + sizeof(struct fileIdentDesc);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
60
  	if (impuse) {
28de7948a   Cyrill Gorcunov   UDF: coding style...
61
62
63
  		if (adinicb || (offset + liu < 0)) {
  			memcpy((uint8_t *)sfi->impUse, impuse, liu);
  		} else if (offset >= 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
  			memcpy(fibh->ebh->b_data + offset, impuse, liu);
28de7948a   Cyrill Gorcunov   UDF: coding style...
65
66
  		} else {
  			memcpy((uint8_t *)sfi->impUse, impuse, -offset);
4b11111ab   Marcin Slusarz   udf: fix coding s...
67
68
  			memcpy(fibh->ebh->b_data, impuse - offset,
  				liu + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
72
  		}
  	}
  
  	offset += liu;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
73
  	if (fileident) {
28de7948a   Cyrill Gorcunov   UDF: coding style...
74
75
76
  		if (adinicb || (offset + lfi < 0)) {
  			memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi);
  		} else if (offset >= 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
  			memcpy(fibh->ebh->b_data + offset, fileident, lfi);
28de7948a   Cyrill Gorcunov   UDF: coding style...
78
  		} else {
4b11111ab   Marcin Slusarz   udf: fix coding s...
79
80
81
82
  			memcpy((uint8_t *)sfi->fileIdent + liu, fileident,
  				-offset);
  			memcpy(fibh->ebh->b_data, fileident - offset,
  				lfi + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
86
  		}
  	}
  
  	offset += lfi;
28de7948a   Cyrill Gorcunov   UDF: coding style...
87
88
89
  	if (adinicb || (offset + padlen < 0)) {
  		memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen);
  	} else if (offset >= 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  		memset(fibh->ebh->b_data + offset, 0x00, padlen);
28de7948a   Cyrill Gorcunov   UDF: coding style...
91
92
  	} else {
  		memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
  		memset(fibh->ebh->b_data, 0x00, padlen + offset);
  	}
5ca4e4be8   Pekka Enberg   Remove struct typ...
95
96
  	crc = crc_itu_t(0, (uint8_t *)cfi + sizeof(struct tag),
  		      sizeof(struct fileIdentDesc) - sizeof(struct tag));
28de7948a   Cyrill Gorcunov   UDF: coding style...
97
98
  
  	if (fibh->sbh == fibh->ebh) {
f845fced9   Bob Copeland   udf: use crc_itu_...
99
  		crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
5ca4e4be8   Pekka Enberg   Remove struct typ...
100
  			      crclen + sizeof(struct tag) -
f845fced9   Bob Copeland   udf: use crc_itu_...
101
  			      sizeof(struct fileIdentDesc));
28de7948a   Cyrill Gorcunov   UDF: coding style...
102
  	} else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
f845fced9   Bob Copeland   udf: use crc_itu_...
103
  		crc = crc_itu_t(crc, fibh->ebh->b_data +
4b11111ab   Marcin Slusarz   udf: fix coding s...
104
105
  					sizeof(struct fileIdentDesc) +
  					fibh->soffset,
5ca4e4be8   Pekka Enberg   Remove struct typ...
106
  			      crclen + sizeof(struct tag) -
f845fced9   Bob Copeland   udf: use crc_itu_...
107
  					sizeof(struct fileIdentDesc));
28de7948a   Cyrill Gorcunov   UDF: coding style...
108
  	} else {
f845fced9   Bob Copeland   udf: use crc_itu_...
109
110
111
  		crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
  			      -fibh->soffset - sizeof(struct fileIdentDesc));
  		crc = crc_itu_t(crc, fibh->ebh->b_data, fibh->eoffset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
113
114
115
  	}
  
  	cfi->descTag.descCRC = cpu_to_le16(crc);
  	cfi->descTag.descCRCLength = cpu_to_le16(crclen);
3f2587bb2   Marcin Slusarz   udf: create commo...
116
  	cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117

28de7948a   Cyrill Gorcunov   UDF: coding style...
118
  	if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) {
4b11111ab   Marcin Slusarz   udf: fix coding s...
119
120
  		memcpy((uint8_t *)sfi, (uint8_t *)cfi,
  			sizeof(struct fileIdentDesc));
28de7948a   Cyrill Gorcunov   UDF: coding style...
121
122
123
  	} else {
  		memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset);
  		memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset,
cb00ea352   Cyrill Gorcunov   UDF: coding style...
124
  		       sizeof(struct fileIdentDesc) + fibh->soffset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
  	}
28de7948a   Cyrill Gorcunov   UDF: coding style...
126
  	if (adinicb) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
  		mark_inode_dirty(inode);
28de7948a   Cyrill Gorcunov   UDF: coding style...
128
  	} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
131
132
133
134
  		if (fibh->sbh != fibh->ebh)
  			mark_buffer_dirty_inode(fibh->ebh, inode);
  		mark_buffer_dirty_inode(fibh->sbh, inode);
  	}
  	return 0;
  }
cb00ea352   Cyrill Gorcunov   UDF: coding style...
135
  static struct fileIdentDesc *udf_find_entry(struct inode *dir,
391e8bbd3   Al Viro   sanitize const/si...
136
  					    const struct qstr *child,
cb00ea352   Cyrill Gorcunov   UDF: coding style...
137
138
  					    struct udf_fileident_bh *fibh,
  					    struct fileIdentDesc *cfi)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
  {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
140
  	struct fileIdentDesc *fi = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
142
  	loff_t f_pos;
  	int block, flen;
391e8bbd3   Al Viro   sanitize const/si...
143
144
  	unsigned char *fname = NULL;
  	unsigned char *nameptr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145
146
  	uint8_t lfi;
  	uint16_t liu;
ec471dc48   KAMBAROV, ZAUR   [PATCH] coverity:...
147
  	loff_t size;
5ca4e4be8   Pekka Enberg   Remove struct typ...
148
  	struct kernel_lb_addr eloc;
ff116fc8d   Jan Kara   UDF: introduce st...
149
  	uint32_t elen;
60448b1d6   Jan Kara   udf: use sector_t...
150
  	sector_t offset;
28de7948a   Cyrill Gorcunov   UDF: coding style...
151
  	struct extent_position epos = {};
48d6d8ff7   Marcin Slusarz   udf: cache struct...
152
  	struct udf_inode_info *dinfo = UDF_I(dir);
9fbb76ce0   Al Viro   [PATCH] get rid o...
153
154
  	int isdotdot = child->len == 2 &&
  		child->name[0] == '.' && child->name[1] == '.';
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155

af793295b   Jan Kara   udf: cleanup dire...
156
157
  	size = udf_ext0_offset(dir) + dir->i_size;
  	f_pos = udf_ext0_offset(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158

b80697c14   Jan Kara   udf: Remove decla...
159
  	fibh->sbh = fibh->ebh = NULL;
af793295b   Jan Kara   udf: cleanup dire...
160
  	fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
b80697c14   Jan Kara   udf: Remove decla...
161
162
163
164
  	if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
  		if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos,
  		    &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30))
  			goto out_err;
97e961fdb   Pekka Enberg   Fix the udf code ...
165
  		block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
166
  		if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
48d6d8ff7   Marcin Slusarz   udf: cache struct...
167
  			if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
5ca4e4be8   Pekka Enberg   Remove struct typ...
168
  				epos.offset -= sizeof(struct short_ad);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
169
  			else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
5ca4e4be8   Pekka Enberg   Remove struct typ...
170
  				epos.offset -= sizeof(struct long_ad);
4b11111ab   Marcin Slusarz   udf: fix coding s...
171
  		} else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172
  			offset = 0;
4b11111ab   Marcin Slusarz   udf: fix coding s...
173
  		fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
b80697c14   Jan Kara   udf: Remove decla...
174
175
  		if (!fibh->sbh)
  			goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
  	}
b80697c14   Jan Kara   udf: Remove decla...
177
178
179
  	fname = kmalloc(UDF_NAME_LEN, GFP_NOFS);
  	if (!fname)
  		goto out_err;
af793295b   Jan Kara   udf: cleanup dire...
180
  	while (f_pos < size) {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
181
182
  		fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
  					&elen, &offset);
b80697c14   Jan Kara   udf: Remove decla...
183
184
  		if (!fi)
  			goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
186
187
  
  		liu = le16_to_cpu(cfi->lengthOfImpUse);
  		lfi = cfi->lengthFileIdent;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
188
  		if (fibh->sbh == fibh->ebh) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
  			nameptr = fi->fileIdent + liu;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
190
  		} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
191
  			int poffset;	/* Unpaded ending offset */
4b11111ab   Marcin Slusarz   udf: fix coding s...
192
193
  			poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
  					liu + lfi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194

4b11111ab   Marcin Slusarz   udf: fix coding s...
195
196
197
198
  			if (poffset >= lfi)
  				nameptr = (uint8_t *)(fibh->ebh->b_data +
  						      poffset - lfi);
  			else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
  				nameptr = fname;
4b11111ab   Marcin Slusarz   udf: fix coding s...
200
201
202
203
  				memcpy(nameptr, fi->fileIdent + liu,
  					lfi - poffset);
  				memcpy(nameptr + lfi - poffset,
  					fibh->ebh->b_data, poffset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
204
205
  			}
  		}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
206
207
  		if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
  			if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
  				continue;
  		}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
210
211
212
  
  		if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
  			if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
213
214
  				continue;
  		}
221e583a7   Rasmus Rohde   udf: Make udf exp...
215
  		if ((cfi->fileCharacteristics & FID_FILE_CHAR_PARENT) &&
a4264b3f4   Jesper Juhl   UDF: Close small ...
216
217
  		    isdotdot)
  			goto out_ok;
221e583a7   Rasmus Rohde   udf: Make udf exp...
218

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
220
  		if (!lfi)
  			continue;
4b11111ab   Marcin Slusarz   udf: fix coding s...
221
  		flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
9fbb76ce0   Al Viro   [PATCH] get rid o...
222
  		if (flen && udf_match(flen, fname, child->len, child->name))
b80697c14   Jan Kara   udf: Remove decla...
223
  			goto out_ok;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
  	}
28de7948a   Cyrill Gorcunov   UDF: coding style...
225

b80697c14   Jan Kara   udf: Remove decla...
226
227
  out_err:
  	fi = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
  	if (fibh->sbh != fibh->ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
229
230
  		brelse(fibh->ebh);
  	brelse(fibh->sbh);
b80697c14   Jan Kara   udf: Remove decla...
231
  out_ok:
3bf25cb40   Jan Kara   udf: use get_bh()
232
  	brelse(epos.bh);
b80697c14   Jan Kara   udf: Remove decla...
233
  	kfree(fname);
28de7948a   Cyrill Gorcunov   UDF: coding style...
234

b80697c14   Jan Kara   udf: Remove decla...
235
  	return fi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
236
  }
cb00ea352   Cyrill Gorcunov   UDF: coding style...
237
  static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
00cd8dd3b   Al Viro   stop passing name...
238
  				 unsigned int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
  {
  	struct inode *inode = NULL;
db9a369ec   Jayachandran C   [PATCH] UDF: Fix ...
241
  	struct fileIdentDesc cfi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
  	struct udf_fileident_bh fibh;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
243
  	if (dentry->d_name.len > UDF_NAME_LEN - 2)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
  		return ERR_PTR(-ENAMETOOLONG);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
245
246
  #ifdef UDF_RECOVERY
  	/* temporary shorthand for specifying files by inode number */
cb00ea352   Cyrill Gorcunov   UDF: coding style...
247
  	if (!strncmp(dentry->d_name.name, ".B=", 3)) {
5ca4e4be8   Pekka Enberg   Remove struct typ...
248
  		struct kernel_lb_addr lb = {
28de7948a   Cyrill Gorcunov   UDF: coding style...
249
  			.logicalBlockNum = 0,
4b11111ab   Marcin Slusarz   udf: fix coding s...
250
251
252
  			.partitionReferenceNum =
  				simple_strtoul(dentry->d_name.name + 3,
  						NULL, 0),
28de7948a   Cyrill Gorcunov   UDF: coding style...
253
  		};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
254
  		inode = udf_iget(dir->i_sb, lb);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
255
  		if (!inode) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
257
  			return ERR_PTR(-EACCES);
  		}
4b11111ab   Marcin Slusarz   udf: fix coding s...
258
  	} else
28de7948a   Cyrill Gorcunov   UDF: coding style...
259
  #endif /* UDF_RECOVERY */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260

9fbb76ce0   Al Viro   [PATCH] get rid o...
261
  	if (udf_find_entry(dir, &dentry->d_name, &fibh, &cfi)) {
97e961fdb   Pekka Enberg   Fix the udf code ...
262
  		struct kernel_lb_addr loc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263
  		if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
264
265
  			brelse(fibh.ebh);
  		brelse(fibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
266

97e961fdb   Pekka Enberg   Fix the udf code ...
267
268
  		loc = lelb_to_cpu(cfi.icb.extLocation);
  		inode = udf_iget(dir->i_sb, &loc);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
269
  		if (!inode) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
270
271
272
  			return ERR_PTR(-EACCES);
  		}
  	}
28de7948a   Cyrill Gorcunov   UDF: coding style...
273

221e583a7   Rasmus Rohde   udf: Make udf exp...
274
  	return d_splice_alias(inode, dentry);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
275
  }
cb00ea352   Cyrill Gorcunov   UDF: coding style...
276
277
278
279
  static struct fileIdentDesc *udf_add_entry(struct inode *dir,
  					   struct dentry *dentry,
  					   struct udf_fileident_bh *fibh,
  					   struct fileIdentDesc *cfi, int *err)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
280
  {
6c79e987d   Marcin Slusarz   udf: remove some ...
281
  	struct super_block *sb = dir->i_sb;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
282
  	struct fileIdentDesc *fi = NULL;
391e8bbd3   Al Viro   sanitize const/si...
283
  	unsigned char *name = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
  	int namelen;
  	loff_t f_pos;
af793295b   Jan Kara   udf: cleanup dire...
286
  	loff_t size = udf_ext0_offset(dir) + dir->i_size;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
287
288
289
290
  	int nfidlen;
  	uint8_t lfi;
  	uint16_t liu;
  	int block;
5ca4e4be8   Pekka Enberg   Remove struct typ...
291
  	struct kernel_lb_addr eloc;
9afadc4b1   Jan Kara   udf: Fix memory c...
292
  	uint32_t elen = 0;
60448b1d6   Jan Kara   udf: use sector_t...
293
  	sector_t offset;
28de7948a   Cyrill Gorcunov   UDF: coding style...
294
  	struct extent_position epos = {};
48d6d8ff7   Marcin Slusarz   udf: cache struct...
295
  	struct udf_inode_info *dinfo;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296

b80697c14   Jan Kara   udf: Remove decla...
297
298
299
300
301
302
  	fibh->sbh = fibh->ebh = NULL;
  	name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
  	if (!name) {
  		*err = -ENOMEM;
  		goto out_err;
  	}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
303
304
  	if (dentry) {
  		if (!dentry->d_name.len) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305
  			*err = -EINVAL;
b80697c14   Jan Kara   udf: Remove decla...
306
  			goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
  		}
4b11111ab   Marcin Slusarz   udf: fix coding s...
308
309
310
  		namelen = udf_put_filename(sb, dentry->d_name.name, name,
  						 dentry->d_name.len);
  		if (!namelen) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
  			*err = -ENAMETOOLONG;
b80697c14   Jan Kara   udf: Remove decla...
312
  			goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
  		}
28de7948a   Cyrill Gorcunov   UDF: coding style...
314
  	} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315
  		namelen = 0;
28de7948a   Cyrill Gorcunov   UDF: coding style...
316
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
  
  	nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3;
af793295b   Jan Kara   udf: cleanup dire...
319
  	f_pos = udf_ext0_offset(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
320

af793295b   Jan Kara   udf: cleanup dire...
321
  	fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
322
  	dinfo = UDF_I(dir);
b80697c14   Jan Kara   udf: Remove decla...
323
324
325
326
  	if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
  		if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos,
  		    &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) {
  			block = udf_get_lb_pblock(dir->i_sb,
97e961fdb   Pekka Enberg   Fix the udf code ...
327
  					&dinfo->i_location, 0);
b80697c14   Jan Kara   udf: Remove decla...
328
329
330
  			fibh->soffset = fibh->eoffset = sb->s_blocksize;
  			goto add;
  		}
97e961fdb   Pekka Enberg   Fix the udf code ...
331
  		block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
332
  		if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
48d6d8ff7   Marcin Slusarz   udf: cache struct...
333
  			if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
5ca4e4be8   Pekka Enberg   Remove struct typ...
334
  				epos.offset -= sizeof(struct short_ad);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
335
  			else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
5ca4e4be8   Pekka Enberg   Remove struct typ...
336
  				epos.offset -= sizeof(struct long_ad);
4b11111ab   Marcin Slusarz   udf: fix coding s...
337
  		} else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
338
  			offset = 0;
4b11111ab   Marcin Slusarz   udf: fix coding s...
339
340
  		fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
  		if (!fibh->sbh) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
  			*err = -EIO;
b80697c14   Jan Kara   udf: Remove decla...
342
  			goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
  		}
48d6d8ff7   Marcin Slusarz   udf: cache struct...
344
  		block = dinfo->i_location.logicalBlockNum;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
  	}
af793295b   Jan Kara   udf: cleanup dire...
346
  	while (f_pos < size) {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
347
348
  		fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
  					&elen, &offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349

cb00ea352   Cyrill Gorcunov   UDF: coding style...
350
  		if (!fi) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
351
  			*err = -EIO;
b80697c14   Jan Kara   udf: Remove decla...
352
  			goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
354
355
356
  		}
  
  		liu = le16_to_cpu(cfi->lengthOfImpUse);
  		lfi = cfi->lengthFileIdent;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
357
  		if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
4b11111ab   Marcin Slusarz   udf: fix coding s...
358
359
  			if (((sizeof(struct fileIdentDesc) +
  					liu + lfi + 3) & ~3) == nfidlen) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
360
361
362
363
364
  				cfi->descTag.tagSerialNum = cpu_to_le16(1);
  				cfi->fileVersionNum = cpu_to_le16(1);
  				cfi->fileCharacteristics = 0;
  				cfi->lengthFileIdent = namelen;
  				cfi->lengthOfImpUse = cpu_to_le16(0);
4b11111ab   Marcin Slusarz   udf: fix coding s...
365
366
  				if (!udf_write_fi(dir, cfi, fi, fibh, NULL,
  						  name))
b80697c14   Jan Kara   udf: Remove decla...
367
  					goto out_ok;
4b11111ab   Marcin Slusarz   udf: fix coding s...
368
  				else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
  					*err = -EIO;
b80697c14   Jan Kara   udf: Remove decla...
370
  					goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
371
372
373
  				}
  			}
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
374
  	}
28de7948a   Cyrill Gorcunov   UDF: coding style...
375
  add:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376
  	f_pos += nfidlen;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
377
  	if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB &&
cb00ea352   Cyrill Gorcunov   UDF: coding style...
378
  	    sb->s_blocksize - fibh->eoffset < nfidlen) {
3bf25cb40   Jan Kara   udf: use get_bh()
379
  		brelse(epos.bh);
ff116fc8d   Jan Kara   UDF: introduce st...
380
  		epos.bh = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
382
  		fibh->soffset -= udf_ext0_offset(dir);
  		fibh->eoffset -= udf_ext0_offset(dir);
af793295b   Jan Kara   udf: cleanup dire...
383
  		f_pos -= udf_ext0_offset(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
384
  		if (fibh->sbh != fibh->ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
385
386
  			brelse(fibh->ebh);
  		brelse(fibh->sbh);
4b11111ab   Marcin Slusarz   udf: fix coding s...
387
388
389
  		fibh->sbh = fibh->ebh =
  				udf_expand_dir_adinicb(dir, &block, err);
  		if (!fibh->sbh)
b80697c14   Jan Kara   udf: Remove decla...
390
  			goto out_err;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
391
  		epos.block = dinfo->i_location;
ff116fc8d   Jan Kara   UDF: introduce st...
392
  		epos.offset = udf_file_entry_alloc_offset(dir);
05343c4f2   Jan Kara   udf: fix adding e...
393
394
  		/* Load extent udf_expand_dir_adinicb() has created */
  		udf_current_aext(dir, &epos, &eloc, &elen, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395
  	}
2c948b3f8   Jan Kara   udf: Avoid IO in ...
396
  	/* Entry fits into current block? */
cb00ea352   Cyrill Gorcunov   UDF: coding style...
397
  	if (sb->s_blocksize - fibh->eoffset >= nfidlen) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398
399
  		fibh->soffset = fibh->eoffset;
  		fibh->eoffset += nfidlen;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
400
  		if (fibh->sbh != fibh->ebh) {
3bf25cb40   Jan Kara   udf: use get_bh()
401
  			brelse(fibh->sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
402
403
  			fibh->sbh = fibh->ebh;
  		}
48d6d8ff7   Marcin Slusarz   udf: cache struct...
404
405
  		if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
  			block = dinfo->i_location.logicalBlockNum;
4b11111ab   Marcin Slusarz   udf: fix coding s...
406
  			fi = (struct fileIdentDesc *)
48d6d8ff7   Marcin Slusarz   udf: cache struct...
407
  					(dinfo->i_ext.i_data +
c0b344385   Marcin Slusarz   udf: remove UDF_I...
408
  					 fibh->soffset -
4b11111ab   Marcin Slusarz   udf: fix coding s...
409
  					 udf_ext0_offset(dir) +
48d6d8ff7   Marcin Slusarz   udf: cache struct...
410
  					 dinfo->i_lenEAttr);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
411
  		} else {
4b11111ab   Marcin Slusarz   udf: fix coding s...
412
413
414
415
416
  			block = eloc.logicalBlockNum +
  					((elen - 1) >>
  						dir->i_sb->s_blocksize_bits);
  			fi = (struct fileIdentDesc *)
  				(fibh->sbh->b_data + fibh->soffset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417
  		}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
418
  	} else {
2c948b3f8   Jan Kara   udf: Avoid IO in ...
419
420
421
422
423
424
425
426
427
  		/* Round up last extent in the file */
  		elen = (elen + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1);
  		if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
  			epos.offset -= sizeof(struct short_ad);
  		else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
  			epos.offset -= sizeof(struct long_ad);
  		udf_write_aext(dir, &epos, &eloc, elen, 1);
  		dinfo->i_lenExtents = (dinfo->i_lenExtents + sb->s_blocksize
  					- 1) & ~(sb->s_blocksize - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
429
  		fibh->soffset = fibh->eoffset - sb->s_blocksize;
  		fibh->eoffset += nfidlen - sb->s_blocksize;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
430
  		if (fibh->sbh != fibh->ebh) {
3bf25cb40   Jan Kara   udf: use get_bh()
431
  			brelse(fibh->sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
433
434
435
  			fibh->sbh = fibh->ebh;
  		}
  
  		block = eloc.logicalBlockNum + ((elen - 1) >>
cb00ea352   Cyrill Gorcunov   UDF: coding style...
436
  						dir->i_sb->s_blocksize_bits);
4b11111ab   Marcin Slusarz   udf: fix coding s...
437
  		fibh->ebh = udf_bread(dir,
af793295b   Jan Kara   udf: cleanup dire...
438
  				f_pos >> dir->i_sb->s_blocksize_bits, 1, err);
b80697c14   Jan Kara   udf: Remove decla...
439
440
  		if (!fibh->ebh)
  			goto out_err;
4651c5900   Jan Kara   udf: Fix director...
441
442
443
444
445
  		/* Extents could have been merged, invalidate our position */
  		brelse(epos.bh);
  		epos.bh = NULL;
  		epos.block = dinfo->i_location;
  		epos.offset = udf_file_entry_alloc_offset(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
446

28de7948a   Cyrill Gorcunov   UDF: coding style...
447
  		if (!fibh->soffset) {
4651c5900   Jan Kara   udf: Fix director...
448
449
450
451
452
  			/* Find the freshly allocated block */
  			while (udf_next_aext(dir, &epos, &eloc, &elen, 1) ==
  				(EXT_RECORDED_ALLOCATED >> 30))
  				;
  			block = eloc.logicalBlockNum + ((elen - 1) >>
28de7948a   Cyrill Gorcunov   UDF: coding style...
453
  					dir->i_sb->s_blocksize_bits);
3bf25cb40   Jan Kara   udf: use get_bh()
454
  			brelse(fibh->sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
  			fibh->sbh = fibh->ebh;
  			fi = (struct fileIdentDesc *)(fibh->sbh->b_data);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
457
  		} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
458
  			fi = (struct fileIdentDesc *)
4b11111ab   Marcin Slusarz   udf: fix coding s...
459
460
  				(fibh->sbh->b_data + sb->s_blocksize +
  					fibh->soffset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
462
463
464
  		}
  	}
  
  	memset(cfi, 0, sizeof(struct fileIdentDesc));
6c79e987d   Marcin Slusarz   udf: remove some ...
465
  	if (UDF_SB(sb)->s_udfrev >= 0x0200)
4b11111ab   Marcin Slusarz   udf: fix coding s...
466
  		udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block,
5ca4e4be8   Pekka Enberg   Remove struct typ...
467
  			    sizeof(struct tag));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
468
  	else
4b11111ab   Marcin Slusarz   udf: fix coding s...
469
  		udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block,
5ca4e4be8   Pekka Enberg   Remove struct typ...
470
  			    sizeof(struct tag));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
472
473
  	cfi->fileVersionNum = cpu_to_le16(1);
  	cfi->lengthFileIdent = namelen;
  	cfi->lengthOfImpUse = cpu_to_le16(0);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
474
  	if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475
  		dir->i_size += nfidlen;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
476
477
  		if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
  			dinfo->i_lenAlloc += nfidlen;
2c948b3f8   Jan Kara   udf: Avoid IO in ...
478
479
480
481
482
483
484
485
486
487
488
489
490
  		else {
  			/* Find the last extent and truncate it to proper size */
  			while (udf_next_aext(dir, &epos, &eloc, &elen, 1) ==
  				(EXT_RECORDED_ALLOCATED >> 30))
  				;
  			elen -= dinfo->i_lenExtents - dir->i_size;
  			if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
  				epos.offset -= sizeof(struct short_ad);
  			else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
  				epos.offset -= sizeof(struct long_ad);
  			udf_write_aext(dir, &epos, &eloc, elen, 1);
  			dinfo->i_lenExtents = dir->i_size;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
491
  		mark_inode_dirty(dir);
b80697c14   Jan Kara   udf: Remove decla...
492
  		goto out_ok;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
493
  	} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
494
  		*err = -EIO;
b80697c14   Jan Kara   udf: Remove decla...
495
  		goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
496
  	}
b80697c14   Jan Kara   udf: Remove decla...
497
498
499
500
501
502
503
504
505
506
  
  out_err:
  	fi = NULL;
  	if (fibh->sbh != fibh->ebh)
  		brelse(fibh->ebh);
  	brelse(fibh->sbh);
  out_ok:
  	brelse(epos.bh);
  	kfree(name);
  	return fi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
507
508
509
  }
  
  static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
cb00ea352   Cyrill Gorcunov   UDF: coding style...
510
511
  			    struct udf_fileident_bh *fibh,
  			    struct fileIdentDesc *cfi)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
512
513
  {
  	cfi->fileCharacteristics |= FID_FILE_CHAR_DELETED;
28de7948a   Cyrill Gorcunov   UDF: coding style...
514

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
  	if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
5ca4e4be8   Pekka Enberg   Remove struct typ...
516
  		memset(&(cfi->icb), 0x00, sizeof(struct long_ad));
28de7948a   Cyrill Gorcunov   UDF: coding style...
517

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
518
519
  	return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL);
  }
4acdaf27e   Al Viro   switch ->create()...
520
  static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode,
ebfc3b49a   Al Viro   don't pass nameid...
521
  		      bool excl)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
522
523
524
525
526
  {
  	struct udf_fileident_bh fibh;
  	struct inode *inode;
  	struct fileIdentDesc cfi, *fi;
  	int err;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
527
  	struct udf_inode_info *iinfo;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
528

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
529
  	inode = udf_new_inode(dir, mode, &err);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
530
  	if (!inode) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
531
532
  		return err;
  	}
48d6d8ff7   Marcin Slusarz   udf: cache struct...
533
534
  	iinfo = UDF_I(inode);
  	if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
535
536
537
538
539
  		inode->i_data.a_ops = &udf_adinicb_aops;
  	else
  		inode->i_data.a_ops = &udf_aops;
  	inode->i_op = &udf_file_inode_operations;
  	inode->i_fop = &udf_file_operations;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
540
  	mark_inode_dirty(inode);
4b11111ab   Marcin Slusarz   udf: fix coding s...
541
542
  	fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
  	if (!fi) {
6d6b77f16   Miklos Szeredi   filesystems: add ...
543
  		inode_dec_link_count(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
544
  		iput(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
545
546
547
  		return err;
  	}
  	cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
548
  	cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
28de7948a   Cyrill Gorcunov   UDF: coding style...
549
  	*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
48d6d8ff7   Marcin Slusarz   udf: cache struct...
550
  		cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
551
  	udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
c0b344385   Marcin Slusarz   udf: remove UDF_I...
552
  	if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
  		mark_inode_dirty(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
554
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
555
556
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
  	d_instantiate(dentry, inode);
28de7948a   Cyrill Gorcunov   UDF: coding style...
558

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
559
560
  	return 0;
  }
1a67aafb5   Al Viro   switch ->mknod() ...
561
  static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
cb00ea352   Cyrill Gorcunov   UDF: coding style...
562
  		     dev_t rdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
  {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
564
  	struct inode *inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
565
566
567
  	struct udf_fileident_bh fibh;
  	struct fileIdentDesc cfi, *fi;
  	int err;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
568
  	struct udf_inode_info *iinfo;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
569
570
571
  
  	if (!old_valid_dev(rdev))
  		return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
572
573
574
575
  	err = -EIO;
  	inode = udf_new_inode(dir, mode, &err);
  	if (!inode)
  		goto out;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
576
  	iinfo = UDF_I(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
577
  	init_special_inode(inode, mode, rdev);
4b11111ab   Marcin Slusarz   udf: fix coding s...
578
579
  	fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
  	if (!fi) {
6d6b77f16   Miklos Szeredi   filesystems: add ...
580
  		inode_dec_link_count(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
581
  		iput(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
582
583
584
  		return err;
  	}
  	cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
585
  	cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
28de7948a   Cyrill Gorcunov   UDF: coding style...
586
  	*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
48d6d8ff7   Marcin Slusarz   udf: cache struct...
587
  		cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
588
  	udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
c0b344385   Marcin Slusarz   udf: remove UDF_I...
589
  	if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
590
  		mark_inode_dirty(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
591
592
593
  	mark_inode_dirty(inode);
  
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
594
595
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
596
597
  	d_instantiate(dentry, inode);
  	err = 0;
28de7948a   Cyrill Gorcunov   UDF: coding style...
598
599
  
  out:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
600
601
  	return err;
  }
18bb1db3e   Al Viro   switch vfs_mkdir(...
602
  static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
603
  {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
604
  	struct inode *inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
605
606
607
  	struct udf_fileident_bh fibh;
  	struct fileIdentDesc cfi, *fi;
  	int err;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
608
609
  	struct udf_inode_info *dinfo = UDF_I(dir);
  	struct udf_inode_info *iinfo;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
610

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
611
  	err = -EIO;
a6c5a0342   Dmitry Monakhov   udf: replace inod...
612
  	inode = udf_new_inode(dir, S_IFDIR | mode, &err);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
613
614
  	if (!inode)
  		goto out;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
615
  	iinfo = UDF_I(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
616
617
  	inode->i_op = &udf_dir_inode_operations;
  	inode->i_fop = &udf_dir_operations;
4b11111ab   Marcin Slusarz   udf: fix coding s...
618
619
  	fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err);
  	if (!fi) {
6d6b77f16   Miklos Szeredi   filesystems: add ...
620
  		inode_dec_link_count(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
621
622
623
  		iput(inode);
  		goto out;
  	}
bfe868486   Miklos Szeredi   filesystems: add ...
624
  	set_nlink(inode, 2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
625
  	cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
626
  	cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location);
28de7948a   Cyrill Gorcunov   UDF: coding style...
627
  	*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
48d6d8ff7   Marcin Slusarz   udf: cache struct...
628
  		cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL);
4b11111ab   Marcin Slusarz   udf: fix coding s...
629
630
  	cfi.fileCharacteristics =
  			FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
631
  	udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL);
3bf25cb40   Jan Kara   udf: use get_bh()
632
  	brelse(fibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
633
  	mark_inode_dirty(inode);
4b11111ab   Marcin Slusarz   udf: fix coding s...
634
635
  	fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
  	if (!fi) {
6d6b77f16   Miklos Szeredi   filesystems: add ...
636
  		clear_nlink(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
637
638
639
640
641
  		mark_inode_dirty(inode);
  		iput(inode);
  		goto out;
  	}
  	cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
642
  	cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
28de7948a   Cyrill Gorcunov   UDF: coding style...
643
  	*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
48d6d8ff7   Marcin Slusarz   udf: cache struct...
644
  		cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
645
646
  	cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY;
  	udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
d8c76e6f4   Dave Hansen   [PATCH] r/o bind ...
647
  	inc_nlink(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
648
649
650
  	mark_inode_dirty(dir);
  	d_instantiate(dentry, inode);
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
651
652
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
653
  	err = 0;
28de7948a   Cyrill Gorcunov   UDF: coding style...
654
655
  
  out:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
656
657
658
659
660
661
662
663
  	return err;
  }
  
  static int empty_dir(struct inode *dir)
  {
  	struct fileIdentDesc *fi, cfi;
  	struct udf_fileident_bh fibh;
  	loff_t f_pos;
af793295b   Jan Kara   udf: cleanup dire...
664
  	loff_t size = udf_ext0_offset(dir) + dir->i_size;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
665
  	int block;
5ca4e4be8   Pekka Enberg   Remove struct typ...
666
  	struct kernel_lb_addr eloc;
ff116fc8d   Jan Kara   UDF: introduce st...
667
  	uint32_t elen;
60448b1d6   Jan Kara   udf: use sector_t...
668
  	sector_t offset;
28de7948a   Cyrill Gorcunov   UDF: coding style...
669
  	struct extent_position epos = {};
48d6d8ff7   Marcin Slusarz   udf: cache struct...
670
  	struct udf_inode_info *dinfo = UDF_I(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
671

af793295b   Jan Kara   udf: cleanup dire...
672
673
  	f_pos = udf_ext0_offset(dir);
  	fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
674

48d6d8ff7   Marcin Slusarz   udf: cache struct...
675
  	if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
676
  		fibh.sbh = fibh.ebh = NULL;
af793295b   Jan Kara   udf: cleanup dire...
677
  	else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
4b11111ab   Marcin Slusarz   udf: fix coding s...
678
679
  			      &epos, &eloc, &elen, &offset) ==
  					(EXT_RECORDED_ALLOCATED >> 30)) {
97e961fdb   Pekka Enberg   Fix the udf code ...
680
  		block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
681
  		if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
48d6d8ff7   Marcin Slusarz   udf: cache struct...
682
  			if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
5ca4e4be8   Pekka Enberg   Remove struct typ...
683
  				epos.offset -= sizeof(struct short_ad);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
684
  			else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
5ca4e4be8   Pekka Enberg   Remove struct typ...
685
  				epos.offset -= sizeof(struct long_ad);
4b11111ab   Marcin Slusarz   udf: fix coding s...
686
  		} else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
687
  			offset = 0;
4b11111ab   Marcin Slusarz   udf: fix coding s...
688
689
  		fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block);
  		if (!fibh.sbh) {
3bf25cb40   Jan Kara   udf: use get_bh()
690
  			brelse(epos.bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691
692
  			return 0;
  		}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
693
  	} else {
3bf25cb40   Jan Kara   udf: use get_bh()
694
  		brelse(epos.bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
695
696
  		return 0;
  	}
af793295b   Jan Kara   udf: cleanup dire...
697
  	while (f_pos < size) {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
698
699
  		fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc,
  					&elen, &offset);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
700
  		if (!fi) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
701
  			if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
702
703
704
  				brelse(fibh.ebh);
  			brelse(fibh.sbh);
  			brelse(epos.bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
705
706
  			return 0;
  		}
28de7948a   Cyrill Gorcunov   UDF: coding style...
707
708
  		if (cfi.lengthFileIdent &&
  		    (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) == 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
709
  			if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
710
711
712
  				brelse(fibh.ebh);
  			brelse(fibh.sbh);
  			brelse(epos.bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
713
714
715
  			return 0;
  		}
  	}
28de7948a   Cyrill Gorcunov   UDF: coding style...
716

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
717
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
718
719
720
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
  	brelse(epos.bh);
28de7948a   Cyrill Gorcunov   UDF: coding style...
721

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
722
723
  	return 1;
  }
cb00ea352   Cyrill Gorcunov   UDF: coding style...
724
  static int udf_rmdir(struct inode *dir, struct dentry *dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
725
726
  {
  	int retval;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
727
  	struct inode *inode = dentry->d_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
728
729
  	struct udf_fileident_bh fibh;
  	struct fileIdentDesc *fi, cfi;
5ca4e4be8   Pekka Enberg   Remove struct typ...
730
  	struct kernel_lb_addr tloc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
731
732
  
  	retval = -ENOENT;
9fbb76ce0   Al Viro   [PATCH] get rid o...
733
  	fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
734
735
736
737
738
  	if (!fi)
  		goto out;
  
  	retval = -EIO;
  	tloc = lelb_to_cpu(cfi.icb.extLocation);
97e961fdb   Pekka Enberg   Fix the udf code ...
739
  	if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
740
741
742
743
744
745
746
747
  		goto end_rmdir;
  	retval = -ENOTEMPTY;
  	if (!empty_dir(inode))
  		goto end_rmdir;
  	retval = udf_delete_entry(dir, fi, &fibh, &cfi);
  	if (retval)
  		goto end_rmdir;
  	if (inode->i_nlink != 2)
a40ecd7b3   Joe Perches   udf: Rename udf_w...
748
749
750
  		udf_warn(inode->i_sb, "empty directory has nlink != 2 (%d)
  ",
  			 inode->i_nlink);
ce71ec368   Dave Hansen   [PATCH] r/o bind ...
751
  	clear_nlink(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
752
  	inode->i_size = 0;
c007c06e3   Stephen Mollett   udf: decrement co...
753
  	inode_dec_link_count(dir);
4b11111ab   Marcin Slusarz   udf: fix coding s...
754
755
  	inode->i_ctime = dir->i_ctime = dir->i_mtime =
  						current_fs_time(dir->i_sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
756
  	mark_inode_dirty(dir);
28de7948a   Cyrill Gorcunov   UDF: coding style...
757
  end_rmdir:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
758
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
759
760
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
28de7948a   Cyrill Gorcunov   UDF: coding style...
761
762
  
  out:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
763
764
  	return retval;
  }
cb00ea352   Cyrill Gorcunov   UDF: coding style...
765
  static int udf_unlink(struct inode *dir, struct dentry *dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
766
767
  {
  	int retval;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
768
  	struct inode *inode = dentry->d_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
769
770
771
  	struct udf_fileident_bh fibh;
  	struct fileIdentDesc *fi;
  	struct fileIdentDesc cfi;
5ca4e4be8   Pekka Enberg   Remove struct typ...
772
  	struct kernel_lb_addr tloc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
773
774
  
  	retval = -ENOENT;
9fbb76ce0   Al Viro   [PATCH] get rid o...
775
  	fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
776
777
778
779
780
  	if (!fi)
  		goto out;
  
  	retval = -EIO;
  	tloc = lelb_to_cpu(cfi.icb.extLocation);
97e961fdb   Pekka Enberg   Fix the udf code ...
781
  	if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
782
  		goto end_unlink;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
783
  	if (!inode->i_nlink) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
784
785
  		udf_debug("Deleting nonexistent file (%lu), %d
  ",
cb00ea352   Cyrill Gorcunov   UDF: coding style...
786
  			  inode->i_ino, inode->i_nlink);
bfe868486   Miklos Szeredi   filesystems: add ...
787
  		set_nlink(inode, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
788
789
790
791
792
793
  	}
  	retval = udf_delete_entry(dir, fi, &fibh, &cfi);
  	if (retval)
  		goto end_unlink;
  	dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb);
  	mark_inode_dirty(dir);
9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
794
  	inode_dec_link_count(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
795
796
  	inode->i_ctime = dir->i_ctime;
  	retval = 0;
28de7948a   Cyrill Gorcunov   UDF: coding style...
797
  end_unlink:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
798
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
799
800
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
28de7948a   Cyrill Gorcunov   UDF: coding style...
801
802
  
  out:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
803
804
  	return retval;
  }
cb00ea352   Cyrill Gorcunov   UDF: coding style...
805
806
  static int udf_symlink(struct inode *dir, struct dentry *dentry,
  		       const char *symname)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
807
  {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
808
  	struct inode *inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
809
  	struct pathComponent *pc;
391e8bbd3   Al Viro   sanitize const/si...
810
  	const char *compstart;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
811
  	struct udf_fileident_bh fibh;
28de7948a   Cyrill Gorcunov   UDF: coding style...
812
  	struct extent_position epos = {};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
813
814
815
  	int eoffset, elen = 0;
  	struct fileIdentDesc *fi;
  	struct fileIdentDesc cfi;
391e8bbd3   Al Viro   sanitize const/si...
816
  	uint8_t *ea;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
817
818
  	int err;
  	int block;
391e8bbd3   Al Viro   sanitize const/si...
819
  	unsigned char *name = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
820
  	int namelen;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
821
  	struct udf_inode_info *iinfo;
d664b6af6   Jan Kara   udf: Move handlin...
822
  	struct super_block *sb = dir->i_sb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
823

a6c5a0342   Dmitry Monakhov   udf: replace inod...
824
  	inode = udf_new_inode(dir, S_IFLNK | S_IRWXUGO, &err);
4b11111ab   Marcin Slusarz   udf: fix coding s...
825
  	if (!inode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
826
  		goto out;
4d0fb621d   Alessio Igor Bogani   udf: Replace bkl ...
827
828
  	iinfo = UDF_I(inode);
  	down_write(&iinfo->i_data_sem);
b80697c14   Jan Kara   udf: Remove decla...
829
830
831
832
833
  	name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
  	if (!name) {
  		err = -ENOMEM;
  		goto out_no_entry;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
834
  	inode->i_data.a_ops = &udf_symlink_aops;
c15d0fc0f   Dmitry Monakhov   udf: add speciffi...
835
  	inode->i_op = &udf_symlink_inode_operations;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
836

48d6d8ff7   Marcin Slusarz   udf: cache struct...
837
  	if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
5ca4e4be8   Pekka Enberg   Remove struct typ...
838
  		struct kernel_lb_addr eloc;
78e917d59   Harvey Harrison   udf: fix sparse w...
839
  		uint32_t bsize;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
840

d664b6af6   Jan Kara   udf: Move handlin...
841
  		block = udf_new_block(sb, inode,
48d6d8ff7   Marcin Slusarz   udf: cache struct...
842
843
  				iinfo->i_location.partitionReferenceNum,
  				iinfo->i_location.logicalBlockNum, &err);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
844
845
  		if (!block)
  			goto out_no_entry;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
846
  		epos.block = iinfo->i_location;
ff116fc8d   Jan Kara   UDF: introduce st...
847
848
  		epos.offset = udf_file_entry_alloc_offset(inode);
  		epos.bh = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
849
  		eloc.logicalBlockNum = block;
4b11111ab   Marcin Slusarz   udf: fix coding s...
850
  		eloc.partitionReferenceNum =
48d6d8ff7   Marcin Slusarz   udf: cache struct...
851
  				iinfo->i_location.partitionReferenceNum;
d664b6af6   Jan Kara   udf: Move handlin...
852
  		bsize = sb->s_blocksize;
78e917d59   Harvey Harrison   udf: fix sparse w...
853
  		iinfo->i_lenExtents = bsize;
97e961fdb   Pekka Enberg   Fix the udf code ...
854
  		udf_add_aext(inode, &epos, &eloc, bsize, 0);
3bf25cb40   Jan Kara   udf: use get_bh()
855
  		brelse(epos.bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
856

d664b6af6   Jan Kara   udf: Move handlin...
857
  		block = udf_get_pblock(sb, block,
48d6d8ff7   Marcin Slusarz   udf: cache struct...
858
  				iinfo->i_location.partitionReferenceNum,
4b11111ab   Marcin Slusarz   udf: fix coding s...
859
  				0);
d664b6af6   Jan Kara   udf: Move handlin...
860
  		epos.bh = udf_tgetblk(sb, block);
ff116fc8d   Jan Kara   UDF: introduce st...
861
  		lock_buffer(epos.bh);
d664b6af6   Jan Kara   udf: Move handlin...
862
  		memset(epos.bh->b_data, 0x00, bsize);
ff116fc8d   Jan Kara   UDF: introduce st...
863
864
865
866
  		set_buffer_uptodate(epos.bh);
  		unlock_buffer(epos.bh);
  		mark_buffer_dirty_inode(epos.bh, inode);
  		ea = epos.bh->b_data + udf_ext0_offset(inode);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
867
868
  	} else
  		ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
869

d664b6af6   Jan Kara   udf: Move handlin...
870
  	eoffset = sb->s_blocksize - udf_ext0_offset(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
871
  	pc = (struct pathComponent *)ea;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
872
873
  	if (*symname == '/') {
  		do {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
874
875
876
877
878
879
  			symname++;
  		} while (*symname == '/');
  
  		pc->componentType = 1;
  		pc->lengthComponentIdent = 0;
  		pc->componentFileVersionNum = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
880
881
882
883
  		elen += sizeof(struct pathComponent);
  	}
  
  	err = -ENAMETOOLONG;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
884
  	while (*symname) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
885
886
887
888
  		if (elen + sizeof(struct pathComponent) > eoffset)
  			goto out_no_entry;
  
  		pc = (struct pathComponent *)(ea + elen);
391e8bbd3   Al Viro   sanitize const/si...
889
  		compstart = symname;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
890

cb00ea352   Cyrill Gorcunov   UDF: coding style...
891
  		do {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
892
893
894
895
896
897
  			symname++;
  		} while (*symname && *symname != '/');
  
  		pc->componentType = 5;
  		pc->lengthComponentIdent = 0;
  		pc->componentFileVersionNum = 0;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
898
899
  		if (compstart[0] == '.') {
  			if ((symname - compstart) == 1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
900
  				pc->componentType = 4;
4b11111ab   Marcin Slusarz   udf: fix coding s...
901
902
  			else if ((symname - compstart) == 2 &&
  					compstart[1] == '.')
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
903
904
  				pc->componentType = 3;
  		}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
905
  		if (pc->componentType == 5) {
d664b6af6   Jan Kara   udf: Move handlin...
906
  			namelen = udf_put_filename(sb, compstart, name,
28de7948a   Cyrill Gorcunov   UDF: coding style...
907
908
  						   symname - compstart);
  			if (!namelen)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
909
  				goto out_no_entry;
4b11111ab   Marcin Slusarz   udf: fix coding s...
910
911
  			if (elen + sizeof(struct pathComponent) + namelen >
  					eoffset)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
912
913
914
915
916
917
918
919
  				goto out_no_entry;
  			else
  				pc->lengthComponentIdent = namelen;
  
  			memcpy(pc->componentIdent, name, namelen);
  		}
  
  		elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
cb00ea352   Cyrill Gorcunov   UDF: coding style...
920
921
  		if (*symname) {
  			do {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
922
923
924
925
  				symname++;
  			} while (*symname == '/');
  		}
  	}
3bf25cb40   Jan Kara   udf: use get_bh()
926
  	brelse(epos.bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
927
  	inode->i_size = elen;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
928
929
  	if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
  		iinfo->i_lenAlloc = inode->i_size;
2c948b3f8   Jan Kara   udf: Avoid IO in ...
930
931
  	else
  		udf_truncate_tail_extent(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
932
  	mark_inode_dirty(inode);
4b11111ab   Marcin Slusarz   udf: fix coding s...
933
934
  	fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
  	if (!fi)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
935
  		goto out_no_entry;
d664b6af6   Jan Kara   udf: Move handlin...
936
  	cfi.icb.extLength = cpu_to_le32(sb->s_blocksize);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
937
  	cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
d664b6af6   Jan Kara   udf: Move handlin...
938
  	if (UDF_SB(inode->i_sb)->s_lvid_bh) {
28de7948a   Cyrill Gorcunov   UDF: coding style...
939
  		*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
d664b6af6   Jan Kara   udf: Move handlin...
940
  			cpu_to_le32(lvid_get_unique_id(sb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
941
942
  	}
  	udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
c0b344385   Marcin Slusarz   udf: remove UDF_I...
943
  	if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
944
  		mark_inode_dirty(dir);
4d0fb621d   Alessio Igor Bogani   udf: Replace bkl ...
945
  	up_write(&iinfo->i_data_sem);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
946
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
947
948
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
949
950
  	d_instantiate(dentry, inode);
  	err = 0;
28de7948a   Cyrill Gorcunov   UDF: coding style...
951
  out:
b80697c14   Jan Kara   udf: Remove decla...
952
  	kfree(name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
953
  	return err;
28de7948a   Cyrill Gorcunov   UDF: coding style...
954
  out_no_entry:
4d0fb621d   Alessio Igor Bogani   udf: Replace bkl ...
955
  	up_write(&iinfo->i_data_sem);
9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
956
  	inode_dec_link_count(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
957
958
959
  	iput(inode);
  	goto out;
  }
cb00ea352   Cyrill Gorcunov   UDF: coding style...
960
961
  static int udf_link(struct dentry *old_dentry, struct inode *dir,
  		    struct dentry *dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
962
963
964
965
966
  {
  	struct inode *inode = old_dentry->d_inode;
  	struct udf_fileident_bh fibh;
  	struct fileIdentDesc cfi, *fi;
  	int err;
4b11111ab   Marcin Slusarz   udf: fix coding s...
967
968
  	fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
  	if (!fi) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
969
970
971
  		return err;
  	}
  	cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
c0b344385   Marcin Slusarz   udf: remove UDF_I...
972
  	cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location);
d664b6af6   Jan Kara   udf: Move handlin...
973
  	if (UDF_SB(inode->i_sb)->s_lvid_bh) {
28de7948a   Cyrill Gorcunov   UDF: coding style...
974
  		*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
d664b6af6   Jan Kara   udf: Move handlin...
975
  			cpu_to_le32(lvid_get_unique_id(inode->i_sb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
976
977
  	}
  	udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
c0b344385   Marcin Slusarz   udf: remove UDF_I...
978
  	if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
979
  		mark_inode_dirty(dir);
28de7948a   Cyrill Gorcunov   UDF: coding style...
980

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
981
  	if (fibh.sbh != fibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
982
983
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
d8c76e6f4   Dave Hansen   [PATCH] r/o bind ...
984
  	inc_nlink(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
985
986
  	inode->i_ctime = current_fs_time(inode->i_sb);
  	mark_inode_dirty(inode);
7de9c6ee3   Al Viro   new helper: ihold()
987
  	ihold(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
988
  	d_instantiate(dentry, inode);
28de7948a   Cyrill Gorcunov   UDF: coding style...
989

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
990
991
992
993
994
995
  	return 0;
  }
  
  /* Anybody can rename anything with this: the permission checks are left to the
   * higher-level routines.
   */
cb00ea352   Cyrill Gorcunov   UDF: coding style...
996
997
  static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
  		      struct inode *new_dir, struct dentry *new_dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
998
  {
cb00ea352   Cyrill Gorcunov   UDF: coding style...
999
1000
  	struct inode *old_inode = old_dentry->d_inode;
  	struct inode *new_inode = new_dentry->d_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1001
  	struct udf_fileident_bh ofibh, nfibh;
4b11111ab   Marcin Slusarz   udf: fix coding s...
1002
1003
  	struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL;
  	struct fileIdentDesc ocfi, ncfi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1004
1005
  	struct buffer_head *dir_bh = NULL;
  	int retval = -ENOENT;
5ca4e4be8   Pekka Enberg   Remove struct typ...
1006
  	struct kernel_lb_addr tloc;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
1007
  	struct udf_inode_info *old_iinfo = UDF_I(old_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1008

9fbb76ce0   Al Viro   [PATCH] get rid o...
1009
  	ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
4b11111ab   Marcin Slusarz   udf: fix coding s...
1010
  	if (ofi) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1011
  		if (ofibh.sbh != ofibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
1012
1013
  			brelse(ofibh.ebh);
  		brelse(ofibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1014
1015
  	}
  	tloc = lelb_to_cpu(ocfi.icb.extLocation);
97e961fdb   Pekka Enberg   Fix the udf code ...
1016
  	if (!ofi || udf_get_lb_pblock(old_dir->i_sb, &tloc, 0)
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1017
  	    != old_inode->i_ino)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1018
  		goto end_rename;
9fbb76ce0   Al Viro   [PATCH] get rid o...
1019
  	nfi = udf_find_entry(new_dir, &new_dentry->d_name, &nfibh, &ncfi);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1020
1021
  	if (nfi) {
  		if (!new_inode) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1022
  			if (nfibh.sbh != nfibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
1023
1024
  				brelse(nfibh.ebh);
  			brelse(nfibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1025
1026
1027
  			nfi = NULL;
  		}
  	}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1028
  	if (S_ISDIR(old_inode->i_mode)) {
7f3fbd089   Marcin Slusarz   udf: fix signedne...
1029
  		int offset = udf_ext0_offset(old_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1030

cb00ea352   Cyrill Gorcunov   UDF: coding style...
1031
  		if (new_inode) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1032
1033
1034
1035
1036
  			retval = -ENOTEMPTY;
  			if (!empty_dir(new_inode))
  				goto end_rename;
  		}
  		retval = -EIO;
48d6d8ff7   Marcin Slusarz   udf: cache struct...
1037
  		if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
4b11111ab   Marcin Slusarz   udf: fix coding s...
1038
  			dir_fi = udf_get_fileident(
48d6d8ff7   Marcin Slusarz   udf: cache struct...
1039
1040
  					old_iinfo->i_ext.i_data -
  					  (old_iinfo->i_efe ?
4b11111ab   Marcin Slusarz   udf: fix coding s...
1041
1042
1043
  					   sizeof(struct extendedFileEntry) :
  					   sizeof(struct fileEntry)),
  					old_inode->i_sb->s_blocksize, &offset);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1044
  		} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1045
1046
1047
  			dir_bh = udf_bread(old_inode, 0, 0, &retval);
  			if (!dir_bh)
  				goto end_rename;
4b11111ab   Marcin Slusarz   udf: fix coding s...
1048
1049
  			dir_fi = udf_get_fileident(dir_bh->b_data,
  					old_inode->i_sb->s_blocksize, &offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1050
1051
1052
1053
  		}
  		if (!dir_fi)
  			goto end_rename;
  		tloc = lelb_to_cpu(dir_fi->icb.extLocation);
97e961fdb   Pekka Enberg   Fix the udf code ...
1054
  		if (udf_get_lb_pblock(old_inode->i_sb, &tloc, 0) !=
4b11111ab   Marcin Slusarz   udf: fix coding s...
1055
  				old_dir->i_ino)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1056
  			goto end_rename;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1057
  	}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1058
  	if (!nfi) {
4b11111ab   Marcin Slusarz   udf: fix coding s...
1059
1060
  		nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi,
  				    &retval);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
  		if (!nfi)
  			goto end_rename;
  	}
  
  	/*
  	 * Like most other Unix systems, set the ctime for inodes on a
  	 * rename.
  	 */
  	old_inode->i_ctime = current_fs_time(old_inode->i_sb);
  	mark_inode_dirty(old_inode);
  
  	/*
  	 * ok, that's it
  	 */
  	ncfi.fileVersionNum = ocfi.fileVersionNum;
  	ncfi.fileCharacteristics = ocfi.fileCharacteristics;
5ca4e4be8   Pekka Enberg   Remove struct typ...
1077
  	memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(struct long_ad));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1078
1079
1080
  	udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL);
  
  	/* The old fid may have moved - find it again */
9fbb76ce0   Al Viro   [PATCH] get rid o...
1081
  	ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1082
  	udf_delete_entry(old_dir, ofi, &ofibh, &ocfi);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1083
  	if (new_inode) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1084
  		new_inode->i_ctime = current_fs_time(new_inode->i_sb);
9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
1085
  		inode_dec_link_count(new_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1086
1087
1088
  	}
  	old_dir->i_ctime = old_dir->i_mtime = current_fs_time(old_dir->i_sb);
  	mark_inode_dirty(old_dir);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1089
  	if (dir_fi) {
c0b344385   Marcin Slusarz   udf: remove UDF_I...
1090
  		dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location);
4b11111ab   Marcin Slusarz   udf: fix coding s...
1091
1092
1093
  		udf_update_tag((char *)dir_fi,
  				(sizeof(struct fileIdentDesc) +
  				le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3);
48d6d8ff7   Marcin Slusarz   udf: cache struct...
1094
  		if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1095
  			mark_inode_dirty(old_inode);
4b11111ab   Marcin Slusarz   udf: fix coding s...
1096
  		else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1097
  			mark_buffer_dirty_inode(dir_bh, old_inode);
4b11111ab   Marcin Slusarz   udf: fix coding s...
1098

9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
1099
  		inode_dec_link_count(old_dir);
4b11111ab   Marcin Slusarz   udf: fix coding s...
1100
  		if (new_inode)
9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
1101
  			inode_dec_link_count(new_inode);
4b11111ab   Marcin Slusarz   udf: fix coding s...
1102
  		else {
d8c76e6f4   Dave Hansen   [PATCH] r/o bind ...
1103
  			inc_nlink(new_dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1104
1105
1106
  			mark_inode_dirty(new_dir);
  		}
  	}
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1107
  	if (ofi) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1108
  		if (ofibh.sbh != ofibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
1109
1110
  			brelse(ofibh.ebh);
  		brelse(ofibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1111
1112
1113
  	}
  
  	retval = 0;
28de7948a   Cyrill Gorcunov   UDF: coding style...
1114
  end_rename:
3bf25cb40   Jan Kara   udf: use get_bh()
1115
  	brelse(dir_bh);
cb00ea352   Cyrill Gorcunov   UDF: coding style...
1116
  	if (nfi) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1117
  		if (nfibh.sbh != nfibh.ebh)
3bf25cb40   Jan Kara   udf: use get_bh()
1118
1119
  			brelse(nfibh.ebh);
  		brelse(nfibh.sbh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1120
  	}
28de7948a   Cyrill Gorcunov   UDF: coding style...
1121

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1122
1123
  	return retval;
  }
221e583a7   Rasmus Rohde   udf: Make udf exp...
1124
1125
  static struct dentry *udf_get_parent(struct dentry *child)
  {
97e961fdb   Pekka Enberg   Fix the udf code ...
1126
  	struct kernel_lb_addr tloc;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1127
  	struct inode *inode = NULL;
26fe57502   Linus Torvalds   vfs: make it poss...
1128
  	struct qstr dotdot = QSTR_INIT("..", 2);
221e583a7   Rasmus Rohde   udf: Make udf exp...
1129
1130
  	struct fileIdentDesc cfi;
  	struct udf_fileident_bh fibh;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1131
1132
1133
1134
1135
1136
  	if (!udf_find_entry(child->d_inode, &dotdot, &fibh, &cfi))
  		goto out_unlock;
  
  	if (fibh.sbh != fibh.ebh)
  		brelse(fibh.ebh);
  	brelse(fibh.sbh);
97e961fdb   Pekka Enberg   Fix the udf code ...
1137
1138
  	tloc = lelb_to_cpu(cfi.icb.extLocation);
  	inode = udf_iget(child->d_inode->i_sb, &tloc);
221e583a7   Rasmus Rohde   udf: Make udf exp...
1139
1140
  	if (!inode)
  		goto out_unlock;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1141

440037287   Christoph Hellwig   [PATCH] switch al...
1142
  	return d_obtain_alias(inode);
221e583a7   Rasmus Rohde   udf: Make udf exp...
1143
  out_unlock:
221e583a7   Rasmus Rohde   udf: Make udf exp...
1144
1145
1146
1147
1148
1149
1150
1151
  	return ERR_PTR(-EACCES);
  }
  
  
  static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block,
  					u16 partref, __u32 generation)
  {
  	struct inode *inode;
5ca4e4be8   Pekka Enberg   Remove struct typ...
1152
  	struct kernel_lb_addr loc;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1153
1154
1155
1156
1157
1158
  
  	if (block == 0)
  		return ERR_PTR(-ESTALE);
  
  	loc.logicalBlockNum = block;
  	loc.partitionReferenceNum = partref;
97e961fdb   Pekka Enberg   Fix the udf code ...
1159
  	inode = udf_iget(sb, &loc);
221e583a7   Rasmus Rohde   udf: Make udf exp...
1160
1161
1162
1163
1164
1165
1166
1167
  
  	if (inode == NULL)
  		return ERR_PTR(-ENOMEM);
  
  	if (generation && inode->i_generation != generation) {
  		iput(inode);
  		return ERR_PTR(-ESTALE);
  	}
440037287   Christoph Hellwig   [PATCH] switch al...
1168
  	return d_obtain_alias(inode);
221e583a7   Rasmus Rohde   udf: Make udf exp...
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
  }
  
  static struct dentry *udf_fh_to_dentry(struct super_block *sb,
  				       struct fid *fid, int fh_len, int fh_type)
  {
  	if ((fh_len != 3 && fh_len != 5) ||
  	    (fh_type != FILEID_UDF_WITH_PARENT &&
  	     fh_type != FILEID_UDF_WITHOUT_PARENT))
  		return NULL;
  
  	return udf_nfs_get_inode(sb, fid->udf.block, fid->udf.partref,
  			fid->udf.generation);
  }
  
  static struct dentry *udf_fh_to_parent(struct super_block *sb,
  				       struct fid *fid, int fh_len, int fh_type)
  {
  	if (fh_len != 5 || fh_type != FILEID_UDF_WITH_PARENT)
  		return NULL;
  
  	return udf_nfs_get_inode(sb, fid->udf.parent_block,
  				 fid->udf.parent_partref,
  				 fid->udf.parent_generation);
  }
b0b0382bb   Al Viro   ->encode_fh() API...
1193
1194
  static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
  			 struct inode *parent)
221e583a7   Rasmus Rohde   udf: Make udf exp...
1195
1196
  {
  	int len = *lenp;
5ca4e4be8   Pekka Enberg   Remove struct typ...
1197
  	struct kernel_lb_addr location = UDF_I(inode)->i_location;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1198
1199
  	struct fid *fid = (struct fid *)fh;
  	int type = FILEID_UDF_WITHOUT_PARENT;
b0b0382bb   Al Viro   ->encode_fh() API...
1200
  	if (parent && (len < 5)) {
5fe0c2378   Aneesh Kumar K.V   exportfs: Return ...
1201
  		*lenp = 5;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1202
  		return 255;
5fe0c2378   Aneesh Kumar K.V   exportfs: Return ...
1203
1204
1205
1206
  	} else if (len < 3) {
  		*lenp = 3;
  		return 255;
  	}
221e583a7   Rasmus Rohde   udf: Make udf exp...
1207
1208
1209
1210
  
  	*lenp = 3;
  	fid->udf.block = location.logicalBlockNum;
  	fid->udf.partref = location.partitionReferenceNum;
0143fc5e9   Mathias Krause   udf: avoid info l...
1211
  	fid->udf.parent_partref = 0;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1212
  	fid->udf.generation = inode->i_generation;
b0b0382bb   Al Viro   ->encode_fh() API...
1213
1214
  	if (parent) {
  		location = UDF_I(parent)->i_location;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1215
1216
1217
  		fid->udf.parent_block = location.logicalBlockNum;
  		fid->udf.parent_partref = location.partitionReferenceNum;
  		fid->udf.parent_generation = inode->i_generation;
221e583a7   Rasmus Rohde   udf: Make udf exp...
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
  		*lenp = 5;
  		type = FILEID_UDF_WITH_PARENT;
  	}
  
  	return type;
  }
  
  const struct export_operations udf_export_ops = {
  	.encode_fh	= udf_encode_fh,
  	.fh_to_dentry   = udf_fh_to_dentry,
  	.fh_to_parent   = udf_fh_to_parent,
  	.get_parent     = udf_get_parent,
  };
c5ef1c42c   Arjan van de Ven   [PATCH] mark stru...
1231
  const struct inode_operations udf_dir_inode_operations = {
28de7948a   Cyrill Gorcunov   UDF: coding style...
1232
1233
1234
1235
1236
1237
1238
1239
1240
  	.lookup				= udf_lookup,
  	.create				= udf_create,
  	.link				= udf_link,
  	.unlink				= udf_unlink,
  	.symlink			= udf_symlink,
  	.mkdir				= udf_mkdir,
  	.rmdir				= udf_rmdir,
  	.mknod				= udf_mknod,
  	.rename				= udf_rename,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1241
  };
c15d0fc0f   Dmitry Monakhov   udf: add speciffi...
1242
1243
1244
1245
  const struct inode_operations udf_symlink_inode_operations = {
  	.readlink	= generic_readlink,
  	.follow_link	= page_follow_link_light,
  	.put_link	= page_put_link,
c15d0fc0f   Dmitry Monakhov   udf: add speciffi...
1246
  };