[PATCH v2 03/13] fs: implement mknod
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Dec 15 03:19:39 PST 2025
On 12/9/25 1:51 PM, Sascha Hauer wrote:
> This implements mknod for the barebox VFS. Use the cdevname for
> connecting a device special node with a cdev. In Linux this is done with
> major/minor numbers which shouldn't be necessary for barebox as we do
> not intend to mount filesystems which contain device special nodes, but
> instead create them in ramfs. If a mounted filesystem contains special
> nodes then these won't work with barebox.
>
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
With two minor points below addressed:
Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> fs/devfs.c | 13 +++++++++++++
> fs/fs.c | 35 +++++++++++++++++++++++++++++++++++
> include/fcntl.h | 6 ++++++
> include/linux/fs.h | 13 +++++++++++++
> 4 files changed, 67 insertions(+)
>
> diff --git a/fs/devfs.c b/fs/devfs.c
> index 15c7a63d3949a5fa7c5ec15f58bc9f4c53b7852b..be3272be49e66eb843823b3ff664a1565f326790 100644
> --- a/fs/devfs.c
> +++ b/fs/devfs.c
> @@ -103,6 +103,12 @@ static int devfs_open(struct inode *inode, struct file *f)
> struct devfs_inode *node = container_of(inode, struct devfs_inode, inode);
> struct cdev *cdev = node->cdev;
>
> + if (inode->cdevname) {
> + cdev = cdev_by_name(inode->cdevname);
> + if (!cdev)
> + return -ENOENT;
> + }
> +
> f->f_size = cdev->flags & DEVFS_IS_CHARACTER_DEV ?
> FILE_SIZE_STREAM : cdev->size;
> f->private_data = cdev;
> @@ -188,6 +194,13 @@ static const struct file_operations devfs_file_operations = {
> .memmap = devfs_memmap,
> };
>
> +void init_special_inode(struct inode *inode, umode_t mode, const char *cdevname)
> +{
> + inode->i_mode = mode;
> + inode->i_fop = &devfs_file_operations;
> + inode->cdevname = strdup(cdevname);
xstrdup_const? or return an error?
> +}
> +
> static int devfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
> {
> struct devfs_inode *dinode;
> diff --git a/fs/fs.c b/fs/fs.c
> index d884726187dd526213f8b51a68a2e0db1bb50e58..45bf89653c7c2e4e9546f1d41f79a6389e0b796d 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -826,6 +826,8 @@ static int dentry_delete_subtree(struct super_block *sb, struct dentry *parent)
>
> static void destroy_inode(struct inode *inode)
> {
> + free(inode->cdevname);
free_const?
Cheers,
Ahmad
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list