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/msdos/namei.c
|
|
|
|
*
|
|
|
|
* Written 1992,1993 by Werner Almesberger
|
|
|
|
* Hidden files 1995 by Albert Cahalan <albert@ccs.neu.edu> <adc@coe.neu.edu>
|
|
|
|
* Rewritten for constant inumbers 1999 by Al Viro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.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
|
|
|
|
|
|
|
/* Characters that are undesirable in an MS-DOS file name */
|
|
|
|
static unsigned char bad_chars[] = "*?<>|\"";
|
2008-07-25 08:46:45 +00:00
|
|
|
static unsigned char bad_if_strict[] = "+=,; ";
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/***** Formats an MS-DOS file name. Rejects invalid names. */
|
|
|
|
static int msdos_format_name(const unsigned char *name, int len,
|
|
|
|
unsigned char *res, struct fat_mount_options *opts)
|
|
|
|
/*
|
|
|
|
* name is the proposed name, len is its length, res is
|
|
|
|
* the resulting name, opts->name_check is either (r)elaxed,
|
|
|
|
* (n)ormal or (s)trict, opts->dotsOK allows dots at the
|
|
|
|
* beginning of name (for hidden files)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
unsigned char *walk;
|
|
|
|
unsigned char c;
|
|
|
|
int space;
|
|
|
|
|
|
|
|
if (name[0] == '.') { /* dotfile because . and .. already done */
|
|
|
|
if (opts->dotsOK) {
|
|
|
|
/* Get rid of dot - test for it elsewhere */
|
|
|
|
name++;
|
|
|
|
len--;
|
2008-07-25 08:46:45 +00:00
|
|
|
} else
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/*
|
2008-07-25 08:46:45 +00:00
|
|
|
* disallow names that _really_ start with a dot
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2008-07-25 08:46:45 +00:00
|
|
|
space = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
c = 0;
|
|
|
|
for (walk = res; len && walk - res < 8; walk++) {
|
|
|
|
c = *name++;
|
|
|
|
len--;
|
|
|
|
if (opts->name_check != 'r' && strchr(bad_chars, c))
|
|
|
|
return -EINVAL;
|
2008-07-25 08:46:45 +00:00
|
|
|
if (opts->name_check == 's' && strchr(bad_if_strict, c))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
|
|
|
|
return -EINVAL;
|
|
|
|
if (c < ' ' || c == ':' || c == '\\')
|
|
|
|
return -EINVAL;
|
|
|
|
/*
|
|
|
|
* 0xE5 is legal as a first character, but we must substitute
|
|
|
|
* 0x05 because 0xE5 marks deleted files. Yes, DOS really
|
|
|
|
* does this.
|
|
|
|
* It seems that Microsoft hacked DOS to support non-US
|
|
|
|
* characters after the 0xE5 character was already in use to
|
|
|
|
* mark deleted files.
|
|
|
|
*/
|
|
|
|
if ((res == walk) && (c == 0xE5))
|
|
|
|
c = 0x05;
|
|
|
|
if (c == '.')
|
|
|
|
break;
|
|
|
|
space = (c == ' ');
|
|
|
|
*walk = (!opts->nocase && c >= 'a' && c <= 'z') ? c - 32 : c;
|
|
|
|
}
|
|
|
|
if (space)
|
|
|
|
return -EINVAL;
|
|
|
|
if (opts->name_check == 's' && len && c != '.') {
|
|
|
|
c = *name++;
|
|
|
|
len--;
|
|
|
|
if (c != '.')
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
while (c != '.' && len--)
|
|
|
|
c = *name++;
|
|
|
|
if (c == '.') {
|
|
|
|
while (walk - res < 8)
|
|
|
|
*walk++ = ' ';
|
|
|
|
while (len > 0 && walk - res < MSDOS_NAME) {
|
|
|
|
c = *name++;
|
|
|
|
len--;
|
|
|
|
if (opts->name_check != 'r' && strchr(bad_chars, c))
|
|
|
|
return -EINVAL;
|
|
|
|
if (opts->name_check == 's' &&
|
2008-07-25 08:46:45 +00:00
|
|
|
strchr(bad_if_strict, c))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
if (c < ' ' || c == ':' || c == '\\')
|
|
|
|
return -EINVAL;
|
|
|
|
if (c == '.') {
|
|
|
|
if (opts->name_check == 's')
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
|
|
|
|
return -EINVAL;
|
|
|
|
space = c == ' ';
|
|
|
|
if (!opts->nocase && c >= 'a' && c <= 'z')
|
|
|
|
*walk++ = c - 32;
|
|
|
|
else
|
|
|
|
*walk++ = c;
|
|
|
|
}
|
|
|
|
if (space)
|
|
|
|
return -EINVAL;
|
|
|
|
if (opts->name_check == 's' && len)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
while (walk - res < MSDOS_NAME)
|
|
|
|
*walk++ = ' ';
|
2006-03-31 10:30:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Locates a directory entry. Uses unformatted name. */
|
|
|
|
static int msdos_find(struct inode *dir, const unsigned char *name, int len,
|
|
|
|
struct fat_slot_info *sinfo)
|
|
|
|
{
|
|
|
|
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
|
|
|
|
unsigned char msdos_name[MSDOS_NAME];
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = msdos_format_name(name, len, msdos_name, &sbi->options);
|
|
|
|
if (err)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
err = fat_scan(dir, msdos_name, sinfo);
|
|
|
|
if (!err && sbi->options.dotsOK) {
|
|
|
|
if (name[0] == '.') {
|
|
|
|
if (!(sinfo->de->attr & ATTR_HIDDEN))
|
|
|
|
err = -ENOENT;
|
|
|
|
} else {
|
|
|
|
if (sinfo->de->attr & ATTR_HIDDEN)
|
|
|
|
err = -ENOENT;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
brelse(sinfo->bh);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the hash for the msdos 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 msdos fs routines will
|
|
|
|
* return ENOENT or EINVAL as appropriate.
|
|
|
|
*/
|
2013-05-21 22:22:44 +00:00
|
|
|
static int msdos_hash(const struct dentry *dentry, struct qstr *qstr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
|
|
|
|
unsigned char msdos_name[MSDOS_NAME];
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = msdos_format_name(qstr->name, qstr->len, msdos_name, options);
|
|
|
|
if (!error)
|
2016-06-10 14:51:30 +00:00
|
|
|
qstr->hash = full_name_hash(dentry, msdos_name, MSDOS_NAME);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare two msdos names. If either of the names are invalid,
|
|
|
|
* we fall back to doing the standard name comparison.
|
|
|
|
*/
|
2016-07-31 20:37:25 +00:00
|
|
|
static int msdos_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
|
|
|
{
|
2016-07-29 22:23:59 +00:00
|
|
|
struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char a_msdos_name[MSDOS_NAME], b_msdos_name[MSDOS_NAME];
|
|
|
|
int error;
|
|
|
|
|
2011-01-07 06:49:27 +00:00
|
|
|
error = msdos_format_name(name->name, name->len, a_msdos_name, options);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (error)
|
|
|
|
goto old_compare;
|
2011-01-07 06:49:27 +00:00
|
|
|
error = msdos_format_name(str, len, b_msdos_name, options);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (error)
|
|
|
|
goto old_compare;
|
|
|
|
error = memcmp(a_msdos_name, b_msdos_name, MSDOS_NAME);
|
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
|
|
|
|
old_compare:
|
|
|
|
error = 1;
|
2011-01-07 06:49:27 +00:00
|
|
|
if (name->len == len)
|
|
|
|
error = memcmp(name->name, str, len);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-02-20 05:59:46 +00:00
|
|
|
static const struct dentry_operations msdos_dentry_operations = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.d_hash = msdos_hash,
|
|
|
|
.d_compare = msdos_cmp,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AV. Wrappers for FAT sb operations. Is it wise?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***** Get inode using directory and name */
|
|
|
|
static struct dentry *msdos_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:53 +00:00
|
|
|
struct inode *inode;
|
|
|
|
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);
|
2008-11-06 20:53:53 +00:00
|
|
|
err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
|
2011-07-09 01:20:11 +00:00
|
|
|
switch (err) {
|
|
|
|
case -ENOENT:
|
|
|
|
inode = NULL;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
inode = ERR_PTR(err);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2010-12-18 15:44:00 +00:00
|
|
|
return d_splice_alias(inode, dentry);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***** Creates a directory entry (name is already formatted). */
|
|
|
|
static int msdos_add_entry(struct inode *dir, const unsigned char *name,
|
|
|
|
int is_dir, int is_hid, int cluster,
|
2018-08-22 04:59:48 +00:00
|
|
|
struct timespec64 *ts, struct fat_slot_info *sinfo)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
fatfs: add UTC timestamp option
Provide a new mount option ("tz=UTC") for DOS (vfat/msdos) filesystems,
allowing timestamps to be in coordinated universal time (UTC) rather than
local time in applications where doing this is advantageous.
In particular, portable devices that use fat/vfat (such as digital
cameras) can benefit from using UTC in their internal clocks, thus
avoiding daylight saving time errors and general time ambiguity issues.
The user of the device does not have to worry about changing the time when
moving from place or when daylight saving changes.
The new mount option, when set, disables the counter-adjustment that Linux
currently makes to FAT timestamp info in anticipation of the normal
userspace time zone correction. When used in this new mode, all daylight
saving time and time zone handling is done in userspace as is normal for
many other filesystems (like ext3). The default mode, which remains
unchanged, is still appropriate when mounting volumes written in Windows
(because of its use of local time).
I originally based this patch on one submitted last year by Paul Collins,
but I updated it to work with current source and changed variable/option
naming. Ogawa Hirofumi (who maintains these filesystems) and I discussed
this patch at length on lkml, and he suggested using the option name in
the attached version of the patch. Barry Bouwsma pointed out a good
addition to the patch as well.
Signed-off-by: Joe Peterson <joe@skyrush.com>
Signed-off-by: Paul Collins <paul@ondioline.org>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Barry Bouwsma <free_beer_for_all@yahoo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-25 08:46:47 +00:00
|
|
|
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct msdos_dir_entry de;
|
|
|
|
__le16 time, date;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memcpy(de.name, name, MSDOS_NAME);
|
|
|
|
de.attr = is_dir ? ATTR_DIR : ATTR_ARCH;
|
|
|
|
if (is_hid)
|
|
|
|
de.attr |= ATTR_HIDDEN;
|
|
|
|
de.lcase = 0;
|
2008-11-06 20:53:47 +00:00
|
|
|
fat_time_unix2fat(sbi, ts, &time, &date, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
de.cdate = de.adate = 0;
|
|
|
|
de.ctime = 0;
|
|
|
|
de.ctime_cs = 0;
|
|
|
|
de.time = time;
|
|
|
|
de.date = date;
|
2012-07-30 21:42:13 +00:00
|
|
|
fat_set_start(&de, cluster);
|
2005-04-16 22:20:36 +00:00
|
|
|
de.size = 0;
|
|
|
|
|
|
|
|
err = fat_add_entries(dir, &de, 1, sinfo);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Create a file */
|
2023-01-13 11:49:13 +00:00
|
|
|
static int msdos_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;
|
2006-09-29 09:00:03 +00:00
|
|
|
struct inode *inode = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
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
|
|
|
unsigned char msdos_name[MSDOS_NAME];
|
|
|
|
int err, is_hid;
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
|
|
|
|
msdos_name, &MSDOS_SB(sb)->options);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
|
|
|
|
/* Have to do it due to foo vs. .foo conflicts */
|
|
|
|
if (!fat_scan(dir, msdos_name, &sinfo)) {
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:48:05 +00:00
|
|
|
ts = current_time(dir);
|
2018-08-22 04:59:48 +00:00
|
|
|
err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
|
|
|
goto out;
|
|
|
|
}
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2006-09-29 09:00:03 +00:00
|
|
|
if (!err)
|
|
|
|
err = fat_flush_inodes(sb, dir, inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Remove a directory */
|
|
|
|
static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2008-05-20 02:53:01 +00:00
|
|
|
struct super_block *sb = dir->i_sb;
|
2015-03-17 22:25:59 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
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 = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &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_CTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
fat_detach(inode);
|
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2006-09-29 09:00:03 +00:00
|
|
|
if (!err)
|
2008-05-20 02:53:01 +00:00
|
|
|
err = fat_flush_inodes(sb, dir, inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Make a directory */
|
2023-01-13 11:49:15 +00:00
|
|
|
static int msdos_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 fat_slot_info sinfo;
|
|
|
|
struct inode *inode;
|
|
|
|
unsigned char msdos_name[MSDOS_NAME];
|
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, is_hid, cluster;
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
|
|
|
|
msdos_name, &MSDOS_SB(sb)->options);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
|
|
|
|
/* foo vs .foo situation */
|
|
|
|
if (!fat_scan(dir, msdos_name, &sinfo)) {
|
|
|
|
brelse(sinfo.bh);
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
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 = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
goto out_free;
|
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;
|
|
|
|
}
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, 2);
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2006-09-29 09:00:03 +00:00
|
|
|
fat_flush_inodes(sb, dir, inode);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Unlink a file */
|
|
|
|
static int msdos_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-17 22:25:59 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2012-10-05 00:14:47 +00:00
|
|
|
struct super_block *sb = inode->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 = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &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_CTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
fat_detach(inode);
|
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2006-09-29 09:00:03 +00:00
|
|
|
if (!err)
|
2008-05-20 02:53:01 +00:00
|
|
|
err = fat_flush_inodes(sb, dir, inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
|
|
|
|
struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, unsigned char *new_name,
|
|
|
|
struct dentry *new_dentry, int is_hid)
|
|
|
|
{
|
|
|
|
struct buffer_head *dotdot_bh;
|
|
|
|
struct msdos_dir_entry *dotdot_de;
|
|
|
|
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;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err, old_attrs, is_dir, update_dotdot, corrupt = 0;
|
|
|
|
|
|
|
|
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);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = fat_scan(old_dir, old_name, &old_sinfo);
|
|
|
|
if (err) {
|
|
|
|
err = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
is_dir = S_ISDIR(old_inode->i_mode);
|
|
|
|
update_dotdot = (is_dir && old_dir != new_dir);
|
|
|
|
if (update_dotdot) {
|
2012-10-05 00:14:45 +00:00
|
|
|
if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
err = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
old_attrs = MSDOS_I(old_inode)->i_attrs;
|
|
|
|
err = fat_scan(new_dir, new_name, &sinfo);
|
|
|
|
if (!err) {
|
|
|
|
if (!new_inode) {
|
|
|
|
/* "foo" -> ".foo" case. just change the ATTR_HIDDEN */
|
|
|
|
if (sinfo.de != old_sinfo.de) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (is_hid)
|
|
|
|
MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
|
|
|
|
else
|
|
|
|
MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
|
|
|
|
if (IS_DIRSYNC(old_dir)) {
|
|
|
|
err = fat_sync_inode(old_inode);
|
|
|
|
if (err) {
|
|
|
|
MSDOS_I(old_inode)->i_attrs = old_attrs;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
mark_inode_dirty(old_inode);
|
|
|
|
|
2017-12-11 11:35:09 +00:00
|
|
|
inode_inc_iversion(old_dir);
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(old_dir, NULL, S_CTIME|S_MTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_DIRSYNC(old_dir))
|
|
|
|
(void)fat_sync_inode(old_dir);
|
|
|
|
else
|
|
|
|
mark_inode_dirty(old_dir);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:48:05 +00:00
|
|
|
ts = current_time(old_inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (new_inode) {
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
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 = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 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);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (is_hid)
|
|
|
|
MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
|
|
|
|
else
|
|
|
|
MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
|
|
|
|
if (IS_DIRSYNC(new_dir)) {
|
|
|
|
err = fat_sync_inode(old_inode);
|
|
|
|
if (err)
|
|
|
|
goto error_inode;
|
|
|
|
} else
|
|
|
|
mark_inode_dirty(old_inode);
|
|
|
|
|
|
|
|
if (update_dotdot) {
|
2012-07-30 21:42:13 +00:00
|
|
|
fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
|
2009-06-07 17:44:36 +00:00
|
|
|
mark_buffer_dirty_inode(dotdot_bh, old_inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_DIRSYNC(new_dir)) {
|
|
|
|
err = sync_dirty_buffer(dotdot_bh);
|
|
|
|
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;
|
2017-12-11 11:35:09 +00:00
|
|
|
inode_inc_iversion(old_dir);
|
2018-10-30 22:06:57 +00:00
|
|
|
fat_truncate_time(old_dir, &ts, S_CTIME|S_MTIME);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (IS_DIRSYNC(old_dir))
|
|
|
|
(void)fat_sync_inode(old_dir);
|
|
|
|
else
|
|
|
|
mark_inode_dirty(old_dir);
|
|
|
|
|
|
|
|
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);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
error_dotdot:
|
|
|
|
/* data cluster is shared, serious corruption */
|
|
|
|
corrupt = 1;
|
|
|
|
|
|
|
|
if (update_dotdot) {
|
2012-07-30 21:42:13 +00:00
|
|
|
fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
|
2009-06-07 17:44:36 +00:00
|
|
|
mark_buffer_dirty_inode(dotdot_bh, old_inode);
|
2005-04-16 22:20:36 +00:00
|
|
|
corrupt |= sync_dirty_buffer(dotdot_bh);
|
|
|
|
}
|
|
|
|
error_inode:
|
|
|
|
fat_detach(old_inode);
|
|
|
|
fat_attach(old_inode, old_sinfo.i_pos);
|
|
|
|
MSDOS_I(old_inode)->i_attrs = old_attrs;
|
|
|
|
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)",
|
2008-04-30 07:55:09 +00:00
|
|
|
__func__, sinfo.i_pos);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
|
2023-01-13 11:49:17 +00:00
|
|
|
static int msdos_rename(struct mnt_idmap *idmap,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct inode *old_dir, struct dentry *old_dentry,
|
fs: support RENAME_NOREPLACE for local filesystems
This is trivial to do:
- add flags argument to foo_rename()
- check if flags doesn't have any other than RENAME_NOREPLACE
- assign foo_rename() to .rename2 instead of .rename
Filesystems converted:
affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos,
nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: Boaz Harrosh <ooo@electrozaur.com>
Acked-by: Richard Weinberger <richard@nod.at>
Acked-by: Bob Copeland <me@bobcopeland.com>
Acked-by: Jan Kara <jack@suse.cz>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dave Kleikamp <shaggy@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Christoph Hellwig <hch@infradead.org>
2016-09-27 09:03:57 +00:00
|
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-05-20 02:53:01 +00:00
|
|
|
struct super_block *sb = old_dir->i_sb;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
|
|
|
|
int err, is_hid;
|
|
|
|
|
fs: support RENAME_NOREPLACE for local filesystems
This is trivial to do:
- add flags argument to foo_rename()
- check if flags doesn't have any other than RENAME_NOREPLACE
- assign foo_rename() to .rename2 instead of .rename
Filesystems converted:
affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos,
nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: Boaz Harrosh <ooo@electrozaur.com>
Acked-by: Richard Weinberger <richard@nod.at>
Acked-by: Bob Copeland <me@bobcopeland.com>
Acked-by: Jan Kara <jack@suse.cz>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dave Kleikamp <shaggy@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Christoph Hellwig <hch@infradead.org>
2016-09-27 09:03:57 +00:00
|
|
|
if (flags & ~RENAME_NOREPLACE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_lock(&MSDOS_SB(sb)->s_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = msdos_format_name(old_dentry->d_name.name,
|
|
|
|
old_dentry->d_name.len, old_msdos_name,
|
|
|
|
&MSDOS_SB(old_dir->i_sb)->options);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
err = msdos_format_name(new_dentry->d_name.name,
|
|
|
|
new_dentry->d_name.len, new_msdos_name,
|
|
|
|
&MSDOS_SB(new_dir->i_sb)->options);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
is_hid =
|
|
|
|
(new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.');
|
|
|
|
|
|
|
|
err = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
|
|
|
|
new_dir, new_msdos_name, new_dentry, is_hid);
|
|
|
|
out:
|
2012-10-06 10:40:03 +00:00
|
|
|
mutex_unlock(&MSDOS_SB(sb)->s_lock);
|
2006-09-29 09:00:03 +00:00
|
|
|
if (!err)
|
2008-05-20 02:53:01 +00:00
|
|
|
err = fat_flush_inodes(sb, old_dir, new_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-02-12 08:55:39 +00:00
|
|
|
static const struct inode_operations msdos_dir_inode_operations = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.create = msdos_create,
|
|
|
|
.lookup = msdos_lookup,
|
|
|
|
.unlink = msdos_unlink,
|
|
|
|
.mkdir = msdos_mkdir,
|
|
|
|
.rmdir = msdos_rmdir,
|
|
|
|
.rename = msdos_rename,
|
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 = &msdos_dir_inode_operations;
|
2010-12-18 15:44:00 +00:00
|
|
|
sb->s_d_op = &msdos_dentry_operations;
|
2017-11-27 21:05:09 +00:00
|
|
|
sb->s_flags |= SB_NOATIME;
|
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
|
|
|
static int msdos_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 msdos_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, msdos_fill_super);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int msdos_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
|
|
|
{
|
|
|
|
return fat_parse_param(fc, param, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations msdos_context_ops = {
|
|
|
|
.parse_param = msdos_parse_param,
|
|
|
|
.get_tree = msdos_get_tree,
|
|
|
|
.reconfigure = fat_reconfigure,
|
|
|
|
.free = fat_free_fc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int msdos_init_fs_context(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Initialize with is_vfat == false */
|
|
|
|
err = fat_init_fs_context(fc, false);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
fc->ops = &msdos_context_ops;
|
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type msdos_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "msdos",
|
|
|
|
.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 = msdos_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("msdos");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int __init init_msdos_fs(void)
|
|
|
|
{
|
|
|
|
return register_filesystem(&msdos_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_msdos_fs(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&msdos_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Werner Almesberger");
|
|
|
|
MODULE_DESCRIPTION("MS-DOS filesystem support");
|
|
|
|
|
|
|
|
module_init(init_msdos_fs)
|
|
|
|
module_exit(exit_msdos_fs)
|