xref: /openbmc/linux/fs/fat/namei_msdos.c (revision d3fe19852e96aabe3084c82ec2f3fb4918ab6d1e)
1990e194eSOGAWA Hirofumi /*
2990e194eSOGAWA Hirofumi  *  linux/fs/msdos/namei.c
3990e194eSOGAWA Hirofumi  *
4990e194eSOGAWA Hirofumi  *  Written 1992,1993 by Werner Almesberger
5990e194eSOGAWA Hirofumi  *  Hidden files 1995 by Albert Cahalan <albert@ccs.neu.edu> <adc@coe.neu.edu>
6990e194eSOGAWA Hirofumi  *  Rewritten for constant inumbers 1999 by Al Viro
7990e194eSOGAWA Hirofumi  */
8990e194eSOGAWA Hirofumi 
9990e194eSOGAWA Hirofumi #include <linux/module.h>
109e975daeSOGAWA Hirofumi #include "fat.h"
11990e194eSOGAWA Hirofumi 
12990e194eSOGAWA Hirofumi /* Characters that are undesirable in an MS-DOS file name */
13990e194eSOGAWA Hirofumi static unsigned char bad_chars[] = "*?<>|\"";
14990e194eSOGAWA Hirofumi static unsigned char bad_if_strict[] = "+=,; ";
15990e194eSOGAWA Hirofumi 
16990e194eSOGAWA Hirofumi /***** Formats an MS-DOS file name. Rejects invalid names. */
17990e194eSOGAWA Hirofumi static int msdos_format_name(const unsigned char *name, int len,
18990e194eSOGAWA Hirofumi 			     unsigned char *res, struct fat_mount_options *opts)
19990e194eSOGAWA Hirofumi 	/*
20990e194eSOGAWA Hirofumi 	 * name is the proposed name, len is its length, res is
21990e194eSOGAWA Hirofumi 	 * the resulting name, opts->name_check is either (r)elaxed,
22990e194eSOGAWA Hirofumi 	 * (n)ormal or (s)trict, opts->dotsOK allows dots at the
23990e194eSOGAWA Hirofumi 	 * beginning of name (for hidden files)
24990e194eSOGAWA Hirofumi 	 */
25990e194eSOGAWA Hirofumi {
26990e194eSOGAWA Hirofumi 	unsigned char *walk;
27990e194eSOGAWA Hirofumi 	unsigned char c;
28990e194eSOGAWA Hirofumi 	int space;
29990e194eSOGAWA Hirofumi 
30990e194eSOGAWA Hirofumi 	if (name[0] == '.') {	/* dotfile because . and .. already done */
31990e194eSOGAWA Hirofumi 		if (opts->dotsOK) {
32990e194eSOGAWA Hirofumi 			/* Get rid of dot - test for it elsewhere */
33990e194eSOGAWA Hirofumi 			name++;
34990e194eSOGAWA Hirofumi 			len--;
35990e194eSOGAWA Hirofumi 		} else
36990e194eSOGAWA Hirofumi 			return -EINVAL;
37990e194eSOGAWA Hirofumi 	}
38990e194eSOGAWA Hirofumi 	/*
39990e194eSOGAWA Hirofumi 	 * disallow names that _really_ start with a dot
40990e194eSOGAWA Hirofumi 	 */
41990e194eSOGAWA Hirofumi 	space = 1;
42990e194eSOGAWA Hirofumi 	c = 0;
43990e194eSOGAWA Hirofumi 	for (walk = res; len && walk - res < 8; walk++) {
44990e194eSOGAWA Hirofumi 		c = *name++;
45990e194eSOGAWA Hirofumi 		len--;
46990e194eSOGAWA Hirofumi 		if (opts->name_check != 'r' && strchr(bad_chars, c))
47990e194eSOGAWA Hirofumi 			return -EINVAL;
48990e194eSOGAWA Hirofumi 		if (opts->name_check == 's' && strchr(bad_if_strict, c))
49990e194eSOGAWA Hirofumi 			return -EINVAL;
50990e194eSOGAWA Hirofumi 		if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
51990e194eSOGAWA Hirofumi 			return -EINVAL;
52990e194eSOGAWA Hirofumi 		if (c < ' ' || c == ':' || c == '\\')
53990e194eSOGAWA Hirofumi 			return -EINVAL;
54990e194eSOGAWA Hirofumi 	/*
55990e194eSOGAWA Hirofumi 	 * 0xE5 is legal as a first character, but we must substitute
56990e194eSOGAWA Hirofumi 	 * 0x05 because 0xE5 marks deleted files.  Yes, DOS really
57990e194eSOGAWA Hirofumi 	 * does this.
58990e194eSOGAWA Hirofumi 	 * It seems that Microsoft hacked DOS to support non-US
59990e194eSOGAWA Hirofumi 	 * characters after the 0xE5 character was already in use to
60990e194eSOGAWA Hirofumi 	 * mark deleted files.
61990e194eSOGAWA Hirofumi 	 */
62990e194eSOGAWA Hirofumi 		if ((res == walk) && (c == 0xE5))
63990e194eSOGAWA Hirofumi 			c = 0x05;
64990e194eSOGAWA Hirofumi 		if (c == '.')
65990e194eSOGAWA Hirofumi 			break;
66990e194eSOGAWA Hirofumi 		space = (c == ' ');
67990e194eSOGAWA Hirofumi 		*walk = (!opts->nocase && c >= 'a' && c <= 'z') ? c - 32 : c;
68990e194eSOGAWA Hirofumi 	}
69990e194eSOGAWA Hirofumi 	if (space)
70990e194eSOGAWA Hirofumi 		return -EINVAL;
71990e194eSOGAWA Hirofumi 	if (opts->name_check == 's' && len && c != '.') {
72990e194eSOGAWA Hirofumi 		c = *name++;
73990e194eSOGAWA Hirofumi 		len--;
74990e194eSOGAWA Hirofumi 		if (c != '.')
75990e194eSOGAWA Hirofumi 			return -EINVAL;
76990e194eSOGAWA Hirofumi 	}
77990e194eSOGAWA Hirofumi 	while (c != '.' && len--)
78990e194eSOGAWA Hirofumi 		c = *name++;
79990e194eSOGAWA Hirofumi 	if (c == '.') {
80990e194eSOGAWA Hirofumi 		while (walk - res < 8)
81990e194eSOGAWA Hirofumi 			*walk++ = ' ';
82990e194eSOGAWA Hirofumi 		while (len > 0 && walk - res < MSDOS_NAME) {
83990e194eSOGAWA Hirofumi 			c = *name++;
84990e194eSOGAWA Hirofumi 			len--;
85990e194eSOGAWA Hirofumi 			if (opts->name_check != 'r' && strchr(bad_chars, c))
86990e194eSOGAWA Hirofumi 				return -EINVAL;
87990e194eSOGAWA Hirofumi 			if (opts->name_check == 's' &&
88990e194eSOGAWA Hirofumi 			    strchr(bad_if_strict, c))
89990e194eSOGAWA Hirofumi 				return -EINVAL;
90990e194eSOGAWA Hirofumi 			if (c < ' ' || c == ':' || c == '\\')
91990e194eSOGAWA Hirofumi 				return -EINVAL;
92990e194eSOGAWA Hirofumi 			if (c == '.') {
93990e194eSOGAWA Hirofumi 				if (opts->name_check == 's')
94990e194eSOGAWA Hirofumi 					return -EINVAL;
95990e194eSOGAWA Hirofumi 				break;
96990e194eSOGAWA Hirofumi 			}
97990e194eSOGAWA Hirofumi 			if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
98990e194eSOGAWA Hirofumi 				return -EINVAL;
99990e194eSOGAWA Hirofumi 			space = c == ' ';
100990e194eSOGAWA Hirofumi 			if (!opts->nocase && c >= 'a' && c <= 'z')
101990e194eSOGAWA Hirofumi 				*walk++ = c - 32;
102990e194eSOGAWA Hirofumi 			else
103990e194eSOGAWA Hirofumi 				*walk++ = c;
104990e194eSOGAWA Hirofumi 		}
105990e194eSOGAWA Hirofumi 		if (space)
106990e194eSOGAWA Hirofumi 			return -EINVAL;
107990e194eSOGAWA Hirofumi 		if (opts->name_check == 's' && len)
108990e194eSOGAWA Hirofumi 			return -EINVAL;
109990e194eSOGAWA Hirofumi 	}
110990e194eSOGAWA Hirofumi 	while (walk - res < MSDOS_NAME)
111990e194eSOGAWA Hirofumi 		*walk++ = ' ';
112990e194eSOGAWA Hirofumi 
113990e194eSOGAWA Hirofumi 	return 0;
114990e194eSOGAWA Hirofumi }
115990e194eSOGAWA Hirofumi 
116990e194eSOGAWA Hirofumi /***** Locates a directory entry.  Uses unformatted name. */
117990e194eSOGAWA Hirofumi static int msdos_find(struct inode *dir, const unsigned char *name, int len,
118990e194eSOGAWA Hirofumi 		      struct fat_slot_info *sinfo)
119990e194eSOGAWA Hirofumi {
120990e194eSOGAWA Hirofumi 	struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
121990e194eSOGAWA Hirofumi 	unsigned char msdos_name[MSDOS_NAME];
122990e194eSOGAWA Hirofumi 	int err;
123990e194eSOGAWA Hirofumi 
124990e194eSOGAWA Hirofumi 	err = msdos_format_name(name, len, msdos_name, &sbi->options);
125990e194eSOGAWA Hirofumi 	if (err)
126990e194eSOGAWA Hirofumi 		return -ENOENT;
127990e194eSOGAWA Hirofumi 
128990e194eSOGAWA Hirofumi 	err = fat_scan(dir, msdos_name, sinfo);
129990e194eSOGAWA Hirofumi 	if (!err && sbi->options.dotsOK) {
130990e194eSOGAWA Hirofumi 		if (name[0] == '.') {
131990e194eSOGAWA Hirofumi 			if (!(sinfo->de->attr & ATTR_HIDDEN))
132990e194eSOGAWA Hirofumi 				err = -ENOENT;
133990e194eSOGAWA Hirofumi 		} else {
134990e194eSOGAWA Hirofumi 			if (sinfo->de->attr & ATTR_HIDDEN)
135990e194eSOGAWA Hirofumi 				err = -ENOENT;
136990e194eSOGAWA Hirofumi 		}
137990e194eSOGAWA Hirofumi 		if (err)
138990e194eSOGAWA Hirofumi 			brelse(sinfo->bh);
139990e194eSOGAWA Hirofumi 	}
140990e194eSOGAWA Hirofumi 	return err;
141990e194eSOGAWA Hirofumi }
142990e194eSOGAWA Hirofumi 
143990e194eSOGAWA Hirofumi /*
144990e194eSOGAWA Hirofumi  * Compute the hash for the msdos name corresponding to the dentry.
145990e194eSOGAWA Hirofumi  * Note: if the name is invalid, we leave the hash code unchanged so
146990e194eSOGAWA Hirofumi  * that the existing dentry can be used. The msdos fs routines will
147990e194eSOGAWA Hirofumi  * return ENOENT or EINVAL as appropriate.
148990e194eSOGAWA Hirofumi  */
149da53be12SLinus Torvalds static int msdos_hash(const struct dentry *dentry, struct qstr *qstr)
150990e194eSOGAWA Hirofumi {
151990e194eSOGAWA Hirofumi 	struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
152990e194eSOGAWA Hirofumi 	unsigned char msdos_name[MSDOS_NAME];
153990e194eSOGAWA Hirofumi 	int error;
154990e194eSOGAWA Hirofumi 
155990e194eSOGAWA Hirofumi 	error = msdos_format_name(qstr->name, qstr->len, msdos_name, options);
156990e194eSOGAWA Hirofumi 	if (!error)
1578387ff25SLinus Torvalds 		qstr->hash = full_name_hash(dentry, msdos_name, MSDOS_NAME);
158990e194eSOGAWA Hirofumi 	return 0;
159990e194eSOGAWA Hirofumi }
160990e194eSOGAWA Hirofumi 
161990e194eSOGAWA Hirofumi /*
162990e194eSOGAWA Hirofumi  * Compare two msdos names. If either of the names are invalid,
163990e194eSOGAWA Hirofumi  * we fall back to doing the standard name comparison.
164990e194eSOGAWA Hirofumi  */
165da53be12SLinus Torvalds static int msdos_cmp(const struct dentry *parent, const struct dentry *dentry,
166621e155aSNick Piggin 		unsigned int len, const char *str, const struct qstr *name)
167990e194eSOGAWA Hirofumi {
168*d3fe1985SAl Viro 	struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
169990e194eSOGAWA Hirofumi 	unsigned char a_msdos_name[MSDOS_NAME], b_msdos_name[MSDOS_NAME];
170990e194eSOGAWA Hirofumi 	int error;
171990e194eSOGAWA Hirofumi 
172621e155aSNick Piggin 	error = msdos_format_name(name->name, name->len, a_msdos_name, options);
173990e194eSOGAWA Hirofumi 	if (error)
174990e194eSOGAWA Hirofumi 		goto old_compare;
175621e155aSNick Piggin 	error = msdos_format_name(str, len, b_msdos_name, options);
176990e194eSOGAWA Hirofumi 	if (error)
177990e194eSOGAWA Hirofumi 		goto old_compare;
178990e194eSOGAWA Hirofumi 	error = memcmp(a_msdos_name, b_msdos_name, MSDOS_NAME);
179990e194eSOGAWA Hirofumi out:
180990e194eSOGAWA Hirofumi 	return error;
181990e194eSOGAWA Hirofumi 
182990e194eSOGAWA Hirofumi old_compare:
183990e194eSOGAWA Hirofumi 	error = 1;
184621e155aSNick Piggin 	if (name->len == len)
185621e155aSNick Piggin 		error = memcmp(name->name, str, len);
186990e194eSOGAWA Hirofumi 	goto out;
187990e194eSOGAWA Hirofumi }
188990e194eSOGAWA Hirofumi 
189ce6cdc47SAl Viro static const struct dentry_operations msdos_dentry_operations = {
190990e194eSOGAWA Hirofumi 	.d_hash		= msdos_hash,
191990e194eSOGAWA Hirofumi 	.d_compare	= msdos_cmp,
192990e194eSOGAWA Hirofumi };
193990e194eSOGAWA Hirofumi 
194990e194eSOGAWA Hirofumi /*
195990e194eSOGAWA Hirofumi  * AV. Wrappers for FAT sb operations. Is it wise?
196990e194eSOGAWA Hirofumi  */
197990e194eSOGAWA Hirofumi 
198990e194eSOGAWA Hirofumi /***** Get inode using directory and name */
199990e194eSOGAWA Hirofumi static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
20000cd8dd3SAl Viro 				   unsigned int flags)
201990e194eSOGAWA Hirofumi {
202990e194eSOGAWA Hirofumi 	struct super_block *sb = dir->i_sb;
203990e194eSOGAWA Hirofumi 	struct fat_slot_info sinfo;
20445cfbe35SOGAWA Hirofumi 	struct inode *inode;
20545cfbe35SOGAWA Hirofumi 	int err;
206990e194eSOGAWA Hirofumi 
207e40b34c7SMarco Stornelli 	mutex_lock(&MSDOS_SB(sb)->s_lock);
20845cfbe35SOGAWA Hirofumi 	err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
209a9049376SAl Viro 	switch (err) {
210a9049376SAl Viro 	case -ENOENT:
21145cfbe35SOGAWA Hirofumi 		inode = NULL;
212a9049376SAl Viro 		break;
213a9049376SAl Viro 	case 0:
214990e194eSOGAWA Hirofumi 		inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
215990e194eSOGAWA Hirofumi 		brelse(sinfo.bh);
216a9049376SAl Viro 		break;
217a9049376SAl Viro 	default:
218a9049376SAl Viro 		inode = ERR_PTR(err);
219990e194eSOGAWA Hirofumi 	}
220e40b34c7SMarco Stornelli 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
2213d23985dSAl Viro 	return d_splice_alias(inode, dentry);
222990e194eSOGAWA Hirofumi }
223990e194eSOGAWA Hirofumi 
224990e194eSOGAWA Hirofumi /***** Creates a directory entry (name is already formatted). */
225990e194eSOGAWA Hirofumi static int msdos_add_entry(struct inode *dir, const unsigned char *name,
226990e194eSOGAWA Hirofumi 			   int is_dir, int is_hid, int cluster,
227990e194eSOGAWA Hirofumi 			   struct timespec *ts, struct fat_slot_info *sinfo)
228990e194eSOGAWA Hirofumi {
229990e194eSOGAWA Hirofumi 	struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
230990e194eSOGAWA Hirofumi 	struct msdos_dir_entry de;
231990e194eSOGAWA Hirofumi 	__le16 time, date;
232990e194eSOGAWA Hirofumi 	int err;
233990e194eSOGAWA Hirofumi 
234990e194eSOGAWA Hirofumi 	memcpy(de.name, name, MSDOS_NAME);
235990e194eSOGAWA Hirofumi 	de.attr = is_dir ? ATTR_DIR : ATTR_ARCH;
236990e194eSOGAWA Hirofumi 	if (is_hid)
237990e194eSOGAWA Hirofumi 		de.attr |= ATTR_HIDDEN;
238990e194eSOGAWA Hirofumi 	de.lcase = 0;
2397decd1cbSOGAWA Hirofumi 	fat_time_unix2fat(sbi, ts, &time, &date, NULL);
240990e194eSOGAWA Hirofumi 	de.cdate = de.adate = 0;
241990e194eSOGAWA Hirofumi 	de.ctime = 0;
242990e194eSOGAWA Hirofumi 	de.ctime_cs = 0;
243990e194eSOGAWA Hirofumi 	de.time = time;
244990e194eSOGAWA Hirofumi 	de.date = date;
245a943ed71SSteven J. Magnani 	fat_set_start(&de, cluster);
246990e194eSOGAWA Hirofumi 	de.size = 0;
247990e194eSOGAWA Hirofumi 
248990e194eSOGAWA Hirofumi 	err = fat_add_entries(dir, &de, 1, sinfo);
249990e194eSOGAWA Hirofumi 	if (err)
250990e194eSOGAWA Hirofumi 		return err;
251990e194eSOGAWA Hirofumi 
252990e194eSOGAWA Hirofumi 	dir->i_ctime = dir->i_mtime = *ts;
253990e194eSOGAWA Hirofumi 	if (IS_DIRSYNC(dir))
254990e194eSOGAWA Hirofumi 		(void)fat_sync_inode(dir);
255990e194eSOGAWA Hirofumi 	else
256990e194eSOGAWA Hirofumi 		mark_inode_dirty(dir);
257990e194eSOGAWA Hirofumi 
258990e194eSOGAWA Hirofumi 	return 0;
259990e194eSOGAWA Hirofumi }
260990e194eSOGAWA Hirofumi 
261990e194eSOGAWA Hirofumi /***** Create a file */
2624acdaf27SAl Viro static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode,
263ebfc3b49SAl Viro 			bool excl)
264990e194eSOGAWA Hirofumi {
265990e194eSOGAWA Hirofumi 	struct super_block *sb = dir->i_sb;
266990e194eSOGAWA Hirofumi 	struct inode *inode = NULL;
267990e194eSOGAWA Hirofumi 	struct fat_slot_info sinfo;
268990e194eSOGAWA Hirofumi 	struct timespec ts;
269990e194eSOGAWA Hirofumi 	unsigned char msdos_name[MSDOS_NAME];
270990e194eSOGAWA Hirofumi 	int err, is_hid;
271990e194eSOGAWA Hirofumi 
272e40b34c7SMarco Stornelli 	mutex_lock(&MSDOS_SB(sb)->s_lock);
273990e194eSOGAWA Hirofumi 
274990e194eSOGAWA Hirofumi 	err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
275990e194eSOGAWA Hirofumi 				msdos_name, &MSDOS_SB(sb)->options);
276990e194eSOGAWA Hirofumi 	if (err)
277990e194eSOGAWA Hirofumi 		goto out;
278990e194eSOGAWA Hirofumi 	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
279990e194eSOGAWA Hirofumi 	/* Have to do it due to foo vs. .foo conflicts */
280990e194eSOGAWA Hirofumi 	if (!fat_scan(dir, msdos_name, &sinfo)) {
281990e194eSOGAWA Hirofumi 		brelse(sinfo.bh);
282990e194eSOGAWA Hirofumi 		err = -EINVAL;
283990e194eSOGAWA Hirofumi 		goto out;
284990e194eSOGAWA Hirofumi 	}
285990e194eSOGAWA Hirofumi 
286990e194eSOGAWA Hirofumi 	ts = CURRENT_TIME_SEC;
287990e194eSOGAWA Hirofumi 	err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
288990e194eSOGAWA Hirofumi 	if (err)
289990e194eSOGAWA Hirofumi 		goto out;
290990e194eSOGAWA Hirofumi 	inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
291990e194eSOGAWA Hirofumi 	brelse(sinfo.bh);
292990e194eSOGAWA Hirofumi 	if (IS_ERR(inode)) {
293990e194eSOGAWA Hirofumi 		err = PTR_ERR(inode);
294990e194eSOGAWA Hirofumi 		goto out;
295990e194eSOGAWA Hirofumi 	}
296990e194eSOGAWA Hirofumi 	inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
297990e194eSOGAWA Hirofumi 	/* timestamp is already written, so mark_inode_dirty() is unneeded. */
298990e194eSOGAWA Hirofumi 
299990e194eSOGAWA Hirofumi 	d_instantiate(dentry, inode);
300990e194eSOGAWA Hirofumi out:
301e40b34c7SMarco Stornelli 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
302990e194eSOGAWA Hirofumi 	if (!err)
303990e194eSOGAWA Hirofumi 		err = fat_flush_inodes(sb, dir, inode);
304990e194eSOGAWA Hirofumi 	return err;
305990e194eSOGAWA Hirofumi }
306990e194eSOGAWA Hirofumi 
307990e194eSOGAWA Hirofumi /***** Remove a directory */
308990e194eSOGAWA Hirofumi static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
309990e194eSOGAWA Hirofumi {
310990e194eSOGAWA Hirofumi 	struct super_block *sb = dir->i_sb;
3112b0143b5SDavid Howells 	struct inode *inode = d_inode(dentry);
312990e194eSOGAWA Hirofumi 	struct fat_slot_info sinfo;
313990e194eSOGAWA Hirofumi 	int err;
314990e194eSOGAWA Hirofumi 
315e40b34c7SMarco Stornelli 	mutex_lock(&MSDOS_SB(sb)->s_lock);
316990e194eSOGAWA Hirofumi 	/*
317990e194eSOGAWA Hirofumi 	 * Check whether the directory is not in use, then check
318990e194eSOGAWA Hirofumi 	 * whether it is empty.
319990e194eSOGAWA Hirofumi 	 */
320990e194eSOGAWA Hirofumi 	err = fat_dir_empty(inode);
321990e194eSOGAWA Hirofumi 	if (err)
322990e194eSOGAWA Hirofumi 		goto out;
323990e194eSOGAWA Hirofumi 	err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
324990e194eSOGAWA Hirofumi 	if (err)
325990e194eSOGAWA Hirofumi 		goto out;
326990e194eSOGAWA Hirofumi 
327990e194eSOGAWA Hirofumi 	err = fat_remove_entries(dir, &sinfo);	/* and releases bh */
328990e194eSOGAWA Hirofumi 	if (err)
329990e194eSOGAWA Hirofumi 		goto out;
330990e194eSOGAWA Hirofumi 	drop_nlink(dir);
331990e194eSOGAWA Hirofumi 
332990e194eSOGAWA Hirofumi 	clear_nlink(inode);
333990e194eSOGAWA Hirofumi 	inode->i_ctime = CURRENT_TIME_SEC;
334990e194eSOGAWA Hirofumi 	fat_detach(inode);
335990e194eSOGAWA Hirofumi out:
336e40b34c7SMarco Stornelli 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
337990e194eSOGAWA Hirofumi 	if (!err)
338990e194eSOGAWA Hirofumi 		err = fat_flush_inodes(sb, dir, inode);
339990e194eSOGAWA Hirofumi 
340990e194eSOGAWA Hirofumi 	return err;
341990e194eSOGAWA Hirofumi }
342990e194eSOGAWA Hirofumi 
343990e194eSOGAWA Hirofumi /***** Make a directory */
34418bb1db3SAl Viro static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
345990e194eSOGAWA Hirofumi {
346990e194eSOGAWA Hirofumi 	struct super_block *sb = dir->i_sb;
347990e194eSOGAWA Hirofumi 	struct fat_slot_info sinfo;
348990e194eSOGAWA Hirofumi 	struct inode *inode;
349990e194eSOGAWA Hirofumi 	unsigned char msdos_name[MSDOS_NAME];
350990e194eSOGAWA Hirofumi 	struct timespec ts;
351990e194eSOGAWA Hirofumi 	int err, is_hid, cluster;
352990e194eSOGAWA Hirofumi 
353e40b34c7SMarco Stornelli 	mutex_lock(&MSDOS_SB(sb)->s_lock);
354990e194eSOGAWA Hirofumi 
355990e194eSOGAWA Hirofumi 	err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
356990e194eSOGAWA Hirofumi 				msdos_name, &MSDOS_SB(sb)->options);
357990e194eSOGAWA Hirofumi 	if (err)
358990e194eSOGAWA Hirofumi 		goto out;
359990e194eSOGAWA Hirofumi 	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
360990e194eSOGAWA Hirofumi 	/* foo vs .foo situation */
361990e194eSOGAWA Hirofumi 	if (!fat_scan(dir, msdos_name, &sinfo)) {
362990e194eSOGAWA Hirofumi 		brelse(sinfo.bh);
363990e194eSOGAWA Hirofumi 		err = -EINVAL;
364990e194eSOGAWA Hirofumi 		goto out;
365990e194eSOGAWA Hirofumi 	}
366990e194eSOGAWA Hirofumi 
367990e194eSOGAWA Hirofumi 	ts = CURRENT_TIME_SEC;
368990e194eSOGAWA Hirofumi 	cluster = fat_alloc_new_dir(dir, &ts);
369990e194eSOGAWA Hirofumi 	if (cluster < 0) {
370990e194eSOGAWA Hirofumi 		err = cluster;
371990e194eSOGAWA Hirofumi 		goto out;
372990e194eSOGAWA Hirofumi 	}
373990e194eSOGAWA Hirofumi 	err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
374990e194eSOGAWA Hirofumi 	if (err)
375990e194eSOGAWA Hirofumi 		goto out_free;
376990e194eSOGAWA Hirofumi 	inc_nlink(dir);
377990e194eSOGAWA Hirofumi 
378990e194eSOGAWA Hirofumi 	inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
379990e194eSOGAWA Hirofumi 	brelse(sinfo.bh);
380990e194eSOGAWA Hirofumi 	if (IS_ERR(inode)) {
381990e194eSOGAWA Hirofumi 		err = PTR_ERR(inode);
382990e194eSOGAWA Hirofumi 		/* the directory was completed, just return a error */
383990e194eSOGAWA Hirofumi 		goto out;
384990e194eSOGAWA Hirofumi 	}
385bfe86848SMiklos Szeredi 	set_nlink(inode, 2);
386990e194eSOGAWA Hirofumi 	inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
387990e194eSOGAWA Hirofumi 	/* timestamp is already written, so mark_inode_dirty() is unneeded. */
388990e194eSOGAWA Hirofumi 
389990e194eSOGAWA Hirofumi 	d_instantiate(dentry, inode);
390990e194eSOGAWA Hirofumi 
391e40b34c7SMarco Stornelli 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
392990e194eSOGAWA Hirofumi 	fat_flush_inodes(sb, dir, inode);
393990e194eSOGAWA Hirofumi 	return 0;
394990e194eSOGAWA Hirofumi 
395990e194eSOGAWA Hirofumi out_free:
396990e194eSOGAWA Hirofumi 	fat_free_clusters(dir, cluster);
397990e194eSOGAWA Hirofumi out:
398e40b34c7SMarco Stornelli 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
399990e194eSOGAWA Hirofumi 	return err;
400990e194eSOGAWA Hirofumi }
401990e194eSOGAWA Hirofumi 
402990e194eSOGAWA Hirofumi /***** Unlink a file */
403990e194eSOGAWA Hirofumi static int msdos_unlink(struct inode *dir, struct dentry *dentry)
404990e194eSOGAWA Hirofumi {
4052b0143b5SDavid Howells 	struct inode *inode = d_inode(dentry);
406990e194eSOGAWA Hirofumi 	struct super_block *sb = inode->i_sb;
407990e194eSOGAWA Hirofumi 	struct fat_slot_info sinfo;
408990e194eSOGAWA Hirofumi 	int err;
409990e194eSOGAWA Hirofumi 
410e40b34c7SMarco Stornelli 	mutex_lock(&MSDOS_SB(sb)->s_lock);
411990e194eSOGAWA Hirofumi 	err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
412990e194eSOGAWA Hirofumi 	if (err)
413990e194eSOGAWA Hirofumi 		goto out;
414990e194eSOGAWA Hirofumi 
415990e194eSOGAWA Hirofumi 	err = fat_remove_entries(dir, &sinfo);	/* and releases bh */
416990e194eSOGAWA Hirofumi 	if (err)
417990e194eSOGAWA Hirofumi 		goto out;
418990e194eSOGAWA Hirofumi 	clear_nlink(inode);
419990e194eSOGAWA Hirofumi 	inode->i_ctime = CURRENT_TIME_SEC;
420990e194eSOGAWA Hirofumi 	fat_detach(inode);
421990e194eSOGAWA Hirofumi out:
422e40b34c7SMarco Stornelli 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
423990e194eSOGAWA Hirofumi 	if (!err)
424990e194eSOGAWA Hirofumi 		err = fat_flush_inodes(sb, dir, inode);
425990e194eSOGAWA Hirofumi 
426990e194eSOGAWA Hirofumi 	return err;
427990e194eSOGAWA Hirofumi }
428990e194eSOGAWA Hirofumi 
429990e194eSOGAWA Hirofumi static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
430990e194eSOGAWA Hirofumi 			   struct dentry *old_dentry,
431990e194eSOGAWA Hirofumi 			   struct inode *new_dir, unsigned char *new_name,
432990e194eSOGAWA Hirofumi 			   struct dentry *new_dentry, int is_hid)
433990e194eSOGAWA Hirofumi {
434990e194eSOGAWA Hirofumi 	struct buffer_head *dotdot_bh;
435990e194eSOGAWA Hirofumi 	struct msdos_dir_entry *dotdot_de;
436990e194eSOGAWA Hirofumi 	struct inode *old_inode, *new_inode;
437990e194eSOGAWA Hirofumi 	struct fat_slot_info old_sinfo, sinfo;
438990e194eSOGAWA Hirofumi 	struct timespec ts;
4397669e8fbSSteven J. Magnani 	loff_t new_i_pos;
440990e194eSOGAWA Hirofumi 	int err, old_attrs, is_dir, update_dotdot, corrupt = 0;
441990e194eSOGAWA Hirofumi 
442990e194eSOGAWA Hirofumi 	old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
4432b0143b5SDavid Howells 	old_inode = d_inode(old_dentry);
4442b0143b5SDavid Howells 	new_inode = d_inode(new_dentry);
445990e194eSOGAWA Hirofumi 
446990e194eSOGAWA Hirofumi 	err = fat_scan(old_dir, old_name, &old_sinfo);
447990e194eSOGAWA Hirofumi 	if (err) {
448990e194eSOGAWA Hirofumi 		err = -EIO;
449990e194eSOGAWA Hirofumi 		goto out;
450990e194eSOGAWA Hirofumi 	}
451990e194eSOGAWA Hirofumi 
452990e194eSOGAWA Hirofumi 	is_dir = S_ISDIR(old_inode->i_mode);
453990e194eSOGAWA Hirofumi 	update_dotdot = (is_dir && old_dir != new_dir);
454990e194eSOGAWA Hirofumi 	if (update_dotdot) {
4557669e8fbSSteven J. Magnani 		if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) {
456990e194eSOGAWA Hirofumi 			err = -EIO;
457990e194eSOGAWA Hirofumi 			goto out;
458990e194eSOGAWA Hirofumi 		}
459990e194eSOGAWA Hirofumi 	}
460990e194eSOGAWA Hirofumi 
461990e194eSOGAWA Hirofumi 	old_attrs = MSDOS_I(old_inode)->i_attrs;
462990e194eSOGAWA Hirofumi 	err = fat_scan(new_dir, new_name, &sinfo);
463990e194eSOGAWA Hirofumi 	if (!err) {
464990e194eSOGAWA Hirofumi 		if (!new_inode) {
465990e194eSOGAWA Hirofumi 			/* "foo" -> ".foo" case. just change the ATTR_HIDDEN */
466990e194eSOGAWA Hirofumi 			if (sinfo.de != old_sinfo.de) {
467990e194eSOGAWA Hirofumi 				err = -EINVAL;
468990e194eSOGAWA Hirofumi 				goto out;
469990e194eSOGAWA Hirofumi 			}
470990e194eSOGAWA Hirofumi 			if (is_hid)
471990e194eSOGAWA Hirofumi 				MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
472990e194eSOGAWA Hirofumi 			else
473990e194eSOGAWA Hirofumi 				MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
474990e194eSOGAWA Hirofumi 			if (IS_DIRSYNC(old_dir)) {
475990e194eSOGAWA Hirofumi 				err = fat_sync_inode(old_inode);
476990e194eSOGAWA Hirofumi 				if (err) {
477990e194eSOGAWA Hirofumi 					MSDOS_I(old_inode)->i_attrs = old_attrs;
478990e194eSOGAWA Hirofumi 					goto out;
479990e194eSOGAWA Hirofumi 				}
480990e194eSOGAWA Hirofumi 			} else
481990e194eSOGAWA Hirofumi 				mark_inode_dirty(old_inode);
482990e194eSOGAWA Hirofumi 
483990e194eSOGAWA Hirofumi 			old_dir->i_version++;
484990e194eSOGAWA Hirofumi 			old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
485990e194eSOGAWA Hirofumi 			if (IS_DIRSYNC(old_dir))
486990e194eSOGAWA Hirofumi 				(void)fat_sync_inode(old_dir);
487990e194eSOGAWA Hirofumi 			else
488990e194eSOGAWA Hirofumi 				mark_inode_dirty(old_dir);
489990e194eSOGAWA Hirofumi 			goto out;
490990e194eSOGAWA Hirofumi 		}
491990e194eSOGAWA Hirofumi 	}
492990e194eSOGAWA Hirofumi 
493990e194eSOGAWA Hirofumi 	ts = CURRENT_TIME_SEC;
494990e194eSOGAWA Hirofumi 	if (new_inode) {
495990e194eSOGAWA Hirofumi 		if (err)
496990e194eSOGAWA Hirofumi 			goto out;
497990e194eSOGAWA Hirofumi 		if (is_dir) {
498990e194eSOGAWA Hirofumi 			err = fat_dir_empty(new_inode);
499990e194eSOGAWA Hirofumi 			if (err)
500990e194eSOGAWA Hirofumi 				goto out;
501990e194eSOGAWA Hirofumi 		}
502990e194eSOGAWA Hirofumi 		new_i_pos = MSDOS_I(new_inode)->i_pos;
503990e194eSOGAWA Hirofumi 		fat_detach(new_inode);
504990e194eSOGAWA Hirofumi 	} else {
505990e194eSOGAWA Hirofumi 		err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0,
506990e194eSOGAWA Hirofumi 				      &ts, &sinfo);
507990e194eSOGAWA Hirofumi 		if (err)
508990e194eSOGAWA Hirofumi 			goto out;
509990e194eSOGAWA Hirofumi 		new_i_pos = sinfo.i_pos;
510990e194eSOGAWA Hirofumi 	}
511990e194eSOGAWA Hirofumi 	new_dir->i_version++;
512990e194eSOGAWA Hirofumi 
513990e194eSOGAWA Hirofumi 	fat_detach(old_inode);
514990e194eSOGAWA Hirofumi 	fat_attach(old_inode, new_i_pos);
515990e194eSOGAWA Hirofumi 	if (is_hid)
516990e194eSOGAWA Hirofumi 		MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
517990e194eSOGAWA Hirofumi 	else
518990e194eSOGAWA Hirofumi 		MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
519990e194eSOGAWA Hirofumi 	if (IS_DIRSYNC(new_dir)) {
520990e194eSOGAWA Hirofumi 		err = fat_sync_inode(old_inode);
521990e194eSOGAWA Hirofumi 		if (err)
522990e194eSOGAWA Hirofumi 			goto error_inode;
523990e194eSOGAWA Hirofumi 	} else
524990e194eSOGAWA Hirofumi 		mark_inode_dirty(old_inode);
525990e194eSOGAWA Hirofumi 
526990e194eSOGAWA Hirofumi 	if (update_dotdot) {
527a943ed71SSteven J. Magnani 		fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
528b522412aSAl Viro 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
529990e194eSOGAWA Hirofumi 		if (IS_DIRSYNC(new_dir)) {
530990e194eSOGAWA Hirofumi 			err = sync_dirty_buffer(dotdot_bh);
531990e194eSOGAWA Hirofumi 			if (err)
532990e194eSOGAWA Hirofumi 				goto error_dotdot;
533990e194eSOGAWA Hirofumi 		}
534990e194eSOGAWA Hirofumi 		drop_nlink(old_dir);
535990e194eSOGAWA Hirofumi 		if (!new_inode)
536990e194eSOGAWA Hirofumi 			inc_nlink(new_dir);
537990e194eSOGAWA Hirofumi 	}
538990e194eSOGAWA Hirofumi 
539990e194eSOGAWA Hirofumi 	err = fat_remove_entries(old_dir, &old_sinfo);	/* and releases bh */
540990e194eSOGAWA Hirofumi 	old_sinfo.bh = NULL;
541990e194eSOGAWA Hirofumi 	if (err)
542990e194eSOGAWA Hirofumi 		goto error_dotdot;
543990e194eSOGAWA Hirofumi 	old_dir->i_version++;
544990e194eSOGAWA Hirofumi 	old_dir->i_ctime = old_dir->i_mtime = ts;
545990e194eSOGAWA Hirofumi 	if (IS_DIRSYNC(old_dir))
546990e194eSOGAWA Hirofumi 		(void)fat_sync_inode(old_dir);
547990e194eSOGAWA Hirofumi 	else
548990e194eSOGAWA Hirofumi 		mark_inode_dirty(old_dir);
549990e194eSOGAWA Hirofumi 
550990e194eSOGAWA Hirofumi 	if (new_inode) {
551990e194eSOGAWA Hirofumi 		drop_nlink(new_inode);
552990e194eSOGAWA Hirofumi 		if (is_dir)
553990e194eSOGAWA Hirofumi 			drop_nlink(new_inode);
554990e194eSOGAWA Hirofumi 		new_inode->i_ctime = ts;
555990e194eSOGAWA Hirofumi 	}
556990e194eSOGAWA Hirofumi out:
557990e194eSOGAWA Hirofumi 	brelse(sinfo.bh);
558990e194eSOGAWA Hirofumi 	brelse(dotdot_bh);
559990e194eSOGAWA Hirofumi 	brelse(old_sinfo.bh);
560990e194eSOGAWA Hirofumi 	return err;
561990e194eSOGAWA Hirofumi 
562990e194eSOGAWA Hirofumi error_dotdot:
563990e194eSOGAWA Hirofumi 	/* data cluster is shared, serious corruption */
564990e194eSOGAWA Hirofumi 	corrupt = 1;
565990e194eSOGAWA Hirofumi 
566990e194eSOGAWA Hirofumi 	if (update_dotdot) {
567a943ed71SSteven J. Magnani 		fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
568b522412aSAl Viro 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
569990e194eSOGAWA Hirofumi 		corrupt |= sync_dirty_buffer(dotdot_bh);
570990e194eSOGAWA Hirofumi 	}
571990e194eSOGAWA Hirofumi error_inode:
572990e194eSOGAWA Hirofumi 	fat_detach(old_inode);
573990e194eSOGAWA Hirofumi 	fat_attach(old_inode, old_sinfo.i_pos);
574990e194eSOGAWA Hirofumi 	MSDOS_I(old_inode)->i_attrs = old_attrs;
575990e194eSOGAWA Hirofumi 	if (new_inode) {
576990e194eSOGAWA Hirofumi 		fat_attach(new_inode, new_i_pos);
577990e194eSOGAWA Hirofumi 		if (corrupt)
578990e194eSOGAWA Hirofumi 			corrupt |= fat_sync_inode(new_inode);
579990e194eSOGAWA Hirofumi 	} else {
580990e194eSOGAWA Hirofumi 		/*
581990e194eSOGAWA Hirofumi 		 * If new entry was not sharing the data cluster, it
582990e194eSOGAWA Hirofumi 		 * shouldn't be serious corruption.
583990e194eSOGAWA Hirofumi 		 */
584990e194eSOGAWA Hirofumi 		int err2 = fat_remove_entries(new_dir, &sinfo);
585990e194eSOGAWA Hirofumi 		if (corrupt)
586990e194eSOGAWA Hirofumi 			corrupt |= err2;
587990e194eSOGAWA Hirofumi 		sinfo.bh = NULL;
588990e194eSOGAWA Hirofumi 	}
589990e194eSOGAWA Hirofumi 	if (corrupt < 0) {
59085c78591SDenis Karpov 		fat_fs_error(new_dir->i_sb,
591990e194eSOGAWA Hirofumi 			     "%s: Filesystem corrupted (i_pos %lld)",
592990e194eSOGAWA Hirofumi 			     __func__, sinfo.i_pos);
593990e194eSOGAWA Hirofumi 	}
594990e194eSOGAWA Hirofumi 	goto out;
595990e194eSOGAWA Hirofumi }
596990e194eSOGAWA Hirofumi 
597990e194eSOGAWA Hirofumi /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
598990e194eSOGAWA Hirofumi static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
599990e194eSOGAWA Hirofumi 			struct inode *new_dir, struct dentry *new_dentry)
600990e194eSOGAWA Hirofumi {
601990e194eSOGAWA Hirofumi 	struct super_block *sb = old_dir->i_sb;
602990e194eSOGAWA Hirofumi 	unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
603990e194eSOGAWA Hirofumi 	int err, is_hid;
604990e194eSOGAWA Hirofumi 
605e40b34c7SMarco Stornelli 	mutex_lock(&MSDOS_SB(sb)->s_lock);
606990e194eSOGAWA Hirofumi 
607990e194eSOGAWA Hirofumi 	err = msdos_format_name(old_dentry->d_name.name,
608990e194eSOGAWA Hirofumi 				old_dentry->d_name.len, old_msdos_name,
609990e194eSOGAWA Hirofumi 				&MSDOS_SB(old_dir->i_sb)->options);
610990e194eSOGAWA Hirofumi 	if (err)
611990e194eSOGAWA Hirofumi 		goto out;
612990e194eSOGAWA Hirofumi 	err = msdos_format_name(new_dentry->d_name.name,
613990e194eSOGAWA Hirofumi 				new_dentry->d_name.len, new_msdos_name,
614990e194eSOGAWA Hirofumi 				&MSDOS_SB(new_dir->i_sb)->options);
615990e194eSOGAWA Hirofumi 	if (err)
616990e194eSOGAWA Hirofumi 		goto out;
617990e194eSOGAWA Hirofumi 
618990e194eSOGAWA Hirofumi 	is_hid =
619990e194eSOGAWA Hirofumi 	     (new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.');
620990e194eSOGAWA Hirofumi 
621990e194eSOGAWA Hirofumi 	err = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
622990e194eSOGAWA Hirofumi 			      new_dir, new_msdos_name, new_dentry, is_hid);
623990e194eSOGAWA Hirofumi out:
624e40b34c7SMarco Stornelli 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
625990e194eSOGAWA Hirofumi 	if (!err)
626990e194eSOGAWA Hirofumi 		err = fat_flush_inodes(sb, old_dir, new_dir);
627990e194eSOGAWA Hirofumi 	return err;
628990e194eSOGAWA Hirofumi }
629990e194eSOGAWA Hirofumi 
630990e194eSOGAWA Hirofumi static const struct inode_operations msdos_dir_inode_operations = {
631990e194eSOGAWA Hirofumi 	.create		= msdos_create,
632990e194eSOGAWA Hirofumi 	.lookup		= msdos_lookup,
633990e194eSOGAWA Hirofumi 	.unlink		= msdos_unlink,
634990e194eSOGAWA Hirofumi 	.mkdir		= msdos_mkdir,
635990e194eSOGAWA Hirofumi 	.rmdir		= msdos_rmdir,
636990e194eSOGAWA Hirofumi 	.rename		= msdos_rename,
637990e194eSOGAWA Hirofumi 	.setattr	= fat_setattr,
638990e194eSOGAWA Hirofumi 	.getattr	= fat_getattr,
639990e194eSOGAWA Hirofumi };
640990e194eSOGAWA Hirofumi 
6413d23985dSAl Viro static void setup(struct super_block *sb)
642990e194eSOGAWA Hirofumi {
643384f5c96SOGAWA Hirofumi 	MSDOS_SB(sb)->dir_ops = &msdos_dir_inode_operations;
6443d23985dSAl Viro 	sb->s_d_op = &msdos_dentry_operations;
6453d23985dSAl Viro 	sb->s_flags |= MS_NOATIME;
646db719222SJan Blunck }
647990e194eSOGAWA Hirofumi 
6483d23985dSAl Viro static int msdos_fill_super(struct super_block *sb, void *data, int silent)
6493d23985dSAl Viro {
650384f5c96SOGAWA Hirofumi 	return fat_fill_super(sb, data, silent, 0, setup);
651990e194eSOGAWA Hirofumi }
652990e194eSOGAWA Hirofumi 
653152a0836SAl Viro static struct dentry *msdos_mount(struct file_system_type *fs_type,
654990e194eSOGAWA Hirofumi 			int flags, const char *dev_name,
655152a0836SAl Viro 			void *data)
656990e194eSOGAWA Hirofumi {
657152a0836SAl Viro 	return mount_bdev(fs_type, flags, dev_name, data, msdos_fill_super);
658990e194eSOGAWA Hirofumi }
659990e194eSOGAWA Hirofumi 
660990e194eSOGAWA Hirofumi static struct file_system_type msdos_fs_type = {
661990e194eSOGAWA Hirofumi 	.owner		= THIS_MODULE,
662990e194eSOGAWA Hirofumi 	.name		= "msdos",
663152a0836SAl Viro 	.mount		= msdos_mount,
664990e194eSOGAWA Hirofumi 	.kill_sb	= kill_block_super,
665990e194eSOGAWA Hirofumi 	.fs_flags	= FS_REQUIRES_DEV,
666990e194eSOGAWA Hirofumi };
6677f78e035SEric W. Biederman MODULE_ALIAS_FS("msdos");
668990e194eSOGAWA Hirofumi 
669990e194eSOGAWA Hirofumi static int __init init_msdos_fs(void)
670990e194eSOGAWA Hirofumi {
671990e194eSOGAWA Hirofumi 	return register_filesystem(&msdos_fs_type);
672990e194eSOGAWA Hirofumi }
673990e194eSOGAWA Hirofumi 
674990e194eSOGAWA Hirofumi static void __exit exit_msdos_fs(void)
675990e194eSOGAWA Hirofumi {
676990e194eSOGAWA Hirofumi 	unregister_filesystem(&msdos_fs_type);
677990e194eSOGAWA Hirofumi }
678990e194eSOGAWA Hirofumi 
679990e194eSOGAWA Hirofumi MODULE_LICENSE("GPL");
680990e194eSOGAWA Hirofumi MODULE_AUTHOR("Werner Almesberger");
681990e194eSOGAWA Hirofumi MODULE_DESCRIPTION("MS-DOS filesystem support");
682990e194eSOGAWA Hirofumi 
683990e194eSOGAWA Hirofumi module_init(init_msdos_fs)
684990e194eSOGAWA Hirofumi module_exit(exit_msdos_fs)
685