diff --git a/fs/Kconfig b/fs/Kconfig index b75820f..4c66543 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -1,6 +1,11 @@ menu "Filesystem support " +config FS + bool + default y + select FILETYPE + config FS_AUTOMOUNT bool diff --git a/fs/fs.c b/fs/fs.c index 0b376a5..8ab1a3a 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -954,6 +954,28 @@ } EXPORT_SYMBOL(register_fs_driver); +static const char *detect_fs(const char *filename) +{ + enum filetype type = file_name_detect_type(filename); + struct driver_d *drv; + struct fs_driver_d *fdrv; + + if (type == filetype_unknown) + return NULL; + + for_each_driver(drv) { + if (drv->bus != &fs_bus) + continue; + + fdrv = drv_to_fs_driver(drv); + + if (type == fdrv->type) + return drv->name; + } + + return NULL; +} + /* * Mount a device to a directory. * We do this by registering a new device on which the filesystem @@ -985,6 +1007,12 @@ } } + if (!fsname) + fsname = detect_fs(device); + + if (!fsname) + return -ENOENT; + fsdev = xzalloc(sizeof(struct fs_device_d)); fsdev->backingstore = xstrdup(device); safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME); @@ -1222,7 +1250,7 @@ fsdev = get_fs_device_and_root_path(&p); if (!fsdev) { - ret = -ENOENT; + ret = -ENODEV; goto out; } fsdrv = fsdev->driver; diff --git a/include/fs.h b/include/fs.h index c0b9f71..22470e6 100644 --- a/include/fs.h +++ b/include/fs.h @@ -2,6 +2,7 @@ #define __FS_H #include +#include #define PATH_MAX 1024 /* include/linux/limits.h */ @@ -72,6 +73,8 @@ struct driver_d drv; + enum filetype type; + unsigned long flags; }; @@ -93,6 +96,8 @@ struct list_head list; }; +#define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv) + /* * standard posix file functions */