Import 2.3.9pre7
[davej-history.git] / fs / umsdos / rdir.c
blobc7bb8fb1bd92c724118312f3d7515f4fd5092631
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 (!list_empty(&dentry->d_hash))
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 dput(demd);
180 if (ret)
181 goto out;
183 /* now retry the original ... */
184 ret = msdos_rmdir (dir, dentry);
186 out:
187 return ret;
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
215 * with missing EMD.
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 static struct file_operations umsdos_rdir_operations =
223 NULL, /* lseek - default */
224 dummy_dir_read, /* read */
225 NULL, /* write - bad */
226 UMSDOS_rreaddir, /* readdir */
227 NULL, /* poll - default */
228 UMSDOS_ioctl_dir, /* ioctl - default */
229 NULL, /* mmap */
230 NULL, /* no special open code */
231 NULL, /* flush */
232 NULL, /* no special release code */
233 NULL /* fsync */
236 struct inode_operations umsdos_rdir_inode_operations =
238 &umsdos_rdir_operations, /* default directory file-ops */
239 msdos_create, /* create */
240 UMSDOS_rlookup, /* lookup */
241 NULL, /* link */
242 msdos_unlink, /* unlink */
243 NULL, /* symlink */
244 msdos_mkdir, /* mkdir */
245 UMSDOS_rrmdir, /* rmdir */
246 NULL, /* mknod */
247 msdos_rename, /* rename */
248 NULL, /* readlink */
249 NULL, /* followlink */
250 NULL, /* readpage */
251 NULL, /* writepage */
252 NULL, /* get_block */
253 NULL, /* truncate */
254 NULL, /* permission */
255 NULL, /* smap */
256 NULL, /* revalidate */