diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2022-02-18 12:59:21 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-02-18 12:59:21 +0100 |
commit | 9481ada6ad354cfe38418354afee48ceca438c05 (patch) | |
tree | e030cda328c36643b1c5085c9be7c5f2210f579b /fs | |
parent | a32d0e18fb1bc738ae1aa79d8713b178c977988c (diff) | |
parent | eedf7a3b5f990dff893b54740ceea917c24e2cb7 (diff) | |
download | barebox-9481ada6ad354cfe38418354afee48ceca438c05.tar.gz barebox-9481ada6ad354cfe38418354afee48ceca438c05.tar.xz |
Merge branch 'for-next/efi'
Diffstat (limited to 'fs')
-rw-r--r-- | fs/devfs-core.c | 103 | ||||
-rw-r--r-- | fs/devfs.c | 50 | ||||
-rw-r--r-- | fs/fs.c | 8 |
3 files changed, 103 insertions, 58 deletions
diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 2d016e0e48..38423e5d1e 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -37,7 +37,7 @@ int devfs_partition_complete(struct string_list *sl, char *instr) len = strlen(instr); - list_for_each_entry(cdev, &cdev_list, list) { + for_each_cdev(cdev) { if (cdev->master && !strncmp(instr, cdev->name, len)) { string_list_add_asprintf(sl, "%s ", cdev->name); @@ -62,7 +62,7 @@ struct cdev *lcdev_by_name(const char *filename) { struct cdev *cdev; - list_for_each_entry(cdev, &cdev_list, list) { + for_each_cdev(cdev) { if (!strcmp(cdev->name, filename)) return cdev; } @@ -84,7 +84,7 @@ struct cdev *cdev_by_device_node(struct device_node *node) { struct cdev *cdev; - list_for_each_entry(cdev, &cdev_list, list) { + for_each_cdev(cdev) { if (!cdev->device_node) continue; if (cdev->device_node == node) @@ -100,8 +100,22 @@ struct cdev *cdev_by_partuuid(const char *partuuid) if (!partuuid) return NULL; - list_for_each_entry(cdev, &cdev_list, list) { - if (!strcasecmp(cdev->partuuid, partuuid)) + for_each_cdev(cdev) { + if (cdev->master && !strcasecmp(cdev->uuid, partuuid)) + return cdev; + } + return NULL; +} + +struct cdev *cdev_by_diskuuid(const char *diskuuid) +{ + struct cdev *cdev; + + if (!diskuuid) + return NULL; + + for_each_cdev(cdev) { + if (!cdev->master && !strcasecmp(cdev->uuid, diskuuid)) return cdev; } return NULL; @@ -155,7 +169,15 @@ int cdev_find_free_index(const char *basename) return -EBUSY; /* all indexes are used */ } -struct cdev *cdev_open(const char *name, unsigned long flags) +int cdev_open(struct cdev *cdev, unsigned long flags) +{ + if (cdev->ops->open) + return cdev->ops->open(cdev, flags); + + return 0; +} + +struct cdev *cdev_open_by_name(const char *name, unsigned long flags) { struct cdev *cdev; int ret; @@ -164,11 +186,9 @@ struct cdev *cdev_open(const char *name, unsigned long flags) if (!cdev) return NULL; - if (cdev->ops->open) { - ret = cdev->ops->open(cdev, flags); - if (ret) - return NULL; - } + ret = cdev_open(cdev, flags); + if (ret) + return NULL; return cdev; } @@ -219,6 +239,67 @@ int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset) return cdev->ops->erase(cdev, count, cdev->offset + offset); } +int cdev_lseek(struct cdev *cdev, loff_t pos) +{ + int ret; + + if (cdev->ops->lseek) { + ret = cdev->ops->lseek(cdev, pos + cdev->offset); + if (ret < 0) + return ret; + } + + return 0; +} + +int cdev_protect(struct cdev *cdev, size_t count, loff_t offset, int prot) +{ + if (!cdev->ops->protect) + return -ENOSYS; + + return cdev->ops->protect(cdev, count, offset + cdev->offset, prot); +} + +int cdev_discard_range(struct cdev *cdev, loff_t count, loff_t offset) +{ + if (!cdev->ops->discard_range) + return -ENOSYS; + + if (cdev->flags & DEVFS_PARTITION_READONLY) + return -EPERM; + + if (offset >= cdev->size) + return 0; + + if (count + offset > cdev->size) + count = cdev->size - offset; + + return cdev->ops->discard_range(cdev, count, offset + cdev->offset); +} + +int cdev_memmap(struct cdev *cdev, void **map, int flags) +{ + int ret = -ENOSYS; + + if (!cdev->ops->memmap) + return -EINVAL; + + ret = cdev->ops->memmap(cdev, map, flags); + + if (!ret) + *map = (void *)((unsigned long)*map + (unsigned long)cdev->offset); + + return ret; +} + +int cdev_truncate(struct cdev *cdev, size_t size) +{ + if (cdev->ops->truncate) + return cdev->ops->truncate(cdev, size); + + return -EPERM; +} + int devfs_create(struct cdev *new) { struct cdev *cdev; diff --git a/fs/devfs.c b/fs/devfs.c index df229cca48..deb244feea 100644 --- a/fs/devfs.c +++ b/fs/devfs.c @@ -35,8 +35,6 @@ struct devfs_inode { struct cdev *cdev; }; -extern struct list_head cdev_list; - static int devfs_read(struct device_d *_dev, FILE *f, void *buf, size_t size) { struct cdev *cdev = f->priv; @@ -57,15 +55,8 @@ static int devfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t s static int devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos) { struct cdev *cdev = f->priv; - int ret; - - if (cdev->ops->lseek) { - ret = cdev->ops->lseek(cdev, pos + cdev->offset); - if (ret < 0) - return ret; - } - return 0; + return cdev_lseek(cdev, pos); } static int devfs_erase(struct device_d *_dev, FILE *f, loff_t count, loff_t offset) @@ -81,14 +72,11 @@ static int devfs_erase(struct device_d *_dev, FILE *f, loff_t count, loff_t offs return cdev_erase(cdev, count, offset); } -static int devfs_protect(struct device_d *_dev, FILE *f, size_t count, loff_t offset, int prot) +static int devfs_protect(struct device_d *dev, FILE *f, size_t count, loff_t offset, int prot) { struct cdev *cdev = f->priv; - if (!cdev->ops->protect) - return -ENOSYS; - - return cdev->ops->protect(cdev, count, offset + cdev->offset, prot); + return cdev_protect(cdev, count, offset, prot); } static int devfs_discard_range(struct device_d *dev, FILE *f, loff_t count, @@ -96,35 +84,14 @@ static int devfs_discard_range(struct device_d *dev, FILE *f, loff_t count, { struct cdev *cdev = f->priv; - if (!cdev->ops->discard_range) - return -ENOSYS; - - if (cdev->flags & DEVFS_PARTITION_READONLY) - return -EPERM; - - if (offset >= cdev->size) - return 0; - - if (count + offset > cdev->size) - count = cdev->size - offset; - - return cdev->ops->discard_range(cdev, count, offset + cdev->offset); + return cdev_discard_range(cdev, count, offset); } static int devfs_memmap(struct device_d *_dev, FILE *f, void **map, int flags) { struct cdev *cdev = f->priv; - int ret = -ENOSYS; - - if (!cdev->ops->memmap) - return -EINVAL; - - ret = cdev->ops->memmap(cdev, map, flags); - if (!ret) - *map = (void *)((unsigned long)*map + (unsigned long)cdev->offset); - - return ret; + return cdev_memmap(cdev, map, flags); } static int devfs_open(struct device_d *_dev, FILE *f, const char *filename) @@ -183,10 +150,7 @@ static int devfs_truncate(struct device_d *dev, FILE *f, loff_t size) { struct cdev *cdev = f->priv; - if (cdev->ops->truncate) - return cdev->ops->truncate(cdev, size); - - return -EPERM; + return cdev_truncate(cdev, size); } static struct inode *devfs_alloc_inode(struct super_block *sb) @@ -213,7 +177,7 @@ static int devfs_iterate(struct file *file, struct dir_context *ctx) dir_emit_dots(file, ctx); - list_for_each_entry(cdev, &cdev_list, list) { + for_each_cdev(cdev) { dir_emit(ctx, cdev->name, strlen(cdev->name), 1 /* FIXME */, DT_REG); } @@ -800,7 +800,7 @@ int fsdev_open_cdev(struct fs_device_d *fsdev) fsdev->cdev = cdev_create_loop(fsdev->backingstore, O_RDWR, offset); } else { - fsdev->cdev = cdev_open(fsdev->backingstore, O_RDWR); + fsdev->cdev = cdev_open_by_name(fsdev->backingstore, O_RDWR); } if (!fsdev->cdev) { path_put(&path); @@ -2999,8 +2999,8 @@ int mount(const char *device, const char *fsname, const char *pathname, cdev_is_mci_main_part_dev(fsdev->cdev->master)) str = get_linux_mmcblkdev(fsdev); - if (!str && fsdev->cdev->partuuid[0] != 0) - str = basprintf("root=PARTUUID=%s", fsdev->cdev->partuuid); + if (!str && fsdev->cdev->uuid[0] != 0) + str = basprintf("root=PARTUUID=%s", fsdev->cdev->uuid); if (str) fsdev_set_linux_rootarg(fsdev, str); @@ -3048,7 +3048,7 @@ int umount(const char *pathname) path_put(&path); if (!fsdev) { - struct cdev *cdev = cdev_open(pathname, O_RDWR); + struct cdev *cdev = cdev_open_by_name(pathname, O_RDWR); if (cdev) { cdev_close(cdev); |