From patchwork Fri Apr 3 14:04:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2089 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225160; bh=CtqnGyt3tbgyARFq5lYYaNidvz5DU2Eb0C+eeEsBILQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=WZ0wDsVZltGN2AreLYBFxaRJAhbaRQjrwHngCpKEP3/uDrO+tWM+MgrzZR1KHNynq ZgvD99q2auBQGADTI1yClUWdEkofV9wULkuK75Kv5kWt4XMmY54akN7vfE1762Tk14 4nSN6wlJ/MaPfnHe4tB//EgDJs5tHsc6+loT0te3wVOUzW8tulSk7ay/QOSR/RKRwS vX8SjtcIBcSDEBanqNsNxt+3GqUqKgYmHbHMnMoUJTUBRQJ4OIC2VnVXKTplYoVurw 71vdym9SwpxovHWoTm85scfg6yPGo9PE1Vm8N1HOk2eyHteLFOIDty/cGrJHfQtXhy 0yUaQkPqdBNqA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 32B4D6A375 for ; Fri, 3 Apr 2026 08:06:00 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 2lsg7raT3SXY for ; Fri, 3 Apr 2026 08:06:00 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225158; bh=CtqnGyt3tbgyARFq5lYYaNidvz5DU2Eb0C+eeEsBILQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=dBNaU9/ANdg+I/ugrzxwLc+G8jTeboTOULaZ0wK87CPgVyLDKNlM8UHdTyHiUfwtS xmmhr3EzCdq6BQn1qQBQ+VbgU0WUQxHN05kVLPjrlPZErpee8HBeeNZQV+2AheYDce FLgEt4Ad3rIeGqdK++eYtS4WiKDyLIh3/fKINm44fTVl3CGXqCeZgDDMGT4JAsJHWR YRWSQDaVqa9Py0ejkr6bTn3ra6ocobr77fXy0eWKptW5/NjJsctLwa3KrlVvWQXf1a cCkbwkxGg25dGIUBjDzJP5367eb2JW9FbJu6QIRz8yq/ZznwXRZRwMN3FycHI0c74C R5DnLxdN+EGow== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4D3DF6A354 for ; Fri, 3 Apr 2026 08:05:58 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225155; bh=hFHqjHoK5F0albQGQLfMwYoMMD3920W6fqqx93oQvR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UhcmOlGqW1KTxiT2li1D7y152qYiVSH6bxrnk2mpU4Uf3L3N/w4i1pB15BEeFFiHR UygdxTlqc/Th/60AnkvMh/A/90Is24LJWa6WKkd8neek3emUha8moYX+QjAqJwpixF relnOHk1IQ+S3n0lu9riOB2nSMDGX7+s5zddqjgr1McNxPrMpWQu5Lw4+cj0nBuWHw t6WvpYqkS9Nk+2TtsftleKnPQYKHnBRsPnP9/4GFEd8allTLKidLH1pcmtfuTphVyV 59fbBlmhaP3yT+8TxjksazF3suKYc86MI6VfZ44h5bRAe+98WBm3PiTaUm6T2q7hh3 vJCfCw8LGt1FQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6C08B6A350; Fri, 3 Apr 2026 08:05:55 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id HZzyMnOpNyDQ; Fri, 3 Apr 2026 08:05:55 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225153; bh=+sdbz/xhaRXVQOPUWh74EUBv4rhWtlTuUqVVEBAG4xo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=woiciE3iU6X1MB2ohjQKPA+r41pLeHcrhvwRmuAhPCivOOYFPXQ33UKpd23Hi6a1/ nuWG3e6vT0SZEf2pkh38umuUr/ybo++qPqO9JWil6ci724Sf3PEaVBS3xa2ePZemsS v3tMQmQ2Z3CaB7zPVLC1vbV7THu+39AMOluau6nb9rawOUzr9TB2nngGbYPmIyjmXs N3+5ysNBP5Nnw5UDJozwwU4APkU8aFjTn2sznEUO61PJLyvVzrLiJH5CdqkyrmaSVR gXxfA1S/n98OA3Sc2dB2+LVJLRje8kUOCjYKl6WhyLk9XsVTb4zQT3axG3rzEE/xjz HaiK486KlWXWA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2E5EE6A347; Fri, 3 Apr 2026 08:05:53 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 3 Apr 2026 08:04:26 -0600 Message-ID: <20260403140523.1998228-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260403140523.1998228-1-sjg@u-boot.org> References: <20260403140523.1998228-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 2NZZPHDPQO6V2MBLFI6YPRJ6PJ6C23O4 X-Message-ID-Hash: 2NZZPHDPQO6V2MBLFI6YPRJ6PJ6C23O4 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/34] sandbox: Add various helpers for mkdir, rmdir, etc. List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add os_mkdir(), os_rmdir(), os_rename(), os_symlink() and os_readlink() wrappers around POSIX calls for sandbox use. Signed-off-by: Simon Glass --- arch/sandbox/cpu/os.c | 44 ++++++++++++++++++++++++++++++++++++++++++ include/os.h | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 8f751d69cf0..7088d8eb5e3 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -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; diff --git a/include/os.h b/include/os.h index 41e3022657c..495ab3a9d0a 100644 --- a/include/os.h +++ b/include/os.h @@ -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 *