2 * linux/fs/umsdos/namei.c
4 * Written 1993 by Jacques Gelinas
5 * Inspired from linux/fs/msdos/... by Werner Almesberger
7 * Maintain and access the --linux alternate directory file.
10 * You are in the maze of twisted functions - half of them shouldn't
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/types.h>
18 #include <linux/fcntl.h>
19 #include <linux/stat.h>
20 #include <linux/string.h>
21 #include <linux/msdos_fs.h>
22 #include <linux/umsdos_fs.h>
23 #include <linux/malloc.h>
25 #define UMSDOS_DIR_LOCK
27 #ifdef UMSDOS_DIR_LOCK
29 static inline void u_sleep_on (struct inode
*dir
)
31 sleep_on (&dir
->u
.umsdos_i
.dir_info
.p
);
34 static inline void u_wake_up (struct inode
*dir
)
36 wake_up (&dir
->u
.umsdos_i
.dir_info
.p
);
40 * Wait for creation exclusivity.
41 * Return 0 if the dir was already available.
42 * Return 1 if a wait was necessary.
43 * When 1 is return, it means a wait was done. It does not
44 * mean the directory is available.
46 static int umsdos_waitcreate (struct inode
*dir
)
50 if (dir
->u
.umsdos_i
.dir_info
.creating
51 && dir
->u
.umsdos_i
.dir_info
.pid
!= current
->pid
) {
52 PRINTK (("creating && dir_info.pid=%lu, current->pid=%u\n", dir
->u
.umsdos_i
.dir_info
.pid
, current
->pid
));
60 * Wait for any lookup process to finish
62 static void umsdos_waitlookup (struct inode
*dir
)
64 while (dir
->u
.umsdos_i
.dir_info
.looking
) {
70 * Lock all other process out of this directory.
72 /* #Specification: file creation / not atomic
73 * File creation is a two step process. First we create (allocate)
74 * an entry in the EMD file and then (using the entry offset) we
75 * build a unique name for MSDOS. We create this name in the msdos
78 * We have to use semaphore (sleep_on/wake_up) to prevent lookup
79 * into a directory when we create a file or directory and to
80 * prevent creation while a lookup is going on. Since many lookup
81 * may happen at the same time, the semaphore is a counter.
83 * Only one creation is allowed at the same time. This protection
84 * may not be necessary. The problem arise mainly when a lookup
85 * or a readdir is done while a file is partially created. The
86 * lookup process see that as a "normal" problem and silently
87 * erase the file from the EMD file. Normal because a file
88 * may be erased during a MSDOS session, but not removed from
91 * The locking is done on a directory per directory basis. Each
92 * directory inode has its wait_queue.
94 * For some operation like hard link, things even get worse. Many
95 * creation must occur at once (atomic). To simplify the design
96 * a process is allowed to recursively lock the directory for
97 * creation. The pid of the locking process is kept along with
98 * a counter so a second level of locking is granted or not.
100 void umsdos_lockcreate (struct inode
*dir
)
103 * Wait for any creation process to finish except
104 * if we (the process) own the lock
106 while (umsdos_waitcreate (dir
) != 0);
107 dir
->u
.umsdos_i
.dir_info
.creating
++;
108 dir
->u
.umsdos_i
.dir_info
.pid
= current
->pid
;
109 umsdos_waitlookup (dir
);
113 * Lock all other process out of those two directories.
115 static void umsdos_lockcreate2 (struct inode
*dir1
, struct inode
*dir2
)
118 * We must check that both directory are available before
119 * locking anyone of them. This is to avoid some deadlock.
120 * Thanks to dglaude@is1.vub.ac.be (GLAUDE DAVID) for pointing
124 if (umsdos_waitcreate (dir1
) == 0
125 && umsdos_waitcreate (dir2
) == 0) {
126 /* We own both now */
127 dir1
->u
.umsdos_i
.dir_info
.creating
++;
128 dir1
->u
.umsdos_i
.dir_info
.pid
= current
->pid
;
129 dir2
->u
.umsdos_i
.dir_info
.creating
++;
130 dir2
->u
.umsdos_i
.dir_info
.pid
= current
->pid
;
134 umsdos_waitlookup (dir1
);
135 umsdos_waitlookup (dir2
);
139 * Wait until creation is finish in this directory.
141 void umsdos_startlookup (struct inode
*dir
)
143 while (umsdos_waitcreate (dir
) != 0);
144 dir
->u
.umsdos_i
.dir_info
.looking
++;
148 * Unlock the directory.
150 void umsdos_unlockcreate (struct inode
*dir
)
152 dir
->u
.umsdos_i
.dir_info
.creating
--;
153 if (dir
->u
.umsdos_i
.dir_info
.creating
< 0) {
154 printk ("UMSDOS: dir->u.umsdos_i.dir_info.creating < 0: %d"
155 ,dir
->u
.umsdos_i
.dir_info
.creating
);
161 * Tell directory lookup is over.
163 void umsdos_endlookup (struct inode
*dir
)
165 dir
->u
.umsdos_i
.dir_info
.looking
--;
166 if (dir
->u
.umsdos_i
.dir_info
.looking
< 0) {
167 printk ("UMSDOS: dir->u.umsdos_i.dir_info.looking < 0: %d"
168 ,dir
->u
.umsdos_i
.dir_info
.looking
);
174 static void umsdos_lockcreate (struct inode
*dir
)
177 static void umsdos_lockcreate2 (struct inode
*dir1
, struct inode
*dir2
)
180 void umsdos_startlookup (struct inode
*dir
)
183 static void umsdos_unlockcreate (struct inode
*dir
)
186 void umsdos_endlookup (struct inode
*dir
)
192 static int umsdos_nevercreat (struct inode
*dir
, struct dentry
*dentry
,
197 if (umsdos_is_pseudodos (dir
, dentry
)) {
198 /* #Specification: pseudo root / any file creation /DOS
199 * The pseudo sub-directory /DOS can't be created!
200 * EEXIST is returned.
202 * The pseudo sub-directory /DOS can't be removed!
211 * Add a new file (ordinary or special) into the alternate directory.
212 * The file is added to the real MSDOS directory. If successful, it
213 * is then added to the EMD file.
215 * Return the status of the operation. 0 mean success.
217 * #Specification: create / file exists in DOS
218 * Here is a situation: we are trying to create a file with
219 * UMSDOS. The file is unknown to UMSDOS but already
220 * exists in the DOS directory.
222 * Here is what we are NOT doing:
224 * We could silently assume that everything is fine
225 * and allows the creation to succeed.
227 * It is possible not all files in the partition
228 * are meant to be visible from linux. By trying to create
229 * those file in some directory, one user may get access
230 * to those file without proper permissions. Looks like
231 * a security hole to me. Off course sharing a file system
232 * with DOS is some kind of security hole :-)
236 * We return EEXIST in this case.
237 * The same is true for directory creation.
239 static int umsdos_create_any (struct inode
*dir
, struct dentry
*dentry
,
240 int mode
, int rdev
, char flags
)
245 struct umsdos_info info
;
247 ret
= umsdos_nevercreat (dir
, dentry
, -EEXIST
);
251 ret
= umsdos_parse (dentry
->d_name
.name
, dentry
->d_name
.len
, &info
);
255 info
.entry
.mode
= mode
;
256 info
.entry
.rdev
= rdev
;
257 info
.entry
.flags
= flags
;
258 info
.entry
.uid
= current
->fsuid
;
259 info
.entry
.gid
= (dir
->i_mode
& S_ISGID
) ? dir
->i_gid
: current
->fsgid
;
260 info
.entry
.ctime
= info
.entry
.atime
= info
.entry
.mtime
= CURRENT_TIME
;
261 info
.entry
.nlink
= 1;
262 ret
= umsdos_newentry (dentry
->d_parent
, &info
);
266 /* do a real lookup to get the short name dentry */
267 fake
= umsdos_covered(dentry
->d_parent
, info
.fake
.fname
, info
.fake
.len
);
272 /* should not exist yet ... */
275 goto out_remove_dput
;
277 ret
= msdos_create (dir
, fake
, S_IFREG
| 0777);
279 goto out_remove_dput
;
281 inode
= fake
->d_inode
;
282 atomic_inc(&inode
->i_count
);
283 d_instantiate (dentry
, inode
);
285 if (atomic_read(&inode
->i_count
) > 1) {
287 "umsdos_create_any: %s/%s, ino=%ld, icount=%d??\n",
288 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
289 inode
->i_ino
, atomic_read(&inode
->i_count
));
291 umsdos_lookup_patch_new(dentry
, &info
);
296 /* Creation failed ... remove the EMD entry */
301 printk(KERN_WARNING
"UMSDOS: out of sync, deleting %s/%s\n",
302 dentry
->d_parent
->d_name
.name
, info
.fake
.fname
);
303 umsdos_delentry (dentry
->d_parent
, &info
, S_ISDIR (info
.entry
.mode
));
308 * Add a new file into the alternate directory.
309 * The file is added to the real MSDOS directory. If successful, it
310 * is then added to the EMD file.
312 * Return the status of the operation. 0 mean success.
314 int UMSDOS_create (struct inode
*dir
, struct dentry
*dentry
, int mode
)
316 return umsdos_create_any (dir
, dentry
, mode
, 0, 0);
321 * Initialise the new_entry from the old for a rename operation.
322 * (Only useful for umsdos_rename_f() below).
324 static void umsdos_ren_init (struct umsdos_info
*new_info
,
325 struct umsdos_info
*old_info
)
327 new_info
->entry
.mode
= old_info
->entry
.mode
;
328 new_info
->entry
.rdev
= old_info
->entry
.rdev
;
329 new_info
->entry
.uid
= old_info
->entry
.uid
;
330 new_info
->entry
.gid
= old_info
->entry
.gid
;
331 new_info
->entry
.ctime
= old_info
->entry
.ctime
;
332 new_info
->entry
.atime
= old_info
->entry
.atime
;
333 new_info
->entry
.mtime
= old_info
->entry
.mtime
;
334 new_info
->entry
.flags
= old_info
->entry
.flags
;
335 new_info
->entry
.nlink
= old_info
->entry
.nlink
;
339 * Rename a file (move) in the file system.
342 static int umsdos_rename_f (struct inode
*old_dir
, struct dentry
*old_dentry
,
343 struct inode
*new_dir
, struct dentry
*new_dentry
,
346 struct inode
*old_inode
= old_dentry
->d_inode
;
347 struct dentry
*old
, *new, *old_emd
;
349 struct umsdos_info old_info
;
350 struct umsdos_info new_info
;
353 err
= umsdos_parse (old_dentry
->d_name
.name
,
354 old_dentry
->d_name
.len
, &old_info
);
357 err
= umsdos_parse (new_dentry
->d_name
.name
,
358 new_dentry
->d_name
.len
, &new_info
);
362 /* Get the EMD dentry for the old parent */
363 old_emd
= umsdos_get_emd_dentry(old_dentry
->d_parent
);
364 ret
= PTR_ERR(old_emd
);
368 umsdos_lockcreate2 (old_dir
, new_dir
);
370 ret
= umsdos_findentry(old_emd
->d_parent
, &old_info
, 0);
374 err
= umsdos_findentry(new_dentry
->d_parent
, &new_info
, 0);
376 /* check whether it _really_ exists ... */
378 if (new_dentry
->d_inode
)
381 /* bogus lookup? complain and fix up the EMD ... */
383 "umsdos_rename_f: entry %s/%s exists, inode NULL??\n",
384 new_dentry
->d_parent
->d_name
.name
, new_info
.entry
.name
);
385 err
= umsdos_delentry(new_dentry
->d_parent
, &new_info
,
386 S_ISDIR(new_info
.entry
.mode
));
389 umsdos_ren_init (&new_info
, &old_info
);
391 new_info
.entry
.flags
= flags
;
392 ret
= umsdos_newentry (new_dentry
->d_parent
, &new_info
);
396 /* If we're moving a hardlink, drop it first */
397 if (old_info
.entry
.flags
& UMSDOS_HLINK
) {
401 old
= umsdos_covered(old_dentry
->d_parent
, old_info
.fake
.fname
,
406 /* make sure it's the same inode! */
408 if (old
->d_inode
!= old_inode
)
411 new = umsdos_covered(new_dentry
->d_parent
, new_info
.fake
.fname
,
417 /* Do the msdos-level rename */
418 ret
= msdos_rename (old_dir
, old
, new_dir
, new);
422 /* If the rename failed, remove the new EMD entry */
424 umsdos_delentry (new_dentry
->d_parent
, &new_info
,
425 S_ISDIR (new_info
.entry
.mode
));
430 * Rename successful ... remove the old name from the EMD.
431 * Note that we use the EMD parent here, as the old dentry
432 * may have moved to a new parent ...
434 err
= umsdos_delentry (old_emd
->d_parent
, &old_info
,
435 S_ISDIR (old_info
.entry
.mode
));
437 /* Failed? Complain a bit, but don't fail the operation */
439 "umsdos_rename_f: delentry %s/%s failed, error=%d\n",
440 old_emd
->d_parent
->d_name
.name
, old_info
.entry
.name
,
445 * Update f_pos so notify_change will succeed
446 * if the file was already in use.
448 umsdos_set_dirinfo_new(old_dentry
, new_info
.f_pos
);
450 /* dput() the dentry if we haven't already */
456 umsdos_unlockcreate (old_dir
);
457 umsdos_unlockcreate (new_dir
);
460 Printk ((" _ret=%d\n", ret
));
465 * Setup a Symbolic link or a (pseudo) hard link
466 * Return a negative error code or 0 if OK.
468 /* #Specification: symbolic links / strategy
469 * A symbolic link is simply a file which holds a path. It is
470 * implemented as a normal MSDOS file (not very space efficient :-()
472 * I see two different ways to do this: One is to place the link data
473 * in unused entries of the EMD file; the other is to have a separate
474 * file dedicated to hold all symbolic links data.
476 * Let's go for simplicity...
480 * AV. Should be called with dir->i_sem down.
482 static int umsdos_symlink_x (struct inode
*dir
, struct dentry
*dentry
,
483 const char *symname
, int mode
, char flags
)
487 ret
= umsdos_create_any (dir
, dentry
, mode
, 0, flags
);
490 "umsdos_symlink: create failed, ret=%d\n", ret
);
494 len
= strlen (symname
);
495 ret
= block_symlink(dentry
->d_inode
, symname
, len
);
502 printk(KERN_WARNING
"umsdos_symlink: write failed, unlinking\n");
503 UMSDOS_unlink (dir
, dentry
);
509 * Setup a Symbolic link.
510 * Return a negative error code or 0 if OK.
512 int UMSDOS_symlink ( struct inode
*dir
, struct dentry
*dentry
,
515 return umsdos_symlink_x (dir
, dentry
, symname
, S_IFLNK
| 0777, 0);
519 * Add a link to an inode in a directory
521 int UMSDOS_link (struct dentry
*olddentry
, struct inode
*dir
,
522 struct dentry
*dentry
)
524 struct inode
*oldinode
= olddentry
->d_inode
;
525 struct inode
*olddir
= olddentry
->d_parent
->d_inode
;
528 unsigned long buffer
;
530 struct umsdos_info old_info
;
531 struct umsdos_info hid_info
;
533 #ifdef UMSDOS_DEBUG_VERBOSE
534 printk("umsdos_link: new %s%s -> %s/%s\n",
535 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
536 olddentry
->d_parent
->d_name
.name
, olddentry
->d_name
.name
);
540 if (S_ISDIR (oldinode
->i_mode
))
543 ret
= umsdos_nevercreat (dir
, dentry
, -EPERM
);
548 buffer
= get_free_page(GFP_KERNEL
);
553 * Lock the link parent if it's not the same directory.
557 if (atomic_read(&olddir
->i_sem
.count
) < 1)
559 down(&olddir
->i_sem
);
563 * Parse the name and get the visible directory entry.
565 ret
= umsdos_parse (olddentry
->d_name
.name
, olddentry
->d_name
.len
,
569 ret
= umsdos_findentry (olddentry
->d_parent
, &old_info
, 1);
571 printk("UMSDOS_link: %s/%s not in EMD, ret=%d\n",
572 olddentry
->d_parent
->d_name
.name
, olddentry
->d_name
.name
, ret
);
577 * If the visible dentry is a pseudo-hardlink, the original
578 * file must be already hidden.
580 if (!(old_info
.entry
.flags
& UMSDOS_HLINK
)) {
583 /* create a hidden link name */
584 ret
= umsdos_newhidden (olddentry
->d_parent
, &hid_info
);
586 printk("umsdos_link: can't make hidden %s/%s, ret=%d\n",
587 olddentry
->d_parent
->d_name
.name
, hid_info
.entry
.name
, ret
);
592 * Make a dentry and rename the original file ...
594 temp
= umsdos_lookup_dentry(olddentry
->d_parent
,
596 hid_info
.entry
.name_len
, 0);
599 printk("umsdos_link: lookup %s/%s failed, ret=%d\n",
600 dentry
->d_parent
->d_name
.name
, hid_info
.entry
.name
, ret
);
603 /* rename the link to the hidden location ... */
604 ret
= umsdos_rename_f(olddir
, olddentry
, olddir
, temp
,
606 d_move(olddentry
, temp
);
609 printk("umsdos_link: rename to %s/%s failed, ret=%d\n",
610 temp
->d_parent
->d_name
.name
, temp
->d_name
.name
, ret
);
613 /* mark the inode as a hardlink */
614 oldinode
->u
.umsdos_i
.i_is_hlink
= 1;
617 * Capture the path to the hidden link.
619 path
= umsdos_d_path(olddentry
, (char *) buffer
, PAGE_SIZE
);
620 Printk(("umsdos_link: hidden link path=%s\n", path
));
623 * Recreate a dentry for the original name and symlink it,
624 * then symlink the new dentry. Don't give up if one fails,
625 * or we'll lose the file completely!
627 * Note: this counts as the "original" reference, so we
628 * don't increment i_nlink for this one.
630 temp
= umsdos_lookup_dentry(olddentry
->d_parent
,
632 old_info
.entry
.name_len
, 0);
635 ret
= umsdos_symlink_x (olddir
, temp
, path
,
636 S_IFREG
| 0777, UMSDOS_HLINK
);
640 /* This symlink increments i_nlink (see below.) */
641 err
= umsdos_symlink_x (dir
, dentry
, path
,
642 S_IFREG
| 0777, UMSDOS_HLINK
);
643 /* fold the two errors */
648 /* creation failed ... remove the link entry */
650 printk("umsdos_link: link failed, ret=%d, removing %s/%s\n",
651 ret
, olddentry
->d_parent
->d_name
.name
, hid_info
.entry
.name
);
652 err
= umsdos_delentry(olddentry
->d_parent
, &hid_info
, 0);
656 Printk(("UMSDOS_link: %s/%s already hidden\n",
657 olddentry
->d_parent
->d_name
.name
, olddentry
->d_name
.name
));
659 * The original file is already hidden, and we need to get
660 * the dentry for its real name, not the visible name.
661 * N.B. make sure it's the hidden inode ...
663 if (!oldinode
->u
.umsdos_i
.i_is_hlink
)
664 printk("UMSDOS_link: %s/%s hidden, ino=%ld not hlink??\n",
665 olddentry
->d_parent
->d_name
.name
,
666 olddentry
->d_name
.name
, oldinode
->i_ino
);
669 * In order to get the correct (real) inode, we just drop
670 * the original dentry.
673 Printk(("UMSDOS_link: hard link %s/%s, fake=%s\n",
674 olddentry
->d_parent
->d_name
.name
, olddentry
->d_name
.name
, old_info
.fake
.fname
));
676 /* Do a real lookup to get the short name dentry */
677 temp
= umsdos_covered(olddentry
->d_parent
, old_info
.fake
.fname
,
683 /* now resolve the link ... */
684 temp
= umsdos_solve_hlink(temp
);
688 path
= umsdos_d_path(temp
, (char *) buffer
, PAGE_SIZE
);
690 Printk(("umsdos_link: %s/%s already hidden, path=%s\n",
691 olddentry
->d_parent
->d_name
.name
, olddentry
->d_name
.name
, path
));
693 /* finally we can symlink it ... */
694 ret
= umsdos_symlink_x (dir
, dentry
, path
, S_IFREG
| 0777,UMSDOS_HLINK
);
697 /* remain locked for the call to notify_change ... */
699 struct iattr newattrs
;
701 #ifdef UMSDOS_PARANOIA
702 if (!oldinode
->u
.umsdos_i
.i_is_hlink
)
703 printk("UMSDOS_link: %s/%s, ino=%ld, not marked as hlink!\n",
704 olddentry
->d_parent
->d_name
.name
, olddentry
->d_name
.name
, oldinode
->i_ino
);
707 Printk(("UMSDOS_link: linked %s/%s, ino=%ld, nlink=%d\n",
708 olddentry
->d_parent
->d_name
.name
, olddentry
->d_name
.name
,
709 oldinode
->i_ino
, oldinode
->i_nlink
));
710 newattrs
.ia_valid
= 0;
711 ret
= umsdos_notify_change_locked(olddentry
, &newattrs
);
713 mark_inode_dirty(olddentry
->d_inode
);
721 Printk (("umsdos_link %d\n", ret
));
727 * Add a sub-directory in a directory
729 /* #Specification: mkdir / Directory already exist in DOS
730 * We do the same thing as for file creation.
731 * For all user it is an error.
733 /* #Specification: mkdir / umsdos directory / create EMD
734 * When we created a new sub-directory in a UMSDOS
735 * directory (one with full UMSDOS semantics), we
736 * create immediately an EMD file in the new
737 * sub-directory so it inherits UMSDOS semantics.
739 int UMSDOS_mkdir (struct inode
*dir
, struct dentry
*dentry
, int mode
)
744 struct umsdos_info info
;
746 ret
= umsdos_nevercreat (dir
, dentry
, -EEXIST
);
750 ret
= umsdos_parse (dentry
->d_name
.name
, dentry
->d_name
.len
, &info
);
754 info
.entry
.mode
= mode
| S_IFDIR
;
756 info
.entry
.uid
= current
->fsuid
;
757 info
.entry
.gid
= (dir
->i_mode
& S_ISGID
) ? dir
->i_gid
: current
->fsgid
;
758 info
.entry
.ctime
= info
.entry
.atime
= info
.entry
.mtime
= CURRENT_TIME
;
759 info
.entry
.flags
= 0;
760 info
.entry
.nlink
= 1;
761 ret
= umsdos_newentry (dentry
->d_parent
, &info
);
765 /* lookup the short name dentry */
766 temp
= umsdos_covered(dentry
->d_parent
, info
.fake
.fname
, info
.fake
.len
);
771 /* Make sure the short name doesn't exist */
774 printk("umsdos_mkdir: short name %s/%s exists\n",
775 dentry
->d_parent
->d_name
.name
, info
.fake
.fname
);
776 goto out_remove_dput
;
779 ret
= msdos_mkdir (dir
, temp
, mode
);
781 goto out_remove_dput
;
784 * Lock the inode to protect the EMD creation ...
786 inode
= temp
->d_inode
;
789 atomic_inc(&inode
->i_count
);
790 d_instantiate(dentry
, inode
);
792 /* N.B. this should have an option to create the EMD ... */
793 umsdos_lookup_patch_new(dentry
, &info
);
796 * Create the EMD file, and set up the dir so it is
797 * promoted to EMD with the EMD file invisible.
799 * N.B. error return if EMD fails?
801 err
= umsdos_make_emd(dentry
);
802 umsdos_setup_dir(dentry
);
808 Printk(("umsdos_mkdir: %s/%s, ret=%d\n",
809 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
, ret
));
812 /* an error occurred ... remove EMD entry. */
816 umsdos_delentry (dentry
->d_parent
, &info
, 1);
821 * Add a new device special file into a directory.
823 * #Specification: Special files / strategy
824 * Device special file, pipes, etc ... are created like normal
825 * file in the msdos file system. Of course they remain empty.
827 * One strategy was to create those files only in the EMD file
828 * since they were not important for MSDOS. The problem with
829 * that, is that there were not getting inode number allocated.
830 * The MSDOS filesystems is playing a nice game to fake inode
831 * number, so why not use it.
833 * The absence of inode number compatible with those allocated
834 * for ordinary files was causing major trouble with hard link
835 * in particular and other parts of the kernel I guess.
837 int UMSDOS_mknod (struct inode
*dir
, struct dentry
*dentry
,
840 return umsdos_create_any (dir
, dentry
, mode
, rdev
, 0);
844 * Remove a sub-directory.
846 int UMSDOS_rmdir (struct inode
*dir
, struct dentry
*dentry
)
850 struct umsdos_info info
;
852 ret
= umsdos_nevercreat (dir
, dentry
, -EPERM
);
857 if (!d_unhashed(dentry
))
860 /* check whether the EMD is empty */
862 empty
= umsdos_isempty (dentry
);
864 /* Have to remove the EMD file? */
868 demd
= umsdos_get_emd_dentry(dentry
);
872 err
= msdos_unlink (dentry
->d_inode
, demd
);
873 Printk (("UMSDOS_rmdir: unlinking empty EMD err=%d", err
));
874 #ifdef UMSDOS_PARANOIA
876 printk("umsdos_rmdir: EMD %s/%s unlink failed, err=%d\n",
877 demd
->d_parent
->d_name
.name
, demd
->d_name
.name
, err
);
885 } else if (empty
== 2)
890 umsdos_parse (dentry
->d_name
.name
, dentry
->d_name
.len
, &info
);
891 /* Call findentry to complete the mangling */
892 umsdos_findentry (dentry
->d_parent
, &info
, 2);
893 temp
= umsdos_covered(dentry
->d_parent
, info
.fake
.fname
, info
.fake
.len
);
898 * Attempt to remove the msdos name.
900 ret
= msdos_rmdir (dir
, temp
);
901 if (ret
&& ret
!= -ENOENT
)
905 /* OK so far ... remove the name from the EMD */
906 ret
= umsdos_delentry (dentry
->d_parent
, &info
, 1);
907 #ifdef UMSDOS_PARANOIA
909 printk("umsdos_rmdir: delentry %s failed, ret=%d\n", info
.entry
.name
, ret
);
912 /* dput() temp if we didn't do it above */
917 Printk (("umsdos_rmdir %d\n", ret
));
923 * Remove a file from the directory.
925 * #Specification: hard link / deleting a link
926 * When we delete a file and this file is a link,
927 * we must subtract 1 from the nlink field of the
930 * If the count goes to 0, we delete this hidden
933 int UMSDOS_unlink (struct inode
*dir
, struct dentry
*dentry
)
935 struct dentry
*temp
, *link
= NULL
;
938 struct umsdos_info info
;
940 Printk(("UMSDOS_unlink: entering %s/%s\n",
941 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
));
943 ret
= umsdos_nevercreat (dir
, dentry
, -EPERM
);
947 ret
= umsdos_parse (dentry
->d_name
.name
, dentry
->d_name
.len
, &info
);
951 umsdos_lockcreate (dir
);
952 ret
= umsdos_findentry (dentry
->d_parent
, &info
, 1);
954 printk("UMSDOS_unlink: %s/%s not in EMD, ret=%d\n",
955 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
, ret
);
959 Printk (("UMSDOS_unlink %.*s ", info
.fake
.len
, info
.fake
.fname
));
962 * Note! If this is a hardlink and the names are aliased,
963 * the short-name lookup will return the hardlink dentry.
964 * In order to get the correct (real) inode, we just drop
965 * the original dentry.
967 if (info
.entry
.flags
& UMSDOS_HLINK
) {
971 /* Do a real lookup to get the short name dentry */
972 temp
= umsdos_covered(dentry
->d_parent
, info
.fake
.fname
, info
.fake
.len
);
978 * Resolve hardlinks now, but defer processing until later.
980 if (info
.entry
.flags
& UMSDOS_HLINK
) {
981 link
= umsdos_solve_hlink(dget(temp
));
984 /* Delete the EMD entry */
985 ret
= umsdos_delentry (dentry
->d_parent
, &info
, 0);
986 if (ret
&& ret
!= -ENOENT
) {
987 printk(KERN_WARNING
"UMSDOS_unlink: delentry %s, error=%d\n",
988 info
.entry
.name
, ret
);
992 ret
= msdos_unlink(dir
, temp
);
995 #ifdef UMSDOS_PARANOIA
997 printk("umsdos_unlink: %s/%s unlink failed, ret=%d\n",
998 temp
->d_parent
->d_name
.name
, temp
->d_name
.name
, ret
);
1001 /* dput() temp if we didn't do it above */
1006 umsdos_unlockcreate (dir
);
1009 * Now check for deferred handling of a hardlink.
1015 printk("umsdos_unlink: failed to resolve %s/%s\n",
1016 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
);
1018 ret
= PTR_ERR(link
);
1022 Printk(("umsdos_unlink: link %s/%s deferred, pending ret=%d\n",
1023 link
->d_parent
->d_name
.name
, link
->d_name
.name
, ret
));
1025 /* already have an error? */
1029 /* make sure the link exists ... */
1030 inode
= link
->d_inode
;
1032 printk(KERN_WARNING
"umsdos_unlink: hard link not found\n");
1037 * If this was the last linked reference, delete it now.
1039 * N.B. Deadlock problem? We should be holding the lock
1040 * for the hardlink's parent, but another process might
1041 * be holding that lock waiting for us to finish ...
1043 if (inode
->i_nlink
<= 1) {
1044 ret
= UMSDOS_unlink (link
->d_parent
->d_inode
, link
);
1047 "umsdos_unlink: link removal failed, ret=%d\n",
1052 struct iattr newattrs
;
1054 newattrs
.ia_valid
= 0;
1055 ret
= umsdos_notify_change_locked(link
, &newattrs
);
1057 mark_inode_dirty(link
->d_inode
);
1065 Printk (("umsdos_unlink %d\n", ret
));
1070 * Rename (move) a file.
1072 int UMSDOS_rename (struct inode
*old_dir
, struct dentry
*old_dentry
,
1073 struct inode
*new_dir
, struct dentry
*new_dentry
)
1077 ret
= umsdos_nevercreat (new_dir
, new_dentry
, -EEXIST
);
1082 * If the target already exists, delete it first.
1084 if (new_dentry
->d_inode
) {
1086 if (S_ISDIR(old_dentry
->d_inode
->i_mode
))
1087 ret
= UMSDOS_rmdir (new_dir
, new_dentry
);
1089 ret
= UMSDOS_unlink (new_dir
, new_dentry
);
1096 ret
= umsdos_rename_f(old_dir
, old_dentry
, new_dir
, new_dentry
, 0);