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/slab.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,
40 struct RDIR_FILLDIR *d = (struct RDIR_FILLDIR *) buf;
43 PRINTK ((KERN_DEBUG "rdir_filldir /mn/: real root!\n"));
44 /* real root of a pseudo_rooted partition */
45 if (name_len != UMSDOS_PSDROOT_LEN
46 || memcmp (name, UMSDOS_PSDROOT_NAME, UMSDOS_PSDROOT_LEN) != 0) {
47 /* So it is not the /linux directory */
48 if (name_len == 2 && name[0] == '.' && name[1] == '.') {
49 /* Make sure the .. entry points back to the pseudo_root */
50 ino = pseudo_root->i_ino;
52 ret = d->filldir (d->dirbuf, name, name_len, offset, ino, DT_UNKNOWN);
55 /* Any DOS directory */
56 ret = d->filldir (d->dirbuf, name, name_len, offset, ino, DT_UNKNOWN);
62 static int UMSDOS_rreaddir (struct file *filp, void *dirbuf, filldir_t filldir)
64 struct inode *dir = filp->f_dentry->d_inode;
65 struct RDIR_FILLDIR bufk;
67 bufk.filldir = filldir;
69 bufk.real_root = pseudo_root && (dir == saved_root->d_inode);
70 return fat_readdir (filp, &bufk, rdir_filldir);
75 * Lookup into a non promoted directory.
76 * If the result is a directory, make sure we find out if it is
77 * a promoted one or not (calling umsdos_setup_dir_inode(inode)).
79 /* #Specification: pseudo root / DOS/..
80 * In the real root directory (c:\), the directory ..
81 * is the pseudo root (c:\linux).
83 struct dentry *umsdos_rlookup_x ( struct inode *dir, struct dentry *dentry, int nopseudo)
87 if (saved_root && dir == saved_root->d_inode && !nopseudo &&
88 dentry->d_name.len == UMSDOS_PSDROOT_LEN &&
89 memcmp (dentry->d_name.name, UMSDOS_PSDROOT_NAME, UMSDOS_PSDROOT_LEN) == 0) {
90 /* #Specification: pseudo root / DOS/linux
91 * Even in the real root directory (c:\), the directory
95 ret = ERR_PTR(-ENOENT);
99 ret = msdos_lookup (dir, dentry);
102 "umsdos_rlookup_x: %s/%s failed, ret=%ld\n",
103 dentry->d_parent->d_name.name, dentry->d_name.name,
107 if (dentry->d_inode) {
108 /* We must install the proper function table
109 * depending on whether this is an MS-DOS or
112 Printk ((KERN_DEBUG "umsdos_rlookup_x: patch_dentry_inode %s/%s\n",
113 dentry->d_parent->d_name.name, dentry->d_name.name));
114 /* only patch if needed (because we get called even for lookup
115 (not only rlookup) stuff sometimes, like in umsdos_covered() */
116 if (dentry->d_inode->u.umsdos_i.i_patched == 0)
117 umsdos_patch_dentry_inode(dentry, 0);
121 /* always install our dentry ops ... */
122 dentry->d_op = &umsdos_dentry_operations;
127 struct dentry *UMSDOS_rlookup ( struct inode *dir, struct dentry *dentry)
129 return umsdos_rlookup_x (dir, dentry, 0);
133 /* #Specification: dual mode / rmdir in a DOS directory
134 * In a DOS (not EMD in it) directory, we use a reverse strategy
135 * compared with a UMSDOS directory. We assume that a subdirectory
136 * of a DOS directory is also a DOS directory. This is not always
137 * true (umssync may be used anywhere), but makes sense.
139 * So we call msdos_rmdir() directly. If it failed with a -ENOTEMPTY
140 * then we check if it is a Umsdos directory. We check if it is
141 * really empty (only . .. and --linux-.--- in it). If it is true
142 * we remove the EMD and do a msdos_rmdir() again.
144 * In a Umsdos directory, we assume all subdirectories are also
145 * Umsdos directories, so we check the EMD file first.
147 /* #Specification: pseudo root / rmdir /DOS
148 * The pseudo sub-directory /DOS can't be removed!
149 * This is done even if the pseudo root is not a Umsdos
150 * directory anymore (very unlikely), but an accident (under
151 * MS-DOS) is always possible.
155 static int UMSDOS_rrmdir ( struct inode *dir, struct dentry *dentry)
160 if (umsdos_is_pseudodos (dir, dentry))
164 if (!d_unhashed(dentry))
167 ret = msdos_rmdir (dir, dentry);
168 if (ret != -ENOTEMPTY)
171 empty = umsdos_isempty (dentry);
174 /* We have to remove the EMD file. */
175 demd = umsdos_get_emd_dentry(dentry);
180 ret = msdos_unlink (dentry->d_inode, demd);
189 /* now retry the original ... */
190 ret = msdos_rmdir (dir, dentry);
196 /* #Specification: dual mode / introduction
197 * One goal of UMSDOS is to allow a practical and simple coexistence
198 * between MS-DOS and Linux in a single partition. Using the EMD file
199 * in each directory, UMSDOS adds Unix semantics and capabilities to
200 * a normal DOS filesystem. To help and simplify coexistence, here is
201 * the logic related to the EMD file.
203 * If it is missing, then the directory is managed by the MS-DOS driver.
204 * The names are limited to DOS limits (8.3). No links, no device special
205 * and pipe and so on.
207 * If it is there, it is the directory. If it is there but empty, then
208 * the directory looks empty. The utility umssync allows synchronisation
209 * of the real DOS directory and the EMD.
211 * Whenever umssync is applied to a directory without EMD, one is
212 * created on the fly. The directory is promoted to full Unix semantics.
213 * Of course, the ls command will show exactly the same content as before
214 * the umssync session.
216 * It is believed that the user/admin will promote directories to Unix
217 * semantics as needed.
219 * The strategy to implement this is to use two function table (struct
220 * inode_operations). One for true UMSDOS directory and one for directory
223 * Functions related to the DOS semantic (but aware of UMSDOS) generally
224 * have a "r" prefix (r for real) such as UMSDOS_rlookup, to differentiate
225 * from the one with full UMSDOS semantics.
227 struct file_operations umsdos_rdir_operations =
229 read: generic_read_dir,
230 readdir: UMSDOS_rreaddir,
231 ioctl: UMSDOS_ioctl_dir,
234 struct inode_operations umsdos_rdir_inode_operations =
236 create: msdos_create,
237 lookup: UMSDOS_rlookup,
238 unlink: msdos_unlink,
240 rmdir: UMSDOS_rrmdir,
241 rename: msdos_rename,
242 setattr: UMSDOS_notify_change,