mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink
@ 2025-01-06  9:18 Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 2/6] fs: squashfs: delete unreferenced source file Ahmad Fatoum
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:18 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

ramfs_unlink and simple_unlink have the same prototype, so we can just
use simple_unlink directly instead of defining a trivial intermediate
function.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/ramfs.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index c1ef7acd9107..e34742e42959 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -164,11 +164,6 @@ static int ramfs_symlink(struct inode *dir, struct dentry *dentry,
 	return 0;
 }
 
-static int ramfs_unlink(struct inode *dir, struct dentry *dentry)
-{
-	return simple_unlink(dir, dentry);
-}
-
 static const char *ramfs_get_link(struct dentry *dentry, struct inode *inode)
 {
 	return inode->i_link;
@@ -185,7 +180,7 @@ static const struct inode_operations ramfs_dir_inode_operations =
 	.symlink = ramfs_symlink,
 	.mkdir = ramfs_mkdir,
 	.rmdir = simple_rmdir,
-	.unlink = ramfs_unlink,
+	.unlink = simple_unlink,
 	.create = ramfs_create,
 };
 
-- 
2.39.5




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/6] fs: squashfs: delete unreferenced source file
  2025-01-06  9:18 [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Ahmad Fatoum
@ 2025-01-06  9:18 ` Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 3/6] fs: collect legacy file system operation in new struct fs_legacy_ops Ahmad Fatoum
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:18 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This file was defines two global functions, but was never built.
squashfs_page_actor_init_special(), which it defines is never called
anywhere and squashfs_page_actor_init is defined in page_actor.h as
static inline function.

Therefore, drop this stale file.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/squashfs/page_actor.c | 99 ----------------------------------------
 1 file changed, 99 deletions(-)
 delete mode 100644 fs/squashfs/page_actor.c

diff --git a/fs/squashfs/page_actor.c b/fs/squashfs/page_actor.c
deleted file mode 100644
index 4eb730857c99..000000000000
--- a/fs/squashfs/page_actor.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2013
- * Phillip Lougher <phillip@squashfs.org.uk>
- *
- * This work is licensed under the terms of the GNU GPL, version 2. See
- * the COPYING file in the top-level directory.
- */
-
-#include <linux/kernel.h>
-#include <linux/pagemap.h>
-#include "page_actor.h"
-
-/*
- * This file contains implementations of page_actor for decompressing into
- * an intermediate buffer, and for decompressing directly into the
- * page cache.
- *
- * Calling code should avoid sleeping between calls to squashfs_first_page()
- * and squashfs_finish_page().
- */
-
-/* Implementation of page_actor for decompressing into intermediate buffer */
-static void *cache_first_page(struct squashfs_page_actor *actor)
-{
-	actor->next_page = 1;
-	return actor->buffer[0];
-}
-
-static void *cache_next_page(struct squashfs_page_actor *actor)
-{
-	if (actor->next_page == actor->pages)
-		return NULL;
-
-	return actor->buffer[actor->next_page++];
-}
-
-static void cache_finish_page(struct squashfs_page_actor *actor)
-{
-	/* empty */
-}
-
-struct squashfs_page_actor *squashfs_page_actor_init(void **buffer,
-	int pages, int length)
-{
-	struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
-
-	if (actor == NULL)
-		return NULL;
-
-	actor->length = length ? : pages * PAGE_CACHE_SIZE;
-	actor->buffer = buffer;
-	actor->pages = pages;
-	actor->next_page = 0;
-	actor->squashfs_first_page = cache_first_page;
-	actor->squashfs_next_page = cache_next_page;
-	actor->squashfs_finish_page = cache_finish_page;
-	return actor;
-}
-
-/* Implementation of page_actor for decompressing directly into page cache. */
-static void *direct_first_page(struct squashfs_page_actor *actor)
-{
-	actor->next_page = 1;
-	return actor->pageaddr = kmap_atomic(actor->page[0]);
-}
-
-static void *direct_next_page(struct squashfs_page_actor *actor)
-{
-	if (actor->pageaddr)
-		kunmap_atomic(actor->pageaddr);
-
-	return actor->pageaddr = actor->next_page == actor->pages ? NULL :
-		kmap_atomic(actor->page[actor->next_page++]);
-}
-
-static void direct_finish_page(struct squashfs_page_actor *actor)
-{
-	if (actor->pageaddr)
-		kunmap_atomic(actor->pageaddr);
-}
-
-struct squashfs_page_actor *squashfs_page_actor_init_special(struct page **page,
-	int pages, int length)
-{
-	struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
-
-	if (actor == NULL)
-		return NULL;
-
-	actor->length = length ? : pages * PAGE_CACHE_SIZE;
-	actor->page = page;
-	actor->pages = pages;
-	actor->next_page = 0;
-	actor->pageaddr = NULL;
-	actor->squashfs_first_page = direct_first_page;
-	actor->squashfs_next_page = direct_next_page;
-	actor->squashfs_finish_page = direct_finish_page;
-	return actor;
-}
-- 
2.39.5




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/6] fs: collect legacy file system operation in new struct fs_legacy_ops
  2025-01-06  9:18 [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 2/6] fs: squashfs: delete unreferenced source file Ahmad Fatoum
@ 2025-01-06  9:18 ` Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 4/6] fs: return error pointer not NULL from cdev_mount_default Ahmad Fatoum
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:18 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Legacy file systemd already select FS_LEGACY in Kconfig, but when
writing new file systems, it's confusing to have the legacy ops
interleaved with those still used for modern file systems.

Let's move the legacy ops into a substructure, so it's directly evident
that these shouldn't be implemented by new file systems.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/bpkfs.c           | 12 +++++++----
 fs/efi.c             | 18 ++++++++++-------
 fs/efivarfs.c        | 14 ++++++++-----
 fs/fat/fat.c         | 16 ++++++++++-----
 fs/legacy.c          | 47 ++++++++++++++++++++++++++------------------
 fs/omap4_usbbootfs.c |  8 ++++++--
 fs/pstore/fs.c       | 14 ++++++++-----
 fs/ratpfs.c          | 12 +++++++----
 fs/smhfs.c           | 14 ++++++++-----
 fs/uimagefs.c        | 12 +++++++----
 include/fs.h         | 31 +++++++++++++++--------------
 11 files changed, 123 insertions(+), 75 deletions(-)

diff --git a/fs/bpkfs.c b/fs/bpkfs.c
index 7b714de66158..e8b15461ccef 100644
--- a/fs/bpkfs.c
+++ b/fs/bpkfs.c
@@ -491,15 +491,19 @@ static int bpkfs_probe(struct device *dev)
 	return ret;
 }
 
+static const struct fs_legacy_ops bpkfs_ops = {
+	.opendir   = bpkfs_opendir,
+	.readdir   = bpkfs_readdir,
+	.closedir  = bpkfs_closedir,
+	.stat      = bpkfs_stat,
+};
+
 static struct fs_driver bpkfs_driver = {
 	.open      = bpkfs_open,
 	.close     = bpkfs_close,
 	.read      = bpkfs_read,
 	.lseek     = bpkfs_lseek,
-	.opendir   = bpkfs_opendir,
-	.readdir   = bpkfs_readdir,
-	.closedir  = bpkfs_closedir,
-	.stat      = bpkfs_stat,
+	.legacy_ops = &bpkfs_ops,
 	.flags     = 0,
 	.type = filetype_bpk,
 	.drv = {
diff --git a/fs/efi.c b/fs/efi.c
index 2125d54ed632..bc762ebb2f9f 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -420,15 +420,9 @@ static void efifs_remove(struct device *dev)
 	free(dev->priv);
 }
 
-static struct fs_driver efifs_driver = {
+static const struct fs_legacy_ops efifs_ops = {
 	.create    = efifs_create,
 	.unlink    = efifs_unlink,
-	.open      = efifs_open,
-	.close     = efifs_close,
-	.truncate  = efifs_truncate,
-	.read      = efifs_read,
-	.write     = efifs_write,
-	.lseek     = efifs_lseek,
 	.mkdir     = efifs_mkdir,
 	.rmdir     = efifs_rmdir,
 	.opendir   = efifs_opendir,
@@ -437,6 +431,16 @@ static struct fs_driver efifs_driver = {
 	.stat      = efifs_stat,
 	.symlink   = efifs_symlink,
 	.readlink  = efifs_readlink,
+};
+
+static struct fs_driver efifs_driver = {
+	.open      = efifs_open,
+	.close     = efifs_close,
+	.truncate  = efifs_truncate,
+	.read      = efifs_read,
+	.write     = efifs_write,
+	.lseek     = efifs_lseek,
+	.legacy_ops = &efifs_ops,
 	.drv = {
 		.probe  = efifs_probe,
 		.remove = efifs_remove,
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index b19931806140..2030bf05d9ee 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -347,18 +347,22 @@ static void efivarfs_remove(struct device *dev)
 	free(priv);
 }
 
-static struct fs_driver efivarfs_driver = {
+static const struct fs_legacy_ops efivarfs_ops = {
 	.create    = efivars_create,
 	.unlink    = efivars_unlink,
+	.opendir   = efivarfs_opendir,
+	.readdir   = efivarfs_readdir,
+	.closedir  = efivarfs_closedir,
+	.stat      = efivarfs_stat,
+};
+
+static struct fs_driver efivarfs_driver = {
 	.open      = efivarfs_open,
 	.close     = efivarfs_close,
 	.read      = efivarfs_read,
 	.write     = efivarfs_write,
 	.truncate  = efivarfs_truncate,
-	.opendir   = efivarfs_opendir,
-	.readdir   = efivarfs_readdir,
-	.closedir  = efivarfs_closedir,
-	.stat      = efivarfs_stat,
+	.legacy_ops = &efivarfs_ops,
 	.drv = {
 		.probe  = efivarfs_probe,
 		.remove = efivarfs_remove,
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index f3c7f9b8630c..f5ad9f07cda9 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -373,11 +373,7 @@ static void fat_remove(struct device *dev)
 	free(dev->priv);
 }
 
-static struct fs_driver fat_driver = {
-	.open      = fat_open,
-	.close     = fat_close,
-	.read      = fat_read,
-	.lseek     = fat_lseek,
+static const struct fs_legacy_ops fat_ops = {
 	.opendir   = fat_opendir,
 	.readdir   = fat_readdir,
 	.closedir  = fat_closedir,
@@ -387,9 +383,19 @@ static struct fs_driver fat_driver = {
 	.unlink    = fat_unlink,
 	.mkdir     = fat_mkdir,
 	.rmdir     = fat_rmdir,
+#endif
+};
+
+static struct fs_driver fat_driver = {
+	.open      = fat_open,
+	.close     = fat_close,
+	.read      = fat_read,
+	.lseek     = fat_lseek,
+#ifdef CONFIG_FS_FAT_WRITE
 	.write     = fat_write,
 	.truncate  = fat_truncate,
 #endif
+	.legacy_ops = &fat_ops,
 	.type = filetype_fat,
 	.flags     = 0,
 	.drv = {
diff --git a/fs/legacy.c b/fs/legacy.c
index 0d4d4d43ebac..c1facfd6d708 100644
--- a/fs/legacy.c
+++ b/fs/legacy.c
@@ -20,6 +20,7 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
 	struct inode *dir = d_inode(dentry);
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	struct dir *d;
 	struct dirent *dirent;
 	char *pathname;
@@ -28,19 +29,19 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	d = fsdev->driver->opendir(&fsdev->dev, pathname);
+	d = legacy_ops->opendir(&fsdev->dev, pathname);
 	if (!d)
 		goto out;
 
 	while (1) {
-		dirent = fsdev->driver->readdir(&fsdev->dev, d);
+		dirent = legacy_ops->readdir(&fsdev->dev, d);
 		if (!dirent)
 			break;
 
 		dir_emit(ctx, dirent->d_name, strlen(dirent->d_name), 0, DT_UNKNOWN);
 	}
 
-	fsdev->driver->closedir(&fsdev->dev, d);
+	legacy_ops->closedir(&fsdev->dev, d);
 out:
 	free(pathname);
 
@@ -52,6 +53,7 @@ static struct dentry *legacy_lookup(struct inode *dir, struct dentry *dentry,
 {
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	struct inode *inode;
 	char *pathname;
 	struct stat s;
@@ -61,7 +63,7 @@ static struct dentry *legacy_lookup(struct inode *dir, struct dentry *dentry,
 	if (!pathname)
 		return NULL;
 
-	ret = fsdev->driver->stat(&fsdev->dev, pathname, &s);
+	ret = legacy_ops->stat(&fsdev->dev, pathname, &s);
 	if (!ret) {
 		inode = legacy_get_inode(sb, dir, s.st_mode);
 		if (!inode)
@@ -80,16 +82,17 @@ static int legacy_create(struct inode *dir, struct dentry *dentry, umode_t mode)
 {
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	struct inode *inode;
 	char *pathname;
 	int ret;
 
-	if (!fsdev->driver->create)
+	if (!legacy_ops->create)
 		return -EROFS;
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	ret = fsdev->driver->create(&fsdev->dev, pathname, mode | S_IFREG);
+	ret = legacy_ops->create(&fsdev->dev, pathname, mode | S_IFREG);
 
 	free(pathname);
 
@@ -107,16 +110,17 @@ static int legacy_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 {
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	struct inode *inode;
 	char *pathname;
 	int ret;
 
-	if (!fsdev->driver->mkdir)
+	if (!legacy_ops->mkdir)
 		return -EROFS;
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	ret = fsdev->driver->mkdir(&fsdev->dev, pathname);
+	ret = legacy_ops->mkdir(&fsdev->dev, pathname);
 
 	free(pathname);
 
@@ -135,16 +139,17 @@ static int legacy_dir_is_empty(struct dentry *dentry)
 	struct inode *dir = d_inode(dentry);
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	struct dir *d;
 	struct dirent *dirent;
 	char *pathname;
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	d = fsdev->driver->opendir(&fsdev->dev, pathname);
-	dirent = fsdev->driver->readdir(&fsdev->dev, d);
+	d = legacy_ops->opendir(&fsdev->dev, pathname);
+	dirent = legacy_ops->readdir(&fsdev->dev, d);
 
-	fsdev->driver->closedir(&fsdev->dev, d);
+	legacy_ops->closedir(&fsdev->dev, d);
 
 	free(pathname);
 
@@ -155,10 +160,11 @@ static int legacy_rmdir(struct inode *dir, struct dentry *dentry)
 {
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	char *pathname;
 	int ret;
 
-	if (!fsdev->driver->rmdir)
+	if (!legacy_ops->rmdir)
 		return -EROFS;
 
 	if (!legacy_dir_is_empty(dentry))
@@ -166,7 +172,7 @@ static int legacy_rmdir(struct inode *dir, struct dentry *dentry)
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	ret = fsdev->driver->rmdir(&fsdev->dev, pathname);
+	ret = legacy_ops->rmdir(&fsdev->dev, pathname);
 
 	free(pathname);
 
@@ -184,15 +190,16 @@ static int legacy_unlink(struct inode *dir, struct dentry *dentry)
 {
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	char *pathname;
 	int ret;
 
-	if (!fsdev->driver->unlink)
+	if (!legacy_ops->unlink)
 		return -EROFS;
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	ret = fsdev->driver->unlink(&fsdev->dev, pathname);
+	ret = legacy_ops->unlink(&fsdev->dev, pathname);
 
 	free(pathname);
 
@@ -210,16 +217,17 @@ static int legacy_symlink(struct inode *dir, struct dentry *dentry,
 {
 	struct super_block *sb = dir->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	struct inode *inode;
 	char *pathname;
 	int ret;
 
-	if (!fsdev->driver->symlink)
+	if (!legacy_ops->symlink)
 		return -ENOSYS;
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	ret = fsdev->driver->symlink(&fsdev->dev, dest, pathname);
+	ret = legacy_ops->symlink(&fsdev->dev, dest, pathname);
 
 	free(pathname);
 
@@ -238,16 +246,17 @@ static const char *legacy_get_link(struct dentry *dentry, struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
 	struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
+	const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
 	char *pathname;
 	int ret;
 	char link[PATH_MAX] = {};
 
-	if (!fsdev->driver->readlink)
+	if (!legacy_ops->readlink)
 		return ERR_PTR(-ENOSYS);
 
 	pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
 
-	ret = fsdev->driver->readlink(&fsdev->dev, pathname, link, PATH_MAX - 1);
+	ret = legacy_ops->readlink(&fsdev->dev, pathname, link, PATH_MAX - 1);
 
 	free(pathname);
 
diff --git a/fs/omap4_usbbootfs.c b/fs/omap4_usbbootfs.c
index 30392d119253..1692e3bb3390 100644
--- a/fs/omap4_usbbootfs.c
+++ b/fs/omap4_usbbootfs.c
@@ -150,12 +150,16 @@ static void omap4_usbbootfs_remove(struct device *dev)
 {
 }
 
+static const struct fs_legacy_ops omap4_usbbootfs_ops = {
+	.opendir = omap4_usbbootfs_opendir,
+	.stat    = omap4_usbbootfs_stat,
+};
+
 static struct fs_driver omap4_usbbootfs_driver = {
 	.open    = omap4_usbbootfs_open,
 	.close   = omap4_usbbootfs_close,
 	.read    = omap4_usbbootfs_read,
-	.opendir = omap4_usbbootfs_opendir,
-	.stat    = omap4_usbbootfs_stat,
+	.legacy_ops = &omap4_usbbootfs_ops,
 	.flags	 = 0,
 	.drv = {
 		.probe	= omap4_usbbootfs_probe,
diff --git a/fs/pstore/fs.c b/fs/pstore/fs.c
index f11db91582aa..4e62a7300ba1 100644
--- a/fs/pstore/fs.c
+++ b/fs/pstore/fs.c
@@ -274,17 +274,21 @@ static int pstore_probe(struct device *dev)
 	return 0;
 }
 
-static struct fs_driver pstore_driver = {
-	.open      = pstore_open,
-	.close     = pstore_close,
-	.read      = pstore_read,
-	.lseek     = pstore_lseek,
+static const struct fs_legacy_ops pstore_ops = {
 	.unlink    = pstore_unlink,
 	.opendir   = pstore_opendir,
 	.readdir   = pstore_readdir,
 	.closedir  = pstore_closedir,
 	.stat      = pstore_stat,
+};
+
+static struct fs_driver pstore_driver = {
+	.open      = pstore_open,
+	.close     = pstore_close,
+	.read      = pstore_read,
+	.lseek     = pstore_lseek,
 	.flags     = FS_DRIVER_NO_DEV,
+	.legacy_ops = &pstore_ops,
 	.type = filetype_uimage,
 	.drv = {
 		.probe  = pstore_probe,
diff --git a/fs/ratpfs.c b/fs/ratpfs.c
index 9e85fc596e87..f1b9ed4ed8f2 100644
--- a/fs/ratpfs.c
+++ b/fs/ratpfs.c
@@ -438,10 +438,7 @@ static void ratpfs_remove(struct device __always_unused *dev)
 	barebox_ratp_fs_mount(NULL);
 }
 
-static struct fs_driver ratpfs_driver = {
-	.open      = ratpfs_open,
-	.close     = ratpfs_close,
-	.read      = ratpfs_read,
+static const struct fs_legacy_ops ratpfs_ops = {
 	.opendir   = ratpfs_opendir,
 	.readdir   = ratpfs_readdir,
 	.closedir  = ratpfs_closedir,
@@ -450,8 +447,15 @@ static struct fs_driver ratpfs_driver = {
 	.unlink    = ratpfs_rm,
 	.mkdir     = ratpfs_mkdir,
 	.rmdir     = ratpfs_rm,
+};
+
+static struct fs_driver ratpfs_driver = {
+	.open      = ratpfs_open,
+	.close     = ratpfs_close,
+	.read      = ratpfs_read,
 	.write     = ratpfs_write,
 	.truncate  = ratpfs_truncate,
+	.legacy_ops = &ratpfs_ops,
 	.flags     = FS_DRIVER_NO_DEV,
 	.drv = {
 		.probe  = ratpfs_probe,
diff --git a/fs/smhfs.c b/fs/smhfs.c
index ce027f203e23..f57d1ff9ced3 100644
--- a/fs/smhfs.c
+++ b/fs/smhfs.c
@@ -133,19 +133,23 @@ static void smhfs_remove(struct device __always_unused *dev)
 {
 }
 
-static struct fs_driver smhfs_driver = {
-	.open      = smhfs_open,
-	.close     = smhfs_close,
-	.read      = smhfs_read,
-	.lseek     = smhfs_lseek,
+static const struct fs_legacy_ops smhfs_ops = {
 	.opendir   = smhfs_opendir,
 	.stat      = smhfs_stat,
 	.create    = smhfs_create,
 	.unlink    = smhfs_rm,
 	.mkdir     = smhfs_mkdir,
 	.rmdir     = smhfs_rm,
+};
+
+static struct fs_driver smhfs_driver = {
+	.open      = smhfs_open,
+	.close     = smhfs_close,
+	.read      = smhfs_read,
+	.lseek     = smhfs_lseek,
 	.write     = smhfs_write,
 	.truncate  = smhfs_truncate,
+	.legacy_ops = &smhfs_ops,
 	.flags     = FS_DRIVER_NO_DEV,
 	.drv = {
 		.probe  = smhfs_probe,
diff --git a/fs/uimagefs.c b/fs/uimagefs.c
index 6913685c0cf6..54541fa7710c 100644
--- a/fs/uimagefs.c
+++ b/fs/uimagefs.c
@@ -516,16 +516,20 @@ static int uimagefs_probe(struct device *dev)
 	return ret;
 }
 
+static const struct fs_legacy_ops uimagefs_ops = {
+	.opendir   = uimagefs_opendir,
+	.readdir   = uimagefs_readdir,
+	.closedir  = uimagefs_closedir,
+	.stat      = uimagefs_stat,
+};
+
 static struct fs_driver uimagefs_driver = {
 	.open      = uimagefs_open,
 	.close     = uimagefs_close,
 	.read      = uimagefs_read,
 	.lseek     = uimagefs_lseek,
-	.opendir   = uimagefs_opendir,
-	.readdir   = uimagefs_readdir,
-	.closedir  = uimagefs_closedir,
-	.stat      = uimagefs_stat,
 	.ioctl	   = uimagefs_ioctl,
+	.legacy_ops = &uimagefs_ops,
 	.flags     = 0,
 	.type = filetype_uimage,
 	.drv = {
diff --git a/include/fs.h b/include/fs.h
index f5950a052923..137eb2d2863e 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -63,10 +63,6 @@ enum erase_type {
 struct fs_driver {
 	int (*probe) (struct device *dev);
 
-	/* create a file. The file is guaranteed to not exist */
-	int (*create)(struct device *dev, const char *pathname, mode_t mode);
-	int (*unlink)(struct device *dev, const char *pathname);
-
 	/* Truncate a file to given size */
 	int (*truncate)(struct device *dev, FILE *f, loff_t size);
 
@@ -88,17 +84,22 @@ struct fs_driver {
 
 	int (*memmap)(struct device *dev, FILE *f, void **map, int flags);
 
-	/* legacy */
-	int (*mkdir)(struct device *dev, const char *pathname);
-	int (*rmdir)(struct device *dev, const char *pathname);
-	int (*symlink)(struct device *dev, const char *pathname,
-		       const char *newpath);
-	int (*readlink)(struct device *dev, const char *pathname, char *name,
-			size_t size);
-	struct dir* (*opendir)(struct device *dev, const char *pathname);
-	struct dirent* (*readdir)(struct device *dev, struct dir *dir);
-	int (*closedir)(struct device *dev, DIR *dir);
-	int (*stat)(struct device *dev, const char *file, struct stat *stat);
+	const struct fs_legacy_ops {
+		/* create a file. The file is guaranteed to not exist */
+		int (*create)(struct device *dev, const char *pathname, mode_t mode);
+		int (*unlink)(struct device *dev, const char *pathname);
+
+		int (*mkdir)(struct device *dev, const char *pathname);
+		int (*rmdir)(struct device *dev, const char *pathname);
+		int (*symlink)(struct device *dev, const char *pathname,
+			       const char *newpath);
+		int (*readlink)(struct device *dev, const char *pathname, char *name,
+				size_t size);
+		struct dir* (*opendir)(struct device *dev, const char *pathname);
+		struct dirent* (*readdir)(struct device *dev, struct dir *dir);
+		int (*closedir)(struct device *dev, DIR *dir);
+		int (*stat)(struct device *dev, const char *file, struct stat *stat);
+	} *legacy_ops;
 
 	struct driver drv;
 
-- 
2.39.5




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/6] fs: return error pointer not NULL from cdev_mount_default
  2025-01-06  9:18 [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 2/6] fs: squashfs: delete unreferenced source file Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 3/6] fs: collect legacy file system operation in new struct fs_legacy_ops Ahmad Fatoum
@ 2025-01-06  9:18 ` Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 5/6] commands: stat: fix size display for FILE_SIZE_STREAM Ahmad Fatoum
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:18 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

cdev_mount_default is documented to return error pointers on errors and
that's what's done everywhere inside the function, except for errors
from the last call to cdev_get_mount_path.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fs.c b/fs/fs.c
index a9d2cc7088e3..6d047f197640 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1152,7 +1152,7 @@ const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions)
 		return ERR_PTR(ret);
 	}
 
-	return cdev_get_mount_path(cdev);
+	return cdev_get_mount_path(cdev) ?: ERR_PTR(-ENODEV);
 }
 
 /*
-- 
2.39.5




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/6] commands: stat: fix size display for FILE_SIZE_STREAM
  2025-01-06  9:18 [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2025-01-06  9:18 ` [PATCH 4/6] fs: return error pointer not NULL from cdev_mount_default Ahmad Fatoum
@ 2025-01-06  9:18 ` Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH 6/6] commands: stat: print mode in octal if type unknown Ahmad Fatoum
  2025-01-06 10:40 ` [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:18 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

FILE_SIZE_STREAM is a special value that indicates that the size field
should be ignored as the cdev in question is a stream device.

Teach the stat command about this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 6d047f197640..8cdd0c55202b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -188,9 +188,13 @@ void stat_print(int dirfd, const char *filename, const struct stat *st)
 		typeprefix = "cdev link to ";
 	}
 
-	printf("\n");
+	printf("\nSize: ");
+
+	if (st->st_size == FILE_SIZE_STREAM)
+		printf("%-20s", "stream");
+	else
+		printf("%-20llu", st->st_size);
 
-	printf("  Size: %-20llu", st->st_size);
 	if (bdev)
 		printf("Blocks: %llu\tIO Block: %u\t",
 		       (u64)bdev->num_blocks, 1 << bdev->blockbits);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 6/6] commands: stat: print mode in octal if type unknown
  2025-01-06  9:18 [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2025-01-06  9:18 ` [PATCH 5/6] commands: stat: fix size display for FILE_SIZE_STREAM Ahmad Fatoum
@ 2025-01-06  9:18 ` Ahmad Fatoum
  2025-01-06 10:40 ` [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:18 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The stat command is meant as debugging aid and thus it's useful to print
information about the mode, even for broken inodes that lack file type
information in their mode field.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 8cdd0c55202b..57bd781025f9 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -201,6 +201,8 @@ void stat_print(int dirfd, const char *filename, const struct stat *st)
 
 	if (type)
 		printf("  %s%s", typeprefix, type);
+	else
+		printf("  unknown (mode=0%o)", st->st_mode);
 
 	fdev = get_fsdevice_by_path(dirfd, filename);
 
-- 
2.39.5




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink
  2025-01-06  9:18 [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2025-01-06  9:18 ` [PATCH 6/6] commands: stat: print mode in octal if type unknown Ahmad Fatoum
@ 2025-01-06 10:40 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2025-01-06 10:40 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 06 Jan 2025 10:18:30 +0100, Ahmad Fatoum wrote:
> ramfs_unlink and simple_unlink have the same prototype, so we can just
> use simple_unlink directly instead of defining a trivial intermediate
> function.
> 
> 

Applied, thanks!

[1/6] fs: ramfs: drop unneeded indirection during unlink
      https://git.pengutronix.de/cgit/barebox/commit/?id=e13a005a74bd (link may not be stable)
[2/6] fs: squashfs: delete unreferenced source file
      https://git.pengutronix.de/cgit/barebox/commit/?id=250241642267 (link may not be stable)
[3/6] fs: collect legacy file system operation in new struct fs_legacy_ops
      https://git.pengutronix.de/cgit/barebox/commit/?id=6a2858e9734a (link may not be stable)
[4/6] fs: return error pointer not NULL from cdev_mount_default
      https://git.pengutronix.de/cgit/barebox/commit/?id=4619539e43ca (link may not be stable)
[5/6] commands: stat: fix size display for FILE_SIZE_STREAM
      https://git.pengutronix.de/cgit/barebox/commit/?id=e796dcf64814 (link may not be stable)
[6/6] commands: stat: print mode in octal if type unknown
      https://git.pengutronix.de/cgit/barebox/commit/?id=fe978a472a3e (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-06 10:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-06  9:18 [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Ahmad Fatoum
2025-01-06  9:18 ` [PATCH 2/6] fs: squashfs: delete unreferenced source file Ahmad Fatoum
2025-01-06  9:18 ` [PATCH 3/6] fs: collect legacy file system operation in new struct fs_legacy_ops Ahmad Fatoum
2025-01-06  9:18 ` [PATCH 4/6] fs: return error pointer not NULL from cdev_mount_default Ahmad Fatoum
2025-01-06  9:18 ` [PATCH 5/6] commands: stat: fix size display for FILE_SIZE_STREAM Ahmad Fatoum
2025-01-06  9:18 ` [PATCH 6/6] commands: stat: print mode in octal if type unknown Ahmad Fatoum
2025-01-06 10:40 ` [PATCH 1/6] fs: ramfs: drop unneeded indirection during unlink Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox