From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 1/2] fs: factor out final file open logic out of openat()
Date: Wed, 15 Oct 2025 10:34:15 +0200 [thread overview]
Message-ID: <20251015083512.4099259-1-a.fatoum@barebox.org> (raw)
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
next reply other threads:[~2025-10-15 8:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 8:34 Ahmad Fatoum [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251015083512.4099259-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox