mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] fs: factor out final file open logic out of openat()
@ 2025-10-15  8:34 Ahmad Fatoum
  2025-10-15  8:34 ` [PATCH 2/2] fs: allocate inodes for O_TMPFILE-created files Ahmad Fatoum
  2025-10-20 10:58 ` [PATCH 1/2] fs: factor out final file open logic out of openat() Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-10-15  8:34 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The final open logic will be reused for the tmpfile logic in a
follow-up commit, so factor it out into a function with semantics
similar to the Linux equivalent.

No functional change intended.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 fs/fs.c | 53 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index e2bcd8ea33b2..76b1ec4c910a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2561,10 +2561,37 @@ static int rmdirat(int dirfd, const char *pathname)
 	return errno_set(error);
 }
 
+static int do_dentry_open(struct file *f)
+{
+	int error;
+
+	f->f_inode = d_inode(f->f_path.dentry);
+
+	if (unlikely(f->f_flags & O_PATH))
+		return 0;
+
+	if (f->f_inode->i_fop->open) {
+		error = f->f_inode->i_fop->open(f->f_inode, f);
+		if (error)
+			return error;
+	}
+
+	if (f->f_flags & O_TRUNC) {
+		error = fsdev_truncate(f, 0);
+		f->f_size = 0;
+		if (error)
+			return error;
+	}
+
+	if (f->f_flags & O_APPEND)
+		f->f_pos = f->f_size;
+
+	return 0;
+}
+
 int openat(int dirfd, const char *pathname, int flags)
 {
 	struct fs_device *fsdev;
-	struct fs_driver *fsdrv;
 	struct super_block *sb;
 	struct file *f;
 	int error = 0;
@@ -2660,29 +2687,13 @@ int openat(int dirfd, const char *pathname, int flags)
 
 	f->path = dpath(dentry, d_root);
 	f->f_path = path;
-	f->f_inode = iget(inode);
 	f->f_flags = flags;
 
-	fsdrv = fsdev->driver;
+	iget(inode);
 
-	if (flags & O_PATH)
-		return file_to_fd(f);
-
-	if (f->f_inode->i_fop->open) {
-		error = f->f_inode->i_fop->open(inode, f);
-		if (error)
-			goto out;
-	}
-
-	if (flags & O_TRUNC) {
-		error = fsdev_truncate(f, 0);
-		f->f_size = 0;
-		if (error)
-			goto out;
-	}
-
-	if (flags & O_APPEND)
-		f->f_pos = f->f_size;
+	error = do_dentry_open(f);
+	if (error)
+		goto out;
 
 	return file_to_fd(f);
 
-- 
2.47.3




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

end of thread, other threads:[~2025-10-20 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-15  8:34 [PATCH 1/2] fs: factor out final file open logic out of openat() Ahmad Fatoum
2025-10-15  8:34 ` [PATCH 2/2] fs: allocate inodes for O_TMPFILE-created files Ahmad Fatoum
2025-10-20 10:58 ` [PATCH 1/2] fs: factor out final file open logic out of openat() Sascha Hauer

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