fs: drop struct mtab_entry
every struct fs_device_d contains a struct mtab_entry, so they have a 1:1 relationship. Instead of having to use container_of to get from a struct mtab_entry to a struct fs_device_d we can better embed the members of struct mtab_entry into struct fs_device_d directly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
4b4bfcc0bf
commit
b55fbf7f5f
|
@ -33,14 +33,14 @@
|
||||||
static int do_mount(int argc, char *argv[])
|
static int do_mount(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct mtab_entry *entry;
|
struct fs_device_d *fsdev;
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
for_each_mtab_entry(entry) {
|
for_each_fs_device(fsdev) {
|
||||||
printf("%s on %s type %s\n",
|
printf("%s on %s type %s\n",
|
||||||
entry->parent_device ? dev_name(entry->parent_device) : "none",
|
fsdev->parent_device ? dev_name(fsdev->parent_device) : "none",
|
||||||
entry->path,
|
fsdev->path,
|
||||||
entry->dev->name);
|
fsdev->dev.name);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
88
fs/fs.c
88
fs/fs.c
|
@ -167,21 +167,21 @@ char *normalise_path(const char *pathname)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(normalise_path);
|
EXPORT_SYMBOL(normalise_path);
|
||||||
|
|
||||||
LIST_HEAD(mtab_list);
|
LIST_HEAD(fs_device_list);
|
||||||
static struct mtab_entry *mtab_root;
|
static struct fs_device_d *fs_dev_root;
|
||||||
|
|
||||||
static struct mtab_entry *get_mtab_entry_by_path(const char *path)
|
static struct fs_device_d *get_fsdevice_by_path(const char *path)
|
||||||
{
|
{
|
||||||
struct mtab_entry *e = NULL;
|
struct fs_device_d *fsdev = NULL;
|
||||||
|
|
||||||
for_each_mtab_entry(e) {
|
for_each_fs_device(fsdev) {
|
||||||
int len = strlen(e->path);
|
int len = strlen(fsdev->path);
|
||||||
if (!strncmp(path, e->path, len) &&
|
if (!strncmp(path, fsdev->path, len) &&
|
||||||
(path[len] == '/' || path[len] == 0))
|
(path[len] == '/' || path[len] == 0))
|
||||||
return e;
|
return fsdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mtab_root;
|
return fs_dev_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FILE files[MAX_FILES];
|
static FILE files[MAX_FILES];
|
||||||
|
@ -218,15 +218,15 @@ static int check_fd(int fd)
|
||||||
|
|
||||||
static struct fs_device_d *get_fs_device_and_root_path(char **path)
|
static struct fs_device_d *get_fs_device_and_root_path(char **path)
|
||||||
{
|
{
|
||||||
struct mtab_entry *e;
|
struct fs_device_d *fsdev;
|
||||||
|
|
||||||
e = get_mtab_entry_by_path(*path);
|
fsdev = get_fsdevice_by_path(*path);
|
||||||
if (!e)
|
if (!fsdev)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (e != mtab_root)
|
if (fsdev != fs_dev_root)
|
||||||
*path += strlen(e->path);
|
*path += strlen(fsdev->path);
|
||||||
|
|
||||||
return dev_to_fs_device(e->dev);
|
return fsdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dir_is_empty(const char *pathname)
|
static int dir_is_empty(const char *pathname)
|
||||||
|
@ -702,7 +702,7 @@ static int fs_match(struct device_d *dev, struct driver_d *drv)
|
||||||
static int fs_probe(struct device_d *dev)
|
static int fs_probe(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
||||||
struct mtab_entry *entry = &fsdev->mtab;
|
struct fs_driver_d *fsdrv = dev_to_fs_driver(dev);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = dev->driver->probe(dev);
|
ret = dev->driver->probe(dev);
|
||||||
|
@ -711,15 +711,15 @@ static int fs_probe(struct device_d *dev)
|
||||||
|
|
||||||
if (fsdev->cdev) {
|
if (fsdev->cdev) {
|
||||||
dev_add_child(fsdev->cdev->dev, &fsdev->dev);
|
dev_add_child(fsdev->cdev->dev, &fsdev->dev);
|
||||||
entry->parent_device = fsdev->cdev->dev;
|
fsdev->parent_device = fsdev->cdev->dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->dev = &fsdev->dev;
|
fsdev->driver = fsdrv;
|
||||||
|
|
||||||
list_add_tail(&entry->list, &mtab_list);
|
list_add_tail(&fsdev->list, &fs_device_list);
|
||||||
|
|
||||||
if (!mtab_root)
|
if (!fs_dev_root)
|
||||||
mtab_root = entry;
|
fs_dev_root = fsdev;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -727,17 +727,16 @@ static int fs_probe(struct device_d *dev)
|
||||||
static void fs_remove(struct device_d *dev)
|
static void fs_remove(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
||||||
struct mtab_entry *entry = &fsdev->mtab;
|
|
||||||
|
|
||||||
if (fsdev->dev.driver) {
|
if (fsdev->dev.driver) {
|
||||||
dev->driver->remove(dev);
|
dev->driver->remove(dev);
|
||||||
list_del(&entry->list);
|
list_del(&fsdev->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(entry->path);
|
free(fsdev->path);
|
||||||
|
|
||||||
if (entry == mtab_root)
|
if (fsdev == fs_dev_root)
|
||||||
mtab_root = NULL;
|
fs_dev_root = NULL;
|
||||||
|
|
||||||
free(fsdev->backingstore);
|
free(fsdev->backingstore);
|
||||||
free(fsdev);
|
free(fsdev);
|
||||||
|
@ -774,10 +773,9 @@ int mount(const char *device, const char *fsname, const char *_path)
|
||||||
|
|
||||||
debug("mount: %s on %s type %s\n", device, path, fsname);
|
debug("mount: %s on %s type %s\n", device, path, fsname);
|
||||||
|
|
||||||
if (mtab_root) {
|
if (fs_dev_root) {
|
||||||
struct mtab_entry *entry;
|
fsdev = get_fsdevice_by_path(path);
|
||||||
entry = get_mtab_entry_by_path(path);
|
if (fsdev != fs_dev_root) {
|
||||||
if (entry != mtab_root) {
|
|
||||||
printf("sorry, no nested mounts\n");
|
printf("sorry, no nested mounts\n");
|
||||||
errno = -EBUSY;
|
errno = -EBUSY;
|
||||||
goto err_free_path;
|
goto err_free_path;
|
||||||
|
@ -796,7 +794,7 @@ int mount(const char *device, const char *fsname, const char *_path)
|
||||||
fsdev->backingstore = xstrdup(device);
|
fsdev->backingstore = xstrdup(device);
|
||||||
safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
|
safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
|
||||||
fsdev->dev.id = get_free_deviceid(fsdev->dev.name);
|
fsdev->dev.id = get_free_deviceid(fsdev->dev.name);
|
||||||
fsdev->mtab.path = xstrdup(path);
|
fsdev->path = xstrdup(path);
|
||||||
fsdev->dev.bus = &fs_bus;
|
fsdev->dev.bus = &fs_bus;
|
||||||
|
|
||||||
if (!strncmp(device, "/dev/", 5))
|
if (!strncmp(device, "/dev/", 5))
|
||||||
|
@ -833,29 +831,29 @@ EXPORT_SYMBOL(mount);
|
||||||
|
|
||||||
int umount(const char *pathname)
|
int umount(const char *pathname)
|
||||||
{
|
{
|
||||||
struct mtab_entry *entry = NULL, *e;
|
struct fs_device_d *fsdev = NULL, *f;
|
||||||
char *p = normalise_path(pathname);
|
char *p = normalise_path(pathname);
|
||||||
|
|
||||||
for_each_mtab_entry(e) {
|
for_each_fs_device(f) {
|
||||||
if (!strcmp(p, e->path)) {
|
if (!strcmp(p, f->path)) {
|
||||||
entry = e;
|
fsdev = f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
|
|
||||||
if (e == mtab_root && !list_is_singular(&mtab_list)) {
|
if (f == fs_dev_root && !list_is_singular(&fs_device_list)) {
|
||||||
errno = -EBUSY;
|
errno = -EBUSY;
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entry) {
|
if (!fsdev) {
|
||||||
errno = -EFAULT;
|
errno = -EFAULT;
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
unregister_device(entry->dev);
|
unregister_device(&fsdev->dev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -915,23 +913,23 @@ int stat(const char *filename, struct stat *s)
|
||||||
{
|
{
|
||||||
struct device_d *dev;
|
struct device_d *dev;
|
||||||
struct fs_driver_d *fsdrv;
|
struct fs_driver_d *fsdrv;
|
||||||
struct mtab_entry *e;
|
struct fs_device_d *fsdev;
|
||||||
char *f = normalise_path(filename);
|
char *f = normalise_path(filename);
|
||||||
char *freep = f;
|
char *freep = f;
|
||||||
|
|
||||||
memset(s, 0, sizeof(struct stat));
|
memset(s, 0, sizeof(struct stat));
|
||||||
|
|
||||||
e = get_mtab_entry_by_path(f);
|
fsdev = get_fsdevice_by_path(f);
|
||||||
if (!e) {
|
if (!fsdev) {
|
||||||
errno = -ENOENT;
|
errno = -ENOENT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e != mtab_root && strcmp(f, e->path)) {
|
if (fsdev != fs_dev_root && strcmp(f, fsdev->path)) {
|
||||||
f += strlen(e->path);
|
f += strlen(fsdev->path);
|
||||||
dev = e->dev;
|
dev = &fsdev->dev;
|
||||||
} else
|
} else
|
||||||
dev = mtab_root->dev;
|
dev = &fs_dev_root->dev;
|
||||||
|
|
||||||
fsdrv = dev_to_fs_driver(dev);
|
fsdrv = dev_to_fs_driver(dev);
|
||||||
|
|
||||||
|
|
15
include/fs.h
15
include/fs.h
|
@ -77,15 +77,8 @@ struct fs_driver_d {
|
||||||
#define dev_to_fs_driver(d) container_of(d->driver, struct fs_driver_d, drv)
|
#define dev_to_fs_driver(d) container_of(d->driver, struct fs_driver_d, drv)
|
||||||
#define dev_to_fs_device(d) container_of(d, struct fs_device_d, dev)
|
#define dev_to_fs_device(d) container_of(d, struct fs_device_d, dev)
|
||||||
|
|
||||||
struct mtab_entry {
|
extern struct list_head fs_device_list;
|
||||||
char *path;
|
#define for_each_fs_device(f) list_for_each_entry(f, &fs_device_list, list)
|
||||||
struct device_d *dev;
|
|
||||||
struct device_d *parent_device;
|
|
||||||
struct list_head list;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct list_head mtab_list;
|
|
||||||
#define for_each_mtab_entry(e) list_for_each_entry(e, &mtab_list, list)
|
|
||||||
|
|
||||||
struct fs_device_d {
|
struct fs_device_d {
|
||||||
char *backingstore; /* the device we are associated with */
|
char *backingstore; /* the device we are associated with */
|
||||||
|
@ -94,7 +87,9 @@ struct fs_device_d {
|
||||||
struct fs_driver_d *driver;
|
struct fs_driver_d *driver;
|
||||||
|
|
||||||
struct cdev *cdev;
|
struct cdev *cdev;
|
||||||
struct mtab_entry mtab;
|
char *path;
|
||||||
|
struct device_d *parent_device;
|
||||||
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue