2019-05-19 12:08:20 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* linux/fs/vfat/namei.c
|
|
|
|
*
|
|
|
|
* Written 1992,1993 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* Windows95/Windows NT compatible extended MSDOS filesystem
|
|
|
|
* by Gordon Chaffee Copyright (C) 1995. Send bug reports for the
|
|
|
|
* VFAT filesystem to <chaffee@cs.berkeley.edu>. Specify
|
|
|
|
* what file operation caused you trouble and if you can duplicate
|
|
|
|
* the problem, send a script that demonstrates it.
|
|
|
|
*
|
|
|
|
* Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de>
|
|
|
|
*
|
|
|
|
* Support Multibyte characters and cleanup by
|
|
|
|
* OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/namei.h>
|
2017-09-08 23:16:50 +00:00
|
|
|
#include <linux/kernel.h>
|
2017-12-11 11:35:09 +00:00
|
|
|
#include <linux/iversion.h>
|
2008-11-06 20:53:46 +00:00
|
|
|
#include "fat.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-09-16 10:44:21 +00:00
|
|
|
static inline unsigned long vfat_d_version(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return (unsigned long) dentry->d_fsdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void vfat_d_version_set(struct dentry *dentry,
|
|
|
|
unsigned long version)
|
|
|
|
{
|
|
|
|
dentry->d_fsdata = (void *) version;
|
|
|
|
}
|
|
|
|
|
2008-11-06 20:53:51 +00:00
|
|
|
/*
|
|
|
|
* If new entry was created in the parent, it could create the 8.3
|
|
|
|
* alias (the shortname of logname). So, the parent may have the
|
|
|
|
* negative-dentry which matches the created 8.3 alias.
|
|
|
|
*
|
|
|
|
* If it happened, the negative dentry isn't actually negative
|
|
|
|
* anymore. So, drop it.
|
|
|
|
*/
|
|
|
|
static int vfat_revalidate_shortname(struct dentry *dentry)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret = 1;
|
2008-11-06 20:53:51 +00:00
|
|
|
spin_lock(&dentry->d_lock);
|
2018-02-01 13:15:25 +00:00
|
|
|
if (!inode_eq_iversion(d_inode(dentry->d_parent), vfat_d_version(dentry)))
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = 0;
|
2008-11-06 20:53:51 +00:00
|
|
|
spin_unlock(&dentry->d_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-10 20:03:43 +00:00
|
|
|
static int vfat_revalidate(struct dentry *dentry, unsigned int flags)
|
2008-11-06 20:53:51 +00:00
|
|
|
{
|
2012-06-10 20:03:43 +00:00
|
|
|
if (flags & LOOKUP_RCU)
|
2011-01-07 06:49:57 +00:00
|
|
|
return -ECHILD;
|
|
|
|
|
2008-11-06 20:53:51 +00:00
|
|
|
/* This is not negative dentry. Always valid. */
|
2015-03-17 22:25:59 +00:00
|
|
|
if (d_really_is_positive(dentry))
|
2008-11-06 20:53:51 +00:00
|
|
|
return 1;
|
|
|
|
return vfat_revalidate_shortname(dentry);
|
|
|
|
}
|
|
|
|
|
2012-06-10 20:03:43 +00:00
|
|
|
static int vfat_revalidate_ci(struct dentry *dentry, unsigned int flags)
|
2008-11-06 20:53:51 +00:00
|
|
|
{
|
2012-06-10 20:03:43 +00:00
|
|
|
if (flags & LOOKUP_RCU)
|
2011-01-07 06:49:57 +00:00
|
|
|
return -ECHILD;
|
|
|
|
|
2008-11-06 20:53:51 +00:00
|
|
|
/*
|
|
|
|
* This is not negative dentry. Always valid.
|
|
|
|
*
|
|
|
|
* Note, rename() to existing directory entry will have ->d_inode,
|
|
|
|
* and will use existing name which isn't specified name by user.
|
|
|
|
*
|
|
|
|
* We may be able to drop this positive dentry here. But dropping
|
|
|
|
* positive dentry isn't good idea. So it's unsupported like
|
|
|
|
* rename("filename", "FILENAME") for now.
|
|
|
|
*/
|
2015-03-17 22:25:59 +00:00
|
|
|
if (d_really_is_positive(dentry))
|
2008-11-06 20:53:51 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This may be nfsd (or something), anyway, we can't see the
|
|
|
|
* intent of this. So, since this can be for creation, drop it.
|
|
|
|
*/
|
2012-06-10 20:03:43 +00:00
|
|
|
if (!flags)
|
2008-11-06 20:53:51 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drop the negative dentry, in order to make sure to use the
|
|
|
|
* case sensitive name which is specified by user if this is
|
|
|
|
* for creation.
|
|
|
|
*/
|
2012-06-10 20:03:43 +00:00
|
|
|
if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
|
2011-06-26 01:37:18 +00:00
|
|
|
return 0;
|
2008-11-06 20:53:51 +00:00
|
|
|
|
|
|
|
return vfat_revalidate_shortname(dentry);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* returns the length of a struct qstr, ignoring trailing dots */
|
2011-01-07 06:49:27 +00:00
|
|
|
static unsigned int __vfat_striptail_len(unsigned int len, const char *name)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-01-07 06:49:27 +00:00
|
|
|
while (len && name[len - 1] == '.')
|
2005-04-16 22:20:36 +00:00
|
|
|
len--;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-01-07 06:49:27 +00:00
|
|
|
static unsigned int vfat_striptail_len(const struct qstr *qstr)
|
|
|
|
{
|
|
|
|
return __vfat_striptail_len(qstr->len, qstr->name);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Compute the hash for the vfat name corresponding to the dentry.
|
|
|
|
* Note: if the name is invalid, we leave the hash code unchanged so
|
|
|
|
* that the existing dentry can be used. The vfat fs routines will
|
|
|
|
* return ENOENT or EINVAL as appropriate.
|
|
|
|
*/
|
2013-05-21 22:22:44 +00:00
|
|
|
static int vfat_hash(const struct dentry *dentry, struct qstr *qstr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-06-10 14:51:30 +00:00
|
|
|
qstr->hash = full_name_hash(dentry, qstr->name, vfat_striptail_len(qstr));
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the hash for the vfat name corresponding to the dentry.
|
|
|
|
* Note: if the name is invalid, we leave the hash code unchanged so
|
|
|
|
* that the existing dentry can be used. The vfat fs routines will
|
|
|
|
* return ENOENT or EINVAL as appropriate.
|
|
|
|
*/
|
2013-05-21 22:22:44 +00:00
|
|
|
static int vfat_hashi(const struct dentry *dentry, struct qstr *qstr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-01-07 06:49:28 +00:00
|
|
|
struct nls_table *t = MSDOS_SB(dentry->d_sb)->nls_io;
|
2005-04-16 22:20:36 +00:00
|
|
|
const unsigned char *name;
|
|
|
|
unsigned int len;
|
|
|
|
unsigned long hash;
|
|
|
|
|
|
|
|
name = qstr->name;
|
|
|
|
len = vfat_striptail_len(qstr);
|
|
|
|
|
2016-06-10 14:51:30 +00:00
|
|
|
hash = init_name_hash(dentry);
|
2005-04-16 22:20:36 +00:00
|
|
|
while (len--)
|
|
|
|
hash = partial_name_hash(nls_tolower(t, *name++), hash);
|
|
|
|
qstr->hash = end_name_hash(hash);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Case insensitive compare of two vfat names.
|
|
|
|
*/
|
2016-07-31 20:37:25 +00:00
|
|
|
static int vfat_cmpi(const struct dentry *dentry,
|
2011-01-07 06:49:27 +00:00
|
|
|
unsigned int len, const char *str, const struct qstr *name)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-07-29 22:23:59 +00:00
|
|
|
struct nls_table *t = MSDOS_SB(dentry->d_sb)->nls_io;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int alen, blen;
|
|
|
|
|
|
|
|
/* A filename cannot end in '.' or we treat it like it has none */
|
2011-01-07 06:49:27 +00:00
|
|
|
alen = vfat_striptail_len(name);
|
|
|
|
blen = __vfat_striptail_len(len, str);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (alen == blen) {
|
2011-01-07 06:49:27 +00:00
|
|
|
if (nls_strnicmp(t, name->name, str, alen) == 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Case sensitive compare of two vfat names.
|
|
|
|
*/
|
2016-07-31 20:37:25 +00:00
|
|
|
static int vfat_cmp(const struct dentry *dentry,
|
2011-01-07 06:49:27 +00:00
|
|
|
unsigned int len, const char *str, const struct qstr *name)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned int alen, blen;
|
|
|
|
|
|
|
|
/* A filename cannot end in '.' or we treat it like it has none */
|
2011-01-07 06:49:27 +00:00
|
|
|
alen = vfat_striptail_len(name);
|
|
|
|
blen = __vfat_striptail_len(len, str);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (alen == blen) {
|
2011-01-07 06:49:27 +00:00
|
|
|
if (strncmp(name->name, str, alen) == 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-20 05:59:46 +00:00
|
|
|
static const struct dentry_operations vfat_ci_dentry_ops = {
|
2008-11-06 20:53:51 +00:00
|
|
|
.d_revalidate = vfat_revalidate_ci,
|
|
|
|
.d_hash = vfat_hashi,
|
|
|
|
.d_compare = vfat_cmpi,
|
|
|
|
};
|
|
|
|
|
2009-02-20 05:59:46 +00:00
|
|
|
static const struct dentry_operations vfat_dentry_ops = {
|
2008-11-06 20:53:51 +00:00
|
|
|
.d_revalidate = vfat_revalidate,
|
|
|
|
.d_hash = vfat_hash,
|
|
|
|
.d_compare = vfat_cmp,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Characters that are undesirable in an MS-DOS file name */
|
|
|
|
|
2022-12-26 14:25:12 +00:00
|
|
|
static inline bool vfat_bad_char(wchar_t w)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
return (w < 0x0020)
|
|
|
|
|| (w == '*') || (w == '?') || (w == '<') || (w == '>')
|
|
|
|
|| (w == '|') || (w == '"') || (w == ':') || (w == '/')
|
|
|
|
|| (w == '\\');
|
|
|
|
}
|
|
|
|
|
2022-12-26 14:25:12 +00:00
|
|
|
static inline bool vfat_replace_char(wchar_t w)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
return (w == '[') || (w == ']') || (w == ';') || (w == ',')
|
|
|
|
|| (w == '+') || (w == '=');
|
|
|
|
}
|
|
|
|
|
|
|
|
static wchar_t vfat_skip_char(wchar_t w)
|
|
|
|
{
|
|
|
|
return (w == '.') || (w == ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int vfat_is_used_badchars(const wchar_t *s, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
if (vfat_bad_char(s[i]))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-04-28 09:16:29 +00:00
|
|
|
if (s[i - 1] == ' ') /* last character cannot be space */
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
2008-04-28 09:16:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_find_form(struct inode *dir, unsigned char *name)
|
|
|
|
{
|
|
|
|
struct fat_slot_info sinfo;
|
|
|
|
int err = fat_scan(dir, name, &sinfo);
|
|
|
|
if (err)
|
|
|
|
return -ENOENT;
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1) Valid characters for the 8.3 format alias are any combination of
|
|
|
|
* letters, uppercase alphabets, digits, any of the
|
|
|
|
* following special characters:
|
|
|
|
* $ % ' ` - @ { } ~ ! # ( ) & _ ^
|
|
|
|
* In this case Longfilename is not stored in disk.
|
|
|
|
*
|
|
|
|
* WinNT's Extension:
|
|
|
|
* File name and extension name is contain uppercase/lowercase
|
|
|
|
* only. And it is expressed by CASE_LOWER_BASE and CASE_LOWER_EXT.
|
|
|
|
*
|
|
|
|
* 2) File name is 8.3 format, but it contain the uppercase and
|
|
|
|
* lowercase char, muliti bytes char, etc. In this case numtail is not
|
|
|
|
* added, but Longfilename is stored.
|
|
|
|
*
|
|
|
|
* 3) When the one except for the above, or the following special
|
|
|
|
* character are contained:
|
|
|
|
* . [ ] ; , + =
|
|
|
|
* numtail is added, and Longfilename must be stored in disk .
|
|
|
|
*/
|
|
|
|
struct shortname_info {
|
|
|
|
unsigned char lower:1,
|
|
|
|
upper:1,
|
|
|
|
valid:1;
|
|
|
|
};
|
|
|
|
#define INIT_SHORTNAME_INFO(x) do { \
|
|
|
|
(x)->lower = 1; \
|
|
|
|
(x)->upper = 1; \
|
|
|
|
(x)->valid = 1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static inline int to_shortname_char(struct nls_table *nls,
|
|
|
|
unsigned char *buf, int buf_size,
|
|
|
|
wchar_t *src, struct shortname_info *info)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (vfat_skip_char(*src)) {
|
|
|
|
info->valid = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (vfat_replace_char(*src)) {
|
|
|
|
info->valid = 0;
|
|
|
|
buf[0] = '_';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = nls->uni2char(*src, buf, buf_size);
|
|
|
|
if (len <= 0) {
|
|
|
|
info->valid = 0;
|
|
|
|
buf[0] = '_';
|
|
|
|
len = 1;
|
|
|
|
} else if (len == 1) {
|
|
|
|
unsigned char prev = buf[0];
|
|
|
|
|
|
|
|
if (buf[0] >= 0x7F) {
|
|
|
|
info->lower = 0;
|
|
|
|
info->upper = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = nls_toupper(nls, buf[0]);
|
|
|
|
if (isalpha(buf[0])) {
|
|
|
|
if (buf[0] == prev)
|
|
|
|
info->lower = 0;
|
|
|
|
else
|
|
|
|
info->upper = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info->lower = 0;
|
|
|
|
info->upper = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a valid longname, create a unique shortname. Make sure the
|
|
|
|
* shortname does not exist
|
|
|
|
* Returns negative number on error, 0 for a normal
|
|
|
|
* return, and 1 for valid shortname
|
|
|
|
*/
|
|
|
|
static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
|
|
|
|
wchar_t *uname, int ulen,
|
|
|
|
unsigned char *name_res, unsigned char *lcase)
|
|
|
|
{
|
|
|
|
struct fat_mount_options *opts = &MSDOS_SB(dir->i_sb)->options;
|
|
|
|
wchar_t *ip, *ext_start, *end, *name_start;
|
2010-03-31 17:21:10 +00:00
|
|
|
unsigned char base[9], ext[4], buf[5], *p;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char charbuf[NLS_MAX_CHARSET_SIZE];
|
|
|
|
int chl, chi;
|
|
|
|
int sz = 0, extlen, baselen, i, numtail_baselen, numtail2_baselen;
|
|
|
|
int is_shortname;
|
|
|
|
struct shortname_info base_info, ext_info;
|
|
|
|
|
|
|
|
is_shortname = 1;
|
|
|
|
INIT_SHORTNAME_INFO(&base_info);
|
|
|
|
INIT_SHORTNAME_INFO(&ext_info);
|
|
|
|
|
|
|
|
/* Now, we need to create a shortname from the long name */
|
|
|
|
ext_start = end = &uname[ulen];
|
|
|
|
while (--ext_start >= uname) {
|
|
|
|
if (*ext_start == 0x002E) { /* is `.' */
|
|
|
|
if (ext_start == end - 1) {
|
|
|
|
sz = ulen;
|
|
|
|
ext_start = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext_start == uname - 1) {
|
|
|
|
sz = ulen;
|
|
|
|
ext_start = NULL;
|
|
|
|
} else if (ext_start) {
|
|
|
|
/*
|
|
|
|
* Names which start with a dot could be just
|
|
|
|
* an extension eg. "...test". In this case Win95
|
|
|
|
* uses the extension as the name and sets no extension.
|
|
|
|
*/
|
|
|
|
name_start = &uname[0];
|
|
|
|
while (name_start < ext_start) {
|
|
|
|
if (!vfat_skip_char(*name_start))
|
|
|
|
break;
|
|
|
|
name_start++;
|
|
|
|
}
|
|
|
|
if (name_start != ext_start) {
|
|
|
|
sz = ext_start - uname;
|
|
|
|
ext_start++;
|
|
|
|
} else {
|
|
|
|
sz = ulen;
|
|
|
|
ext_start = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
numtail_baselen = 6;
|
|
|
|
numtail2_baselen = 2;
|
|
|
|
for (baselen = i = 0, p = base, ip = uname; i < sz; i++, ip++) {
|
|
|
|
chl = to_shortname_char(nls, charbuf, sizeof(charbuf),
|
|
|
|
ip, &base_info);
|
|
|
|
if (chl == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (baselen < 2 && (baselen + chl) > 2)
|
|
|
|
numtail2_baselen = baselen;
|
|
|
|
if (baselen < 6 && (baselen + chl) > 6)
|
|
|
|
numtail_baselen = baselen;
|
|
|
|
for (chi = 0; chi < chl; chi++) {
|
|
|
|
*p++ = charbuf[chi];
|
|
|
|
baselen++;
|
|
|
|
if (baselen >= 8)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (baselen >= 8) {
|
|
|
|
if ((chi < chl - 1) || (ip + 1) - uname < sz)
|
|
|
|
is_shortname = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (baselen == 0) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
extlen = 0;
|
|
|
|
if (ext_start) {
|
|
|
|
for (p = ext, ip = ext_start; extlen < 3 && ip < end; ip++) {
|
|
|
|
chl = to_shortname_char(nls, charbuf, sizeof(charbuf),
|
|
|
|
ip, &ext_info);
|
|
|
|
if (chl == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((extlen + chl) > 3) {
|
|
|
|
is_shortname = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (chi = 0; chi < chl; chi++) {
|
|
|
|
*p++ = charbuf[chi];
|
|
|
|
extlen++;
|
|
|
|
}
|
|
|
|
if (extlen >= 3) {
|
|
|
|
if (ip + 1 != end)
|
|
|
|
is_shortname = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ext[extlen] = '\0';
|
|
|
|
base[baselen] = '\0';
|
|
|
|
|
|
|
|
/* Yes, it can happen. ".\xe5" would do it. */
|
|
|
|
if (base[0] == DELETED_FLAG)
|
|
|
|
base[0] = 0x05;
|
|
|
|
|
|
|
|
/* OK, at this point we know that base is not longer than 8 symbols,
|
|
|
|
* ext is not longer than 3, base is nonempty, both don't contain
|
|
|
|
* any bad symbols (lowercase transformed to uppercase).
|
|
|
|
*/
|
|
|
|
|
|
|
|
memset(name_res, ' ', MSDOS_NAME);
|
|
|
|
memcpy(name_res, base, baselen);
|
|
|
|
memcpy(name_res + 8, ext, extlen);
|
|
|
|
*lcase = 0;
|
|
|
|
if (is_shortname && base_info.valid && ext_info.valid) {
|
|
|
|
if (vfat_find_form(dir, name_res) == 0)
|
|
|
|
return -EEXIST;
|
|
|
|
|
|
|
|
if (opts->shortname & VFAT_SFN_CREATE_WIN95) {
|
|
|
|
return (base_info.upper && ext_info.upper);
|
|
|
|
} else if (opts->shortname & VFAT_SFN_CREATE_WINNT) {
|
|
|
|
if ((base_info.upper || base_info.lower) &&
|
|
|
|
(ext_info.upper || ext_info.lower)) {
|
|
|
|
if (!base_info.upper && base_info.lower)
|
|
|
|
*lcase |= CASE_LOWER_BASE;
|
|
|
|
if (!ext_info.upper && ext_info.lower)
|
|
|
|
*lcase |= CASE_LOWER_EXT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->numtail == 0)
|
|
|
|
if (vfat_find_form(dir, name_res) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find a unique extension. This used to
|
|
|
|
* iterate through all possibilities sequentially,
|
|
|
|
* but that gave extremely bad performance. Windows
|
|
|
|
* only tries a few cases before using random
|
|
|
|
* values for part of the base.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (baselen > 6) {
|
|
|
|
baselen = numtail_baselen;
|
|
|
|
name_res[7] = ' ';
|
|
|
|
}
|
|
|
|
name_res[baselen] = '~';
|
|
|
|
for (i = 1; i < 10; i++) {
|
|
|
|
name_res[baselen + 1] = i + '0';
|
|
|
|
if (vfat_find_form(dir, name_res) < 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-31 17:21:10 +00:00
|
|
|
i = jiffies;
|
2005-04-16 22:20:36 +00:00
|
|
|
sz = (jiffies >> 16) & 0x7;
|
|
|
|
if (baselen > 2) {
|
|
|
|
baselen = numtail2_baselen;
|
|
|
|
name_res[7] = ' ';
|
|
|
|
}
|
|
|
|
name_res[baselen + 4] = '~';
|
|
|
|
name_res[baselen + 5] = '1' + sz;
|
|
|
|
while (1) {
|
2010-03-31 17:21:10 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%04X", i & 0xffff);
|
2005-04-16 22:20:36 +00:00
|
|
|
memcpy(&name_res[baselen], buf, 4);
|
|
|
|
if (vfat_find_form(dir, name_res) < 0)
|
|
|
|
break;
|
|
|
|
i -= 11;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate a string, including coded sequences into Unicode */
|
|
|
|
static int
|
|
|
|
xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
|
|
|
|
int *longlen, int *outlen, int escape, int utf8,
|
|
|
|
struct nls_table *nls)
|
|
|
|
{
|
|
|
|
const unsigned char *ip;
|
|
|
|
unsigned char *op;
|
2017-09-08 23:16:50 +00:00
|
|
|
int i, fill;
|
2005-04-16 22:20:36 +00:00
|
|
|
int charlen;
|
|
|
|
|
|
|
|
if (utf8) {
|
2011-11-17 21:42:19 +00:00
|
|
|
*outlen = utf8s_to_utf16s(name, len, UTF16_HOST_ENDIAN,
|
|
|
|
(wchar_t *) outname, FAT_LFN_LEN + 2);
|
2009-08-01 12:30:31 +00:00
|
|
|
if (*outlen < 0)
|
|
|
|
return *outlen;
|
2010-02-10 14:43:40 +00:00
|
|
|
else if (*outlen > FAT_LFN_LEN)
|
2008-04-28 09:16:29 +00:00
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
op = &outname[*outlen * sizeof(wchar_t)];
|
|
|
|
} else {
|
2012-03-23 22:02:38 +00:00
|
|
|
for (i = 0, ip = name, op = outname, *outlen = 0;
|
2012-03-23 22:02:39 +00:00
|
|
|
i < len && *outlen < FAT_LFN_LEN;
|
2012-03-23 22:02:38 +00:00
|
|
|
*outlen += 1) {
|
|
|
|
if (escape && (*ip == ':')) {
|
2017-09-08 23:16:50 +00:00
|
|
|
u8 uc[2];
|
|
|
|
|
2012-03-23 22:02:38 +00:00
|
|
|
if (i > len - 5)
|
|
|
|
return -EINVAL;
|
2017-09-08 23:16:50 +00:00
|
|
|
|
|
|
|
if (hex2bin(uc, ip + 1, 2) < 0)
|
2012-03-23 22:02:38 +00:00
|
|
|
return -EINVAL;
|
2017-09-08 23:16:50 +00:00
|
|
|
|
|
|
|
*(wchar_t *)op = uc[0] << 8 | uc[1];
|
|
|
|
|
|
|
|
op += 2;
|
2012-03-23 22:02:38 +00:00
|
|
|
ip += 5;
|
|
|
|
i += 5;
|
|
|
|
} else {
|
|
|
|
charlen = nls->char2uni(ip, len - i,
|
2017-09-08 23:16:50 +00:00
|
|
|
(wchar_t *)op);
|
2012-03-23 22:02:38 +00:00
|
|
|
if (charlen < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
ip += charlen;
|
|
|
|
i += charlen;
|
|
|
|
op += 2;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-23 22:02:38 +00:00
|
|
|
if (i < len)
|
|
|
|
return -ENAMETOOLONG;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*longlen = *outlen;
|
|
|
|
if (*outlen % 13) {
|
|
|
|
*op++ = 0;
|
|
|
|
*op++ = 0;
|
|
|
|
*outlen += 1;
|
|
|
|
if (*outlen % 13) {
|
|
|
|
fill = 13 - (*outlen % 13);
|
|
|
|
for (i = 0; i < fill; i++) {
|
|
|
|
*op++ = 0xff;
|
|
|
|
*op++ = 0xff;
|
|
|
|
}
|
|
|
|
*outlen += fill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_build_slots(struct inode *dir, const unsigned char *name,
|
|
|
|
int len, int is_dir, int cluster,
|
2018-08-22 04:59:48 +00:00
|
|
|
struct timespec64 *ts,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct msdos_dir_slot *slots, int *nr_slots)
|
|
|
|
{
|
|
|
|
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
|
|
|
|
struct fat_mount_options *opts = &sbi->options;
|
|
|
|
struct msdos_dir_slot *ps;
|
|
|
|
struct msdos_dir_entry *de;
|
|
|
|
unsigned char cksum, lcase;
|
|
|
|
unsigned char msdos_name[MSDOS_NAME];
|
|
|
|
wchar_t *uname;
|
|
|
|
__le16 time, date;
|
2008-11-06 20:53:47 +00:00
|
|
|
u8 time_cs;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err, ulen, usize, i;
|
|
|
|
loff_t offset;
|
|
|
|
|
|
|
|
*nr_slots = 0;
|
|
|
|
|
2008-04-28 09:16:29 +00:00
|
|
|
uname = __getname();
|
|
|
|
if (!uname)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
err = xlate_to_uni(name, len, (unsigned char *)uname, &ulen, &usize,
|
|
|
|
opts->unicode_xlate, opts->utf8, sbi->nls_io);
|
|
|
|
if (err)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
err = vfat_is_used_badchars(uname, ulen);
|
|
|
|
if (err)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
err = vfat_create_shortname(dir, sbi->nls_disk, uname, ulen,
|
|
|
|
msdos_name, &lcase);
|
|
|
|
if (err < 0)
|
|
|
|
goto out_free;
|
|
|
|
else if (err == 1) {
|
|
|
|
de = (struct msdos_dir_entry *)slots;
|
|
|
|
err = 0;
|
|
|
|
goto shortname;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build the entry of long file name */
|
2005-10-30 23:03:49 +00:00
|
|
|
cksum = fat_checksum(msdos_name);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*nr_slots = usize / 13;
|
|
|
|
for (ps = slots, i = *nr_slots; i > 0; i--, ps++) {
|
|
|
|
ps->id = i;
|
|
|
|
ps->attr = ATTR_EXT;
|
|
|
|
ps->reserved = 0;
|
|
|
|
ps->alias_checksum = cksum;
|
|
|
|
ps->start = 0;
|
|
|
|
offset = (i - 1) * 13;
|
|
|
|
fatwchar_to16(ps->name0_4, uname + offset, 5);
|
|
|
|
fatwchar_to16(ps->name5_10, uname + offset + 5, 6);
|
|
|
|
fatwchar_to16(ps->name11_12, uname + offset + 11, 2);
|
|
|
|
}
|
|
|
|
slots[0].id |= 0x40;
|
|
|
|
de = (struct msdos_dir_entry *)ps;
|
|
|
|
|
|
|
|
shortname:
|
|
|
|
/* build the entry of 8.3 alias name */
|
|
|
|
(*nr_slots)++;
|
|
|
|
memcpy(de->name, msdos_name, MSDOS_NAME);
|
|
|
|
de->attr = is_dir ? ATTR_DIR : ATTR_ARCH;
|
|
|
|
de->lcase = lcase;
|
2008-11-06 20:53:47 +00:00
|
|
|
fat_time_unix2fat(sbi, ts, &time, &date, &time_cs);
|
2005-04-16 22:20:36 +00:00
|
|
|
de->time = de->ctime = time;
|
|
|
|
de->date = de->cdate = de->adate = date;
|
2008-11-06 20:53:47 +00:00
|
|
|
de->ctime_cs = time_cs;
|
2012-07-30 21:42:13 +00:00
|
|
|
fat_set_start(de, cluster);
|
2005-04-16 22:20:36 +00:00
|
|
|
de->size = 0;
|
|
|
|
out_free:
|
2008-04-28 09:16:29 +00:00
|
|
|
__putname(uname);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-07-21 02:43:14 +00:00
|
|
|
static int vfat_add_entry(struct inode *dir, const struct qstr *qname,
|
2018-08-22 04:59:48 +00:00
|
|
|
int is_dir, int cluster, struct timespec64 *ts,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct fat_slot_info *sinfo)
|
|
|
|
{
|
|
|
|
struct msdos_dir_slot *slots;
|
|
|
|
unsigned int len;
|
|
|
|
int err, nr_slots;
|
|
|
|
|
|
|
|
len = vfat_striptail_len(qname);
|
|
|
|
if (len == 0)
|
|
|
|
return -ENOENT;
|
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
slots = kmalloc_array(MSDOS_SLOTS, sizeof(*slots), GFP_NOFS);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (slots == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
err = vfat_build_slots(dir, qname->name, len, is_dir, cluster, ts,
|
|
|
|
slots, &nr_slots);
|
|
|
|
if (err)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
err = fat_add_entries(dir, slots, nr_slots, sinfo);
|
|
|
|
if (err)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* update timestamp */
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(dir, ts, S_CTIME|S_MTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_DIRSYNC(dir))
|
|
|
|
(void)fat_sync_inode(dir);
|
|
|
|
else
|
|
|
|
mark_inode_dirty(dir);
|
|
|
|
cleanup:
|
|
|
|
kfree(slots);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-07-21 02:43:14 +00:00
|
|
|
static int vfat_find(struct inode *dir, const struct qstr *qname,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct fat_slot_info *sinfo)
|
|
|
|
{
|
|
|
|
unsigned int len = vfat_striptail_len(qname);
|
|
|
|
if (len == 0)
|
|
|
|
return -ENOENT;
|
|
|
|
return fat_search_long(dir, qname->name, len, sinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
|
2012-06-10 21:13:09 +00:00
|
|
|
unsigned int flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct fat_slot_info sinfo;
|
2008-11-06 20:53:51 +00:00
|
|
|
struct inode *inode;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct dentry *alias;
|
2008-11-06 20:53:51 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = vfat_find(dir, &dentry->d_name, &sinfo);
|
|
|
|
if (err) {
|
2008-11-06 20:53:51 +00:00
|
|
|
if (err == -ENOENT) {
|
|
|
|
inode = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2008-11-06 20:53:51 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
if (IS_ERR(inode)) {
|
2008-11-06 20:53:51 +00:00
|
|
|
err = PTR_ERR(inode);
|
|
|
|
goto error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-11-06 20:53:51 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
alias = d_find_alias(inode);
|
2014-12-02 23:59:37 +00:00
|
|
|
/*
|
|
|
|
* Checking "alias->d_parent == dentry->d_parent" to make sure
|
|
|
|
* FS is not corrupted (especially double linked dir).
|
|
|
|
*/
|
2018-04-25 14:32:51 +00:00
|
|
|
if (alias && alias->d_parent == dentry->d_parent) {
|
2008-11-06 20:53:51 +00:00
|
|
|
/*
|
2010-01-11 18:32:24 +00:00
|
|
|
* This inode has non anonymous-DCACHE_DISCONNECTED
|
|
|
|
* dentry. This means, the user did ->lookup() by an
|
|
|
|
* another name (longname vs 8.3 alias of it) in past.
|
2008-11-06 20:53:51 +00:00
|
|
|
*
|
|
|
|
* Switch to new one for reason of locality if possible.
|
|
|
|
*/
|
2008-11-06 20:53:52 +00:00
|
|
|
if (!S_ISDIR(inode->i_mode))
|
|
|
|
d_move(alias, dentry);
|
|
|
|
iput(inode);
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2008-11-06 20:53:52 +00:00
|
|
|
return alias;
|
2010-01-11 18:32:24 +00:00
|
|
|
} else
|
|
|
|
dput(alias);
|
|
|
|
|
2008-11-06 20:53:51 +00:00
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2014-12-02 23:59:37 +00:00
|
|
|
if (!inode)
|
2017-12-11 11:35:09 +00:00
|
|
|
vfat_d_version_set(dentry, inode_query_iversion(dir));
|
2014-12-02 23:59:37 +00:00
|
|
|
return d_splice_alias(inode, dentry);
|
2008-11-06 20:53:51 +00:00
|
|
|
error:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2008-11-06 20:53:51 +00:00
|
|
|
return ERR_PTR(err);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2023-01-13 11:49:13 +00:00
|
|
|
static int vfat_create(struct mnt_idmap *idmap, struct inode *dir,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct dentry *dentry, umode_t mode, bool excl)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct inode *inode;
|
|
|
|
struct fat_slot_info sinfo;
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 02:36:02 +00:00
|
|
|
struct timespec64 ts;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err;
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-09-14 14:48:05 +00:00
|
|
|
ts = current_time(dir);
|
2018-08-22 04:59:48 +00:00
|
|
|
err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &ts, &sinfo);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2017-12-11 11:35:09 +00:00
|
|
|
inode_inc_iversion(dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
|
|
|
goto out;
|
|
|
|
}
|
2017-12-11 11:35:09 +00:00
|
|
|
inode_inc_iversion(inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-17 22:25:59 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2008-05-20 02:53:01 +00:00
|
|
|
struct super_block *sb = dir->i_sb;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct fat_slot_info sinfo;
|
|
|
|
int err;
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = fat_dir_empty(inode);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
err = vfat_find(dir, &dentry->d_name, &sinfo);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = fat_remove_entries(dir, &sinfo); /* and releases bh */
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2006-10-01 06:29:03 +00:00
|
|
|
drop_nlink(dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-10-01 06:29:06 +00:00
|
|
|
clear_nlink(inode);
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(inode, NULL, S_ATIME|S_MTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
fat_detach(inode);
|
2017-12-11 11:35:09 +00:00
|
|
|
vfat_d_version_set(dentry, inode_query_iversion(dir));
|
2005-04-16 22:20:36 +00:00
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-17 22:25:59 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2008-05-20 02:53:01 +00:00
|
|
|
struct super_block *sb = dir->i_sb;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct fat_slot_info sinfo;
|
|
|
|
int err;
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = vfat_find(dir, &dentry->d_name, &sinfo);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = fat_remove_entries(dir, &sinfo); /* and releases bh */
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2006-10-01 06:29:06 +00:00
|
|
|
clear_nlink(inode);
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(inode, NULL, S_ATIME|S_MTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
fat_detach(inode);
|
2017-12-11 11:35:09 +00:00
|
|
|
vfat_d_version_set(dentry, inode_query_iversion(dir));
|
2005-04-16 22:20:36 +00:00
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-01-13 11:49:15 +00:00
|
|
|
static int vfat_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct dentry *dentry, umode_t mode)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct inode *inode;
|
|
|
|
struct fat_slot_info sinfo;
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 02:36:02 +00:00
|
|
|
struct timespec64 ts;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err, cluster;
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-09-14 14:48:05 +00:00
|
|
|
ts = current_time(dir);
|
2018-08-22 04:59:48 +00:00
|
|
|
cluster = fat_alloc_new_dir(dir, &ts);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cluster < 0) {
|
|
|
|
err = cluster;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-08-22 04:59:48 +00:00
|
|
|
err = vfat_add_entry(dir, &dentry->d_name, 1, cluster, &ts, &sinfo);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
goto out_free;
|
2017-12-11 11:35:09 +00:00
|
|
|
inode_inc_iversion(dir);
|
2006-10-01 06:29:04 +00:00
|
|
|
inc_nlink(dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
|
|
|
/* the directory was completed, just return a error */
|
|
|
|
goto out;
|
|
|
|
}
|
2017-12-11 11:35:09 +00:00
|
|
|
inode_inc_iversion(inode);
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
fat_free_clusters(dir, cluster);
|
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2022-06-10 07:57:19 +00:00
|
|
|
static int vfat_get_dotdot_de(struct inode *inode, struct buffer_head **bh,
|
|
|
|
struct msdos_dir_entry **de)
|
|
|
|
{
|
|
|
|
if (S_ISDIR(inode->i_mode)) {
|
|
|
|
if (fat_get_dotdot_entry(inode, bh, de))
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_sync_ipos(struct inode *dir, struct inode *inode)
|
|
|
|
{
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
|
|
return fat_sync_inode(inode);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_update_dotdot_de(struct inode *dir, struct inode *inode,
|
|
|
|
struct buffer_head *dotdot_bh,
|
|
|
|
struct msdos_dir_entry *dotdot_de)
|
|
|
|
{
|
|
|
|
fat_set_start(dotdot_de, MSDOS_I(dir)->i_logstart);
|
|
|
|
mark_buffer_dirty_inode(dotdot_bh, inode);
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
|
|
return sync_dirty_buffer(dotdot_bh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vfat_update_dir_metadata(struct inode *dir, struct timespec64 *ts)
|
|
|
|
{
|
|
|
|
inode_inc_iversion(dir);
|
|
|
|
fat_truncate_time(dir, ts, S_CTIME | S_MTIME);
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
|
|
(void)fat_sync_inode(dir);
|
|
|
|
else
|
|
|
|
mark_inode_dirty(dir);
|
|
|
|
}
|
|
|
|
|
2022-06-10 07:57:18 +00:00
|
|
|
static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct buffer_head *dotdot_bh;
|
2022-06-10 07:57:19 +00:00
|
|
|
struct msdos_dir_entry *dotdot_de = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct inode *old_inode, *new_inode;
|
|
|
|
struct fat_slot_info old_sinfo, sinfo;
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 02:36:02 +00:00
|
|
|
struct timespec64 ts;
|
2012-10-05 00:14:45 +00:00
|
|
|
loff_t new_i_pos;
|
2022-06-10 07:57:19 +00:00
|
|
|
int err, is_dir, corrupt = 0;
|
2008-05-20 02:53:01 +00:00
|
|
|
struct super_block *sb = old_dir->i_sb;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
|
2015-03-17 22:25:59 +00:00
|
|
|
old_inode = d_inode(old_dentry);
|
|
|
|
new_inode = d_inode(new_dentry);
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
err = vfat_find(old_dir, &old_dentry->d_name, &old_sinfo);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2022-06-10 07:57:19 +00:00
|
|
|
if (old_dir != new_dir) {
|
|
|
|
err = vfat_get_dotdot_de(old_inode, &dotdot_bh, &dotdot_de);
|
|
|
|
if (err)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-06-10 07:57:19 +00:00
|
|
|
is_dir = S_ISDIR(old_inode->i_mode);
|
2016-09-14 14:48:05 +00:00
|
|
|
ts = current_time(old_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (new_inode) {
|
|
|
|
if (is_dir) {
|
|
|
|
err = fat_dir_empty(new_inode);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
2005-10-30 23:03:50 +00:00
|
|
|
new_i_pos = MSDOS_I(new_inode)->i_pos;
|
2005-04-16 22:20:36 +00:00
|
|
|
fat_detach(new_inode);
|
|
|
|
} else {
|
|
|
|
err = vfat_add_entry(new_dir, &new_dentry->d_name, is_dir, 0,
|
2018-08-22 04:59:48 +00:00
|
|
|
&ts, &sinfo);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2005-10-30 23:03:50 +00:00
|
|
|
new_i_pos = sinfo.i_pos;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2017-12-11 11:35:09 +00:00
|
|
|
inode_inc_iversion(new_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
fat_detach(old_inode);
|
2005-10-30 23:03:50 +00:00
|
|
|
fat_attach(old_inode, new_i_pos);
|
2022-06-10 07:57:19 +00:00
|
|
|
err = vfat_sync_ipos(new_dir, old_inode);
|
|
|
|
if (err)
|
|
|
|
goto error_inode;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2022-06-10 07:57:19 +00:00
|
|
|
if (dotdot_de) {
|
|
|
|
err = vfat_update_dotdot_de(new_dir, old_inode, dotdot_bh,
|
|
|
|
dotdot_de);
|
|
|
|
if (err)
|
|
|
|
goto error_dotdot;
|
2006-10-01 06:29:03 +00:00
|
|
|
drop_nlink(old_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!new_inode)
|
2006-10-01 06:29:04 +00:00
|
|
|
inc_nlink(new_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = fat_remove_entries(old_dir, &old_sinfo); /* and releases bh */
|
|
|
|
old_sinfo.bh = NULL;
|
|
|
|
if (err)
|
|
|
|
goto error_dotdot;
|
2022-06-10 07:57:19 +00:00
|
|
|
vfat_update_dir_metadata(old_dir, &ts);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (new_inode) {
|
2006-10-01 06:29:03 +00:00
|
|
|
drop_nlink(new_inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (is_dir)
|
2006-10-01 06:29:03 +00:00
|
|
|
drop_nlink(new_inode);
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(new_inode, &ts, S_CTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
brelse(dotdot_bh);
|
|
|
|
brelse(old_sinfo.bh);
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
error_dotdot:
|
|
|
|
/* data cluster is shared, serious corruption */
|
|
|
|
corrupt = 1;
|
|
|
|
|
2022-06-10 07:57:19 +00:00
|
|
|
if (dotdot_de) {
|
|
|
|
corrupt |= vfat_update_dotdot_de(old_dir, old_inode, dotdot_bh,
|
|
|
|
dotdot_de);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
error_inode:
|
|
|
|
fat_detach(old_inode);
|
|
|
|
fat_attach(old_inode, old_sinfo.i_pos);
|
|
|
|
if (new_inode) {
|
2005-10-30 23:03:50 +00:00
|
|
|
fat_attach(new_inode, new_i_pos);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (corrupt)
|
|
|
|
corrupt |= fat_sync_inode(new_inode);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If new entry was not sharing the data cluster, it
|
|
|
|
* shouldn't be serious corruption.
|
|
|
|
*/
|
|
|
|
int err2 = fat_remove_entries(new_dir, &sinfo);
|
|
|
|
if (corrupt)
|
|
|
|
corrupt |= err2;
|
|
|
|
sinfo.bh = NULL;
|
|
|
|
}
|
|
|
|
if (corrupt < 0) {
|
2009-06-03 17:34:22 +00:00
|
|
|
fat_fs_error(new_dir->i_sb,
|
2005-04-16 22:20:36 +00:00
|
|
|
"%s: Filesystem corrupted (i_pos %lld)",
|
2024-10-04 06:03:49 +00:00
|
|
|
__func__, new_i_pos);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-06-10 07:57:20 +00:00
|
|
|
static void vfat_exchange_ipos(struct inode *old_inode, struct inode *new_inode,
|
|
|
|
loff_t old_i_pos, loff_t new_i_pos)
|
|
|
|
{
|
|
|
|
fat_detach(old_inode);
|
|
|
|
fat_detach(new_inode);
|
|
|
|
fat_attach(old_inode, new_i_pos);
|
|
|
|
fat_attach(new_inode, old_i_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vfat_move_nlink(struct inode *src, struct inode *dst)
|
|
|
|
{
|
|
|
|
drop_nlink(src);
|
|
|
|
inc_nlink(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
|
|
{
|
|
|
|
struct buffer_head *old_dotdot_bh = NULL, *new_dotdot_bh = NULL;
|
|
|
|
struct msdos_dir_entry *old_dotdot_de = NULL, *new_dotdot_de = NULL;
|
|
|
|
struct inode *old_inode, *new_inode;
|
|
|
|
struct timespec64 ts = current_time(old_dir);
|
|
|
|
loff_t old_i_pos, new_i_pos;
|
|
|
|
int err, corrupt = 0;
|
|
|
|
struct super_block *sb = old_dir->i_sb;
|
|
|
|
|
|
|
|
old_inode = d_inode(old_dentry);
|
|
|
|
new_inode = d_inode(new_dentry);
|
|
|
|
|
|
|
|
/* Acquire super block lock for the operation to be atomic */
|
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
|
|
|
|
|
|
|
/* if directories are not the same, get ".." info to update */
|
|
|
|
if (old_dir != new_dir) {
|
|
|
|
err = vfat_get_dotdot_de(old_inode, &old_dotdot_bh,
|
|
|
|
&old_dotdot_de);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = vfat_get_dotdot_de(new_inode, &new_dotdot_bh,
|
|
|
|
&new_dotdot_de);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_i_pos = MSDOS_I(old_inode)->i_pos;
|
|
|
|
new_i_pos = MSDOS_I(new_inode)->i_pos;
|
|
|
|
|
|
|
|
vfat_exchange_ipos(old_inode, new_inode, old_i_pos, new_i_pos);
|
|
|
|
|
|
|
|
err = vfat_sync_ipos(old_dir, new_inode);
|
|
|
|
if (err)
|
|
|
|
goto error_exchange;
|
|
|
|
err = vfat_sync_ipos(new_dir, old_inode);
|
|
|
|
if (err)
|
|
|
|
goto error_exchange;
|
|
|
|
|
|
|
|
/* update ".." directory entry info */
|
|
|
|
if (old_dotdot_de) {
|
|
|
|
err = vfat_update_dotdot_de(new_dir, old_inode, old_dotdot_bh,
|
|
|
|
old_dotdot_de);
|
|
|
|
if (err)
|
|
|
|
goto error_old_dotdot;
|
|
|
|
}
|
|
|
|
if (new_dotdot_de) {
|
|
|
|
err = vfat_update_dotdot_de(old_dir, new_inode, new_dotdot_bh,
|
|
|
|
new_dotdot_de);
|
|
|
|
if (err)
|
|
|
|
goto error_new_dotdot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if cross directory and only one is a directory, adjust nlink */
|
|
|
|
if (!old_dotdot_de != !new_dotdot_de) {
|
|
|
|
if (old_dotdot_de)
|
|
|
|
vfat_move_nlink(old_dir, new_dir);
|
|
|
|
else
|
|
|
|
vfat_move_nlink(new_dir, old_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
vfat_update_dir_metadata(old_dir, &ts);
|
|
|
|
/* if directories are not the same, update new_dir as well */
|
|
|
|
if (old_dir != new_dir)
|
|
|
|
vfat_update_dir_metadata(new_dir, &ts);
|
|
|
|
|
|
|
|
out:
|
|
|
|
brelse(old_dotdot_bh);
|
|
|
|
brelse(new_dotdot_bh);
|
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
error_new_dotdot:
|
|
|
|
if (new_dotdot_de) {
|
|
|
|
corrupt |= vfat_update_dotdot_de(new_dir, new_inode,
|
|
|
|
new_dotdot_bh, new_dotdot_de);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_old_dotdot:
|
|
|
|
if (old_dotdot_de) {
|
|
|
|
corrupt |= vfat_update_dotdot_de(old_dir, old_inode,
|
|
|
|
old_dotdot_bh, old_dotdot_de);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_exchange:
|
|
|
|
vfat_exchange_ipos(old_inode, new_inode, new_i_pos, old_i_pos);
|
|
|
|
corrupt |= vfat_sync_ipos(new_dir, new_inode);
|
|
|
|
corrupt |= vfat_sync_ipos(old_dir, old_inode);
|
|
|
|
|
|
|
|
if (corrupt < 0) {
|
|
|
|
fat_fs_error(new_dir->i_sb,
|
|
|
|
"%s: Filesystem corrupted (i_pos %lld, %lld)",
|
|
|
|
__func__, old_i_pos, new_i_pos);
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2023-01-13 11:49:17 +00:00
|
|
|
static int vfat_rename2(struct mnt_idmap *idmap, struct inode *old_dir,
|
2022-06-10 07:57:18 +00:00
|
|
|
struct dentry *old_dentry, struct inode *new_dir,
|
|
|
|
struct dentry *new_dentry, unsigned int flags)
|
|
|
|
{
|
2022-06-10 07:57:20 +00:00
|
|
|
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
|
2022-06-10 07:57:18 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2022-06-10 07:57:20 +00:00
|
|
|
if (flags & RENAME_EXCHANGE) {
|
|
|
|
return vfat_rename_exchange(old_dir, old_dentry,
|
|
|
|
new_dir, new_dentry);
|
|
|
|
}
|
|
|
|
|
2022-06-10 07:57:18 +00:00
|
|
|
/* VFS already handled RENAME_NOREPLACE, handle it as a normal rename */
|
|
|
|
return vfat_rename(old_dir, old_dentry, new_dir, new_dentry);
|
|
|
|
}
|
|
|
|
|
2007-02-12 08:55:40 +00:00
|
|
|
static const struct inode_operations vfat_dir_inode_operations = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.create = vfat_create,
|
|
|
|
.lookup = vfat_lookup,
|
|
|
|
.unlink = vfat_unlink,
|
|
|
|
.mkdir = vfat_mkdir,
|
|
|
|
.rmdir = vfat_rmdir,
|
2022-06-10 07:57:18 +00:00
|
|
|
.rename = vfat_rename2,
|
2008-04-28 09:16:25 +00:00
|
|
|
.setattr = fat_setattr,
|
2006-11-16 09:19:28 +00:00
|
|
|
.getattr = fat_getattr,
|
2018-10-30 22:06:53 +00:00
|
|
|
.update_time = fat_update_time,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2010-12-18 15:44:00 +00:00
|
|
|
static void setup(struct super_block *sb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-04-12 12:08:37 +00:00
|
|
|
MSDOS_SB(sb)->dir_ops = &vfat_dir_inode_operations;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (MSDOS_SB(sb)->options.name_check != 's')
|
2010-12-18 15:44:00 +00:00
|
|
|
sb->s_d_op = &vfat_ci_dentry_ops;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2010-12-18 15:44:00 +00:00
|
|
|
sb->s_d_op = &vfat_dentry_ops;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
fat: Convert to new mount api
vfat and msdos share a common set of options, with additional, unique
options for each filesystem.
Each filesystem calls common fc initialization and parsing routines,
with an "is_vfat" parameter. For parsing, if the option is not found
in the common parameter_spec, parsing is retried with the fs-specific
parameter_spec.
This patch leaves nls loading to fill_super, so the codepage and charset
options are not validated as they are requested. This matches current
behavior. It would be possible to test-load as each option is parsed,
but that would make i.e.
mount -o "iocharset=nope,iocharset=iso8859-1"
fail, where it does not fail today because only the last iocharset
option is considered.
The obsolete "conv=" option is set up with an enum of acceptable values;
currently invalid "conv=" options are rejected as such, even though the
option is obsolete, so this patch preserves that behavior.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Link: https://lore.kernel.org/r/a9411b02-5f8e-4e1e-90aa-0c032d66c312@redhat.com
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-07-02 22:44:27 +00:00
|
|
|
static int vfat_fill_super(struct super_block *sb, struct fs_context *fc)
|
2010-12-18 15:44:00 +00:00
|
|
|
{
|
fat: Convert to new mount api
vfat and msdos share a common set of options, with additional, unique
options for each filesystem.
Each filesystem calls common fc initialization and parsing routines,
with an "is_vfat" parameter. For parsing, if the option is not found
in the common parameter_spec, parsing is retried with the fs-specific
parameter_spec.
This patch leaves nls loading to fill_super, so the codepage and charset
options are not validated as they are requested. This matches current
behavior. It would be possible to test-load as each option is parsed,
but that would make i.e.
mount -o "iocharset=nope,iocharset=iso8859-1"
fail, where it does not fail today because only the last iocharset
option is considered.
The obsolete "conv=" option is set up with an enum of acceptable values;
currently invalid "conv=" options are rejected as such, even though the
option is obsolete, so this patch preserves that behavior.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Link: https://lore.kernel.org/r/a9411b02-5f8e-4e1e-90aa-0c032d66c312@redhat.com
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-07-02 22:44:27 +00:00
|
|
|
return fat_fill_super(sb, fc, setup);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
fat: Convert to new mount api
vfat and msdos share a common set of options, with additional, unique
options for each filesystem.
Each filesystem calls common fc initialization and parsing routines,
with an "is_vfat" parameter. For parsing, if the option is not found
in the common parameter_spec, parsing is retried with the fs-specific
parameter_spec.
This patch leaves nls loading to fill_super, so the codepage and charset
options are not validated as they are requested. This matches current
behavior. It would be possible to test-load as each option is parsed,
but that would make i.e.
mount -o "iocharset=nope,iocharset=iso8859-1"
fail, where it does not fail today because only the last iocharset
option is considered.
The obsolete "conv=" option is set up with an enum of acceptable values;
currently invalid "conv=" options are rejected as such, even though the
option is obsolete, so this patch preserves that behavior.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Link: https://lore.kernel.org/r/a9411b02-5f8e-4e1e-90aa-0c032d66c312@redhat.com
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-07-02 22:44:27 +00:00
|
|
|
static int vfat_get_tree(struct fs_context *fc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
fat: Convert to new mount api
vfat and msdos share a common set of options, with additional, unique
options for each filesystem.
Each filesystem calls common fc initialization and parsing routines,
with an "is_vfat" parameter. For parsing, if the option is not found
in the common parameter_spec, parsing is retried with the fs-specific
parameter_spec.
This patch leaves nls loading to fill_super, so the codepage and charset
options are not validated as they are requested. This matches current
behavior. It would be possible to test-load as each option is parsed,
but that would make i.e.
mount -o "iocharset=nope,iocharset=iso8859-1"
fail, where it does not fail today because only the last iocharset
option is considered.
The obsolete "conv=" option is set up with an enum of acceptable values;
currently invalid "conv=" options are rejected as such, even though the
option is obsolete, so this patch preserves that behavior.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Link: https://lore.kernel.org/r/a9411b02-5f8e-4e1e-90aa-0c032d66c312@redhat.com
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-07-02 22:44:27 +00:00
|
|
|
return get_tree_bdev(fc, vfat_fill_super);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vfat_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
|
|
|
{
|
|
|
|
return fat_parse_param(fc, param, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations vfat_context_ops = {
|
|
|
|
.parse_param = vfat_parse_param,
|
|
|
|
.get_tree = vfat_get_tree,
|
|
|
|
.reconfigure = fat_reconfigure,
|
|
|
|
.free = fat_free_fc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int vfat_init_fs_context(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Initialize with is_vfat == true */
|
|
|
|
err = fat_init_fs_context(fc, true);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
fc->ops = &vfat_context_ops;
|
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type vfat_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "vfat",
|
|
|
|
.kill_sb = kill_block_super,
|
2021-01-21 13:19:56 +00:00
|
|
|
.fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
|
fat: Convert to new mount api
vfat and msdos share a common set of options, with additional, unique
options for each filesystem.
Each filesystem calls common fc initialization and parsing routines,
with an "is_vfat" parameter. For parsing, if the option is not found
in the common parameter_spec, parsing is retried with the fs-specific
parameter_spec.
This patch leaves nls loading to fill_super, so the codepage and charset
options are not validated as they are requested. This matches current
behavior. It would be possible to test-load as each option is parsed,
but that would make i.e.
mount -o "iocharset=nope,iocharset=iso8859-1"
fail, where it does not fail today because only the last iocharset
option is considered.
The obsolete "conv=" option is set up with an enum of acceptable values;
currently invalid "conv=" options are rejected as such, even though the
option is obsolete, so this patch preserves that behavior.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Link: https://lore.kernel.org/r/a9411b02-5f8e-4e1e-90aa-0c032d66c312@redhat.com
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-07-02 22:44:27 +00:00
|
|
|
.init_fs_context = vfat_init_fs_context,
|
|
|
|
.parameters = fat_param_spec,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
2013-03-03 03:39:14 +00:00
|
|
|
MODULE_ALIAS_FS("vfat");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int __init init_vfat_fs(void)
|
|
|
|
{
|
|
|
|
return register_filesystem(&vfat_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_vfat_fs(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&vfat_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("VFAT filesystem support");
|
|
|
|
MODULE_AUTHOR("Gordon Chaffee");
|
|
|
|
|
|
|
|
module_init(init_vfat_fs)
|
|
|
|
module_exit(exit_vfat_fs)
|