Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/msdos/namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Written 1992,1993 by Werner Almesberger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Hidden files 1995 by Albert Cahalan <albert@ccs.neu.edu> <adc@coe.neu.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Rewritten for constant inumbers 1999 by Al Viro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "fat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /* Characters that are undesirable in an MS-DOS file name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static unsigned char bad_chars[] = "*?<>|\"";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static unsigned char bad_if_strict[] = "+=,; ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /***** Formats an MS-DOS file name. Rejects invalid names. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static int msdos_format_name(const unsigned char *name, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 			     unsigned char *res, struct fat_mount_options *opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	 * name is the proposed name, len is its length, res is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	 * the resulting name, opts->name_check is either (r)elaxed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	 * (n)ormal or (s)trict, opts->dotsOK allows dots at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	 * beginning of name (for hidden files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	unsigned char *walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	unsigned char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (name[0] == '.') {	/* dotfile because . and .. already done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		if (opts->dotsOK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			/* Get rid of dot - test for it elsewhere */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	 * disallow names that _really_ start with a dot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	space = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	for (walk = res; len && walk - res < 8; walk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		c = *name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		if (opts->name_check != 'r' && strchr(bad_chars, c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		if (opts->name_check == 's' && strchr(bad_if_strict, c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		if (c < ' ' || c == ':' || c == '\\')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * 0xE5 is legal as a first character, but we must substitute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * 0x05 because 0xE5 marks deleted files.  Yes, DOS really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 * does this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * It seems that Microsoft hacked DOS to support non-US
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 * characters after the 0xE5 character was already in use to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * mark deleted files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		if ((res == walk) && (c == 0xE5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			c = 0x05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		if (c == '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		space = (c == ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		*walk = (!opts->nocase && c >= 'a' && c <= 'z') ? c - 32 : c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (opts->name_check == 's' && len && c != '.') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		c = *name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (c != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	while (c != '.' && len--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		c = *name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (c == '.') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		while (walk - res < 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			*walk++ = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		while (len > 0 && walk - res < MSDOS_NAME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			c = *name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			if (opts->name_check != 'r' && strchr(bad_chars, c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			if (opts->name_check == 's' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			    strchr(bad_if_strict, c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			if (c < ' ' || c == ':' || c == '\\')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			if (c == '.') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				if (opts->name_check == 's')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 					return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			space = c == ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			if (!opts->nocase && c >= 'a' && c <= 'z')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				*walk++ = c - 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				*walk++ = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		if (space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (opts->name_check == 's' && len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	while (walk - res < MSDOS_NAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		*walk++ = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /***** Locates a directory entry.  Uses unformatted name. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int msdos_find(struct inode *dir, const unsigned char *name, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		      struct fat_slot_info *sinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	unsigned char msdos_name[MSDOS_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	err = msdos_format_name(name, len, msdos_name, &sbi->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	err = fat_scan(dir, msdos_name, sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!err && sbi->options.dotsOK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (name[0] == '.') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			if (!(sinfo->de->attr & ATTR_HIDDEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			if (sinfo->de->attr & ATTR_HIDDEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			brelse(sinfo->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * Compute the hash for the msdos name corresponding to the dentry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * Note: if the name is invalid, we leave the hash code unchanged so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * that the existing dentry can be used. The msdos fs routines will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * return ENOENT or EINVAL as appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int msdos_hash(const struct dentry *dentry, struct qstr *qstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	unsigned char msdos_name[MSDOS_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	error = msdos_format_name(qstr->name, qstr->len, msdos_name, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		qstr->hash = full_name_hash(dentry, msdos_name, MSDOS_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * Compare two msdos names. If either of the names are invalid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * we fall back to doing the standard name comparison.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int msdos_cmp(const struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		unsigned int len, const char *str, const struct qstr *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	unsigned char a_msdos_name[MSDOS_NAME], b_msdos_name[MSDOS_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	error = msdos_format_name(name->name, name->len, a_msdos_name, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		goto old_compare;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	error = msdos_format_name(str, len, b_msdos_name, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		goto old_compare;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	error = memcmp(a_msdos_name, b_msdos_name, MSDOS_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) old_compare:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (name->len == len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		error = memcmp(name->name, str, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static const struct dentry_operations msdos_dentry_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.d_hash		= msdos_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	.d_compare	= msdos_cmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * AV. Wrappers for FAT sb operations. Is it wise?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /***** Get inode using directory and name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				   unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct fat_slot_info sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	mutex_lock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	switch (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		brelse(sinfo.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		inode = ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /***** Creates a directory entry (name is already formatted). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int msdos_add_entry(struct inode *dir, const unsigned char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			   int is_dir, int is_hid, int cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			   struct timespec64 *ts, struct fat_slot_info *sinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct msdos_dir_entry de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	__le16 time, date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	memcpy(de.name, name, MSDOS_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	de.attr = is_dir ? ATTR_DIR : ATTR_ARCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (is_hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		de.attr |= ATTR_HIDDEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	de.lcase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	fat_time_unix2fat(sbi, ts, &time, &date, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	de.cdate = de.adate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	de.ctime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	de.ctime_cs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	de.time = time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	de.date = date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	fat_set_start(&de, cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	de.size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	err = fat_add_entries(dir, &de, 1, sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	fat_truncate_time(dir, ts, S_CTIME|S_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		(void)fat_sync_inode(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /***** Create a file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct fat_slot_info sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	unsigned char msdos_name[MSDOS_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	int err, is_hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	mutex_lock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				msdos_name, &MSDOS_SB(sb)->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* Have to do it due to foo vs. .foo conflicts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (!fat_scan(dir, msdos_name, &sinfo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		brelse(sinfo.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	ts = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	brelse(sinfo.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	/* timestamp is already written, so mark_inode_dirty() is unneeded. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		err = fat_flush_inodes(sb, dir, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /***** Remove a directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct fat_slot_info sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	mutex_lock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	err = fat_dir_empty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	err = fat_remove_entries(dir, &sinfo);	/* and releases bh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	drop_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	fat_truncate_time(inode, NULL, S_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	fat_detach(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		err = fat_flush_inodes(sb, dir, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /***** Make a directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct fat_slot_info sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	unsigned char msdos_name[MSDOS_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	int err, is_hid, cluster;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	mutex_lock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				msdos_name, &MSDOS_SB(sb)->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	/* foo vs .foo situation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (!fat_scan(dir, msdos_name, &sinfo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		brelse(sinfo.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	ts = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	cluster = fat_alloc_new_dir(dir, &ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (cluster < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		err = cluster;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	inc_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	brelse(sinfo.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		/* the directory was completed, just return a error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	set_nlink(inode, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/* timestamp is already written, so mark_inode_dirty() is unneeded. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	fat_flush_inodes(sb, dir, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	fat_free_clusters(dir, cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /***** Unlink a file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static int msdos_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct fat_slot_info sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	mutex_lock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	err = fat_remove_entries(dir, &sinfo);	/* and releases bh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	fat_truncate_time(inode, NULL, S_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	fat_detach(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		err = fat_flush_inodes(sb, dir, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			   struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			   struct inode *new_dir, unsigned char *new_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			   struct dentry *new_dentry, int is_hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	struct buffer_head *dotdot_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct msdos_dir_entry *dotdot_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	struct inode *old_inode, *new_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	struct fat_slot_info old_sinfo, sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	loff_t new_i_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	int err, old_attrs, is_dir, update_dotdot, corrupt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	old_inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	new_inode = d_inode(new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	err = fat_scan(old_dir, old_name, &old_sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	is_dir = S_ISDIR(old_inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	update_dotdot = (is_dir && old_dir != new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (update_dotdot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	old_attrs = MSDOS_I(old_inode)->i_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	err = fat_scan(new_dir, new_name, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		if (!new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			/* "foo" -> ".foo" case. just change the ATTR_HIDDEN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			if (sinfo.de != old_sinfo.de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 				err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 			if (is_hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 				MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 				MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			if (IS_DIRSYNC(old_dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 				err = fat_sync_inode(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 					MSDOS_I(old_inode)->i_attrs = old_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 					goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 				mark_inode_dirty(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			inode_inc_iversion(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			fat_truncate_time(old_dir, NULL, S_CTIME|S_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			if (IS_DIRSYNC(old_dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 				(void)fat_sync_inode(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 				mark_inode_dirty(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	ts = current_time(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		if (is_dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			err = fat_dir_empty(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		new_i_pos = MSDOS_I(new_inode)->i_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		fat_detach(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 				      &ts, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		new_i_pos = sinfo.i_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	inode_inc_iversion(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	fat_detach(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	fat_attach(old_inode, new_i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	if (is_hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (IS_DIRSYNC(new_dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		err = fat_sync_inode(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			goto error_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		mark_inode_dirty(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	if (update_dotdot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		if (IS_DIRSYNC(new_dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			err = sync_dirty_buffer(dotdot_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 				goto error_dotdot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		drop_nlink(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		if (!new_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			inc_nlink(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	err = fat_remove_entries(old_dir, &old_sinfo);	/* and releases bh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	old_sinfo.bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		goto error_dotdot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	inode_inc_iversion(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	fat_truncate_time(old_dir, &ts, S_CTIME|S_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (IS_DIRSYNC(old_dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		(void)fat_sync_inode(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		mark_inode_dirty(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		drop_nlink(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		if (is_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 			drop_nlink(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		fat_truncate_time(new_inode, &ts, S_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	brelse(sinfo.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	brelse(dotdot_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	brelse(old_sinfo.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) error_dotdot:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	/* data cluster is shared, serious corruption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	corrupt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	if (update_dotdot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		corrupt |= sync_dirty_buffer(dotdot_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) error_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	fat_detach(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	fat_attach(old_inode, old_sinfo.i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	MSDOS_I(old_inode)->i_attrs = old_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		fat_attach(new_inode, new_i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		if (corrupt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 			corrupt |= fat_sync_inode(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		 * If new entry was not sharing the data cluster, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		 * shouldn't be serious corruption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		int err2 = fat_remove_entries(new_dir, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		if (corrupt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 			corrupt |= err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		sinfo.bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	if (corrupt < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		fat_fs_error(new_dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 			     "%s: Filesystem corrupted (i_pos %lld)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 			     __func__, sinfo.i_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 			struct inode *new_dir, struct dentry *new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 			unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	struct super_block *sb = old_dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	int err, is_hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (flags & ~RENAME_NOREPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	mutex_lock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	err = msdos_format_name(old_dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 				old_dentry->d_name.len, old_msdos_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 				&MSDOS_SB(old_dir->i_sb)->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	err = msdos_format_name(new_dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 				new_dentry->d_name.len, new_msdos_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 				&MSDOS_SB(new_dir->i_sb)->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	is_hid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	     (new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	err = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 			      new_dir, new_msdos_name, new_dentry, is_hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	mutex_unlock(&MSDOS_SB(sb)->s_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		err = fat_flush_inodes(sb, old_dir, new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) static const struct inode_operations msdos_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	.create		= msdos_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	.lookup		= msdos_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	.unlink		= msdos_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	.mkdir		= msdos_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	.rmdir		= msdos_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	.rename		= msdos_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	.setattr	= fat_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	.getattr	= fat_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	.update_time	= fat_update_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static void setup(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	MSDOS_SB(sb)->dir_ops = &msdos_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	sb->s_d_op = &msdos_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	sb->s_flags |= SB_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static int msdos_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	return fat_fill_super(sb, data, silent, 0, setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static struct dentry *msdos_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 			int flags, const char *dev_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 			void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	return mount_bdev(fs_type, flags, dev_name, data, msdos_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static struct file_system_type msdos_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	.name		= "msdos",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	.mount		= msdos_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	.kill_sb	= kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) MODULE_ALIAS_FS("msdos");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static int __init init_msdos_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	return register_filesystem(&msdos_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static void __exit exit_msdos_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	unregister_filesystem(&msdos_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) MODULE_AUTHOR("Werner Almesberger");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) MODULE_DESCRIPTION("MS-DOS filesystem support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) module_init(init_msdos_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) module_exit(exit_msdos_fs)