Blame view

fs/reiserfs/namei.c 44.2 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
  /*
   * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
   *
   * Trivial changes by Alan Cox to remove EHASHCOLLISION for compatibility
   *
   * Trivial Changes:
   * Rights granted to Hans Reiser to redistribute under other terms providing
   * he accepts all liability including but not limited to patent, fitness
   * for purpose, and direct or indirect claims arising from failure to perform.
   *
   * NO WARRANTY
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
  #include <linux/time.h>
  #include <linux/bitops.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
15
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
  #include <linux/reiserfs_fs.h>
  #include <linux/reiserfs_acl.h>
  #include <linux/reiserfs_xattr.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  #include <linux/quotaops.h>
bfe868486   Miklos Szeredi   filesystems: add ...
20
  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); }
9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
21
  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
24
  
  // directory item contains array of entry headers. This performs
  // binary search through that array
bd4c625c0   Linus Torvalds   reiserfs: run scr...
25
  static int bin_search_in_dir_item(struct reiserfs_dir_entry *de, loff_t off)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  	struct item_head *ih = de->de_ih;
  	struct reiserfs_de_head *deh = de->de_deh;
  	int rbound, lbound, j;
  
  	lbound = 0;
  	rbound = I_ENTRY_COUNT(ih) - 1;
  
  	for (j = (rbound + lbound) / 2; lbound <= rbound;
  	     j = (rbound + lbound) / 2) {
  		if (off < deh_offset(deh + j)) {
  			rbound = j - 1;
  			continue;
  		}
  		if (off > deh_offset(deh + j)) {
  			lbound = j + 1;
  			continue;
  		}
  		// this is not name found, but matched third key component
  		de->de_entry_num = j;
  		return NAME_FOUND;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48

bd4c625c0   Linus Torvalds   reiserfs: run scr...
49
50
  	de->de_entry_num = lbound;
  	return NAME_NOT_FOUND;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
  // comment?  maybe something like set de to point to what the path points to?
bd4c625c0   Linus Torvalds   reiserfs: run scr...
53
  static inline void set_de_item_location(struct reiserfs_dir_entry *de,
fec6d055d   Josef "Jeff" Sipek   [PATCH] struct pa...
54
  					struct treepath *path)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
56
57
58
59
60
  	de->de_bh = get_last_bh(path);
  	de->de_ih = get_ih(path);
  	de->de_deh = B_I_DEH(de->de_bh, de->de_ih);
  	de->de_item_num = PATH_LAST_POSITION(path);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
  
  // de_bh, de_ih, de_deh (points to first element of array), de_item_num is set
bd4c625c0   Linus Torvalds   reiserfs: run scr...
63
  inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
65
  	struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66

14a61442c   Eric Sesterhenn   BUG_ON conversion...
67
  	BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68

bd4c625c0   Linus Torvalds   reiserfs: run scr...
69
70
71
72
73
  	de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num);
  	de->de_namelen = de->de_entrylen - (de_with_sd(deh) ? SD_SIZE : 0);
  	de->de_name = B_I_PITEM(de->de_bh, de->de_ih) + deh_location(deh);
  	if (de->de_name[de->de_namelen - 1] == 0)
  		de->de_namelen = strlen(de->de_name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  // what entry points to
bd4c625c0   Linus Torvalds   reiserfs: run scr...
76
  static inline void set_de_object_key(struct reiserfs_dir_entry *de)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
  {
14a61442c   Eric Sesterhenn   BUG_ON conversion...
78
  	BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
bd4c625c0   Linus Torvalds   reiserfs: run scr...
79
80
  	de->de_dir_id = deh_dir_id(&(de->de_deh[de->de_entry_num]));
  	de->de_objectid = deh_objectid(&(de->de_deh[de->de_entry_num]));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
82
  static inline void store_de_entry_key(struct reiserfs_dir_entry *de)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
84
  	struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
14a61442c   Eric Sesterhenn   BUG_ON conversion...
85
  	BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
bd4c625c0   Linus Torvalds   reiserfs: run scr...
86
87
88
89
90
91
92
93
94
  
  	/* store key of the found entry */
  	de->de_entry_key.version = KEY_FORMAT_3_5;
  	de->de_entry_key.on_disk_key.k_dir_id =
  	    le32_to_cpu(de->de_ih->ih_key.k_dir_id);
  	de->de_entry_key.on_disk_key.k_objectid =
  	    le32_to_cpu(de->de_ih->ih_key.k_objectid);
  	set_cpu_key_k_offset(&(de->de_entry_key), deh_offset(deh));
  	set_cpu_key_k_type(&(de->de_entry_key), TYPE_DIRENTRY);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
99
100
101
102
  /* We assign a key to each directory item, and place multiple entries
  in a single directory item.  A directory item has a key equal to the
  key of the first directory entry in it.
  
  This function first calls search_by_key, then, if item whose first
  entry matches is not found it looks for the entry inside directory
  item found by search_by_key. Fills the path to the entry, and to the
0222e6571   Jeff Mahoney   reiserfs: strip t...
103
  entry position in the item
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
106
107
  
  */
  
  /* The function is NOT SCHEDULE-SAFE! */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
108
  int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
fec6d055d   Josef "Jeff" Sipek   [PATCH] struct pa...
109
  			struct treepath *path, struct reiserfs_dir_entry *de)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
111
112
113
114
115
116
  	int retval;
  
  	retval = search_item(sb, key, path);
  	switch (retval) {
  	case ITEM_NOT_FOUND:
  		if (!PATH_LAST_POSITION(path)) {
0030b6457   Jeff Mahoney   reiserfs: use rei...
117
118
  			reiserfs_error(sb, "vs-7000", "search_by_key "
  				       "returned item position == 0");
bd4c625c0   Linus Torvalds   reiserfs: run scr...
119
120
121
122
123
124
125
126
127
128
129
130
131
  			pathrelse(path);
  			return IO_ERROR;
  		}
  		PATH_LAST_POSITION(path)--;
  
  	case ITEM_FOUND:
  		break;
  
  	case IO_ERROR:
  		return retval;
  
  	default:
  		pathrelse(path);
0030b6457   Jeff Mahoney   reiserfs: use rei...
132
  		reiserfs_error(sb, "vs-7002", "no path to here");
bd4c625c0   Linus Torvalds   reiserfs: run scr...
133
  		return IO_ERROR;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135

bd4c625c0   Linus Torvalds   reiserfs: run scr...
136
  	set_de_item_location(de, path);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
138
  
  #ifdef CONFIG_REISERFS_CHECK
bd4c625c0   Linus Torvalds   reiserfs: run scr...
139
140
141
  	if (!is_direntry_le_ih(de->de_ih) ||
  	    COMP_SHORT_KEYS(&(de->de_ih->ih_key), key)) {
  		print_block(de->de_bh, 0, -1, -1);
c3a9c2109   Jeff Mahoney   reiserfs: rework ...
142
143
144
  		reiserfs_panic(sb, "vs-7005", "found item %h is not directory "
  			       "item or does not belong to the same directory "
  			       "as key %K", de->de_ih, key);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
145
146
147
148
149
150
151
152
153
154
155
156
157
  	}
  #endif				/* CONFIG_REISERFS_CHECK */
  
  	/* binary search in directory item by third componen t of the
  	   key. sets de->de_entry_num of de */
  	retval = bin_search_in_dir_item(de, cpu_key_k_offset(key));
  	path->pos_in_item = de->de_entry_num;
  	if (retval != NAME_NOT_FOUND) {
  		// ugly, but rename needs de_bh, de_deh, de_name, de_namelen, de_objectid set
  		set_de_name_and_namelen(de);
  		set_de_object_key(de);
  	}
  	return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
160
161
162
163
164
  /* Keyed 32-bit hash function using TEA in a Davis-Meyer function */
  
  /* The third component is hashed, and you can choose from more than
     one hash function.  Per directory hashes are not yet implemented
     but are thought about. This function should be moved to hashes.c
     Jedi, please do so.  -Hans */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
165
166
  static __u32 get_third_component(struct super_block *s,
  				 const char *name, int len)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
167
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  	__u32 res;
  
  	if (!len || (len == 1 && name[0] == '.'))
  		return DOT_OFFSET;
  	if (len == 2 && name[0] == '.' && name[1] == '.')
  		return DOT_DOT_OFFSET;
  
  	res = REISERFS_SB(s)->s_hash_function(name, len);
  
  	// take bits from 7-th to 30-th including both bounds
  	res = GET_HASH_VALUE(res);
  	if (res == 0)
  		// needed to have no names before "." and ".." those have hash
  		// value == 0 and generation conters 1 and 2 accordingly
  		res = 128;
  	return res + MAX_GENERATION_NUMBER;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
185
186
  static int reiserfs_match(struct reiserfs_dir_entry *de,
  			  const char *name, int namelen)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
188
  	int retval = NAME_NOT_FOUND;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189

bd4c625c0   Linus Torvalds   reiserfs: run scr...
190
191
192
193
194
  	if ((namelen == de->de_namelen) &&
  	    !memcmp(de->de_name, name, de->de_namelen))
  		retval =
  		    (de_visible(de->de_deh + de->de_entry_num) ? NAME_FOUND :
  		     NAME_FOUND_INVISIBLE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195

bd4c625c0   Linus Torvalds   reiserfs: run scr...
196
  	return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198
199
200
  /* de's de_bh, de_ih, de_deh, de_item_num, de_entry_num are set already */
  
  				/* used when hash collisions exist */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
201
202
203
  static int linear_search_in_dir_item(struct cpu_key *key,
  				     struct reiserfs_dir_entry *de,
  				     const char *name, int namelen)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
204
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
205
206
207
  	struct reiserfs_de_head *deh = de->de_deh;
  	int retval;
  	int i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208

bd4c625c0   Linus Torvalds   reiserfs: run scr...
209
  	i = de->de_entry_num;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
210

bd4c625c0   Linus Torvalds   reiserfs: run scr...
211
212
213
214
215
  	if (i == I_ENTRY_COUNT(de->de_ih) ||
  	    GET_HASH_VALUE(deh_offset(deh + i)) !=
  	    GET_HASH_VALUE(cpu_key_k_offset(key))) {
  		i--;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216

bd4c625c0   Linus Torvalds   reiserfs: run scr...
217
218
  	RFALSE(de->de_deh != B_I_DEH(de->de_bh, de->de_ih),
  	       "vs-7010: array of entry headers not found");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219

bd4c625c0   Linus Torvalds   reiserfs: run scr...
220
  	deh += i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221

bd4c625c0   Linus Torvalds   reiserfs: run scr...
222
223
224
225
226
227
228
229
230
231
  	for (; i >= 0; i--, deh--) {
  		if (GET_HASH_VALUE(deh_offset(deh)) !=
  		    GET_HASH_VALUE(cpu_key_k_offset(key))) {
  			// hash value does not match, no need to check whole name
  			return NAME_NOT_FOUND;
  		}
  
  		/* mark, that this generation number is used */
  		if (de->de_gen_number_bit_string)
  			set_bit(GET_GENERATION_NUMBER(deh_offset(deh)),
3af1efe8a   Jeff Mahoney   [PATCH] reiserfs:...
232
  				de->de_gen_number_bit_string);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233

bd4c625c0   Linus Torvalds   reiserfs: run scr...
234
235
236
  		// calculate pointer to name and namelen
  		de->de_entry_num = i;
  		set_de_name_and_namelen(de);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237

bd4c625c0   Linus Torvalds   reiserfs: run scr...
238
239
240
  		if ((retval =
  		     reiserfs_match(de, name, namelen)) != NAME_NOT_FOUND) {
  			// de's de_name, de_namelen, de_recordlen are set. Fill the rest:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241

bd4c625c0   Linus Torvalds   reiserfs: run scr...
242
243
  			// key of pointed object
  			set_de_object_key(de);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244

bd4c625c0   Linus Torvalds   reiserfs: run scr...
245
  			store_de_entry_key(de);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246

bd4c625c0   Linus Torvalds   reiserfs: run scr...
247
248
249
  			// retval can be NAME_FOUND or NAME_FOUND_INVISIBLE
  			return retval;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
250
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
251

bd4c625c0   Linus Torvalds   reiserfs: run scr...
252
253
254
255
256
257
258
259
260
  	if (GET_GENERATION_NUMBER(le_ih_k_offset(de->de_ih)) == 0)
  		/* we have reached left most entry in the node. In common we
  		   have to go to the left neighbor, but if generation counter
  		   is 0 already, we know for sure, that there is no name with
  		   the same hash value */
  		// FIXME: this work correctly only because hash value can not
  		// be 0. Btw, in case of Yura's hash it is probably possible,
  		// so, this is a bug
  		return NAME_NOT_FOUND;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261

bd4c625c0   Linus Torvalds   reiserfs: run scr...
262
263
  	RFALSE(de->de_item_num,
  	       "vs-7015: two diritems of the same directory in one node?");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
264

bd4c625c0   Linus Torvalds   reiserfs: run scr...
265
266
  	return GOTO_PREVIOUS_ITEM;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267
268
269
  
  // may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND
  // FIXME: should add something like IOERROR
bd4c625c0   Linus Torvalds   reiserfs: run scr...
270
  static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen,
fec6d055d   Josef "Jeff" Sipek   [PATCH] struct pa...
271
  			       struct treepath *path_to_entry,
bd4c625c0   Linus Torvalds   reiserfs: run scr...
272
  			       struct reiserfs_dir_entry *de)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
273
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  	struct cpu_key key_to_search;
  	int retval;
  
  	if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize))
  		return NAME_NOT_FOUND;
  
  	/* we will search for this key in the tree */
  	make_cpu_key(&key_to_search, dir,
  		     get_third_component(dir->i_sb, name, namelen),
  		     TYPE_DIRENTRY, 3);
  
  	while (1) {
  		retval =
  		    search_by_entry_key(dir->i_sb, &key_to_search,
  					path_to_entry, de);
  		if (retval == IO_ERROR) {
0030b6457   Jeff Mahoney   reiserfs: use rei...
290
  			reiserfs_error(dir->i_sb, "zam-7001", "io error");
bd4c625c0   Linus Torvalds   reiserfs: run scr...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  			return IO_ERROR;
  		}
  
  		/* compare names for all entries having given hash value */
  		retval =
  		    linear_search_in_dir_item(&key_to_search, de, name,
  					      namelen);
  		if (retval != GOTO_PREVIOUS_ITEM) {
  			/* there is no need to scan directory anymore. Given entry found or does not exist */
  			path_to_entry->pos_in_item = de->de_entry_num;
  			return retval;
  		}
  
  		/* there is left neighboring item of this directory and given entry can be there */
  		set_cpu_key_k_offset(&key_to_search,
  				     le_ih_k_offset(de->de_ih) - 1);
  		pathrelse(path_to_entry);
  
  	}			/* while (1) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
311
312
  static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
  				      struct nameidata *nd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
314
  	int retval;
b1c839bb2   Frederic Weisbecker   kill-the-bkl/reis...
315
  	int lock_depth;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
316
317
318
319
320
321
  	struct inode *inode = NULL;
  	struct reiserfs_dir_entry de;
  	INITIALIZE_PATH(path_to_entry);
  
  	if (REISERFS_MAX_NAME(dir->i_sb->s_blocksize) < dentry->d_name.len)
  		return ERR_PTR(-ENAMETOOLONG);
b1c839bb2   Frederic Weisbecker   kill-the-bkl/reis...
322
323
324
325
326
327
  	/*
  	 * Might be called with or without the write lock, must be careful
  	 * to not recursively hold it in case we want to release the lock
  	 * before rescheduling.
  	 */
  	lock_depth = reiserfs_write_lock_once(dir->i_sb);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
328
329
330
331
332
333
  	de.de_gen_number_bit_string = NULL;
  	retval =
  	    reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
  				&path_to_entry, &de);
  	pathrelse(&path_to_entry);
  	if (retval == NAME_FOUND) {
677c9b2e3   Jeff Mahoney   reiserfs: remove ...
334
335
  		inode = reiserfs_iget(dir->i_sb,
  				      (struct cpu_key *)&(de.de_dir_id));
bd4c625c0   Linus Torvalds   reiserfs: run scr...
336
  		if (!inode || IS_ERR(inode)) {
b1c839bb2   Frederic Weisbecker   kill-the-bkl/reis...
337
  			reiserfs_write_unlock_once(dir->i_sb, lock_depth);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
338
339
  			return ERR_PTR(-EACCES);
  		}
6dfede696   Jeff Mahoney   reiserfs: remove ...
340
341
342
343
  		/* Propagate the private flag so we know we're
  		 * in the priv tree */
  		if (IS_PRIVATE(dir))
  			inode->i_flags |= S_PRIVATE;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
344
  	}
b1c839bb2   Frederic Weisbecker   kill-the-bkl/reis...
345
  	reiserfs_write_unlock_once(dir->i_sb, lock_depth);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
346
347
  	if (retval == IO_ERROR) {
  		return ERR_PTR(-EIO);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
  	}
d9975d6ba   Pekka Enberg   [PATCH] reiserfs:...
349
  	return d_splice_alias(inode, dentry);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
350
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
351

0222e6571   Jeff Mahoney   reiserfs: strip t...
352
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
354
355
356
357
  ** looks up the dentry of the parent directory for child.
  ** taken from ext2_get_parent
  */
  struct dentry *reiserfs_get_parent(struct dentry *child)
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
358
359
360
361
  	int retval;
  	struct inode *inode = NULL;
  	struct reiserfs_dir_entry de;
  	INITIALIZE_PATH(path_to_entry);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
  	struct inode *dir = child->d_inode;
  
  	if (dir->i_nlink == 0) {
  		return ERR_PTR(-ENOENT);
  	}
  	de.de_gen_number_bit_string = NULL;
  
  	reiserfs_write_lock(dir->i_sb);
  	retval = reiserfs_find_entry(dir, "..", 2, &path_to_entry, &de);
  	pathrelse(&path_to_entry);
  	if (retval != NAME_FOUND) {
  		reiserfs_write_unlock(dir->i_sb);
  		return ERR_PTR(-ENOENT);
  	}
  	inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377
  	reiserfs_write_unlock(dir->i_sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
378

440037287   Christoph Hellwig   [PATCH] switch al...
379
  	return d_obtain_alias(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
380
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381

0222e6571   Jeff Mahoney   reiserfs: strip t...
382
  /* add entry to the directory (entry can be hidden).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
386
  
  insert definition of when hidden directories are used here -Hans
  
   Does not mark dir   inode dirty, do it after successesfull call to it */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
387
388
389
  static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
  			      struct inode *dir, const char *name, int namelen,
  			      struct inode *inode, int visible)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
391
392
393
394
  	struct cpu_key entry_key;
  	struct reiserfs_de_head *deh;
  	INITIALIZE_PATH(path);
  	struct reiserfs_dir_entry de;
3af1efe8a   Jeff Mahoney   [PATCH] reiserfs:...
395
  	DECLARE_BITMAP(bit_string, MAX_GENERATION_NUMBER + 1);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
  	int gen_number;
  	char small_buf[32 + DEH_SIZE];	/* 48 bytes now and we avoid kmalloc
  					   if we create file with short name */
  	char *buffer;
  	int buflen, paste_size;
  	int retval;
  
  	BUG_ON(!th->t_trans_id);
  
  	/* cannot allow items to be added into a busy deleted directory */
  	if (!namelen)
  		return -EINVAL;
  
  	if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize))
  		return -ENAMETOOLONG;
  
  	/* each entry has unique key. compose it */
  	make_cpu_key(&entry_key, dir,
  		     get_third_component(dir->i_sb, name, namelen),
  		     TYPE_DIRENTRY, 3);
  
  	/* get memory for composing the entry */
  	buflen = DEH_SIZE + ROUND_UP(namelen);
  	if (buflen > sizeof(small_buf)) {
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
420
  		buffer = kmalloc(buflen, GFP_NOFS);
9dce07f1a   Al Viro   NULL noise: fs/*,...
421
  		if (!buffer)
bd4c625c0   Linus Torvalds   reiserfs: run scr...
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
  			return -ENOMEM;
  	} else
  		buffer = small_buf;
  
  	paste_size =
  	    (get_inode_sd_version(dir) ==
  	     STAT_DATA_V1) ? (DEH_SIZE + namelen) : buflen;
  
  	/* fill buffer : directory entry head, name[, dir objectid | , stat data | ,stat data, dir objectid ] */
  	deh = (struct reiserfs_de_head *)buffer;
  	deh->deh_location = 0;	/* JDM Endian safe if 0 */
  	put_deh_offset(deh, cpu_key_k_offset(&entry_key));
  	deh->deh_state = 0;	/* JDM Endian safe if 0 */
  	/* put key (ino analog) to de */
  	deh->deh_dir_id = INODE_PKEY(inode)->k_dir_id;	/* safe: k_dir_id is le */
  	deh->deh_objectid = INODE_PKEY(inode)->k_objectid;	/* safe: k_objectid is le */
  
  	/* copy name */
  	memcpy((char *)(deh + 1), name, namelen);
  	/* padd by 0s to the 4 byte boundary */
  	padd_item((char *)(deh + 1), ROUND_UP(namelen), namelen);
  
  	/* entry is ready to be pasted into tree, set 'visibility' and 'stat data in entry' attributes */
  	mark_de_without_sd(deh);
  	visible ? mark_de_visible(deh) : mark_de_hidden(deh);
  
  	/* find the proper place for the new entry */
  	memset(bit_string, 0, sizeof(bit_string));
3af1efe8a   Jeff Mahoney   [PATCH] reiserfs:...
450
  	de.de_gen_number_bit_string = bit_string;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
451
452
453
  	retval = reiserfs_find_entry(dir, name, namelen, &path, &de);
  	if (retval != NAME_NOT_FOUND) {
  		if (buffer != small_buf)
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
454
  			kfree(buffer);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
455
456
457
458
459
460
461
  		pathrelse(&path);
  
  		if (retval == IO_ERROR) {
  			return -EIO;
  		}
  
  		if (retval != NAME_FOUND) {
0030b6457   Jeff Mahoney   reiserfs: use rei...
462
463
464
  			reiserfs_error(dir->i_sb, "zam-7002",
  				       "reiserfs_find_entry() returned "
  				       "unexpected value (%d)", retval);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
465
466
467
468
  		}
  
  		return -EEXIST;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
469

bd4c625c0   Linus Torvalds   reiserfs: run scr...
470
  	gen_number =
3af1efe8a   Jeff Mahoney   [PATCH] reiserfs:...
471
  	    find_first_zero_bit(bit_string,
bd4c625c0   Linus Torvalds   reiserfs: run scr...
472
473
474
  				MAX_GENERATION_NUMBER + 1);
  	if (gen_number > MAX_GENERATION_NUMBER) {
  		/* there is no free generation number */
45b03d5e8   Jeff Mahoney   reiserfs: rework ...
475
476
477
  		reiserfs_warning(dir->i_sb, "reiserfs-7010",
  				 "Congratulations! we have got hash function "
  				 "screwed up");
bd4c625c0   Linus Torvalds   reiserfs: run scr...
478
  		if (buffer != small_buf)
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
479
  			kfree(buffer);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
480
481
482
483
484
485
486
487
488
489
490
491
492
  		pathrelse(&path);
  		return -EBUSY;
  	}
  	/* adjust offset of directory enrty */
  	put_deh_offset(deh, SET_GENERATION_NUMBER(deh_offset(deh), gen_number));
  	set_cpu_key_k_offset(&entry_key, deh_offset(deh));
  
  	/* update max-hash-collisions counter in reiserfs_sb_info */
  	PROC_INFO_MAX(th->t_super, max_hash_collisions, gen_number);
  
  	if (gen_number != 0) {	/* we need to re-search for the insertion point */
  		if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) !=
  		    NAME_NOT_FOUND) {
45b03d5e8   Jeff Mahoney   reiserfs: rework ...
493
494
495
  			reiserfs_warning(dir->i_sb, "vs-7032",
  					 "entry with this key (%K) already "
  					 "exists", &entry_key);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
496
497
  
  			if (buffer != small_buf)
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
498
  				kfree(buffer);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
499
500
501
  			pathrelse(&path);
  			return -EBUSY;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
502
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
503
504
505
506
507
  	/* perform the insertion of the entry that we have prepared */
  	retval =
  	    reiserfs_paste_into_item(th, &path, &entry_key, dir, buffer,
  				     paste_size);
  	if (buffer != small_buf)
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
508
  		kfree(buffer);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
509
510
511
  	if (retval) {
  		reiserfs_check_path(&path);
  		return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
512
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
513

bd4c625c0   Linus Torvalds   reiserfs: run scr...
514
515
516
517
518
  	dir->i_size += paste_size;
  	dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
  	if (!S_ISDIR(inode->i_mode) && visible)
  		// reiserfs_mkdir or reiserfs_rename will do that by itself
  		reiserfs_update_sd(th, dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
519

bd4c625c0   Linus Torvalds   reiserfs: run scr...
520
521
  	reiserfs_check_path(&path);
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
522
523
524
525
526
527
528
  }
  
  /* quota utility function, call if you've had to abort after calling
  ** new_inode_init, and have not called reiserfs_new_inode yet.
  ** This should only be called on inodes that do not have stat data
  ** inserted into the tree yet.
  */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
529
530
  static int drop_new_inode(struct inode *inode)
  {
9f7547580   Christoph Hellwig   dquot: cleanup dq...
531
  	dquot_drop(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
532
533
534
535
  	make_bad_inode(inode);
  	inode->i_flags |= S_NOQUOTA;
  	iput(inode);
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
536
  }
0222e6571   Jeff Mahoney   reiserfs: strip t...
537
  /* utility function that does setup for reiserfs_new_inode.
871a29315   Christoph Hellwig   dquot: cleanup dq...
538
  ** dquot_initialize needs lots of credits so it's better to have it
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
539
540
541
  ** outside of a transaction, so we had to pull some bits of
  ** reiserfs_new_inode out into this func.
  */
8e0718924   Al Viro   reiserfs: propaga...
542
  static int new_inode_init(struct inode *inode, struct inode *dir, umode_t mode)
bd4c625c0   Linus Torvalds   reiserfs: run scr...
543
  {
1b0a74d1c   Jan Kara   [PATCH] Fix error...
544
545
546
  	/* Make inode invalid - just in case we are going to drop it before
  	 * the initialization happens */
  	INODE_PKEY(inode)->k_objectid = 0;
04b7ed0d3   Dmitry Monakhov   reiserfs: replace...
547
548
549
550
  	/* the quota init calls have to know who to charge the quota to, so
  	 ** we have to set uid and gid here
  	 */
  	inode_init_owner(inode, dir, mode);
871a29315   Christoph Hellwig   dquot: cleanup dq...
551
  	dquot_initialize(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
552
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
  }
4acdaf27e   Al Viro   switch ->create()...
554
  static int reiserfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
bd4c625c0   Linus Torvalds   reiserfs: run scr...
555
  			   struct nameidata *nd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
557
558
559
560
561
562
563
564
  	int retval;
  	struct inode *inode;
  	/* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
  	int jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 2 +
  	    2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
  		 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
  	struct reiserfs_transaction_handle th;
57fe60df6   Jeff Mahoney   reiserfs: add ato...
565
  	struct reiserfs_security_handle security;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
566

871a29315   Christoph Hellwig   dquot: cleanup dq...
567
  	dquot_initialize(dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
568

bd4c625c0   Linus Torvalds   reiserfs: run scr...
569
570
571
572
  	if (!(inode = new_inode(dir->i_sb))) {
  		return -ENOMEM;
  	}
  	new_inode_init(inode, dir, mode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
573

0ab2621eb   Jeff Mahoney   reiserfs: journal...
574
  	jbegin_count += reiserfs_cache_default_acl(dir);
2a7dba391   Eric Paris   fs/vfs/security: ...
575
  	retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
57fe60df6   Jeff Mahoney   reiserfs: add ato...
576
577
578
579
580
  	if (retval < 0) {
  		drop_new_inode(inode);
  		return retval;
  	}
  	jbegin_count += retval;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
581
  	reiserfs_write_lock(dir->i_sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
582

bd4c625c0   Linus Torvalds   reiserfs: run scr...
583
584
585
586
587
588
589
590
  	retval = journal_begin(&th, dir->i_sb, jbegin_count);
  	if (retval) {
  		drop_new_inode(inode);
  		goto out_failed;
  	}
  
  	retval =
  	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
57fe60df6   Jeff Mahoney   reiserfs: add ato...
591
  			       inode, &security);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
592
593
  	if (retval)
  		goto out_failed;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
594
595
596
597
598
599
600
601
602
  	inode->i_op = &reiserfs_file_inode_operations;
  	inode->i_fop = &reiserfs_file_operations;
  	inode->i_mapping->a_ops = &reiserfs_address_space_operations;
  
  	retval =
  	    reiserfs_add_entry(&th, dir, dentry->d_name.name,
  			       dentry->d_name.len, inode, 1 /*visible */ );
  	if (retval) {
  		int err;
6d6b77f16   Miklos Szeredi   filesystems: add ...
603
  		drop_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
604
605
606
607
  		reiserfs_update_sd(&th, inode);
  		err = journal_end(&th, dir->i_sb, jbegin_count);
  		if (err)
  			retval = err;
c1eaa26b6   Al Viro   nfsd race fixes: ...
608
  		unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
609
610
611
612
613
  		iput(inode);
  		goto out_failed;
  	}
  	reiserfs_update_inode_transaction(inode);
  	reiserfs_update_inode_transaction(dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
614

bd4c625c0   Linus Torvalds   reiserfs: run scr...
615
  	d_instantiate(dentry, inode);
c1eaa26b6   Al Viro   nfsd race fixes: ...
616
  	unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
617
  	retval = journal_end(&th, dir->i_sb, jbegin_count);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
618

bd4c625c0   Linus Torvalds   reiserfs: run scr...
619
        out_failed:
bd4c625c0   Linus Torvalds   reiserfs: run scr...
620
621
622
  	reiserfs_write_unlock(dir->i_sb);
  	return retval;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
623

1a67aafb5   Al Viro   switch ->mknod() ...
624
  static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
bd4c625c0   Linus Torvalds   reiserfs: run scr...
625
626
627
628
629
  			  dev_t rdev)
  {
  	int retval;
  	struct inode *inode;
  	struct reiserfs_transaction_handle th;
57fe60df6   Jeff Mahoney   reiserfs: add ato...
630
  	struct reiserfs_security_handle security;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
631
632
633
634
635
  	/* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
  	int jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 3 +
  	    2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
  		 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
bd4c625c0   Linus Torvalds   reiserfs: run scr...
636
637
638
  
  	if (!new_valid_dev(rdev))
  		return -EINVAL;
871a29315   Christoph Hellwig   dquot: cleanup dq...
639
  	dquot_initialize(dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
640

bd4c625c0   Linus Torvalds   reiserfs: run scr...
641
642
643
644
  	if (!(inode = new_inode(dir->i_sb))) {
  		return -ENOMEM;
  	}
  	new_inode_init(inode, dir, mode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
645

0ab2621eb   Jeff Mahoney   reiserfs: journal...
646
  	jbegin_count += reiserfs_cache_default_acl(dir);
2a7dba391   Eric Paris   fs/vfs/security: ...
647
  	retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
57fe60df6   Jeff Mahoney   reiserfs: add ato...
648
649
650
651
652
  	if (retval < 0) {
  		drop_new_inode(inode);
  		return retval;
  	}
  	jbegin_count += retval;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
653
  	reiserfs_write_lock(dir->i_sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
654

bd4c625c0   Linus Torvalds   reiserfs: run scr...
655
656
657
658
659
  	retval = journal_begin(&th, dir->i_sb, jbegin_count);
  	if (retval) {
  		drop_new_inode(inode);
  		goto out_failed;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
660

bd4c625c0   Linus Torvalds   reiserfs: run scr...
661
662
  	retval =
  	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
57fe60df6   Jeff Mahoney   reiserfs: add ato...
663
  			       inode, &security);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
664
665
666
  	if (retval) {
  		goto out_failed;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
667

bd4c625c0   Linus Torvalds   reiserfs: run scr...
668
669
670
671
672
673
674
675
676
677
678
679
680
681
  	inode->i_op = &reiserfs_special_inode_operations;
  	init_special_inode(inode, inode->i_mode, rdev);
  
  	//FIXME: needed for block and char devices only
  	reiserfs_update_sd(&th, inode);
  
  	reiserfs_update_inode_transaction(inode);
  	reiserfs_update_inode_transaction(dir);
  
  	retval =
  	    reiserfs_add_entry(&th, dir, dentry->d_name.name,
  			       dentry->d_name.len, inode, 1 /*visible */ );
  	if (retval) {
  		int err;
6d6b77f16   Miklos Szeredi   filesystems: add ...
682
  		drop_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
683
684
685
686
  		reiserfs_update_sd(&th, inode);
  		err = journal_end(&th, dir->i_sb, jbegin_count);
  		if (err)
  			retval = err;
c1eaa26b6   Al Viro   nfsd race fixes: ...
687
  		unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
688
689
690
  		iput(inode);
  		goto out_failed;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691

bd4c625c0   Linus Torvalds   reiserfs: run scr...
692
  	d_instantiate(dentry, inode);
c1eaa26b6   Al Viro   nfsd race fixes: ...
693
  	unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
694
  	retval = journal_end(&th, dir->i_sb, jbegin_count);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
695

bd4c625c0   Linus Torvalds   reiserfs: run scr...
696
        out_failed:
bd4c625c0   Linus Torvalds   reiserfs: run scr...
697
698
  	reiserfs_write_unlock(dir->i_sb);
  	return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
699
  }
18bb1db3e   Al Viro   switch vfs_mkdir(...
700
  static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
701
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
702
703
704
  	int retval;
  	struct inode *inode;
  	struct reiserfs_transaction_handle th;
57fe60df6   Jeff Mahoney   reiserfs: add ato...
705
  	struct reiserfs_security_handle security;
b10ab4c33   Frederic Weisbecker   kill-the-bkl/reis...
706
  	int lock_depth;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
707
708
709
710
711
  	/* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
  	int jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 3 +
  	    2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
  		 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
712

871a29315   Christoph Hellwig   dquot: cleanup dq...
713
  	dquot_initialize(dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
714

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
715
  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
bd4c625c0   Linus Torvalds   reiserfs: run scr...
716
717
  	/* set flag that new packing locality created and new blocks for the content     * of that directory are not displaced yet */
  	REISERFS_I(dir)->new_packing_locality = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
718
  #endif
bd4c625c0   Linus Torvalds   reiserfs: run scr...
719
720
721
722
723
  	mode = S_IFDIR | mode;
  	if (!(inode = new_inode(dir->i_sb))) {
  		return -ENOMEM;
  	}
  	new_inode_init(inode, dir, mode);
0ab2621eb   Jeff Mahoney   reiserfs: journal...
724
  	jbegin_count += reiserfs_cache_default_acl(dir);
2a7dba391   Eric Paris   fs/vfs/security: ...
725
  	retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
57fe60df6   Jeff Mahoney   reiserfs: add ato...
726
727
728
729
730
  	if (retval < 0) {
  		drop_new_inode(inode);
  		return retval;
  	}
  	jbegin_count += retval;
b10ab4c33   Frederic Weisbecker   kill-the-bkl/reis...
731
  	lock_depth = reiserfs_write_lock_once(dir->i_sb);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
732
733
734
735
736
737
  
  	retval = journal_begin(&th, dir->i_sb, jbegin_count);
  	if (retval) {
  		drop_new_inode(inode);
  		goto out_failed;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
738

bd4c625c0   Linus Torvalds   reiserfs: run scr...
739
740
741
742
743
744
745
746
  	/* inc the link count now, so another writer doesn't overflow it while
  	 ** we sleep later on.
  	 */
  	INC_DIR_INODE_NLINK(dir)
  
  	    retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
  					old_format_only(dir->i_sb) ?
  					EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
57fe60df6   Jeff Mahoney   reiserfs: add ato...
747
  					dentry, inode, &security);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
748
  	if (retval) {
99890a3be   Al Viro   fix reiserfs mkdi...
749
  		DEC_DIR_INODE_NLINK(dir)
bd4c625c0   Linus Torvalds   reiserfs: run scr...
750
751
  		goto out_failed;
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
752
753
754
755
756
757
758
759
760
761
762
763
  	reiserfs_update_inode_transaction(inode);
  	reiserfs_update_inode_transaction(dir);
  
  	inode->i_op = &reiserfs_dir_inode_operations;
  	inode->i_fop = &reiserfs_dir_operations;
  
  	// note, _this_ add_entry will not update dir's stat data
  	retval =
  	    reiserfs_add_entry(&th, dir, dentry->d_name.name,
  			       dentry->d_name.len, inode, 1 /*visible */ );
  	if (retval) {
  		int err;
6d6b77f16   Miklos Szeredi   filesystems: add ...
764
  		clear_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
765
766
767
768
769
  		DEC_DIR_INODE_NLINK(dir);
  		reiserfs_update_sd(&th, inode);
  		err = journal_end(&th, dir->i_sb, jbegin_count);
  		if (err)
  			retval = err;
c1eaa26b6   Al Viro   nfsd race fixes: ...
770
  		unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
771
772
773
774
775
776
777
  		iput(inode);
  		goto out_failed;
  	}
  	// the above add_entry did not update dir's stat data
  	reiserfs_update_sd(&th, dir);
  
  	d_instantiate(dentry, inode);
c1eaa26b6   Al Viro   nfsd race fixes: ...
778
  	unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
779
  	retval = journal_end(&th, dir->i_sb, jbegin_count);
b10ab4c33   Frederic Weisbecker   kill-the-bkl/reis...
780
781
  out_failed:
  	reiserfs_write_unlock_once(dir->i_sb, lock_depth);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
782
  	return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
783
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
784
  static inline int reiserfs_empty_dir(struct inode *inode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
785
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
786
787
  	/* we can cheat because an old format dir cannot have
  	 ** EMPTY_DIR_SIZE, and a new format dir cannot have
0222e6571   Jeff Mahoney   reiserfs: strip t...
788
  	 ** EMPTY_DIR_SIZE_V1.  So, if the inode is either size,
bd4c625c0   Linus Torvalds   reiserfs: run scr...
789
790
791
792
793
794
795
  	 ** regardless of disk format version, the directory is empty.
  	 */
  	if (inode->i_size != EMPTY_DIR_SIZE &&
  	    inode->i_size != EMPTY_DIR_SIZE_V1) {
  		return 0;
  	}
  	return 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
796
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
797
  static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
798
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
799
800
801
802
803
804
805
806
807
808
809
810
811
812
  	int retval, err;
  	struct inode *inode;
  	struct reiserfs_transaction_handle th;
  	int jbegin_count;
  	INITIALIZE_PATH(path);
  	struct reiserfs_dir_entry de;
  
  	/* we will be doing 2 balancings and update 2 stat data, we change quotas
  	 * of the owner of the directory and of the owner of the parent directory.
  	 * The quota structure is possibly deleted only on last iput => outside
  	 * of this transaction */
  	jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 2 + 2 +
  	    4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
871a29315   Christoph Hellwig   dquot: cleanup dq...
813
  	dquot_initialize(dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
814

bd4c625c0   Linus Torvalds   reiserfs: run scr...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
  	reiserfs_write_lock(dir->i_sb);
  	retval = journal_begin(&th, dir->i_sb, jbegin_count);
  	if (retval)
  		goto out_rmdir;
  
  	de.de_gen_number_bit_string = NULL;
  	if ((retval =
  	     reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
  				 &path, &de)) == NAME_NOT_FOUND) {
  		retval = -ENOENT;
  		goto end_rmdir;
  	} else if (retval == IO_ERROR) {
  		retval = -EIO;
  		goto end_rmdir;
  	}
  
  	inode = dentry->d_inode;
  
  	reiserfs_update_inode_transaction(inode);
  	reiserfs_update_inode_transaction(dir);
  
  	if (de.de_objectid != inode->i_ino) {
  		// FIXME: compare key of an object and a key found in the
  		// entry
  		retval = -EIO;
  		goto end_rmdir;
  	}
  	if (!reiserfs_empty_dir(inode)) {
  		retval = -ENOTEMPTY;
  		goto end_rmdir;
  	}
  
  	/* cut entry from dir directory */
  	retval = reiserfs_cut_from_item(&th, &path, &(de.de_entry_key), dir, NULL,	/* page */
  					0 /*new file size - not used here */ );
  	if (retval < 0)
  		goto end_rmdir;
  
  	if (inode->i_nlink != 2 && inode->i_nlink != 1)
0030b6457   Jeff Mahoney   reiserfs: use rei...
854
855
856
  		reiserfs_error(inode->i_sb, "reiserfs-7040",
  			       "empty directory has nlink != 2 (%d)",
  			       inode->i_nlink);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
857

ce71ec368   Dave Hansen   [PATCH] r/o bind ...
858
  	clear_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
  	inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
  	reiserfs_update_sd(&th, inode);
  
  	DEC_DIR_INODE_NLINK(dir)
  	    dir->i_size -= (DEH_SIZE + de.de_entrylen);
  	reiserfs_update_sd(&th, dir);
  
  	/* prevent empty directory from getting lost */
  	add_save_link(&th, inode, 0 /* not truncate */ );
  
  	retval = journal_end(&th, dir->i_sb, jbegin_count);
  	reiserfs_check_path(&path);
        out_rmdir:
  	reiserfs_write_unlock(dir->i_sb);
  	return retval;
  
        end_rmdir:
  	/* we must release path, because we did not call
  	   reiserfs_cut_from_item, or reiserfs_cut_from_item does not
  	   release path if operation was not complete */
  	pathrelse(&path);
  	err = journal_end(&th, dir->i_sb, jbegin_count);
  	reiserfs_write_unlock(dir->i_sb);
  	return err ? err : retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
883
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
884
  static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
885
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
886
887
888
889
890
891
892
  	int retval, err;
  	struct inode *inode;
  	struct reiserfs_dir_entry de;
  	INITIALIZE_PATH(path);
  	struct reiserfs_transaction_handle th;
  	int jbegin_count;
  	unsigned long savelink;
c674905ca   Frederic Weisbecker   reiserfs: Fix unw...
893
  	int depth;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
894

871a29315   Christoph Hellwig   dquot: cleanup dq...
895
  	dquot_initialize(dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
896

bd4c625c0   Linus Torvalds   reiserfs: run scr...
897
898
899
900
901
902
903
904
905
  	inode = dentry->d_inode;
  
  	/* in this transaction we can be doing at max two balancings and update
  	 * two stat datas, we change quotas of the owner of the directory and of
  	 * the owner of the parent directory. The quota structure is possibly
  	 * deleted only on iput => outside of this transaction */
  	jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 2 + 2 +
  	    4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
c674905ca   Frederic Weisbecker   reiserfs: Fix unw...
906
  	depth = reiserfs_write_lock_once(dir->i_sb);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
  	retval = journal_begin(&th, dir->i_sb, jbegin_count);
  	if (retval)
  		goto out_unlink;
  
  	de.de_gen_number_bit_string = NULL;
  	if ((retval =
  	     reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
  				 &path, &de)) == NAME_NOT_FOUND) {
  		retval = -ENOENT;
  		goto end_unlink;
  	} else if (retval == IO_ERROR) {
  		retval = -EIO;
  		goto end_unlink;
  	}
  
  	reiserfs_update_inode_transaction(inode);
  	reiserfs_update_inode_transaction(dir);
  
  	if (de.de_objectid != inode->i_ino) {
  		// FIXME: compare key of an object and a key found in the
  		// entry
  		retval = -EIO;
  		goto end_unlink;
  	}
  
  	if (!inode->i_nlink) {
45b03d5e8   Jeff Mahoney   reiserfs: rework ...
933
934
935
  		reiserfs_warning(inode->i_sb, "reiserfs-7042",
  				 "deleting nonexistent file (%lu), %d",
  				 inode->i_ino, inode->i_nlink);
bfe868486   Miklos Szeredi   filesystems: add ...
936
  		set_nlink(inode, 1);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
937
  	}
9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
938
  	drop_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
939
940
941
942
943
944
945
946
947
948
949
  
  	/*
  	 * we schedule before doing the add_save_link call, save the link
  	 * count so we don't race
  	 */
  	savelink = inode->i_nlink;
  
  	retval =
  	    reiserfs_cut_from_item(&th, &path, &(de.de_entry_key), dir, NULL,
  				   0);
  	if (retval < 0) {
d8c76e6f4   Dave Hansen   [PATCH] r/o bind ...
950
  		inc_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
  		goto end_unlink;
  	}
  	inode->i_ctime = CURRENT_TIME_SEC;
  	reiserfs_update_sd(&th, inode);
  
  	dir->i_size -= (de.de_entrylen + DEH_SIZE);
  	dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
  	reiserfs_update_sd(&th, dir);
  
  	if (!savelink)
  		/* prevent file from getting lost */
  		add_save_link(&th, inode, 0 /* not truncate */ );
  
  	retval = journal_end(&th, dir->i_sb, jbegin_count);
  	reiserfs_check_path(&path);
c674905ca   Frederic Weisbecker   reiserfs: Fix unw...
966
  	reiserfs_write_unlock_once(dir->i_sb, depth);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
967
968
969
970
971
972
  	return retval;
  
        end_unlink:
  	pathrelse(&path);
  	err = journal_end(&th, dir->i_sb, jbegin_count);
  	reiserfs_check_path(&path);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
973
  	if (err)
bd4c625c0   Linus Torvalds   reiserfs: run scr...
974
975
  		retval = err;
        out_unlink:
c674905ca   Frederic Weisbecker   reiserfs: Fix unw...
976
  	reiserfs_write_unlock_once(dir->i_sb, depth);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
977
  	return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
978
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
979
980
  static int reiserfs_symlink(struct inode *parent_dir,
  			    struct dentry *dentry, const char *symname)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
981
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
982
983
984
985
986
  	int retval;
  	struct inode *inode;
  	char *name;
  	int item_len;
  	struct reiserfs_transaction_handle th;
57fe60df6   Jeff Mahoney   reiserfs: add ato...
987
  	struct reiserfs_security_handle security;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
988
989
990
991
992
993
  	int mode = S_IFLNK | S_IRWXUGO;
  	/* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
  	int jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 3 +
  	    2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) +
  		 REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb));
871a29315   Christoph Hellwig   dquot: cleanup dq...
994
  	dquot_initialize(parent_dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
995

bd4c625c0   Linus Torvalds   reiserfs: run scr...
996
997
998
999
  	if (!(inode = new_inode(parent_dir->i_sb))) {
  		return -ENOMEM;
  	}
  	new_inode_init(inode, parent_dir, mode);
2a7dba391   Eric Paris   fs/vfs/security: ...
1000
1001
  	retval = reiserfs_security_init(parent_dir, inode, &dentry->d_name,
  					&security);
57fe60df6   Jeff Mahoney   reiserfs: add ato...
1002
1003
1004
1005
1006
  	if (retval < 0) {
  		drop_new_inode(inode);
  		return retval;
  	}
  	jbegin_count += retval;
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1007
1008
1009
1010
1011
1012
1013
  	reiserfs_write_lock(parent_dir->i_sb);
  	item_len = ROUND_UP(strlen(symname));
  	if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) {
  		retval = -ENAMETOOLONG;
  		drop_new_inode(inode);
  		goto out_failed;
  	}
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
1014
  	name = kmalloc(item_len, GFP_NOFS);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1015
1016
1017
1018
1019
1020
1021
  	if (!name) {
  		drop_new_inode(inode);
  		retval = -ENOMEM;
  		goto out_failed;
  	}
  	memcpy(name, symname, strlen(symname));
  	padd_item(name, item_len, strlen(symname));
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1022
1023
1024
  	retval = journal_begin(&th, parent_dir->i_sb, jbegin_count);
  	if (retval) {
  		drop_new_inode(inode);
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
1025
  		kfree(name);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1026
1027
1028
1029
1030
  		goto out_failed;
  	}
  
  	retval =
  	    reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
57fe60df6   Jeff Mahoney   reiserfs: add ato...
1031
  			       dentry, inode, &security);
d739b42b8   Pekka Enberg   [PATCH] reiserfs:...
1032
  	kfree(name);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1033
1034
1035
  	if (retval) {		/* reiserfs_new_inode iputs for us */
  		goto out_failed;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1036

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
  	reiserfs_update_inode_transaction(inode);
  	reiserfs_update_inode_transaction(parent_dir);
  
  	inode->i_op = &reiserfs_symlink_inode_operations;
  	inode->i_mapping->a_ops = &reiserfs_address_space_operations;
  
  	// must be sure this inode is written with this transaction
  	//
  	//reiserfs_update_sd (&th, inode, READ_BLOCKS);
  
  	retval = reiserfs_add_entry(&th, parent_dir, dentry->d_name.name,
  				    dentry->d_name.len, inode, 1 /*visible */ );
  	if (retval) {
  		int err;
6d6b77f16   Miklos Szeredi   filesystems: add ...
1051
  		drop_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1052
1053
1054
1055
  		reiserfs_update_sd(&th, inode);
  		err = journal_end(&th, parent_dir->i_sb, jbegin_count);
  		if (err)
  			retval = err;
c1eaa26b6   Al Viro   nfsd race fixes: ...
1056
  		unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1057
1058
1059
  		iput(inode);
  		goto out_failed;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1060

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1061
  	d_instantiate(dentry, inode);
c1eaa26b6   Al Viro   nfsd race fixes: ...
1062
  	unlock_new_inode(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1063
1064
1065
1066
  	retval = journal_end(&th, parent_dir->i_sb, jbegin_count);
        out_failed:
  	reiserfs_write_unlock(parent_dir->i_sb);
  	return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1067
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
  static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
  			 struct dentry *dentry)
  {
  	int retval;
  	struct inode *inode = old_dentry->d_inode;
  	struct reiserfs_transaction_handle th;
  	/* We need blocks for transaction + update of quotas for the owners of the directory */
  	int jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 3 +
  	    2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
871a29315   Christoph Hellwig   dquot: cleanup dq...
1078
  	dquot_initialize(dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
1079

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1080
1081
1082
1083
1084
1085
  	reiserfs_write_lock(dir->i_sb);
  	if (inode->i_nlink >= REISERFS_LINK_MAX) {
  		//FIXME: sd_nlink is 32 bit for new files
  		reiserfs_write_unlock(dir->i_sb);
  		return -EMLINK;
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1086
1087
  
  	/* inc before scheduling so reiserfs_unlink knows we are here */
d8c76e6f4   Dave Hansen   [PATCH] r/o bind ...
1088
  	inc_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1089
1090
1091
  
  	retval = journal_begin(&th, dir->i_sb, jbegin_count);
  	if (retval) {
6d6b77f16   Miklos Szeredi   filesystems: add ...
1092
  		drop_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
  		reiserfs_write_unlock(dir->i_sb);
  		return retval;
  	}
  
  	/* create new entry */
  	retval =
  	    reiserfs_add_entry(&th, dir, dentry->d_name.name,
  			       dentry->d_name.len, inode, 1 /*visible */ );
  
  	reiserfs_update_inode_transaction(inode);
  	reiserfs_update_inode_transaction(dir);
  
  	if (retval) {
  		int err;
6d6b77f16   Miklos Szeredi   filesystems: add ...
1107
  		drop_nlink(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1108
1109
1110
1111
1112
1113
1114
  		err = journal_end(&th, dir->i_sb, jbegin_count);
  		reiserfs_write_unlock(dir->i_sb);
  		return err ? err : retval;
  	}
  
  	inode->i_ctime = CURRENT_TIME_SEC;
  	reiserfs_update_sd(&th, inode);
7de9c6ee3   Al Viro   new helper: ihold()
1115
  	ihold(inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1116
1117
1118
1119
1120
  	d_instantiate(dentry, inode);
  	retval = journal_end(&th, dir->i_sb, jbegin_count);
  	reiserfs_write_unlock(dir->i_sb);
  	return retval;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1121

0222e6571   Jeff Mahoney   reiserfs: strip t...
1122
  /* de contains information pointing to an entry which */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1123
1124
  static int de_still_valid(const char *name, int len,
  			  struct reiserfs_dir_entry *de)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1125
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1126
1127
1128
1129
1130
1131
1132
1133
  	struct reiserfs_dir_entry tmp = *de;
  
  	// recalculate pointer to name and name length
  	set_de_name_and_namelen(&tmp);
  	// FIXME: could check more
  	if (tmp.de_namelen != len || memcmp(name, de->de_name, len))
  		return 0;
  	return 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1134
  }
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1135
1136
1137
  static int entry_points_to_object(const char *name, int len,
  				  struct reiserfs_dir_entry *de,
  				  struct inode *inode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1138
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1139
1140
1141
1142
1143
  	if (!de_still_valid(name, len, de))
  		return 0;
  
  	if (inode) {
  		if (!de_visible(de->de_deh + de->de_entry_num))
c3a9c2109   Jeff Mahoney   reiserfs: rework ...
1144
1145
  			reiserfs_panic(inode->i_sb, "vs-7042",
  				       "entry must be visible");
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1146
1147
  		return (de->de_objectid == inode->i_ino) ? 1 : 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1148

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1149
1150
  	/* this must be added hidden entry */
  	if (de_visible(de->de_deh + de->de_entry_num))
c3a9c2109   Jeff Mahoney   reiserfs: rework ...
1151
  		reiserfs_panic(NULL, "vs-7043", "entry must be visible");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1152

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1153
  	return 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1154
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1155
  /* sets key of objectid the entry has to point to */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1156
1157
  static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de,
  				 struct reiserfs_key *key)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1158
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1159
1160
1161
  	/* JDM These operations are endian safe - both are le */
  	de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id;
  	de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1162
  }
0222e6571   Jeff Mahoney   reiserfs: strip t...
1163
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1164
1165
   * process, that is going to call fix_nodes/do_balance must hold only
   * one path. If it holds 2 or more, it can get into endless waiting in
0222e6571   Jeff Mahoney   reiserfs: strip t...
1166
   * get_empty_nodes or its clones
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1167
   */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1168
1169
  static int reiserfs_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
1170
  {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
  	int retval;
  	INITIALIZE_PATH(old_entry_path);
  	INITIALIZE_PATH(new_entry_path);
  	INITIALIZE_PATH(dot_dot_entry_path);
  	struct item_head new_entry_ih, old_entry_ih, dot_dot_ih;
  	struct reiserfs_dir_entry old_de, new_de, dot_dot_de;
  	struct inode *old_inode, *new_dentry_inode;
  	struct reiserfs_transaction_handle th;
  	int jbegin_count;
  	umode_t old_inode_mode;
  	unsigned long savelink = 1;
  	struct timespec ctime;
  
  	/* three balancings: (1) old name removal, (2) new name insertion
  	   and (3) maybe "save" link insertion
  	   stat data updates: (1) old directory,
  	   (2) new directory and (3) maybe old object stat data (when it is
  	   directory) and (4) maybe stat data of object to which new entry
  	   pointed initially and (5) maybe block containing ".." of
  	   renamed directory
  	   quota updates: two parent directories */
  	jbegin_count =
  	    JOURNAL_PER_BALANCE_CNT * 3 + 5 +
  	    4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb);
871a29315   Christoph Hellwig   dquot: cleanup dq...
1195
1196
  	dquot_initialize(old_dir);
  	dquot_initialize(new_dir);
907f4554e   Christoph Hellwig   dquot: move dquot...
1197

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
  	old_inode = old_dentry->d_inode;
  	new_dentry_inode = new_dentry->d_inode;
  
  	// make sure, that oldname still exists and points to an object we
  	// are going to rename
  	old_de.de_gen_number_bit_string = NULL;
  	reiserfs_write_lock(old_dir->i_sb);
  	retval =
  	    reiserfs_find_entry(old_dir, old_dentry->d_name.name,
  				old_dentry->d_name.len, &old_entry_path,
  				&old_de);
  	pathrelse(&old_entry_path);
  	if (retval == IO_ERROR) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1211
  		reiserfs_write_unlock(old_dir->i_sb);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1212
  		return -EIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1213
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1214
1215
1216
1217
  
  	if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) {
  		reiserfs_write_unlock(old_dir->i_sb);
  		return -ENOENT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1218
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1219
1220
  	old_inode_mode = old_inode->i_mode;
  	if (S_ISDIR(old_inode_mode)) {
0222e6571   Jeff Mahoney   reiserfs: strip t...
1221
  		// make sure, that directory being renamed has correct ".."
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1222
1223
1224
1225
1226
1227
1228
1229
1230
  		// and that its new parent directory has not too many links
  		// already
  
  		if (new_dentry_inode) {
  			if (!reiserfs_empty_dir(new_dentry_inode)) {
  				reiserfs_write_unlock(old_dir->i_sb);
  				return -ENOTEMPTY;
  			}
  		}
0222e6571   Jeff Mahoney   reiserfs: strip t...
1231
1232
  		/* directory is renamed, its parent directory will be changed,
  		 ** so find ".." entry
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
  		 */
  		dot_dot_de.de_gen_number_bit_string = NULL;
  		retval =
  		    reiserfs_find_entry(old_inode, "..", 2, &dot_dot_entry_path,
  					&dot_dot_de);
  		pathrelse(&dot_dot_entry_path);
  		if (retval != NAME_FOUND) {
  			reiserfs_write_unlock(old_dir->i_sb);
  			return -EIO;
  		}
  
  		/* inode number of .. must equal old_dir->i_ino */
  		if (dot_dot_de.de_objectid != old_dir->i_ino) {
  			reiserfs_write_unlock(old_dir->i_sb);
  			return -EIO;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1249
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1250
1251
1252
1253
1254
  
  	retval = journal_begin(&th, old_dir->i_sb, jbegin_count);
  	if (retval) {
  		reiserfs_write_unlock(old_dir->i_sb);
  		return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1255
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1256
1257
1258
1259
1260
1261
1262
  
  	/* add new entry (or find the existing one) */
  	retval =
  	    reiserfs_add_entry(&th, new_dir, new_dentry->d_name.name,
  			       new_dentry->d_name.len, old_inode, 0);
  	if (retval == -EEXIST) {
  		if (!new_dentry_inode) {
c3a9c2109   Jeff Mahoney   reiserfs: rework ...
1263
1264
  			reiserfs_panic(old_dir->i_sb, "vs-7050",
  				       "new entry is found, new inode == 0");
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1265
1266
1267
1268
1269
  		}
  	} else if (retval) {
  		int err = journal_end(&th, old_dir->i_sb, jbegin_count);
  		reiserfs_write_unlock(old_dir->i_sb);
  		return err ? err : retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1270
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
  	reiserfs_update_inode_transaction(old_dir);
  	reiserfs_update_inode_transaction(new_dir);
  
  	/* this makes it so an fsync on an open fd for the old name will
  	 ** commit the rename operation
  	 */
  	reiserfs_update_inode_transaction(old_inode);
  
  	if (new_dentry_inode)
  		reiserfs_update_inode_transaction(new_dentry_inode);
  
  	while (1) {
  		// look for old name using corresponding entry key (found by reiserfs_find_entry)
  		if ((retval =
  		     search_by_entry_key(new_dir->i_sb, &old_de.de_entry_key,
  					 &old_entry_path,
  					 &old_de)) != NAME_FOUND) {
  			pathrelse(&old_entry_path);
  			journal_end(&th, old_dir->i_sb, jbegin_count);
  			reiserfs_write_unlock(old_dir->i_sb);
  			return -EIO;
  		}
  
  		copy_item_head(&old_entry_ih, get_ih(&old_entry_path));
  
  		reiserfs_prepare_for_journal(old_inode->i_sb, old_de.de_bh, 1);
  
  		// look for new name by reiserfs_find_entry
  		new_de.de_gen_number_bit_string = NULL;
  		retval =
  		    reiserfs_find_entry(new_dir, new_dentry->d_name.name,
  					new_dentry->d_name.len, &new_entry_path,
  					&new_de);
  		// reiserfs_add_entry should not return IO_ERROR, because it is called with essentially same parameters from
  		// reiserfs_add_entry above, and we'll catch any i/o errors before we get here.
  		if (retval != NAME_FOUND_INVISIBLE && retval != NAME_FOUND) {
  			pathrelse(&new_entry_path);
  			pathrelse(&old_entry_path);
  			journal_end(&th, old_dir->i_sb, jbegin_count);
  			reiserfs_write_unlock(old_dir->i_sb);
  			return -EIO;
  		}
  
  		copy_item_head(&new_entry_ih, get_ih(&new_entry_path));
  
  		reiserfs_prepare_for_journal(old_inode->i_sb, new_de.de_bh, 1);
  
  		if (S_ISDIR(old_inode->i_mode)) {
  			if ((retval =
  			     search_by_entry_key(new_dir->i_sb,
  						 &dot_dot_de.de_entry_key,
  						 &dot_dot_entry_path,
  						 &dot_dot_de)) != NAME_FOUND) {
  				pathrelse(&dot_dot_entry_path);
  				pathrelse(&new_entry_path);
  				pathrelse(&old_entry_path);
  				journal_end(&th, old_dir->i_sb, jbegin_count);
  				reiserfs_write_unlock(old_dir->i_sb);
  				return -EIO;
  			}
  			copy_item_head(&dot_dot_ih,
  				       get_ih(&dot_dot_entry_path));
  			// node containing ".." gets into transaction
  			reiserfs_prepare_for_journal(old_inode->i_sb,
  						     dot_dot_de.de_bh, 1);
  		}
  		/* we should check seals here, not do
  		   this stuff, yes? Then, having
  		   gathered everything into RAM we
  		   should lock the buffers, yes?  -Hans */
0222e6571   Jeff Mahoney   reiserfs: strip t...
1341
1342
1343
  		/* probably.  our rename needs to hold more
  		 ** than one path at once.  The seals would
  		 ** have to be written to deal with multi-path
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
  		 ** issues -chris
  		 */
  		/* sanity checking before doing the rename - avoid races many
  		 ** of the above checks could have scheduled.  We have to be
  		 ** sure our items haven't been shifted by another process.
  		 */
  		if (item_moved(&new_entry_ih, &new_entry_path) ||
  		    !entry_points_to_object(new_dentry->d_name.name,
  					    new_dentry->d_name.len,
  					    &new_de, new_dentry_inode) ||
  		    item_moved(&old_entry_ih, &old_entry_path) ||
  		    !entry_points_to_object(old_dentry->d_name.name,
  					    old_dentry->d_name.len,
  					    &old_de, old_inode)) {
  			reiserfs_restore_prepared_buffer(old_inode->i_sb,
  							 new_de.de_bh);
  			reiserfs_restore_prepared_buffer(old_inode->i_sb,
  							 old_de.de_bh);
  			if (S_ISDIR(old_inode_mode))
  				reiserfs_restore_prepared_buffer(old_inode->
  								 i_sb,
  								 dot_dot_de.
  								 de_bh);
  			continue;
  		}
  		if (S_ISDIR(old_inode_mode)) {
  			if (item_moved(&dot_dot_ih, &dot_dot_entry_path) ||
  			    !entry_points_to_object("..", 2, &dot_dot_de,
  						    old_dir)) {
  				reiserfs_restore_prepared_buffer(old_inode->
  								 i_sb,
  								 old_de.de_bh);
  				reiserfs_restore_prepared_buffer(old_inode->
  								 i_sb,
  								 new_de.de_bh);
  				reiserfs_restore_prepared_buffer(old_inode->
  								 i_sb,
  								 dot_dot_de.
  								 de_bh);
  				continue;
  			}
  		}
  
  		RFALSE(S_ISDIR(old_inode_mode) &&
  		       !buffer_journal_prepared(dot_dot_de.de_bh), "");
  
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1391
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1392
1393
  	/* ok, all the changes can be done in one fell swoop when we
  	   have claimed all the buffers needed. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1394

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1395
1396
1397
  	mark_de_visible(new_de.de_deh + new_de.de_entry_num);
  	set_ino_in_dir_entry(&new_de, INODE_PKEY(old_inode));
  	journal_mark_dirty(&th, old_dir->i_sb, new_de.de_bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1398

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
  	mark_de_hidden(old_de.de_deh + old_de.de_entry_num);
  	journal_mark_dirty(&th, old_dir->i_sb, old_de.de_bh);
  	ctime = CURRENT_TIME_SEC;
  	old_dir->i_ctime = old_dir->i_mtime = ctime;
  	new_dir->i_ctime = new_dir->i_mtime = ctime;
  	/* thanks to Alex Adriaanse <alex_a@caltech.edu> for patch which adds ctime update of
  	   renamed object */
  	old_inode->i_ctime = ctime;
  
  	if (new_dentry_inode) {
  		// adjust link number of the victim
  		if (S_ISDIR(new_dentry_inode->i_mode)) {
ce71ec368   Dave Hansen   [PATCH] r/o bind ...
1411
  			clear_nlink(new_dentry_inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1412
  		} else {
9a53c3a78   Dave Hansen   [PATCH] r/o bind ...
1413
  			drop_nlink(new_dentry_inode);
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1414
1415
1416
  		}
  		new_dentry_inode->i_ctime = ctime;
  		savelink = new_dentry_inode->i_nlink;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1417
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1418

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1419
  	if (S_ISDIR(old_inode_mode)) {
0222e6571   Jeff Mahoney   reiserfs: strip t...
1420
  		/* adjust ".." of renamed directory */
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
  		set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
  		journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh);
  
  		if (!new_dentry_inode)
  			/* there (in new_dir) was no directory, so it got new link
  			   (".."  of renamed directory) */
  			INC_DIR_INODE_NLINK(new_dir);
  
  		/* old directory lost one link - ".. " of renamed directory */
  		DEC_DIR_INODE_NLINK(old_dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1431
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1432
1433
1434
  	// looks like in 2.3.99pre3 brelse is atomic. so we can use pathrelse
  	pathrelse(&new_entry_path);
  	pathrelse(&dot_dot_entry_path);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1435

bd4c625c0   Linus Torvalds   reiserfs: run scr...
1436
1437
1438
1439
1440
1441
  	// FIXME: this reiserfs_cut_from_item's return value may screw up
  	// anybody, but it will panic if will not be able to find the
  	// entry. This needs one more clean up
  	if (reiserfs_cut_from_item
  	    (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL,
  	     0) < 0)
0030b6457   Jeff Mahoney   reiserfs: use rei...
1442
1443
  		reiserfs_error(old_dir->i_sb, "vs-7060",
  			       "couldn't not cut old name. Fsck later?");
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
  
  	old_dir->i_size -= DEH_SIZE + old_de.de_entrylen;
  
  	reiserfs_update_sd(&th, old_dir);
  	reiserfs_update_sd(&th, new_dir);
  	reiserfs_update_sd(&th, old_inode);
  
  	if (new_dentry_inode) {
  		if (savelink == 0)
  			add_save_link(&th, new_dentry_inode,
  				      0 /* not truncate */ );
  		reiserfs_update_sd(&th, new_dentry_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1456
  	}
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1457
1458
1459
1460
  
  	retval = journal_end(&th, old_dir->i_sb, jbegin_count);
  	reiserfs_write_unlock(old_dir->i_sb);
  	return retval;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1461
1462
1463
1464
1465
  }
  
  /*
   * directories can handle most operations...
   */
c5ef1c42c   Arjan van de Ven   [PATCH] mark stru...
1466
  const struct inode_operations reiserfs_dir_inode_operations = {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
  	//&reiserfs_dir_operations,   /* default_file_ops */
  	.create = reiserfs_create,
  	.lookup = reiserfs_lookup,
  	.link = reiserfs_link,
  	.unlink = reiserfs_unlink,
  	.symlink = reiserfs_symlink,
  	.mkdir = reiserfs_mkdir,
  	.rmdir = reiserfs_rmdir,
  	.mknod = reiserfs_mknod,
  	.rename = reiserfs_rename,
  	.setattr = reiserfs_setattr,
  	.setxattr = reiserfs_setxattr,
  	.getxattr = reiserfs_getxattr,
  	.listxattr = reiserfs_listxattr,
  	.removexattr = reiserfs_removexattr,
  	.permission = reiserfs_permission,
4e34e719e   Christoph Hellwig   fs: take the ACL ...
1483
  	.get_acl = reiserfs_get_acl,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1484
1485
1486
1487
1488
1489
  };
  
  /*
   * symlink operations.. same as page_symlink_inode_operations, with xattr
   * stuff added
   */
c5ef1c42c   Arjan van de Ven   [PATCH] mark stru...
1490
  const struct inode_operations reiserfs_symlink_inode_operations = {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1491
1492
1493
1494
1495
1496
1497
1498
1499
  	.readlink = generic_readlink,
  	.follow_link = page_follow_link_light,
  	.put_link = page_put_link,
  	.setattr = reiserfs_setattr,
  	.setxattr = reiserfs_setxattr,
  	.getxattr = reiserfs_getxattr,
  	.listxattr = reiserfs_listxattr,
  	.removexattr = reiserfs_removexattr,
  	.permission = reiserfs_permission,
4e34e719e   Christoph Hellwig   fs: take the ACL ...
1500
  	.get_acl = reiserfs_get_acl,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1501
1502
  
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1503
1504
1505
  /*
   * special file operations.. just xattr/acl stuff
   */
c5ef1c42c   Arjan van de Ven   [PATCH] mark stru...
1506
  const struct inode_operations reiserfs_special_inode_operations = {
bd4c625c0   Linus Torvalds   reiserfs: run scr...
1507
1508
1509
1510
1511
1512
  	.setattr = reiserfs_setattr,
  	.setxattr = reiserfs_setxattr,
  	.getxattr = reiserfs_getxattr,
  	.listxattr = reiserfs_listxattr,
  	.removexattr = reiserfs_removexattr,
  	.permission = reiserfs_permission,
4e34e719e   Christoph Hellwig   fs: take the ACL ...
1513
  	.get_acl = reiserfs_get_acl,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1514
  };