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 v2 035/113] fs: implement openat and friends
Date: Mon,  4 Mar 2024 19:59:20 +0100	[thread overview]
Message-ID: <20240304190038.3486881-36-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240304190038.3486881-1-a.fatoum@pengutronix.de>

The EFI file system API takes as handle an arbitrary file within the
volume. Directory iteration should happen relative to that file, which
lends itself well to mapping this to openat and friends.

Add support for these to barebox in preparation.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/readlink.c |   2 +-
 fs/fs.c             | 140 +++++++++++++++++++++++++-------------------
 include/fcntl.h     |  14 ++++-
 include/fs.h        |   2 +-
 include/sys/stat.h  |   8 ++-
 include/unistd.h    |  35 +++++++++--
 6 files changed, 132 insertions(+), 69 deletions(-)

diff --git a/commands/readlink.c b/commands/readlink.c
index 81ad25c733ab..55f8249028e1 100644
--- a/commands/readlink.c
+++ b/commands/readlink.c
@@ -31,7 +31,7 @@ static int do_readlink(int argc, char *argv[])
 		return COMMAND_ERROR_USAGE;
 
 	if (canonicalize) {
-		char *buf = canonicalize_path(argv[optind]);
+		char *buf = canonicalize_path(AT_FDCWD, argv[optind]);
 		struct stat s;
 
 		if (!buf)
diff --git a/fs/fs.c b/fs/fs.c
index bf527f1b2d9b..6b71440318af 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -130,10 +130,11 @@ void cdev_print(const struct cdev *cdev)
 }
 EXPORT_SYMBOL(cdev_print);
 
-static struct fs_device *get_fsdevice_by_path(const char *path);
+static struct fs_device *get_fsdevice_by_path(int dirfd, const char *path);
 
 void stat_print(const char *filename, const struct stat *st)
 {
+	int dirfd = AT_FDCWD;
 	struct block_device *bdev = NULL;
 	struct fs_device *fdev;
 	struct cdev *cdev = NULL;
@@ -156,7 +157,7 @@ void stat_print(const char *filename, const struct stat *st)
 	if (st->st_mode & S_IFCHR) {
 		char *path;
 
-		path = canonicalize_path(filename);
+		path = canonicalize_path(dirfd, filename);
 		if (path) {
 			const char *devicefile = devpath_to_name(path);
 			struct cdev *lcdev;
@@ -198,7 +199,7 @@ void stat_print(const char *filename, const struct stat *st)
 	if (type)
 		printf("  %s%s", typeprefix, type);
 
-	fdev = get_fsdevice_by_path(filename);
+	fdev = get_fsdevice_by_path(dirfd, filename);
 
 	printf("\nDevice: %s\tInode: %lu\n",
 	       fdev ? dev_name(&fdev->dev) : "<unknown>",
@@ -235,7 +236,7 @@ postcore_initcall(init_fs);
 
 struct filename;
 
-static int filename_lookup(struct filename *name, unsigned flags,
+static int filename_lookup(int dirfd, struct filename *name, unsigned flags,
 			   struct path *path);;
 static struct filename *getname(const char *filename);
 static void path_put(const struct path *path);
@@ -282,7 +283,7 @@ struct cdev *get_cdev_by_mountpath(const char *path)
 {
 	struct fs_device *fsdev;
 
-	fsdev = get_fsdevice_by_path(path);
+	fsdev = get_fsdevice_by_path(AT_FDCWD, path);
 	if (!fsdev)
 		return NULL;
 
@@ -293,7 +294,7 @@ char *get_mounted_path(const char *path)
 {
 	struct fs_device *fdev;
 
-	fdev = get_fsdevice_by_path(path);
+	fdev = get_fsdevice_by_path(AT_FDCWD, path);
 	if (!fdev)
 		return NULL;
 
@@ -828,7 +829,7 @@ static void fs_remove(struct device *dev)
 	if (fsdev->loop && fsdev->cdev) {
 		cdev_remove_loop(fsdev->cdev);
 
-		ret = filename_lookup(getname(fsdev->backingstore),
+		ret = filename_lookup(AT_FDCWD, getname(fsdev->backingstore),
 				      LOOKUP_FOLLOW, &path);
 		if (!ret) {
 			mntput(path.mnt);
@@ -912,7 +913,7 @@ int fsdev_open_cdev(struct fs_device *fsdev)
 	parseopt_b(fsdev->options, "loop", &fsdev->loop);
 	parseopt_llu_suffix(fsdev->options, "offset", &offset);
 	if (fsdev->loop) {
-		ret = filename_lookup(getname(fsdev->backingstore),
+		ret = filename_lookup(AT_FDCWD, getname(fsdev->backingstore),
 				      LOOKUP_FOLLOW, &path);
 		if (ret)
 			return ret;
@@ -1194,7 +1195,7 @@ char *path_get_linux_rootarg(const char *path)
 	struct fs_device *fsdev;
 	const char *str;
 
-	fsdev = get_fsdevice_by_path(path);
+	fsdev = get_fsdevice_by_path(AT_FDCWD, path);
 	if (!fsdev)
 		return ERR_PTR(-EINVAL);
 
@@ -1217,7 +1218,7 @@ bool __is_tftp_fs(const char *path)
 {
 	struct fs_device *fsdev;
 
-	fsdev = get_fsdevice_by_path(path);
+	fsdev = get_fsdevice_by_path(AT_FDCWD, path);
 	if (!fsdev)
 		return false;
 
@@ -2156,9 +2157,10 @@ static int link_path_walk(const char *name, struct nameidata *nd)
 	}
 }
 
-static const char *path_init(struct nameidata *nd, unsigned flags)
+static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
 {
 	const char *s = nd->name->name;
+	FILE *f = NULL;
 
 	nd->last_type = LAST_ROOT; /* if there are only slashes... */
 	nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
@@ -2167,12 +2169,23 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
 	nd->path.mnt = NULL;
 	nd->path.dentry = NULL;
 
+	/* We don't check for error here yet, as POSIX allows checking
+	 * whether paths are absolute with openat(-1, path, O_PATH)
+	 */
+	if (dirfd != AT_FDCWD)
+		f = fd_to_file(dirfd);
+
 	if (*s == '/') {
 		get_root(&nd->path);
-		return s;
-	} else {
+	} else if (dirfd == AT_FDCWD) {
 		get_pwd(&nd->path);
-		return s;
+	} else {
+		if (IS_ERR(f))
+			return ERR_CAST(f);
+
+		nd->path.mnt = &f->fsdev->vfsmount;
+		nd->path.dentry = f->dentry;
+		follow_mount(&nd->path);
 	}
 
 	return s;
@@ -2210,10 +2223,10 @@ static void terminate_walk(struct nameidata *nd)
 }
 
 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
-static int path_parentat(struct nameidata *nd, unsigned flags,
+static int path_parentat(int dirfd, struct nameidata *nd, unsigned flags,
 				struct path *parent)
 {
-	const char *s = path_init(nd, flags);
+	const char *s = path_init(dirfd, nd, flags);
 	int err;
 
 	if (IS_ERR(s))
@@ -2229,7 +2242,8 @@ static int path_parentat(struct nameidata *nd, unsigned flags,
 	return err;
 }
 
-static struct filename *filename_parentat(struct filename *name,
+static struct filename *filename_parentat(int dirfd,
+				struct filename *name,
 				unsigned int flags, struct path *parent,
 				struct qstr *last, int *type)
 {
@@ -2241,7 +2255,7 @@ static struct filename *filename_parentat(struct filename *name,
 
 	set_nameidata(&nd, name);
 
-	retval = path_parentat(&nd, flags, parent);
+	retval = path_parentat(dirfd, &nd, flags, parent);
 	if (likely(!retval)) {
 		*last = nd.last;
 		*type = nd.last_type;
@@ -2253,7 +2267,7 @@ static struct filename *filename_parentat(struct filename *name,
 	return name;
 }
 
-static struct dentry *filename_create(struct filename *name,
+static struct dentry *filename_create(int dirfd, struct filename *name,
 				struct path *path, unsigned int lookup_flags)
 {
 	struct dentry *dentry = ERR_PTR(-EEXIST);
@@ -2262,7 +2276,7 @@ static struct dentry *filename_create(struct filename *name,
 	int error;
 	bool is_dir = (lookup_flags & LOOKUP_DIRECTORY);
 
-	name = filename_parentat(name, 0, path, &last, &type);
+	name = filename_parentat(dirfd, name, 0, path, &last, &type);
 	if (IS_ERR(name))
 		return ERR_CAST(name);
 
@@ -2306,7 +2320,7 @@ static struct dentry *filename_create(struct filename *name,
 	return dentry;
 }
 
-static int filename_lookup(struct filename *name, unsigned flags,
+static int filename_lookup(int dirfd, struct filename *name, unsigned flags,
 			   struct path *path)
 {
 	int err;
@@ -2318,7 +2332,7 @@ static int filename_lookup(struct filename *name, unsigned flags,
 
 	set_nameidata(&nd, name);
 
-	s = path_init(&nd, flags);
+	s = path_init(dirfd, &nd, flags);
 	if (IS_ERR(s))
 		return PTR_ERR(s);
 
@@ -2345,13 +2359,13 @@ static int filename_lookup(struct filename *name, unsigned flags,
 	return err;
 }
 
-static struct fs_device *get_fsdevice_by_path(const char *pathname)
+static struct fs_device *get_fsdevice_by_path(int dirfd, const char *pathname)
 {
 	struct fs_device *fsdev;
 	struct path path;
 	int ret;
 
-	ret = filename_lookup(getname(pathname), 0, &path);
+	ret = filename_lookup(dirfd, getname(pathname), 0, &path);
 	if (ret)
 		return NULL;
 
@@ -2403,14 +2417,14 @@ static int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 /* libfs.c */
 
 /* ---------------------------------------------------------------- */
-int mkdir (const char *pathname, mode_t mode)
+int mkdirat(int dirfd, const char *pathname, mode_t mode)
 {
 	struct dentry *dentry;
 	struct path path;
 	int error;
 	unsigned int lookup_flags = LOOKUP_DIRECTORY;
 
-	dentry = filename_create(getname(pathname), &path, lookup_flags);
+	dentry = filename_create(dirfd, getname(pathname), &path, lookup_flags);
 	if (IS_ERR(dentry)) {
 		error = PTR_ERR(dentry);
 		goto out;
@@ -2423,9 +2437,9 @@ int mkdir (const char *pathname, mode_t mode)
 out:
 	return errno_set(error);
 }
-EXPORT_SYMBOL(mkdir);
+EXPORT_SYMBOL(mkdirat);
 
-int rmdir (const char *pathname)
+static int rmdirat(int dirfd, const char *pathname)
 {
 	int error = 0;
 	struct filename *name;
@@ -2434,7 +2448,7 @@ int rmdir (const char *pathname)
 	struct qstr last;
 	int type;
 
-	name = filename_parentat(getname(pathname), 0,
+	name = filename_parentat(dirfd, getname(pathname), 0,
 				&path, &last, &type);
 	if (IS_ERR(name))
 		return PTR_ERR(name);
@@ -2475,9 +2489,8 @@ int rmdir (const char *pathname)
 
 	return errno_set(error);
 }
-EXPORT_SYMBOL(rmdir);
 
-int open(const char *pathname, int flags, ...)
+int openat(int dirfd, const char *pathname, int flags)
 {
 	struct fs_device *fsdev;
 	struct fs_driver *fsdrv;
@@ -2491,7 +2504,7 @@ int open(const char *pathname, int flags, ...)
 	struct filename *filename;
 
 	if (flags & O_TMPFILE) {
-		fsdev = get_fsdevice_by_path(pathname);
+		fsdev = get_fsdevice_by_path(dirfd, pathname);
 		if (!fsdev) {
 			errno = ENOENT;
 			return -errno;
@@ -2525,7 +2538,7 @@ int open(const char *pathname, int flags, ...)
 
 	set_nameidata(&nd, filename);
 
-	s = path_init(&nd, LOOKUP_FOLLOW);
+	s = path_init(dirfd, &nd, LOOKUP_FOLLOW);
 	if (IS_ERR(s))
 		return PTR_ERR(s);
 
@@ -2592,7 +2605,7 @@ int open(const char *pathname, int flags, ...)
 		goto out1;
 	}
 
-	f->path = xstrdup(pathname);
+	f->path = dpath(dentry, d_root);
 	f->dentry = dentry;
 	f->f_inode = iget(inode);
 	f->flags = flags;
@@ -2631,7 +2644,7 @@ int open(const char *pathname, int flags, ...)
 out1:
 	return errno_set(error);
 }
-EXPORT_SYMBOL(open);
+EXPORT_SYMBOL(openat);
 
 static const char *fd_getpath(int fd)
 {
@@ -2647,14 +2660,19 @@ static const char *fd_getpath(int fd)
 	return f->path;
 }
 
-int unlink(const char *pathname)
+int unlinkat(int dirfd, const char *pathname, int flags)
 {
 	int ret;
 	struct dentry *dentry;
 	struct inode *inode;
 	struct path path;
 
-	ret = filename_lookup(getname(pathname), 0, &path);
+	if (flags == AT_REMOVEDIR)
+		return rmdirat(dirfd, pathname);
+	if (flags)
+		return -EINVAL;
+
+	ret = filename_lookup(dirfd, getname(pathname), 0, &path);
 	if (ret)
 		goto out;
 
@@ -2683,7 +2701,7 @@ int unlink(const char *pathname)
 out:
 	return errno_set(ret);
 }
-EXPORT_SYMBOL(unlink);
+EXPORT_SYMBOL(unlinkat);
 
 static int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
 {
@@ -2700,7 +2718,7 @@ int symlink(const char *pathname, const char *newpath)
 	int error;
 	unsigned int lookup_flags = LOOKUP_DIRECTORY;
 
-	dentry = filename_create(getname(newpath), &path, lookup_flags);
+	dentry = filename_create(AT_FDCWD, getname(newpath), &path, lookup_flags);
 	if (IS_ERR(dentry)) {
 		error = PTR_ERR(dentry);
 		goto out;
@@ -2757,7 +2775,7 @@ DIR *opendir(const char *pathname)
 	DIR *d;
 	struct path path = {};
 
-	ret = filename_lookup(getname(pathname),
+	ret = filename_lookup(AT_FDCWD, getname(pathname),
 			      LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
 	if (ret)
 		goto out;
@@ -2844,7 +2862,7 @@ int rewinddir(DIR *dir)
 }
 EXPORT_SYMBOL(rewinddir);
 
-int readlink(const char *pathname, char *buf, size_t bufsiz)
+int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
 {
 	int ret;
 	struct dentry *dentry;
@@ -2852,7 +2870,7 @@ int readlink(const char *pathname, char *buf, size_t bufsiz)
 	const char *link;
 	struct path path = {};
 
-	ret = filename_lookup(getname(pathname), 0, &path);
+	ret = filename_lookup(dirfd, getname(pathname), 0, &path);
 	if (ret)
 		goto out;
 
@@ -2884,16 +2902,16 @@ int readlink(const char *pathname, char *buf, size_t bufsiz)
 out:
 	return errno_set(ret);
 }
-EXPORT_SYMBOL(readlink);
+EXPORT_SYMBOL(readlinkat);
 
-static int stat_filename(const char *filename, struct stat *s, unsigned int flags)
+static int stat_filename(int dirfd, const char *filename, struct stat *s, unsigned int flags)
 {
 	int ret;
 	struct dentry *dentry;
 	struct inode *inode;
 	struct path path = {};
 
-	ret = filename_lookup(getname(filename), flags, &path);
+	ret = filename_lookup(dirfd, getname(filename), flags, &path);
 	if (ret)
 		goto out;
 
@@ -2915,17 +2933,17 @@ static int stat_filename(const char *filename, struct stat *s, unsigned int flag
 	return errno_set(ret);
 }
 
-int stat(const char *filename, struct stat *s)
+int statat(int dirfd, const char *filename, struct stat *s)
 {
-	return stat_filename(filename, s, LOOKUP_FOLLOW);
+	return stat_filename(dirfd, filename, s, LOOKUP_FOLLOW);
 }
-EXPORT_SYMBOL(stat);
+EXPORT_SYMBOL(statat);
 
-int lstat(const char *filename, struct stat *s)
+int lstatat(int dirfd, const char *filename, struct stat *s)
 {
-	return stat_filename(filename, s, 0);
+	return stat_filename(dirfd, filename, s, 0);
 }
-EXPORT_SYMBOL(lstat);
+EXPORT_SYMBOL(lstatat);
 
 static char *__dpath(struct dentry *dentry, struct dentry *root)
 {
@@ -2981,6 +2999,8 @@ char *dpath(struct dentry *dentry, struct dentry *root)
 
 /**
  * canonicalize_path - resolve links in path
+ *
+ * @dirfd: directory file descriptor to look up relative to
  * @pathname: The input path
  *
  * This function resolves all links in @pathname and returns
@@ -2988,13 +3008,13 @@ char *dpath(struct dentry *dentry, struct dentry *root)
  *
  * Return: Path with links resolved. Allocated, must be freed after use.
  */
-char *canonicalize_path(const char *pathname)
+char *canonicalize_path(int dirfd, const char *pathname)
 {
 	char *res = NULL;
 	struct path path;
 	int ret;
 
-	ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+	ret = filename_lookup(dirfd, getname(pathname), LOOKUP_FOLLOW, &path);
 	if (ret)
 		goto out;
 
@@ -3016,7 +3036,7 @@ int chdir(const char *pathname)
 	struct path path;
 	int ret;
 
-	ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
+	ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
 	if (ret)
 		goto out;
 
@@ -3135,7 +3155,7 @@ int mount(const char *device, const char *fsname, const char *pathname,
 	struct path path = {};
 
 	if (d_root) {
-		ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+		ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
 		if (ret)
 			goto out;
 
@@ -3242,7 +3262,7 @@ int umount(const char *pathname)
 	struct path path = {};
 	int ret;
 
-	ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+	ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
 	if (ret)
 		return ret;
 
@@ -3313,7 +3333,7 @@ void automount_remove(const char *pathname)
 	struct path path;
 	int ret;
 
-	ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+	ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
 	if (ret)
 		return;
 
@@ -3329,7 +3349,7 @@ int automount_add(const char *pathname, const char *cmd)
 	struct path path;
 	int ret;
 
-	ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+	ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
 	if (ret)
 		return ret;
 
@@ -3441,14 +3461,14 @@ static int do_lookup_dentry(int argc, char *argv[])
 	if (argc < 2)
 		return COMMAND_ERROR_USAGE;
 
-	ret = filename_lookup(getname(argv[1]), 0, &path);
+	ret = filename_lookup(AT_FDCWD, getname(argv[1]), 0, &path);
 	if (ret) {
 		printf("Cannot lookup path \"%s\": %s\n",
 		       argv[1], strerror(-ret));
 		return 1;
 	}
 
-	canon = canonicalize_path(argv[1]);
+	canon = canonicalize_path(AT_FDCWD, argv[1]);
 
 	printf("path \"%s\":\n", argv[1]);
 	printf("dentry: 0x%p\n", path.dentry);
diff --git a/include/fcntl.h b/include/fcntl.h
index 06289abc4376..a6ed50b92eaf 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -4,6 +4,13 @@
 
 #include <linux/types.h>
 
+#define AT_FDCWD		-100    /* Special value used to indicate
+                                           openat should use the current
+                                           working directory. */
+
+#define AT_REMOVEDIR		0x200   /* Remove directory instead of
+                                           unlinking file.  */
+
 /* open/fcntl - O_SYNC is only implemented on blocks devices and on files
    located on an ext2 file system */
 #define O_ACCMODE	00000003
@@ -28,7 +35,12 @@
 #define O_RWSIZE_4	004000000
 #define O_RWSIZE_8	010000000
 
-int open(const char *pathname, int flags, ...);
+int openat(int dirfd, const char *pathname, int flags);
+
+static inline int open(const char *pathname, int flags, ...)
+{
+	return openat(AT_FDCWD, pathname, flags);
+}
 
 static inline int creat(const char *pathname, mode_t mode)
 {
diff --git a/include/fs.h b/include/fs.h
index a61982e59ade..c4af8659b0d3 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -150,7 +150,7 @@ char *mkmodestr(unsigned long mode, char *str);
 void stat_print(const char *filename, const struct stat *st);
 void cdev_print(const struct cdev *cdev);
 
-char *canonicalize_path(const char *pathname);
+char *canonicalize_path(int dirfd, const char *pathname);
 
 char *get_mounted_path(const char *path);
 
diff --git a/include/sys/stat.h b/include/sys/stat.h
index 0dd43d1f02c8..7af49a1d3ccc 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -5,7 +5,13 @@
 
 #include <linux/types.h>
 #include <linux/stat.h>
+#include <fcntl.h>
 
-int mkdir (const char *pathname, mode_t mode);
+int mkdirat(int dirfd, const char *pathname, mode_t mode);
+
+static inline int mkdir(const char *pathname, mode_t mode)
+{
+	return mkdirat(AT_FDCWD, pathname, mode);
+}
 
 #endif /* __STAT_H */
diff --git a/include/unistd.h b/include/unistd.h
index f7fe737d002b..b78acbfd737a 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -3,26 +3,51 @@
 #define __UNISTD_H
 
 #include <linux/types.h>
+#include <fcntl.h>
 
 struct stat;
 
-int unlink(const char *pathname);
+int unlinkat(int dirfd, const char *pathname, int flags);
 int close(int fd);
-int lstat(const char *filename, struct stat *s);
-int stat(const char *filename, struct stat *s);
+int lstatat(int dirfd, const char *filename, struct stat *s);
+int statat(int dirfd, const char *filename, struct stat *s);
 int fstat(int fd, struct stat *s);
 ssize_t read(int fd, void *buf, size_t count);
 ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
 ssize_t write(int fd, const void *buf, size_t count);
 ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset);
 loff_t lseek(int fildes, loff_t offset, int whence);
-int rmdir (const char *pathname);
 int symlink(const char *pathname, const char *newpath);
-int readlink(const char *path, char *buf, size_t bufsiz);
+int readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz);
 int chdir(const char *pathname);
 char *pushd(const char *dir);
 int popd(char *dir);
 const char *getcwd(void);
 int ftruncate(int fd, loff_t length);
 
+static inline int unlink(const char *pathname)
+{
+	return unlinkat(AT_FDCWD, pathname, 0);
+}
+
+static inline int lstat(const char *filename, struct stat *s)
+{
+	return lstatat(AT_FDCWD, filename, s);
+}
+
+static inline int stat(const char *filename, struct stat *s)
+{
+	return statat(AT_FDCWD, filename, s);
+}
+
+static inline int rmdir(const char *pathname)
+{
+	return unlinkat(AT_FDCWD, pathname, AT_REMOVEDIR);
+}
+
+static inline int readlink(const char *path, char *buf, size_t bufsiz)
+{
+	return readlinkat(AT_FDCWD, path, buf, bufsiz);
+}
+
 #endif /* __UNISTD_H */
-- 
2.39.2




  parent reply	other threads:[~2024-03-04 19:11 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 001/113] string: implement strcmp_ptr and streq_ptr helpers Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 002/113] commands: efiexit: flush console and shutdown barebox Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 003/113] treewide: add errno_set helper for returning positive error code in errno Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 004/113] vsprintf: guard against NULL in UUID %pU Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 005/113] common: add option to poweroff system on failure Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 006/113] boot: print error code when booting fails Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 007/113] common: efi: move directory to top-level Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 008/113] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 009/113] efi: payload: image: return actual read_file() error Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 010/113] of: don't report failure to of_read_file twice Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 011/113] efi: payload: make missing state reporting less verbose Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 012/113] libfile: factor out read_file_into_buf helper Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 013/113] efi: payload: image: allocate image via loader if it exceeds malloc area Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 014/113] efi: payload: image: use assigned barebox loader type on x86 Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 015/113] efi: payload: iomem: adjust types to avoid casting Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 016/113] commands: kallsyms: add command-line interface Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 017/113] block: define BLOCKSIZE globally in block.h Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 018/113] cdev: implement setter/getter for cdev device node Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 019/113] block: virtio: assign virtio-mmio device tree node to cdevs Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 020/113] commands: stat: print DT node for cdevs if available Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 021/113] partitions: have parsers record bootable bits Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 022/113] commands: stat: display bootable partition table bit info Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 023/113] block: record block device type Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 024/113] include: add definitions for UAPI discoverable partitions spec Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 025/113] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86 Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 026/113] fs: fix unreaddir, so readdir returns unread dirent first Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 027/113] fs: turn creat into static inline helper Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 028/113] fs: drop unused LOOKUP_ flags Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 029/113] fs: opendir: reference mount point until closedir is called Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 030/113] fs: factor out opendir iteration Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 031/113] fs: implement fdopendir and rewinddir Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 032/113] fs: remove unused member from struct nameidata Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 033/113] fs: always check path_init for errors Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 034/113] fs: set current working dir directly when mounting root Ahmad Fatoum
2024-03-04 18:59 ` Ahmad Fatoum [this message]
2024-03-04 18:59 ` [PATCH v2 036/113] fs: implement O_PATH Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 037/113] fs: support different root directories Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 038/113] fs: implement O_CHROOT Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 039/113] commands: introduce new findmnt command Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 040/113] fs: initialize struct nameidata::last Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 041/113] fs: support opening / Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 042/113] test: self: add dirfd tests Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 043/113] commands: stat: add option for statat Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 044/113] efi: payload: lower command line options print from error to info Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 045/113] efi: payload: init: warn if /boot FS is unknown Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 046/113] commands: time: switch to using getopt for -n Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 047/113] commands: time: reduce strjoin runtime, drop trailing space Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 048/113] commands: time: refactor into new strjoin Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 049/113] test: self: add strjoin tests Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 050/113] filetype: have cdev_detect_type take a cdev Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 051/113] ARM: mmu-early: gracefully handle already enabled MMU Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 052/113] efi: don't hide structs, enums or unions behind _t Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 053/113] efi: make headers self-contained Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 054/113] efi: unify whitespace for GUIDs Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 055/113] efi: efi-guid: add more GUIDs Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 056/113] ARM64: cpu: setupc: rewrite to be fully PIC Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 057/113] ARM64: runtime-offset: make get_runtime_offset " Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 058/113] pbl: introduce CONFIG_PBL_FULLY_PIC Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 059/113] efi: payload: fix ARM build Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 060/113] efi: payload: init: restrict barebox mem to first 1G only on x86 Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 061/113] efi: add efi_is_loader/efi_is_payload helpers Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 062/113] efi: payload: suppress EFI payload initcalls when not EFI-loaded Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 063/113] ARM: make board data definitions accessible to other architectures Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 064/113] boarddata: add barebox_boarddata_is_machine helper Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 065/113] common: add PE/COFF loader Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 066/113] efi: use efi_handle_t where appropriate Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 067/113] efi: block: move definitions into header file Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 068/113] efi: define efi_handle_t as opaque pointer Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 069/113] efi: constify guid_t in API Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 070/113] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 071/113] efi: add EFI_WARN constants Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 072/113] efi-stdio: fix wait_for_event argument Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 073/113] efi-stdio: wait for extended input key event when using extended input Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 074/113] efi: flesh out EFI definitions in header Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 075/113] efi: add efi_driver_binding_protocol Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 076/113] efi: improve usability of EFI_PAGE_* macros Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 077/113] fs: efi: move definitions into header Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 078/113] efi: fs: flesh out file system definitions Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 079/113] efi: stdio: fix efi_register_keystroke_notify prototype Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 080/113] video: mark EFI_GOP driver x86-only for now Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 081/113] filetype: add new file types for EFI-enabled Linux images Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 082/113] efi: payload: register handler for EFI-stubbed ARM64 kernel Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 083/113] efi: payload: factor C efi_main into dedicated file Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 084/113] efi: payload: early-mem: simplify error message reporting Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 085/113] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 086/113] ARM64: add optional EFI stub Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 087/113] efi: devicepath: improve const safety Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 088/113] efi: refactor device_path_to_partuuid for code reuse Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 089/113] efi: devicepath: implement device_path_to_str_buf variant Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 090/113] lib: vsprintf: align documentation with current feature set Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 091/113] vsprintf: add %pD for printing EFI device path Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 092/113] lib: string: import Linux strreplace helper Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 093/113] efi: payload: dynamically determine bootloader file name Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 094/113] efi: payload: iomem: register later Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 095/113] efi: payload: protect against buggy EFI implementations Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 096/113] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 097/113] commands: add cpuinfo -s option for stacktrace Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 098/113] efi: devicepath: align MemoryMapped name with spec Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 099/113] efi: devicepath: pretty print BBS BEV DeviceType Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 100/113] efi: devicepath: format GUIDs as little endian Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 101/113] efi: devicepath: move END device node definitions into header Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 102/113] efi: devicepath: drop underscores in hex constants Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 103/113] efi: devicepath: namespace definitions Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 104/113] efi: devicepath: use flexible array members for trailing strings Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 105/113] efi: devicepath: drop unused macro Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 106/113] efi: devicepath: let compiler worry about unaligned unpacking Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 107/113] efi: devicepath: correct formatting of BBS Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 108/113] commands: provide efi_handle_dump in both payload and loader Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 109/113] lib: uuid: implement uuid/guid_parse Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 110/113] commands: efi_handle_dump: prepare for supporting EFI loader Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 111/113] commands: efi_handle_dump: print loaded image devpath Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 112/113] commands: efi_handle_dump: use guid_parse instead of open-coding Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 113/113] commands: efi_handle_dump: don't ignore failure to parse GUID Ahmad Fatoum
2024-03-05 15:28 ` [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support 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=20240304190038.3486881-36-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