Skip to content

Commit 79c0b2d

Browse files
Miklos SzerediLinus Torvalds
authored andcommitted
add filesystem subtype support
There's a slight problem with filesystem type representation in fuse based filesystems. From the kernel's view, there are just two filesystem types: fuse and fuseblk. From the user's view there are lots of different filesystem types. The user is not even much concerned if the filesystem is fuse based or not. So there's a conflict of interest in how this should be represented in fstab, mtab and /proc/mounts. The current scheme is to encode the real filesystem type in the mount source. So an sshfs mount looks like this: sshfs#user@server:/ /mnt/server fuse rw,nosuid,nodev,... This url-ish syntax works OK for sshfs and similar filesystems. However for block device based filesystems (ntfs-3g, zfs) it doesn't work, since the kernel expects the mount source to be a real device name. A possibly better scheme would be to encode the real type in the type field as "type.subtype". So fuse mounts would look like this: /dev/hda1 /mnt/windows fuseblk.ntfs-3g rw,... user@server:/ /mnt/server fuse.sshfs rw,nosuid,nodev,... This patch adds the necessary code to the kernel so that this can be correctly displayed in /proc/mounts. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 880afc4 commit 79c0b2d

5 files changed

Lines changed: 55 additions & 6 deletions

File tree

‎fs/filesystems.c‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ void put_filesystem(struct file_system_type *fs)
4141
module_put(fs->owner);
4242
}
4343

44-
static struct file_system_type **find_filesystem(const char *name)
44+
static struct file_system_type **find_filesystem(const char *name, unsigned len)
4545
{
4646
struct file_system_type **p;
4747
for (p=&file_systems; *p; p=&(*p)->next)
48-
if (strcmp((*p)->name,name) == 0)
48+
if (strlen((*p)->name) == len &&
49+
strncmp((*p)->name, name, len) == 0)
4950
break;
5051
return p;
5152
}
@@ -68,11 +69,12 @@ int register_filesystem(struct file_system_type * fs)
6869
int res = 0;
6970
struct file_system_type ** p;
7071

72+
BUG_ON(strchr(fs->name, '.'));
7173
if (fs->next)
7274
return -EBUSY;
7375
INIT_LIST_HEAD(&fs->fs_supers);
7476
write_lock(&file_systems_lock);
75-
p = find_filesystem(fs->name);
77+
p = find_filesystem(fs->name, strlen(fs->name));
7678
if (*p)
7779
res = -EBUSY;
7880
else
@@ -215,19 +217,26 @@ int get_filesystem_list(char * buf)
215217
struct file_system_type *get_fs_type(const char *name)
216218
{
217219
struct file_system_type *fs;
220+
const char *dot = strchr(name, '.');
221+
unsigned len = dot ? dot - name : strlen(name);
218222

219223
read_lock(&file_systems_lock);
220-
fs = *(find_filesystem(name));
224+
fs = *(find_filesystem(name, len));
221225
if (fs && !try_module_get(fs->owner))
222226
fs = NULL;
223227
read_unlock(&file_systems_lock);
224-
if (!fs && (request_module("%s", name) == 0)) {
228+
if (!fs && (request_module("%.*s", len, name) == 0)) {
225229
read_lock(&file_systems_lock);
226-
fs = *(find_filesystem(name));
230+
fs = *(find_filesystem(name, len));
227231
if (fs && !try_module_get(fs->owner))
228232
fs = NULL;
229233
read_unlock(&file_systems_lock);
230234
}
235+
236+
if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
237+
put_filesystem(fs);
238+
fs = NULL;
239+
}
231240
return fs;
232241
}
233242

‎fs/fuse/inode.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ static int fuse_get_sb(struct file_system_type *fs_type,
636636
static struct file_system_type fuse_fs_type = {
637637
.owner = THIS_MODULE,
638638
.name = "fuse",
639+
.fs_flags = FS_HAS_SUBTYPE,
639640
.get_sb = fuse_get_sb,
640641
.kill_sb = kill_anon_super,
641642
};
@@ -652,6 +653,7 @@ static int fuse_get_sb_blk(struct file_system_type *fs_type,
652653
static struct file_system_type fuseblk_fs_type = {
653654
.owner = THIS_MODULE,
654655
.name = "fuseblk",
656+
.fs_flags = FS_HAS_SUBTYPE,
655657
.get_sb = fuse_get_sb_blk,
656658
.kill_sb = kill_block_super,
657659
.fs_flags = FS_REQUIRES_DEV,

‎fs/namespace.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ static int show_vfsmnt(struct seq_file *m, void *v)
377377
seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
378378
seq_putc(m, ' ');
379379
mangle(m, mnt->mnt_sb->s_type->name);
380+
if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
381+
seq_putc(m, '.');
382+
mangle(m, mnt->mnt_sb->s_subtype);
383+
}
380384
seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
381385
for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
382386
if (mnt->mnt_sb->s_flags & fs_infop->flag)

‎fs/super.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
107107
static inline void destroy_super(struct super_block *s)
108108
{
109109
security_sb_free(s);
110+
kfree(s->s_subtype);
110111
kfree(s);
111112
}
112113

@@ -907,6 +908,29 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
907908

908909
EXPORT_SYMBOL_GPL(vfs_kern_mount);
909910

911+
static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype)
912+
{
913+
int err;
914+
const char *subtype = strchr(fstype, '.');
915+
if (subtype) {
916+
subtype++;
917+
err = -EINVAL;
918+
if (!subtype[0])
919+
goto err;
920+
} else
921+
subtype = "";
922+
923+
mnt->mnt_sb->s_subtype = kstrdup(subtype, GFP_KERNEL);
924+
err = -ENOMEM;
925+
if (!mnt->mnt_sb->s_subtype)
926+
goto err;
927+
return mnt;
928+
929+
err:
930+
mntput(mnt);
931+
return ERR_PTR(err);
932+
}
933+
910934
struct vfsmount *
911935
do_kern_mount(const char *fstype, int flags, const char *name, void *data)
912936
{
@@ -915,6 +939,9 @@ do_kern_mount(const char *fstype, int flags, const char *name, void *data)
915939
if (!type)
916940
return ERR_PTR(-ENODEV);
917941
mnt = vfs_kern_mount(type, flags, name, data);
942+
if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
943+
!mnt->mnt_sb->s_subtype)
944+
mnt = fs_set_subtype(mnt, fstype);
918945
put_filesystem(type);
919946
return mnt;
920947
}

‎include/linux/fs.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern int dir_notify_enable;
9292
/* public flags for file_system_type */
9393
#define FS_REQUIRES_DEV 1
9494
#define FS_BINARY_MOUNTDATA 2
95+
#define FS_HAS_SUBTYPE 4
9596
#define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */
9697
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move()
9798
* during rename() internally.
@@ -961,6 +962,12 @@ struct super_block {
961962
/* Granularity of c/m/atime in ns.
962963
Cannot be worse than a second */
963964
u32 s_time_gran;
965+
966+
/*
967+
* Filesystem subtype. If non-empty the filesystem type field
968+
* in /proc/mounts will be "type.subtype"
969+
*/
970+
char *s_subtype;
964971
};
965972

966973
extern struct timespec current_fs_time(struct super_block *sb);

0 commit comments

Comments
 (0)