isofs: Fix off-by-one in 'session' mount option parsing
[sfrench/cifs-2.6.git] / fs / isofs / inode.c
index 020ba093614641e02920cf622840444c47edbbc1..217a5e7815da6a896daeddb53d8200dcba56a303 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/parser.h>
 #include <linux/mpage.h>
 #include <linux/user_namespace.h>
+#include <linux/seq_file.h>
 
 #include "isofs.h"
 #include "zisofs.h"
@@ -57,6 +58,7 @@ static void isofs_put_super(struct super_block *sb)
 
 static int isofs_read_inode(struct inode *, int relocated);
 static int isofs_statfs (struct dentry *, struct kstatfs *);
+static int isofs_show_options(struct seq_file *, struct dentry *);
 
 static struct kmem_cache *isofs_inode_cachep;
 
@@ -123,7 +125,7 @@ static const struct super_operations isofs_sops = {
        .put_super      = isofs_put_super,
        .statfs         = isofs_statfs,
        .remount_fs     = isofs_remount,
-       .show_options   = generic_show_options,
+       .show_options   = isofs_show_options,
 };
 
 
@@ -408,7 +410,11 @@ static int parse_options(char *options, struct iso9660_options *popt)
                        if (match_int(&args[0], &option))
                                return 0;
                        n = option;
-                       if (n > 99)
+                       /*
+                        * Track numbers are supposed to be in range 1-99, the
+                        * mount option starts indexing at 0.
+                        */
+                       if (n >= 99)
                                return 0;
                        popt->session = n + 1;
                        break;
@@ -472,6 +478,48 @@ static int parse_options(char *options, struct iso9660_options *popt)
        return 1;
 }
 
+/*
+ * Display the mount options in /proc/mounts.
+ */
+static int isofs_show_options(struct seq_file *m, struct dentry *root)
+{
+       struct isofs_sb_info *sbi = ISOFS_SB(root->d_sb);
+
+       if (!sbi->s_rock)               seq_puts(m, ",norock");
+       else if (!sbi->s_joliet_level)  seq_puts(m, ",nojoliet");
+       if (sbi->s_cruft)               seq_puts(m, ",cruft");
+       if (sbi->s_hide)                seq_puts(m, ",hide");
+       if (sbi->s_nocompress)          seq_puts(m, ",nocompress");
+       if (sbi->s_overriderockperm)    seq_puts(m, ",overriderockperm");
+       if (sbi->s_showassoc)           seq_puts(m, ",showassoc");
+       if (sbi->s_utf8)                seq_puts(m, ",utf8");
+
+       if (sbi->s_check)               seq_printf(m, ",check=%c", sbi->s_check);
+       if (sbi->s_mapping)             seq_printf(m, ",map=%c", sbi->s_mapping);
+       if (sbi->s_session != 255)      seq_printf(m, ",session=%u", sbi->s_session - 1);
+       if (sbi->s_sbsector != -1)      seq_printf(m, ",sbsector=%u", sbi->s_sbsector);
+
+       if (root->d_sb->s_blocksize != 1024)
+               seq_printf(m, ",blocksize=%lu", root->d_sb->s_blocksize);
+
+       if (sbi->s_uid_set)
+               seq_printf(m, ",uid=%u",
+                          from_kuid_munged(&init_user_ns, sbi->s_uid));
+       if (sbi->s_gid_set)
+               seq_printf(m, ",gid=%u",
+                          from_kgid_munged(&init_user_ns, sbi->s_gid));
+
+       if (sbi->s_dmode != ISOFS_INVALID_MODE)
+               seq_printf(m, ",dmode=%o", sbi->s_dmode);
+       if (sbi->s_fmode != ISOFS_INVALID_MODE)
+               seq_printf(m, ",fmode=%o", sbi->s_fmode);
+
+       if (sbi->s_nls_iocharset &&
+           strcmp(sbi->s_nls_iocharset->charset, CONFIG_NLS_DEFAULT) != 0)
+               seq_printf(m, ",iocharset=%s", sbi->s_nls_iocharset->charset);
+       return 0;
+}
+
 /*
  * look if the driver can tell the multi session redirection value
  *
@@ -499,7 +547,7 @@ static unsigned int isofs_get_last_session(struct super_block *sb, s32 session)
 
        vol_desc_start=0;
        ms_info.addr_format=CDROM_LBA;
-       if(session >= 0 && session <= 99) {
+       if (session > 0) {
                struct cdrom_tocentry Te;
                Te.cdte_track=session;
                Te.cdte_format=CDROM_LBA;
@@ -583,8 +631,6 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
        int table, error = -EINVAL;
        unsigned int vol_desc_start;
 
-       save_mount_options(s, data);
-
        sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
@@ -605,6 +651,8 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
        opt.blocksize = sb_min_blocksize(s, opt.blocksize);
 
        sbi->s_high_sierra = 0; /* default is iso9660 */
+       sbi->s_session = opt.session;
+       sbi->s_sbsector = opt.sbsector;
 
        vol_desc_start = (opt.sbsector != -1) ?
                opt.sbsector : isofs_get_last_session(s,opt.session);
@@ -911,6 +959,7 @@ root_found:
                table += 2;
        if (opt.check == 'r')
                table++;
+       sbi->s_check = opt.check;
 
        if (table)
                s->s_d_op = &isofs_dentry_ops[table - 1];