From: Simon Glass <sjg@chromium.org>
Add os_mkdir(), os_rmdir(), os_rename(), os_symlink() and os_readlink()
wrappers around POSIX calls for sandbox use.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/cpu/os.c | 44 ++++++++++++++++++++++++++++++++++++++++++
include/os.h | 45 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
@@ -152,6 +152,50 @@ int os_unlink(const char *pathname)
return unlink(pathname);
}
+int os_mkdir(const char *pathname, int mode)
+{
+ if (mkdir(pathname, mode))
+ return -errno;
+
+ return 0;
+}
+
+int os_rmdir(const char *pathname)
+{
+ if (rmdir(pathname))
+ return -errno;
+
+ return 0;
+}
+
+int os_rename(const char *old_path, const char *new_path)
+{
+ if (rename(old_path, new_path))
+ return -errno;
+
+ return 0;
+}
+
+int os_symlink(const char *target, const char *linkpath)
+{
+ if (symlink(target, linkpath))
+ return -errno;
+
+ return 0;
+}
+
+int os_readlink(const char *pathname, char *buf, int size)
+{
+ ssize_t len;
+
+ len = readlink(pathname, buf, size - 1);
+ if (len < 0)
+ return -errno;
+ buf[len] = '\0';
+
+ return len;
+}
+
char *os_fgets(char *str, int size, int fd)
{
char *s = str;
@@ -108,6 +108,51 @@ int os_isatty(int fd);
*/
int os_unlink(const char *pathname);
+/**
+ * os_mkdir() - Create a directory
+ *
+ * @pathname: Path of directory to create
+ * @mode: Permissions (e.g. 0755)
+ * Return: 0 for success, -errno on error
+ */
+int os_mkdir(const char *pathname, int mode);
+
+/**
+ * os_rmdir() - Remove an empty directory
+ *
+ * @pathname: Path of directory to remove
+ * Return: 0 for success, -errno on error
+ */
+int os_rmdir(const char *pathname);
+
+/**
+ * os_readlink() - Read the target of a symbolic link
+ *
+ * @pathname: Path of the symbolic link
+ * @buf: Buffer to receive the target path
+ * @size: Size of buffer
+ * Return: length of target on success, -errno on error
+ */
+int os_readlink(const char *pathname, char *buf, int size);
+
+/**
+ * os_symlink() - Create a symbolic link
+ *
+ * @target: Target path
+ * @linkpath: Path of the symbolic link to create
+ * Return: 0 for success, -errno on error
+ */
+int os_symlink(const char *target, const char *linkpath);
+
+/**
+ * os_rename() - Rename or move a file or directory
+ *
+ * @old_path: Current path
+ * @new_path: New path
+ * Return: 0 for success, -errno on error
+ */
+int os_rename(const char *old_path, const char *new_path);
+
/**
* os_fgets() - read a string from a file stream
*