2 * linux/fs/umsdos/rdir.c
4 * Written 1994 by Jacques Gelinas
6 * Extended MS-DOS directory pure MS-DOS handling functions
7 * (For directory without EMD file).
10 #include <linux/sched.h>
12 #include <linux/msdos_fs.h>
13 #include <linux/errno.h>
14 #include <linux/stat.h>
15 #include <linux/limits.h>
16 #include <linux/umsdos_fs.h>
17 #include <linux/malloc.h>
19 #include <asm/uaccess.h>
22 extern struct dentry
*saved_root
;
23 extern struct inode
*pseudo_root
;
24 extern struct dentry_operations umsdos_dentry_operations
;
32 static int rdir_filldir ( void *buf
,
39 struct RDIR_FILLDIR
*d
= (struct RDIR_FILLDIR
*) buf
;
42 PRINTK ((KERN_DEBUG
"rdir_filldir /mn/: real root!\n"));
43 /* real root of a pseudo_rooted partition */
44 if (name_len
!= UMSDOS_PSDROOT_LEN
45 || memcmp (name
, UMSDOS_PSDROOT_NAME
, UMSDOS_PSDROOT_LEN
) != 0) {
46 /* So it is not the /linux directory */
47 if (name_len
== 2 && name
[0] == '.' && name
[1] == '.') {
48 /* Make sure the .. entry points back to the pseudo_root */
49 ino
= pseudo_root
->i_ino
;
51 ret
= d
->filldir (d
->dirbuf
, name
, name_len
, offset
, ino
);
54 /* Any DOS directory */
55 ret
= d
->filldir (d
->dirbuf
, name
, name_len
, offset
, ino
);
61 static int UMSDOS_rreaddir (struct file
*filp
, void *dirbuf
, filldir_t filldir
)
63 struct inode
*dir
= filp
->f_dentry
->d_inode
;
64 struct RDIR_FILLDIR bufk
;
66 bufk
.filldir
= filldir
;
68 bufk
.real_root
= pseudo_root
&& (dir
== saved_root
->d_inode
);
69 return fat_readdir (filp
, &bufk
, rdir_filldir
);
74 * Lookup into a non promoted directory.
75 * If the result is a directory, make sure we find out if it is
76 * a promoted one or not (calling umsdos_setup_dir_inode(inode)).
78 /* #Specification: pseudo root / DOS/..
79 * In the real root directory (c:\), the directory ..
80 * is the pseudo root (c:\linux).
82 struct dentry
*umsdos_rlookup_x ( struct inode
*dir
, struct dentry
*dentry
, int nopseudo
)
86 if (saved_root
&& dir
== saved_root
->d_inode
&& !nopseudo
&&
87 dentry
->d_name
.len
== UMSDOS_PSDROOT_LEN
&&
88 memcmp (dentry
->d_name
.name
, UMSDOS_PSDROOT_NAME
, UMSDOS_PSDROOT_LEN
) == 0) {
89 /* #Specification: pseudo root / DOS/linux
90 * Even in the real root directory (c:\), the directory
94 ret
= ERR_PTR(-ENOENT
);
98 ret
= msdos_lookup (dir
, dentry
);
101 "umsdos_rlookup_x: %s/%s failed, ret=%ld\n",
102 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
106 if (dentry
->d_inode
) {
107 /* We must install the proper function table
108 * depending on whether this is an MS-DOS or
111 Printk ((KERN_DEBUG
"umsdos_rlookup_x: patch_dentry_inode %s/%s\n",
112 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
));
113 umsdos_patch_dentry_inode(dentry
, 0);
117 /* always install our dentry ops ... */
118 dentry
->d_op
= &umsdos_dentry_operations
;
123 struct dentry
*UMSDOS_rlookup ( struct inode
*dir
, struct dentry
*dentry
)
125 return umsdos_rlookup_x (dir
, dentry
, 0);
129 /* #Specification: dual mode / rmdir in a DOS directory
130 * In a DOS (not EMD in it) directory, we use a reverse strategy
131 * compared with a UMSDOS directory. We assume that a subdirectory
132 * of a DOS directory is also a DOS directory. This is not always
133 * true (umssync may be used anywhere), but makes sense.
135 * So we call msdos_rmdir() directly. If it failed with a -ENOTEMPTY
136 * then we check if it is a Umsdos directory. We check if it is
137 * really empty (only . .. and --linux-.--- in it). If it is true
138 * we remove the EMD and do a msdos_rmdir() again.
140 * In a Umsdos directory, we assume all subdirectories are also
141 * Umsdos directories, so we check the EMD file first.
143 /* #Specification: pseudo root / rmdir /DOS
144 * The pseudo sub-directory /DOS can't be removed!
145 * This is done even if the pseudo root is not a Umsdos
146 * directory anymore (very unlikely), but an accident (under
147 * MS-DOS) is always possible.
151 static int UMSDOS_rrmdir ( struct inode
*dir
, struct dentry
*dentry
)
156 if (umsdos_is_pseudodos (dir
, dentry
))
160 if (!list_empty(&dentry
->d_hash
))
163 ret
= msdos_rmdir (dir
, dentry
);
164 if (ret
!= -ENOTEMPTY
)
167 empty
= umsdos_isempty (dentry
);
170 /* We have to remove the EMD file. */
171 demd
= umsdos_get_emd_dentry(dentry
);
176 ret
= msdos_unlink (dentry
->d_inode
, demd
);
183 /* now retry the original ... */
184 ret
= msdos_rmdir (dir
, dentry
);
190 /* #Specification: dual mode / introduction
191 * One goal of UMSDOS is to allow a practical and simple coexistence
192 * between MS-DOS and Linux in a single partition. Using the EMD file
193 * in each directory, UMSDOS adds Unix semantics and capabilities to
194 * a normal DOS filesystem. To help and simplify coexistence, here is
195 * the logic related to the EMD file.
197 * If it is missing, then the directory is managed by the MS-DOS driver.
198 * The names are limited to DOS limits (8.3). No links, no device special
199 * and pipe and so on.
201 * If it is there, it is the directory. If it is there but empty, then
202 * the directory looks empty. The utility umssync allows synchronisation
203 * of the real DOS directory and the EMD.
205 * Whenever umssync is applied to a directory without EMD, one is
206 * created on the fly. The directory is promoted to full Unix semantics.
207 * Of course, the ls command will show exactly the same content as before
208 * the umssync session.
210 * It is believed that the user/admin will promote directories to Unix
211 * semantics as needed.
213 * The strategy to implement this is to use two function table (struct
214 * inode_operations). One for true UMSDOS directory and one for directory
217 * Functions related to the DOS semantic (but aware of UMSDOS) generally
218 * have a "r" prefix (r for real) such as UMSDOS_rlookup, to differentiate
219 * from the one with full UMSDOS semantics.
221 struct file_operations umsdos_rdir_operations
=
223 read
: generic_read_dir
,
224 readdir
: UMSDOS_rreaddir
,
225 ioctl
: UMSDOS_ioctl_dir
,
228 struct inode_operations umsdos_rdir_inode_operations
=
230 create
: msdos_create
,
231 lookup
: UMSDOS_rlookup
,
232 unlink
: msdos_unlink
,
234 rmdir
: UMSDOS_rrmdir
,
235 rename
: msdos_rename
,
236 setattr
: UMSDOS_notify_change
,