Commit 23059a0d authored by Linus Torvalds's avatar Linus Torvalds
parents 4858704d 21bea495
...@@ -132,6 +132,11 @@ rodir -- FAT has the ATTR_RO (read-only) attribute. On Windows, ...@@ -132,6 +132,11 @@ rodir -- FAT has the ATTR_RO (read-only) attribute. On Windows,
If you want to use ATTR_RO as read-only flag even for If you want to use ATTR_RO as read-only flag even for
the directory, set this option. the directory, set this option.
errors=panic|continue|remount-ro
-- specify FAT behavior on critical errors: panic, continue
without doing anything or remount the partition in
read-only mode (default behavior).
<bool>: 0,1,yes,no,true,false <bool>: 0,1,yes,no,true,false
TODO TODO
......
...@@ -241,7 +241,7 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus) ...@@ -241,7 +241,7 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
while (*fclus < cluster) { while (*fclus < cluster) {
/* prevent the infinite loop of cluster chain */ /* prevent the infinite loop of cluster chain */
if (*fclus > limit) { if (*fclus > limit) {
fat_fs_panic(sb, "%s: detected the cluster chain loop" fat_fs_error(sb, "%s: detected the cluster chain loop"
" (i_pos %lld)", __func__, " (i_pos %lld)", __func__,
MSDOS_I(inode)->i_pos); MSDOS_I(inode)->i_pos);
nr = -EIO; nr = -EIO;
...@@ -252,7 +252,7 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus) ...@@ -252,7 +252,7 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
if (nr < 0) if (nr < 0)
goto out; goto out;
else if (nr == FAT_ENT_FREE) { else if (nr == FAT_ENT_FREE) {
fat_fs_panic(sb, "%s: invalid cluster chain" fat_fs_error(sb, "%s: invalid cluster chain"
" (i_pos %lld)", __func__, " (i_pos %lld)", __func__,
MSDOS_I(inode)->i_pos); MSDOS_I(inode)->i_pos);
nr = -EIO; nr = -EIO;
...@@ -285,7 +285,7 @@ static int fat_bmap_cluster(struct inode *inode, int cluster) ...@@ -285,7 +285,7 @@ static int fat_bmap_cluster(struct inode *inode, int cluster)
if (ret < 0) if (ret < 0)
return ret; return ret;
else if (ret == FAT_ENT_EOF) { else if (ret == FAT_ENT_EOF) {
fat_fs_panic(sb, "%s: request beyond EOF (i_pos %lld)", fat_fs_error(sb, "%s: request beyond EOF (i_pos %lld)",
__func__, MSDOS_I(inode)->i_pos); __func__, MSDOS_I(inode)->i_pos);
return -EIO; return -EIO;
} }
......
...@@ -1334,7 +1334,7 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots, ...@@ -1334,7 +1334,7 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
goto error_remove; goto error_remove;
} }
if (dir->i_size & (sbi->cluster_size - 1)) { if (dir->i_size & (sbi->cluster_size - 1)) {
fat_fs_panic(sb, "Odd directory size"); fat_fs_error(sb, "Odd directory size");
dir->i_size = (dir->i_size + sbi->cluster_size - 1) dir->i_size = (dir->i_size + sbi->cluster_size - 1)
& ~((loff_t)sbi->cluster_size - 1); & ~((loff_t)sbi->cluster_size - 1);
} }
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
#define VFAT_SFN_CREATE_WIN95 0x0100 /* emulate win95 rule for create */ #define VFAT_SFN_CREATE_WIN95 0x0100 /* emulate win95 rule for create */
#define VFAT_SFN_CREATE_WINNT 0x0200 /* emulate winnt rule for create */ #define VFAT_SFN_CREATE_WINNT 0x0200 /* emulate winnt rule for create */
#define FAT_ERRORS_CONT 1 /* ignore error and continue */
#define FAT_ERRORS_PANIC 2 /* panic on error */
#define FAT_ERRORS_RO 3 /* remount r/o on error */
struct fat_mount_options { struct fat_mount_options {
uid_t fs_uid; uid_t fs_uid;
gid_t fs_gid; gid_t fs_gid;
...@@ -26,6 +30,7 @@ struct fat_mount_options { ...@@ -26,6 +30,7 @@ struct fat_mount_options {
char *iocharset; /* Charset used for filename input/display */ char *iocharset; /* Charset used for filename input/display */
unsigned short shortname; /* flags for shortname display/create rule */ unsigned short shortname; /* flags for shortname display/create rule */
unsigned char name_check; /* r = relaxed, n = normal, s = strict */ unsigned char name_check; /* r = relaxed, n = normal, s = strict */
unsigned char errors; /* On error: continue, panic, remount-ro */
unsigned short allow_utime;/* permission for setting the [am]time */ unsigned short allow_utime;/* permission for setting the [am]time */
unsigned quiet:1, /* set = fake successful chmods and chowns */ unsigned quiet:1, /* set = fake successful chmods and chowns */
showexec:1, /* set = only set x bit for com/exe/bat */ showexec:1, /* set = only set x bit for com/exe/bat */
...@@ -316,7 +321,7 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent, ...@@ -316,7 +321,7 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent,
extern int fat_flush_inodes(struct super_block *sb, struct inode *i1, extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
struct inode *i2); struct inode *i2);
/* fat/misc.c */ /* fat/misc.c */
extern void fat_fs_panic(struct super_block *s, const char *fmt, ...) extern void fat_fs_error(struct super_block *s, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3))) __cold; __attribute__ ((format (printf, 2, 3))) __cold;
extern void fat_clusters_flush(struct super_block *sb); extern void fat_clusters_flush(struct super_block *sb);
extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster); extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster);
......
...@@ -348,7 +348,7 @@ int fat_ent_read(struct inode *inode, struct fat_entry *fatent, int entry) ...@@ -348,7 +348,7 @@ int fat_ent_read(struct inode *inode, struct fat_entry *fatent, int entry)
if (entry < FAT_START_ENT || sbi->max_cluster <= entry) { if (entry < FAT_START_ENT || sbi->max_cluster <= entry) {
fatent_brelse(fatent); fatent_brelse(fatent);
fat_fs_panic(sb, "invalid access to FAT (entry 0x%08x)", entry); fat_fs_error(sb, "invalid access to FAT (entry 0x%08x)", entry);
return -EIO; return -EIO;
} }
...@@ -560,7 +560,7 @@ int fat_free_clusters(struct inode *inode, int cluster) ...@@ -560,7 +560,7 @@ int fat_free_clusters(struct inode *inode, int cluster)
err = cluster; err = cluster;
goto error; goto error;
} else if (cluster == FAT_ENT_FREE) { } else if (cluster == FAT_ENT_FREE) {
fat_fs_panic(sb, "%s: deleting FAT entry beyond EOF", fat_fs_error(sb, "%s: deleting FAT entry beyond EOF",
__func__); __func__);
err = -EIO; err = -EIO;
goto error; goto error;
......
...@@ -18,15 +18,8 @@ ...@@ -18,15 +18,8 @@
#include <linux/security.h> #include <linux/security.h>
#include "fat.h" #include "fat.h"
int fat_generic_ioctl(struct inode *inode, struct file *filp, static int fat_ioctl_get_attributes(struct inode *inode, u32 __user *user_attr)
unsigned int cmd, unsigned long arg)
{ {
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
u32 __user *user_attr = (u32 __user *)arg;
switch (cmd) {
case FAT_IOCTL_GET_ATTRIBUTES:
{
u32 attr; u32 attr;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
...@@ -34,22 +27,25 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp, ...@@ -34,22 +27,25 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return put_user(attr, user_attr); return put_user(attr, user_attr);
} }
case FAT_IOCTL_SET_ATTRIBUTES:
{ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
{
struct inode *inode = file->f_path.dentry->d_inode;
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
int is_dir = S_ISDIR(inode->i_mode);
u32 attr, oldattr; u32 attr, oldattr;
int err, is_dir = S_ISDIR(inode->i_mode);
struct iattr ia; struct iattr ia;
int err;
err = get_user(attr, user_attr); err = get_user(attr, user_attr);
if (err) if (err)
return err; goto out;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
err = mnt_want_write(file->f_path.mnt);
err = mnt_want_write(filp->f_path.mnt);
if (err) if (err)
goto up_no_drop_write; goto out_unlock_inode;
/* /*
* ATTR_VOLUME and ATTR_DIR cannot be changed; this also * ATTR_VOLUME and ATTR_DIR cannot be changed; this also
...@@ -76,16 +72,14 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp, ...@@ -76,16 +72,14 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
/* The root directory has no attributes */ /* The root directory has no attributes */
if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) { if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) {
err = -EINVAL; err = -EINVAL;
goto up; goto out_drop_write;
} }
if (sbi->options.sys_immutable) { if (sbi->options.sys_immutable &&
if ((attr | oldattr) & ATTR_SYS) { ((attr | oldattr) & ATTR_SYS) &&
if (!capable(CAP_LINUX_IMMUTABLE)) { !capable(CAP_LINUX_IMMUTABLE)) {
err = -EPERM; err = -EPERM;
goto up; goto out_drop_write;
}
}
} }
/* /*
...@@ -93,16 +87,16 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp, ...@@ -93,16 +87,16 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
* out the RO attribute for checking by the security * out the RO attribute for checking by the security
* module, just because it maps to a file mode. * module, just because it maps to a file mode.
*/ */
err = security_inode_setattr(filp->f_path.dentry, &ia); err = security_inode_setattr(file->f_path.dentry, &ia);
if (err) if (err)
goto up; goto out_drop_write;
/* This MUST be done before doing anything irreversible... */ /* This MUST be done before doing anything irreversible... */
err = fat_setattr(filp->f_path.dentry, &ia); err = fat_setattr(file->f_path.dentry, &ia);
if (err) if (err)
goto up; goto out_drop_write;
fsnotify_change(filp->f_path.dentry, ia.ia_valid); fsnotify_change(file->f_path.dentry, ia.ia_valid);
if (sbi->options.sys_immutable) { if (sbi->options.sys_immutable) {
if (attr & ATTR_SYS) if (attr & ATTR_SYS)
inode->i_flags |= S_IMMUTABLE; inode->i_flags |= S_IMMUTABLE;
...@@ -112,12 +106,24 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp, ...@@ -112,12 +106,24 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
fat_save_attrs(inode, attr); fat_save_attrs(inode, attr);
mark_inode_dirty(inode); mark_inode_dirty(inode);
up: out_drop_write:
mnt_drop_write(filp->f_path.mnt); mnt_drop_write(file->f_path.mnt);
up_no_drop_write: out_unlock_inode:
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
out:
return err; return err;
} }
int fat_generic_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
u32 __user *user_attr = (u32 __user *)arg;
switch (cmd) {
case FAT_IOCTL_GET_ATTRIBUTES:
return fat_ioctl_get_attributes(inode, user_attr);
case FAT_IOCTL_SET_ATTRIBUTES:
return fat_ioctl_set_attributes(filp, user_attr);
default: default:
return -ENOTTY; /* Inappropriate ioctl for device */ return -ENOTTY; /* Inappropriate ioctl for device */
} }
...@@ -225,7 +231,7 @@ static int fat_free(struct inode *inode, int skip) ...@@ -225,7 +231,7 @@ static int fat_free(struct inode *inode, int skip)
fatent_brelse(&fatent); fatent_brelse(&fatent);
return 0; return 0;
} else if (ret == FAT_ENT_FREE) { } else if (ret == FAT_ENT_FREE) {
fat_fs_panic(sb, fat_fs_error(sb,
"%s: invalid cluster chain (i_pos %lld)", "%s: invalid cluster chain (i_pos %lld)",
__func__, MSDOS_I(inode)->i_pos); __func__, MSDOS_I(inode)->i_pos);
ret = -EIO; ret = -EIO;
......
...@@ -76,7 +76,7 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock, ...@@ -76,7 +76,7 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,
return 0; return 0;
if (iblock != MSDOS_I(inode)->mmu_private >> sb->s_blocksize_bits) { if (iblock != MSDOS_I(inode)->mmu_private >> sb->s_blocksize_bits) {
fat_fs_panic(sb, "corrupted file size (i_pos %lld, %lld)", fat_fs_error(sb, "corrupted file size (i_pos %lld, %lld)",
MSDOS_I(inode)->i_pos, MSDOS_I(inode)->mmu_private); MSDOS_I(inode)->i_pos, MSDOS_I(inode)->mmu_private);
return -EIO; return -EIO;
} }
...@@ -856,6 +856,12 @@ static int fat_show_options(struct seq_file *m, struct vfsmount *mnt) ...@@ -856,6 +856,12 @@ static int fat_show_options(struct seq_file *m, struct vfsmount *mnt)
seq_puts(m, ",flush"); seq_puts(m, ",flush");
if (opts->tz_utc) if (opts->tz_utc)
seq_puts(m, ",tz=UTC"); seq_puts(m, ",tz=UTC");
if (opts->errors == FAT_ERRORS_CONT)
seq_puts(m, ",errors=continue");
else if (opts->errors == FAT_ERRORS_PANIC)
seq_puts(m, ",errors=panic");
else
seq_puts(m, ",errors=remount-ro");
return 0; return 0;
} }
...@@ -868,7 +874,8 @@ enum { ...@@ -868,7 +874,8 @@ enum {
Opt_charset, Opt_shortname_lower, Opt_shortname_win95, Opt_charset, Opt_shortname_lower, Opt_shortname_win95,
Opt_shortname_winnt, Opt_shortname_mixed, Opt_utf8_no, Opt_utf8_yes, Opt_shortname_winnt, Opt_shortname_mixed, Opt_utf8_no, Opt_utf8_yes,
Opt_uni_xl_no, Opt_uni_xl_yes, Opt_nonumtail_no, Opt_nonumtail_yes, Opt_uni_xl_no, Opt_uni_xl_yes, Opt_nonumtail_no, Opt_nonumtail_yes,
Opt_obsolate, Opt_flush, Opt_tz_utc, Opt_rodir, Opt_err, Opt_obsolate, Opt_flush, Opt_tz_utc, Opt_rodir, Opt_err_cont,
Opt_err_panic, Opt_err_ro, Opt_err,
}; };
static const match_table_t fat_tokens = { static const match_table_t fat_tokens = {
...@@ -891,6 +898,11 @@ static const match_table_t fat_tokens = { ...@@ -891,6 +898,11 @@ static const match_table_t fat_tokens = {
{Opt_showexec, "showexec"}, {Opt_showexec, "showexec"},
{Opt_debug, "debug"}, {Opt_debug, "debug"},
{Opt_immutable, "sys_immutable"}, {Opt_immutable, "sys_immutable"},
{Opt_flush, "flush"},
{Opt_tz_utc, "tz=UTC"},
{Opt_err_cont, "errors=continue"},
{Opt_err_panic, "errors=panic"},
{Opt_err_ro, "errors=remount-ro"},
{Opt_obsolate, "conv=binary"}, {Opt_obsolate, "conv=binary"},
{Opt_obsolate, "conv=text"}, {Opt_obsolate, "conv=text"},
{Opt_obsolate, "conv=auto"}, {Opt_obsolate, "conv=auto"},
...@@ -902,8 +914,6 @@ static const match_table_t fat_tokens = { ...@@ -902,8 +914,6 @@ static const match_table_t fat_tokens = {
{Opt_obsolate, "cvf_format=%20s"}, {Opt_obsolate, "cvf_format=%20s"},
{Opt_obsolate, "cvf_options=%100s"}, {Opt_obsolate, "cvf_options=%100s"},
{Opt_obsolate, "posix"}, {Opt_obsolate, "posix"},
{Opt_flush, "flush"},
{Opt_tz_utc, "tz=UTC"},
{Opt_err, NULL}, {Opt_err, NULL},
}; };
static const match_table_t msdos_tokens = { static const match_table_t msdos_tokens = {
...@@ -973,6 +983,7 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug, ...@@ -973,6 +983,7 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,
opts->numtail = 1; opts->numtail = 1;
opts->usefree = opts->nocase = 0; opts->usefree = opts->nocase = 0;
opts->tz_utc = 0; opts->tz_utc = 0;
opts->errors = FAT_ERRORS_RO;
*debug = 0; *debug = 0;
if (!options) if (!options)
...@@ -1065,6 +1076,15 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug, ...@@ -1065,6 +1076,15 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,
case Opt_tz_utc: case Opt_tz_utc:
opts->tz_utc = 1; opts->tz_utc = 1;
break; break;
case Opt_err_cont:
opts->errors = FAT_ERRORS_CONT;
break;
case Opt_err_panic:
opts->errors = FAT_ERRORS_PANIC;
break;
case Opt_err_ro:
opts->errors = FAT_ERRORS_RO;
break;
/* msdos specific */ /* msdos specific */
case Opt_dots: case Opt_dots:
......
...@@ -12,14 +12,19 @@ ...@@ -12,14 +12,19 @@
#include "fat.h" #include "fat.h"
/* /*
* fat_fs_panic reports a severe file system problem and sets the file system * fat_fs_error reports a file system problem that might indicate fa data
* read-only. The file system can be made writable again by remounting it. * corruption/inconsistency. Depending on 'errors' mount option the
* panic() is called, or error message is printed FAT and nothing is done,
* or filesystem is remounted read-only (default behavior).
* In case the file system is remounted read-only, it can be made writable
* again by remounting it.
*/ */
void fat_fs_panic(struct super_block *s, const char *fmt, ...) void fat_fs_error(struct super_block *s, const char *fmt, ...)
{ {
struct fat_mount_options *opts = &MSDOS_SB(s)->options;
va_list args; va_list args;
printk(KERN_ERR "FAT: Filesystem panic (dev %s)\n", s->s_id); printk(KERN_ERR "FAT: Filesystem error (dev %s)\n", s->s_id);
printk(KERN_ERR " "); printk(KERN_ERR " ");
va_start(args, fmt); va_start(args, fmt);
...@@ -27,13 +32,14 @@ void fat_fs_panic(struct super_block *s, const char *fmt, ...) ...@@ -27,13 +32,14 @@ void fat_fs_panic(struct super_block *s, const char *fmt, ...)
va_end(args); va_end(args);
printk("\n"); printk("\n");
if (!(s->s_flags & MS_RDONLY)) { if (opts->errors == FAT_ERRORS_PANIC)
panic(" FAT fs panic from previous error\n");
else if (opts->errors == FAT_ERRORS_RO && !(s->s_flags & MS_RDONLY)) {
s->s_flags |= MS_RDONLY; s->s_flags |= MS_RDONLY;
printk(KERN_ERR " File system has been set read-only\n"); printk(KERN_ERR " File system has been set read-only\n");
} }
} }
EXPORT_SYMBOL_GPL(fat_fs_error);
EXPORT_SYMBOL_GPL(fat_fs_panic);
/* Flushes the number of free clusters on FAT32 */ /* Flushes the number of free clusters on FAT32 */
/* XXX: Need to write one per FSINFO block. Currently only writes 1 */ /* XXX: Need to write one per FSINFO block. Currently only writes 1 */
...@@ -124,7 +130,7 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster) ...@@ -124,7 +130,7 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
mark_inode_dirty(inode); mark_inode_dirty(inode);
} }
if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits - 9))) { if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits - 9))) {
fat_fs_panic(sb, "clusters badly computed (%d != %llu)", fat_fs_error(sb, "clusters badly computed (%d != %llu)",
new_fclus, new_fclus,
(llu)(inode->i_blocks >> (sbi->cluster_bits - 9))); (llu)(inode->i_blocks >> (sbi->cluster_bits - 9)));
fat_cache_inval_inode(inode); fat_cache_inval_inode(inode);
......
...@@ -608,7 +608,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, ...@@ -608,7 +608,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
sinfo.bh = NULL; sinfo.bh = NULL;
} }
if (corrupt < 0) { if (corrupt < 0) {
fat_fs_panic(new_dir->i_sb, fat_fs_error(new_dir->i_sb,
"%s: Filesystem corrupted (i_pos %lld)", "%s: Filesystem corrupted (i_pos %lld)",
__func__, sinfo.i_pos); __func__, sinfo.i_pos);
} }
......
...@@ -1030,7 +1030,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -1030,7 +1030,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
sinfo.bh = NULL; sinfo.bh = NULL;
} }
if (corrupt < 0) { if (corrupt < 0) {
fat_fs_panic(new_dir->i_sb, fat_fs_error(new_dir->i_sb,
"%s: Filesystem corrupted (i_pos %lld)", "%s: Filesystem corrupted (i_pos %lld)",
__func__, sinfo.i_pos); __func__, sinfo.i_pos);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment