mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/8] fs: retire FILE.in_use member
Date: Tue,  7 Jan 2025 08:59:34 +0100	[thread overview]
Message-ID: <20250107075939.2841119-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250107075939.2841119-1-a.fatoum@pengutronix.de>

The upstream struct file doesn't have an in_use member. As we already
have an fsdev member in struct filep, we can just use that to mark that
the file descriptor is already in use.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c      | 21 +++++++++------------
 include/fs.h |  1 -
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 57d173beb737..2adce54a61b6 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -304,14 +304,14 @@ char *get_mounted_path(const char *path)
 	return fdev->path;
 }
 
-static FILE *get_file(void)
+static FILE *get_file(struct fs_device *fsdev)
 {
 	int i;
 
 	for (i = 3; i < MAX_FILES; i++) {
-		if (!files[i].in_use) {
+		if (!files[i].fsdev) {
 			memset(&files[i], 0, sizeof(FILE));
-			files[i].in_use = 1;
+			files[i].fsdev = fsdev;
 			return &files[i];
 		}
 	}
@@ -330,14 +330,14 @@ static void put_file(FILE *f)
 {
 	free(f->path);
 	f->path = NULL;
-	f->in_use = 0;
+	f->fsdev = NULL;
 	iput(f->f_inode);
 	dput(f->dentry);
 }
 
 static FILE *fd_to_file(int fd, bool o_path_ok)
 {
-	if (fd < 0 || fd >= MAX_FILES || !files[fd].in_use) {
+	if (fd < 0 || fd >= MAX_FILES || !files[fd].fsdev) {
 		errno = EBADF;
 		return ERR_PTR(-errno);
 	}
@@ -2564,7 +2564,7 @@ int openat(int dirfd, const char *pathname, int flags)
 			return -errno;
 		}
 
-		f = get_file();
+		f = get_file(fsdev);
 		if (!f) {
 			errno = EMFILE;
 			return -errno;
@@ -2576,7 +2576,6 @@ int openat(int dirfd, const char *pathname, int flags)
 		f->f_inode->i_mode = S_IFREG;
 		f->flags = flags;
 		f->size = 0;
-		f->fsdev = fsdev;
 
 		return file_to_fd(f);
 	}
@@ -2647,8 +2646,10 @@ int openat(int dirfd, const char *pathname, int flags)
 	}
 
 	inode = d_inode(dentry);
+	sb = inode->i_sb;
+	fsdev = container_of(sb, struct fs_device, sb);
 
-	f = get_file();
+	f = get_file(fsdev);
 	if (!f) {
 		error = -EMFILE;
 		goto out1;
@@ -2660,12 +2661,8 @@ int openat(int dirfd, const char *pathname, int flags)
 	f->flags = flags;
 	f->size = inode->i_size;
 
-	sb = inode->i_sb;
-	fsdev = container_of(sb, struct fs_device, sb);
 	fsdrv = fsdev->driver;
 
-	f->fsdev = fsdev;
-
 	if (flags & O_PATH)
 		return file_to_fd(f);
 
diff --git a/include/fs.h b/include/fs.h
index 5525dc1c9f17..1deb1a87bb7f 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -29,7 +29,6 @@ typedef struct filep {
 
 	void *priv;         /* private to the filesystem driver              */
 
-	char in_use;
 
 	struct inode *f_inode;
 	struct dentry *dentry;
-- 
2.39.5




  parent reply	other threads:[~2025-01-07  8:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07  7:59 [PATCH 0/8] fs: merge struct filep (FILE) and struct file Ahmad Fatoum
2025-01-07  7:59 ` [PATCH 1/8] fs: derive file descriptor number by pointer arithmetic Ahmad Fatoum
2025-01-07  7:59 ` [PATCH 2/8] fs: drop ifdefs in linux/fs.h Ahmad Fatoum
2025-01-07  7:59 ` Ahmad Fatoum [this message]
2025-01-07  7:59 ` [PATCH 4/8] fs: align FILE struct member names with upstream struct file Ahmad Fatoum
2025-01-07  7:59 ` [PATCH 5/8] fs: fat: rename f_size to f_len Ahmad Fatoum
2025-01-07  7:59 ` [PATCH 6/8] fs: replace FILE.size by f_inode.i_size Ahmad Fatoum
2025-01-07  7:59 ` [PATCH 7/8] fs: merge struct file and struct filep Ahmad Fatoum
2025-01-07  7:59 ` [PATCH 8/8] fs: retire FILE typdef Ahmad Fatoum
2025-01-08 14:02 ` [PATCH 0/8] fs: merge struct filep (FILE) and struct file 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=20250107075939.2841119-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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