[PATCH 1/2] fs: factor out final file open logic out of openat()
Ahmad Fatoum
a.fatoum at barebox.org
Wed Oct 15 01:34:15 PDT 2025
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 at 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
More information about the barebox
mailing list