mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Adrian Negreanu <adrian.negreanu@nxp.com>, Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH v2 1/4] fs: devfs: implement cdev_fdopen
Date: Mon, 30 Jan 2023 08:27:04 +0100	[thread overview]
Message-ID: <20230130072707.2423294-2-ahmad@a3f.at> (raw)
In-Reply-To: <20230130072707.2423294-1-ahmad@a3f.at>

As an alternative to cdev_open and using cdev_read/write, we define a
new cdev_fdopen function that returns a file descriptor. The benefit of
this is that code using it may use all the more high level helpers we
have for reading/writing file descriptors.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 fs/devfs-core.c  | 20 ++++++++++++++++++++
 include/driver.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 2a259c2fe0ef..fbcf68e81597 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -177,6 +177,26 @@ int cdev_open(struct cdev *cdev, unsigned long flags)
 	return 0;
 }
 
+int cdev_fdopen(struct cdev *cdev, unsigned long flags)
+{
+	char *path;
+	int fd;
+
+	if (!cdev)
+		return -ENODEV;
+	if (IS_ERR(cdev))
+		return PTR_ERR(cdev);
+
+	path = basprintf("/dev/%s", cdev->name);
+	if (!path)
+		return -ENOMEM;
+
+	fd = open(path, flags);
+
+	free(path);
+	return fd;
+}
+
 struct cdev *cdev_open_by_name(const char *name, unsigned long flags)
 {
 	struct cdev *cdev;
diff --git a/include/driver.h b/include/driver.h
index f0a0b9d6ae8f..f53668711b81 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -535,6 +535,7 @@ struct cdev *cdev_open_by_name(const char *name, unsigned long flags);
 struct cdev *cdev_create_loop(const char *path, ulong flags, loff_t offset);
 void cdev_remove_loop(struct cdev *cdev);
 int cdev_open(struct cdev *, unsigned long flags);
+int cdev_fdopen(struct cdev *cdev, unsigned long flags);
 void cdev_close(struct cdev *cdev);
 int cdev_flush(struct cdev *cdev);
 ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags);
-- 
2.38.1




  reply	other threads:[~2023-01-30 18:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30  7:27 [PATCH v2 0/4] video: add support for QEMU ramfb Ahmad Fatoum
2023-01-30  7:27 ` Ahmad Fatoum [this message]
2023-01-30  7:27 ` [PATCH v2 2/4] asm-generic: avoid compiler warnings due to PCI_IOBASE Ahmad Fatoum
2023-01-30  7:27 ` [PATCH v2 3/4] firmware: add QEMU FW CFG driver Ahmad Fatoum
2023-01-30  7:27 ` [PATCH v2 4/4] video: add support for QEMU ramfb Ahmad Fatoum
2023-01-31  8:19 ` [PATCH v2 0/4] " 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=20230130072707.2423294-2-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --cc=adrian.negreanu@nxp.com \
    --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