1 /*
2  *  linux/fs/hpfs/namei.c
3  *
4  *  Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
5  *
6  *  adding & removing files & directories
7  */
8 #include <linux/sched.h>
9 #include "hpfs_fn.h"
10 
hpfs_mkdir(struct inode * dir,struct dentry * dentry,int mode)11 static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
12 {
13 	const unsigned char *name = dentry->d_name.name;
14 	unsigned len = dentry->d_name.len;
15 	struct quad_buffer_head qbh0;
16 	struct buffer_head *bh;
17 	struct hpfs_dirent *de;
18 	struct fnode *fnode;
19 	struct dnode *dnode;
20 	struct inode *result;
21 	fnode_secno fno;
22 	dnode_secno dno;
23 	int r;
24 	struct hpfs_dirent dee;
25 	int err;
26 	if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err;
27 	hpfs_lock(dir->i_sb);
28 	err = -ENOSPC;
29 	fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
30 	if (!fnode)
31 		goto bail;
32 	dnode = hpfs_alloc_dnode(dir->i_sb, fno, &dno, &qbh0);
33 	if (!dnode)
34 		goto bail1;
35 	memset(&dee, 0, sizeof dee);
36 	dee.directory = 1;
37 	if (!(mode & 0222)) dee.read_only = 1;
38 	/*dee.archive = 0;*/
39 	dee.hidden = name[0] == '.';
40 	dee.fnode = cpu_to_le32(fno);
41 	dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
42 	result = new_inode(dir->i_sb);
43 	if (!result)
44 		goto bail2;
45 	hpfs_init_inode(result);
46 	result->i_ino = fno;
47 	hpfs_i(result)->i_parent_dir = dir->i_ino;
48 	hpfs_i(result)->i_dno = dno;
49 	result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
50 	result->i_ctime.tv_nsec = 0;
51 	result->i_mtime.tv_nsec = 0;
52 	result->i_atime.tv_nsec = 0;
53 	hpfs_i(result)->i_ea_size = 0;
54 	result->i_mode |= S_IFDIR;
55 	result->i_op = &hpfs_dir_iops;
56 	result->i_fop = &hpfs_dir_ops;
57 	result->i_blocks = 4;
58 	result->i_size = 2048;
59 	result->i_nlink = 2;
60 	if (dee.read_only)
61 		result->i_mode &= ~0222;
62 
63 	r = hpfs_add_dirent(dir, name, len, &dee);
64 	if (r == 1)
65 		goto bail3;
66 	if (r == -1) {
67 		err = -EEXIST;
68 		goto bail3;
69 	}
70 	fnode->len = len;
71 	memcpy(fnode->name, name, len > 15 ? 15 : len);
72 	fnode->up = cpu_to_le32(dir->i_ino);
73 	fnode->dirflag = 1;
74 	fnode->btree.n_free_nodes = 7;
75 	fnode->btree.n_used_nodes = 1;
76 	fnode->btree.first_free = cpu_to_le16(0x14);
77 	fnode->u.external[0].disk_secno = cpu_to_le32(dno);
78 	fnode->u.external[0].file_secno = cpu_to_le32(-1);
79 	dnode->root_dnode = 1;
80 	dnode->up = cpu_to_le32(fno);
81 	de = hpfs_add_de(dir->i_sb, dnode, "\001\001", 2, 0);
82 	de->creation_date = de->write_date = de->read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
83 	if (!(mode & 0222)) de->read_only = 1;
84 	de->first = de->directory = 1;
85 	/*de->hidden = de->system = 0;*/
86 	de->fnode = cpu_to_le32(fno);
87 	mark_buffer_dirty(bh);
88 	brelse(bh);
89 	hpfs_mark_4buffers_dirty(&qbh0);
90 	hpfs_brelse4(&qbh0);
91 	inc_nlink(dir);
92 	insert_inode_hash(result);
93 
94 	if (result->i_uid != current_fsuid() ||
95 	    result->i_gid != current_fsgid() ||
96 	    result->i_mode != (mode | S_IFDIR)) {
97 		result->i_uid = current_fsuid();
98 		result->i_gid = current_fsgid();
99 		result->i_mode = mode | S_IFDIR;
100 		hpfs_write_inode_nolock(result);
101 	}
102 	d_instantiate(dentry, result);
103 	hpfs_unlock(dir->i_sb);
104 	return 0;
105 bail3:
106 	iput(result);
107 bail2:
108 	hpfs_brelse4(&qbh0);
109 	hpfs_free_dnode(dir->i_sb, dno);
110 bail1:
111 	brelse(bh);
112 	hpfs_free_sectors(dir->i_sb, fno, 1);
113 bail:
114 	hpfs_unlock(dir->i_sb);
115 	return err;
116 }
117 
hpfs_create(struct inode * dir,struct dentry * dentry,int mode,struct nameidata * nd)118 static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
119 {
120 	const unsigned char *name = dentry->d_name.name;
121 	unsigned len = dentry->d_name.len;
122 	struct inode *result = NULL;
123 	struct buffer_head *bh;
124 	struct fnode *fnode;
125 	fnode_secno fno;
126 	int r;
127 	struct hpfs_dirent dee;
128 	int err;
129 	if ((err = hpfs_chk_name(name, &len)))
130 		return err==-ENOENT ? -EINVAL : err;
131 	hpfs_lock(dir->i_sb);
132 	err = -ENOSPC;
133 	fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
134 	if (!fnode)
135 		goto bail;
136 	memset(&dee, 0, sizeof dee);
137 	if (!(mode & 0222)) dee.read_only = 1;
138 	dee.archive = 1;
139 	dee.hidden = name[0] == '.';
140 	dee.fnode = cpu_to_le32(fno);
141 	dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
142 
143 	result = new_inode(dir->i_sb);
144 	if (!result)
145 		goto bail1;
146 
147 	hpfs_init_inode(result);
148 	result->i_ino = fno;
149 	result->i_mode |= S_IFREG;
150 	result->i_mode &= ~0111;
151 	result->i_op = &hpfs_file_iops;
152 	result->i_fop = &hpfs_file_ops;
153 	result->i_nlink = 1;
154 	hpfs_i(result)->i_parent_dir = dir->i_ino;
155 	result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
156 	result->i_ctime.tv_nsec = 0;
157 	result->i_mtime.tv_nsec = 0;
158 	result->i_atime.tv_nsec = 0;
159 	hpfs_i(result)->i_ea_size = 0;
160 	if (dee.read_only)
161 		result->i_mode &= ~0222;
162 	result->i_blocks = 1;
163 	result->i_size = 0;
164 	result->i_data.a_ops = &hpfs_aops;
165 	hpfs_i(result)->mmu_private = 0;
166 
167 	r = hpfs_add_dirent(dir, name, len, &dee);
168 	if (r == 1)
169 		goto bail2;
170 	if (r == -1) {
171 		err = -EEXIST;
172 		goto bail2;
173 	}
174 	fnode->len = len;
175 	memcpy(fnode->name, name, len > 15 ? 15 : len);
176 	fnode->up = cpu_to_le32(dir->i_ino);
177 	mark_buffer_dirty(bh);
178 	brelse(bh);
179 
180 	insert_inode_hash(result);
181 
182 	if (result->i_uid != current_fsuid() ||
183 	    result->i_gid != current_fsgid() ||
184 	    result->i_mode != (mode | S_IFREG)) {
185 		result->i_uid = current_fsuid();
186 		result->i_gid = current_fsgid();
187 		result->i_mode = mode | S_IFREG;
188 		hpfs_write_inode_nolock(result);
189 	}
190 	d_instantiate(dentry, result);
191 	hpfs_unlock(dir->i_sb);
192 	return 0;
193 
194 bail2:
195 	iput(result);
196 bail1:
197 	brelse(bh);
198 	hpfs_free_sectors(dir->i_sb, fno, 1);
199 bail:
200 	hpfs_unlock(dir->i_sb);
201 	return err;
202 }
203 
hpfs_mknod(struct inode * dir,struct dentry * dentry,int mode,dev_t rdev)204 static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
205 {
206 	const unsigned char *name = dentry->d_name.name;
207 	unsigned len = dentry->d_name.len;
208 	struct buffer_head *bh;
209 	struct fnode *fnode;
210 	fnode_secno fno;
211 	int r;
212 	struct hpfs_dirent dee;
213 	struct inode *result = NULL;
214 	int err;
215 	if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err;
216 	if (hpfs_sb(dir->i_sb)->sb_eas < 2) return -EPERM;
217 	if (!new_valid_dev(rdev))
218 		return -EINVAL;
219 	hpfs_lock(dir->i_sb);
220 	err = -ENOSPC;
221 	fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
222 	if (!fnode)
223 		goto bail;
224 	memset(&dee, 0, sizeof dee);
225 	if (!(mode & 0222)) dee.read_only = 1;
226 	dee.archive = 1;
227 	dee.hidden = name[0] == '.';
228 	dee.fnode = cpu_to_le32(fno);
229 	dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
230 
231 	result = new_inode(dir->i_sb);
232 	if (!result)
233 		goto bail1;
234 
235 	hpfs_init_inode(result);
236 	result->i_ino = fno;
237 	hpfs_i(result)->i_parent_dir = dir->i_ino;
238 	result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
239 	result->i_ctime.tv_nsec = 0;
240 	result->i_mtime.tv_nsec = 0;
241 	result->i_atime.tv_nsec = 0;
242 	hpfs_i(result)->i_ea_size = 0;
243 	result->i_uid = current_fsuid();
244 	result->i_gid = current_fsgid();
245 	result->i_nlink = 1;
246 	result->i_size = 0;
247 	result->i_blocks = 1;
248 	init_special_inode(result, mode, rdev);
249 
250 	r = hpfs_add_dirent(dir, name, len, &dee);
251 	if (r == 1)
252 		goto bail2;
253 	if (r == -1) {
254 		err = -EEXIST;
255 		goto bail2;
256 	}
257 	fnode->len = len;
258 	memcpy(fnode->name, name, len > 15 ? 15 : len);
259 	fnode->up = cpu_to_le32(dir->i_ino);
260 	mark_buffer_dirty(bh);
261 
262 	insert_inode_hash(result);
263 
264 	hpfs_write_inode_nolock(result);
265 	d_instantiate(dentry, result);
266 	brelse(bh);
267 	hpfs_unlock(dir->i_sb);
268 	return 0;
269 bail2:
270 	iput(result);
271 bail1:
272 	brelse(bh);
273 	hpfs_free_sectors(dir->i_sb, fno, 1);
274 bail:
275 	hpfs_unlock(dir->i_sb);
276 	return err;
277 }
278 
hpfs_symlink(struct inode * dir,struct dentry * dentry,const char * symlink)279 static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *symlink)
280 {
281 	const unsigned char *name = dentry->d_name.name;
282 	unsigned len = dentry->d_name.len;
283 	struct buffer_head *bh;
284 	struct fnode *fnode;
285 	fnode_secno fno;
286 	int r;
287 	struct hpfs_dirent dee;
288 	struct inode *result;
289 	int err;
290 	if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err;
291 	hpfs_lock(dir->i_sb);
292 	if (hpfs_sb(dir->i_sb)->sb_eas < 2) {
293 		hpfs_unlock(dir->i_sb);
294 		return -EPERM;
295 	}
296 	err = -ENOSPC;
297 	fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
298 	if (!fnode)
299 		goto bail;
300 	memset(&dee, 0, sizeof dee);
301 	dee.archive = 1;
302 	dee.hidden = name[0] == '.';
303 	dee.fnode = cpu_to_le32(fno);
304 	dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
305 
306 	result = new_inode(dir->i_sb);
307 	if (!result)
308 		goto bail1;
309 	result->i_ino = fno;
310 	hpfs_init_inode(result);
311 	hpfs_i(result)->i_parent_dir = dir->i_ino;
312 	result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
313 	result->i_ctime.tv_nsec = 0;
314 	result->i_mtime.tv_nsec = 0;
315 	result->i_atime.tv_nsec = 0;
316 	hpfs_i(result)->i_ea_size = 0;
317 	result->i_mode = S_IFLNK | 0777;
318 	result->i_uid = current_fsuid();
319 	result->i_gid = current_fsgid();
320 	result->i_blocks = 1;
321 	result->i_nlink = 1;
322 	result->i_size = strlen(symlink);
323 	result->i_op = &page_symlink_inode_operations;
324 	result->i_data.a_ops = &hpfs_symlink_aops;
325 
326 	r = hpfs_add_dirent(dir, name, len, &dee);
327 	if (r == 1)
328 		goto bail2;
329 	if (r == -1) {
330 		err = -EEXIST;
331 		goto bail2;
332 	}
333 	fnode->len = len;
334 	memcpy(fnode->name, name, len > 15 ? 15 : len);
335 	fnode->up = cpu_to_le32(dir->i_ino);
336 	hpfs_set_ea(result, fnode, "SYMLINK", symlink, strlen(symlink));
337 	mark_buffer_dirty(bh);
338 	brelse(bh);
339 
340 	insert_inode_hash(result);
341 
342 	hpfs_write_inode_nolock(result);
343 	d_instantiate(dentry, result);
344 	hpfs_unlock(dir->i_sb);
345 	return 0;
346 bail2:
347 	iput(result);
348 bail1:
349 	brelse(bh);
350 	hpfs_free_sectors(dir->i_sb, fno, 1);
351 bail:
352 	hpfs_unlock(dir->i_sb);
353 	return err;
354 }
355 
hpfs_unlink(struct inode * dir,struct dentry * dentry)356 static int hpfs_unlink(struct inode *dir, struct dentry *dentry)
357 {
358 	const unsigned char *name = dentry->d_name.name;
359 	unsigned len = dentry->d_name.len;
360 	struct quad_buffer_head qbh;
361 	struct hpfs_dirent *de;
362 	struct inode *inode = dentry->d_inode;
363 	dnode_secno dno;
364 	int r;
365 	int rep = 0;
366 	int err;
367 
368 	hpfs_lock(dir->i_sb);
369 	hpfs_adjust_length(name, &len);
370 again:
371 	err = -ENOENT;
372 	de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh);
373 	if (!de)
374 		goto out;
375 
376 	err = -EPERM;
377 	if (de->first)
378 		goto out1;
379 
380 	err = -EISDIR;
381 	if (de->directory)
382 		goto out1;
383 
384 	r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
385 	switch (r) {
386 	case 1:
387 		hpfs_error(dir->i_sb, "there was error when removing dirent");
388 		err = -EFSERROR;
389 		break;
390 	case 2:		/* no space for deleting, try to truncate file */
391 
392 		err = -ENOSPC;
393 		if (rep++)
394 			break;
395 
396 		dentry_unhash(dentry);
397 		if (!d_unhashed(dentry)) {
398 			dput(dentry);
399 			hpfs_unlock(dir->i_sb);
400 			return -ENOSPC;
401 		}
402 		if (generic_permission(inode, MAY_WRITE, 0, NULL) ||
403 		    !S_ISREG(inode->i_mode) ||
404 		    get_write_access(inode)) {
405 			d_rehash(dentry);
406 			dput(dentry);
407 		} else {
408 			struct iattr newattrs;
409 			/*printk("HPFS: truncating file before delete.\n");*/
410 			newattrs.ia_size = 0;
411 			newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
412 			err = notify_change(dentry, &newattrs);
413 			put_write_access(inode);
414 			dput(dentry);
415 			if (!err)
416 				goto again;
417 		}
418 		hpfs_unlock(dir->i_sb);
419 		return -ENOSPC;
420 	default:
421 		drop_nlink(inode);
422 		err = 0;
423 	}
424 	goto out;
425 
426 out1:
427 	hpfs_brelse4(&qbh);
428 out:
429 	hpfs_unlock(dir->i_sb);
430 	return err;
431 }
432 
hpfs_rmdir(struct inode * dir,struct dentry * dentry)433 static int hpfs_rmdir(struct inode *dir, struct dentry *dentry)
434 {
435 	const unsigned char *name = dentry->d_name.name;
436 	unsigned len = dentry->d_name.len;
437 	struct quad_buffer_head qbh;
438 	struct hpfs_dirent *de;
439 	struct inode *inode = dentry->d_inode;
440 	dnode_secno dno;
441 	int n_items = 0;
442 	int err;
443 	int r;
444 
445 	hpfs_adjust_length(name, &len);
446 	hpfs_lock(dir->i_sb);
447 	err = -ENOENT;
448 	de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh);
449 	if (!de)
450 		goto out;
451 
452 	err = -EPERM;
453 	if (de->first)
454 		goto out1;
455 
456 	err = -ENOTDIR;
457 	if (!de->directory)
458 		goto out1;
459 
460 	hpfs_count_dnodes(dir->i_sb, hpfs_i(inode)->i_dno, NULL, NULL, &n_items);
461 	err = -ENOTEMPTY;
462 	if (n_items)
463 		goto out1;
464 
465 	r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
466 	switch (r) {
467 	case 1:
468 		hpfs_error(dir->i_sb, "there was error when removing dirent");
469 		err = -EFSERROR;
470 		break;
471 	case 2:
472 		err = -ENOSPC;
473 		break;
474 	default:
475 		drop_nlink(dir);
476 		clear_nlink(inode);
477 		err = 0;
478 	}
479 	goto out;
480 out1:
481 	hpfs_brelse4(&qbh);
482 out:
483 	hpfs_unlock(dir->i_sb);
484 	return err;
485 }
486 
hpfs_symlink_readpage(struct file * file,struct page * page)487 static int hpfs_symlink_readpage(struct file *file, struct page *page)
488 {
489 	char *link = kmap(page);
490 	struct inode *i = page->mapping->host;
491 	struct fnode *fnode;
492 	struct buffer_head *bh;
493 	int err;
494 
495 	err = -EIO;
496 	hpfs_lock(i->i_sb);
497 	if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh)))
498 		goto fail;
499 	err = hpfs_read_ea(i->i_sb, fnode, "SYMLINK", link, PAGE_SIZE);
500 	brelse(bh);
501 	if (err)
502 		goto fail;
503 	hpfs_unlock(i->i_sb);
504 	SetPageUptodate(page);
505 	kunmap(page);
506 	unlock_page(page);
507 	return 0;
508 
509 fail:
510 	hpfs_unlock(i->i_sb);
511 	SetPageError(page);
512 	kunmap(page);
513 	unlock_page(page);
514 	return err;
515 }
516 
517 const struct address_space_operations hpfs_symlink_aops = {
518 	.readpage	= hpfs_symlink_readpage
519 };
520 
hpfs_rename(struct inode * old_dir,struct dentry * old_dentry,struct inode * new_dir,struct dentry * new_dentry)521 static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
522 		struct inode *new_dir, struct dentry *new_dentry)
523 {
524 	const unsigned char *old_name = old_dentry->d_name.name;
525 	unsigned old_len = old_dentry->d_name.len;
526 	const unsigned char *new_name = new_dentry->d_name.name;
527 	unsigned new_len = new_dentry->d_name.len;
528 	struct inode *i = old_dentry->d_inode;
529 	struct inode *new_inode = new_dentry->d_inode;
530 	struct quad_buffer_head qbh, qbh1;
531 	struct hpfs_dirent *dep, *nde;
532 	struct hpfs_dirent de;
533 	dnode_secno dno;
534 	int r;
535 	struct buffer_head *bh;
536 	struct fnode *fnode;
537 	int err;
538 	if ((err = hpfs_chk_name(new_name, &new_len))) return err;
539 	err = 0;
540 	hpfs_adjust_length(old_name, &old_len);
541 
542 	hpfs_lock(i->i_sb);
543 	/* order doesn't matter, due to VFS exclusion */
544 
545 	/* Erm? Moving over the empty non-busy directory is perfectly legal */
546 	if (new_inode && S_ISDIR(new_inode->i_mode)) {
547 		err = -EINVAL;
548 		goto end1;
549 	}
550 
551 	if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) {
552 		hpfs_error(i->i_sb, "lookup succeeded but map dirent failed");
553 		err = -ENOENT;
554 		goto end1;
555 	}
556 	copy_de(&de, dep);
557 	de.hidden = new_name[0] == '.';
558 
559 	if (new_inode) {
560 		int r;
561 		if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 1)) != 2) {
562 			if ((nde = map_dirent(new_dir, hpfs_i(new_dir)->i_dno, new_name, new_len, NULL, &qbh1))) {
563 				clear_nlink(new_inode);
564 				copy_de(nde, &de);
565 				memcpy(nde->name, new_name, new_len);
566 				hpfs_mark_4buffers_dirty(&qbh1);
567 				hpfs_brelse4(&qbh1);
568 				goto end;
569 			}
570 			hpfs_error(new_dir->i_sb, "hpfs_rename: could not find dirent");
571 			err = -EFSERROR;
572 			goto end1;
573 		}
574 		err = r == 2 ? -ENOSPC : r == 1 ? -EFSERROR : 0;
575 		goto end1;
576 	}
577 
578 	if (new_dir == old_dir) hpfs_brelse4(&qbh);
579 
580 	if ((r = hpfs_add_dirent(new_dir, new_name, new_len, &de))) {
581 		if (r == -1) hpfs_error(new_dir->i_sb, "hpfs_rename: dirent already exists!");
582 		err = r == 1 ? -ENOSPC : -EFSERROR;
583 		if (new_dir != old_dir) hpfs_brelse4(&qbh);
584 		goto end1;
585 	}
586 
587 	if (new_dir == old_dir)
588 		if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) {
589 			hpfs_error(i->i_sb, "lookup succeeded but map dirent failed at #2");
590 			err = -ENOENT;
591 			goto end1;
592 		}
593 
594 	if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 0))) {
595 		hpfs_error(i->i_sb, "hpfs_rename: could not remove dirent");
596 		err = r == 2 ? -ENOSPC : -EFSERROR;
597 		goto end1;
598 	}
599 
600 	end:
601 	hpfs_i(i)->i_parent_dir = new_dir->i_ino;
602 	if (S_ISDIR(i->i_mode)) {
603 		inc_nlink(new_dir);
604 		drop_nlink(old_dir);
605 	}
606 	if ((fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) {
607 		fnode->up = cpu_to_le32(new_dir->i_ino);
608 		fnode->len = new_len;
609 		memcpy(fnode->name, new_name, new_len>15?15:new_len);
610 		if (new_len < 15) memset(&fnode->name[new_len], 0, 15 - new_len);
611 		mark_buffer_dirty(bh);
612 		brelse(bh);
613 	}
614 end1:
615 	hpfs_unlock(i->i_sb);
616 	return err;
617 }
618 
619 const struct inode_operations hpfs_dir_iops =
620 {
621 	.create		= hpfs_create,
622 	.lookup		= hpfs_lookup,
623 	.unlink		= hpfs_unlink,
624 	.symlink	= hpfs_symlink,
625 	.mkdir		= hpfs_mkdir,
626 	.rmdir		= hpfs_rmdir,
627 	.mknod		= hpfs_mknod,
628 	.rename		= hpfs_rename,
629 	.setattr	= hpfs_setattr,
630 };
631