Linux-2.4.0-test2
[davej-history.git] / fs / umsdos / rdir.c
bloba477ade2cfc13ba25cc5a7698fb13c7f1487d71f
1 /*
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).
8 */
10 #include <linux/sched.h>
11 #include <linux/fs.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;
26 struct RDIR_FILLDIR {
27 void *dirbuf;
28 filldir_t filldir;
29 int real_root;
32 static int rdir_filldir ( void *buf,
33 const char *name,
34 int name_len,
35 off_t offset,
36 ino_t ino)
38 int ret = 0;
39 struct RDIR_FILLDIR *d = (struct RDIR_FILLDIR *) buf;
41 if (d->real_root) {
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);
53 } else {
54 /* Any DOS directory */
55 ret = d->filldir (d->dirbuf, name, name_len, offset, ino);
57 return ret;
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;
67 bufk.dirbuf = dirbuf;
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)
84 struct dentry *ret;
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
91 * /linux won't show
94 ret = ERR_PTR(-ENOENT);
95 goto out;
98 ret = msdos_lookup (dir, dentry);
99 if (ret) {
100 printk(KERN_WARNING
101 "umsdos_rlookup_x: %s/%s failed, ret=%ld\n",
102 dentry->d_parent->d_name.name, dentry->d_name.name,
103 PTR_ERR(ret));
104 goto out;
106 if (dentry->d_inode) {
107 /* We must install the proper function table
108 * depending on whether this is an MS-DOS or
109 * a UMSDOS directory
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);
116 out:
117 /* always install our dentry ops ... */
118 dentry->d_op = &umsdos_dentry_operations;
119 return ret;
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.
149 * EPERM is returned.
151 static int UMSDOS_rrmdir ( struct inode *dir, struct dentry *dentry)
153 int ret, empty;
155 ret = -EPERM;
156 if (umsdos_is_pseudodos (dir, dentry))
157 goto out;
159 ret = -EBUSY;
160 if (!d_unhashed(dentry))
161 goto out;
163 ret = msdos_rmdir (dir, dentry);
164 if (ret != -ENOTEMPTY)
165 goto out;
167 empty = umsdos_isempty (dentry);
168 if (empty == 1) {
169 struct dentry *demd;
170 /* We have to remove the EMD file. */
171 demd = umsdos_get_emd_dentry(dentry);
172 ret = PTR_ERR(demd);
173 if (!IS_ERR(demd)) {
174 ret = 0;
175 if (demd->d_inode)
176 ret = msdos_unlink (dentry->d_inode, demd);
177 if (!ret)
178 d_delete(demd);
179 dput(demd);
182 if (ret)
183 goto out;
185 /* now retry the original ... */
186 ret = msdos_rmdir (dir, dentry);
188 out:
189 return ret;
192 /* #Specification: dual mode / introduction
193 * One goal of UMSDOS is to allow a practical and simple coexistence
194 * between MS-DOS and Linux in a single partition. Using the EMD file
195 * in each directory, UMSDOS adds Unix semantics and capabilities to
196 * a normal DOS filesystem. To help and simplify coexistence, here is
197 * the logic related to the EMD file.
199 * If it is missing, then the directory is managed by the MS-DOS driver.
200 * The names are limited to DOS limits (8.3). No links, no device special
201 * and pipe and so on.
203 * If it is there, it is the directory. If it is there but empty, then
204 * the directory looks empty. The utility umssync allows synchronisation
205 * of the real DOS directory and the EMD.
207 * Whenever umssync is applied to a directory without EMD, one is
208 * created on the fly. The directory is promoted to full Unix semantics.
209 * Of course, the ls command will show exactly the same content as before
210 * the umssync session.
212 * It is believed that the user/admin will promote directories to Unix
213 * semantics as needed.
215 * The strategy to implement this is to use two function table (struct
216 * inode_operations). One for true UMSDOS directory and one for directory
217 * with missing EMD.
219 * Functions related to the DOS semantic (but aware of UMSDOS) generally
220 * have a "r" prefix (r for real) such as UMSDOS_rlookup, to differentiate
221 * from the one with full UMSDOS semantics.
223 struct file_operations umsdos_rdir_operations =
225 read: generic_read_dir,
226 readdir: UMSDOS_rreaddir,
227 ioctl: UMSDOS_ioctl_dir,
230 struct inode_operations umsdos_rdir_inode_operations =
232 create: msdos_create,
233 lookup: UMSDOS_rlookup,
234 unlink: msdos_unlink,
235 mkdir: msdos_mkdir,
236 rmdir: UMSDOS_rrmdir,
237 rename: msdos_rename,
238 setattr: UMSDOS_notify_change,