From patchwork Wed Dec 31 22:29:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1139 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=1767220237; bh=VJRoA0R0roMb4gAggk1HXePXYH3Gf/JaE0Mp33Y2VEk=; 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=A+ur736AGbgVFAJPsR00z04CRhc3p65eF5oToKXwQJ7NSbyEQWJeogS5Vs83LhoOm XdQUKCDoBnR6PfqStJ74lnLOXTA5iov/U786e2OCHtg73I9HhWCxPddjmNDXp0xCwi +kgTfOur2/5o/FcXfyaY+zAeLUsRCSM6/lEn3QN6H7LQsjWk/hoj8lpGMNxwx8vPQW vIt8ysfYqKqxGwQOkht0ALD3ceECZIToFi5yCu87KG158AKirrEpXwxRm/eo13gMwJ wNselcAPgqm9k9Fbt/CPmTOYetFcPWc1VxZX+9vAI9JDqpv7bJu6tjQMi4rQORPHTp YWIcwqu2WUHcg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9025068FCD for ; Wed, 31 Dec 2025 15:30:37 -0700 (MST) 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 3rJz63XDUZ45 for ; Wed, 31 Dec 2025 15:30:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220237; bh=VJRoA0R0roMb4gAggk1HXePXYH3Gf/JaE0Mp33Y2VEk=; 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=A+ur736AGbgVFAJPsR00z04CRhc3p65eF5oToKXwQJ7NSbyEQWJeogS5Vs83LhoOm XdQUKCDoBnR6PfqStJ74lnLOXTA5iov/U786e2OCHtg73I9HhWCxPddjmNDXp0xCwi +kgTfOur2/5o/FcXfyaY+zAeLUsRCSM6/lEn3QN6H7LQsjWk/hoj8lpGMNxwx8vPQW vIt8ysfYqKqxGwQOkht0ALD3ceECZIToFi5yCu87KG158AKirrEpXwxRm/eo13gMwJ wNselcAPgqm9k9Fbt/CPmTOYetFcPWc1VxZX+9vAI9JDqpv7bJu6tjQMi4rQORPHTp YWIcwqu2WUHcg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7C4C568FC4 for ; Wed, 31 Dec 2025 15:30:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220235; bh=Eglq/O2e/daTjEgfUWIvBpfrRMUhY3i4L5L6Sr0LCkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=poMfhcOr3U/p/HFMyWnDQYE4yH6ciHspcEkpdkeRcUy2Ga3pyHgNQldSPj9xTMKNV 7QSIFu/bj4HhUb/u4o2Zz/YhMWTys1hX4dXiY6ccpYkii2K/+1VJlglcQ+MulzDvSe ygeYc3LCdqX2nZohXLCjTjL5yh8lUkp85AyvQobdM9kqlldnCjCQFdHOMhj8dEZ2/Z NnVkn5DtoDtuvkrlJvlD6JIrLjknHGTueOmFQ1ewTpYpEl4E28MLgJ3AsLHHg8LbKp ukxQnXut3T0iLp/nZF5rmF8U8AR1IEAJ1Mdo3f7DCWOzcHUcZGXSMzqXmZQSQVpDRe JT8n9xGNUyC0g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AB86268F65; Wed, 31 Dec 2025 15:30:35 -0700 (MST) 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 FfDKz2ItX-PR; Wed, 31 Dec 2025 15:30:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220231; bh=mVK0/+O8rAn9aOLKliyDF6AALjSSkXdM1QrfCSSWwqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBXAU/uVUA1rPT+edXZdmdVTWtnMOldPSw8HE81fVBxgxZOyowxC1nAaf4f+lKuzU k7IuQzYJang02HdQj+A++p1mjRRYEo6Tve3q3dXBDyMgywmqubHPW5nWOf+G9r/fGn BD/whhmnEgyU/UH6jZlijViW+QIDsGNOWjUlM6mR5jWbLqpk3Ye1l/V0EqnLU94hx/ zxdCZ7lWvq0YnIRMu/BA+fCEfFbyeahvxQjqMsbJFWXJrz62USa2Z5RIExxHlkEYpq dWS+4/0kRfPu5TF1Wl9/mg1toSCBc1je+wVy504WM6fFYHr0JaMa72SKkc5kZffdhB C7y9wXuw+mjfQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4AC3968C5D; Wed, 31 Dec 2025 15:30:31 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:34 -0700 Message-ID: <20251231223008.3251711-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KUPZNT6J22JDOAU4OTBCD7XLXM4LRPBC X-Message-ID-Hash: KUPZNT6J22JDOAU4OTBCD7XLXM4LRPBC 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/26] sandbox: os: Check executable directory for persistent files 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 When os_persistent_file() is called without a directory set in the environment variable and the file isn't found in the current directory, also check in the executable's directory. This allows tests like dm_test_host to work when run directly from the build directory rather than through the pytest framework, avoiding the need to set U_BOOT_PERSISTENT_DATA_DIR manually. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- arch/sandbox/cpu/os.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 891dfd9c9b8..5278ce55766 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -5,6 +5,7 @@ #define _GNU_SOURCE +#include #include #include #include @@ -338,10 +339,30 @@ int os_persistent_file(char *buf, int maxsize, const char *fname) } strcpy(ptr, fname); - if (access(buf, F_OK) == -1) - return -ENOENT; + if (access(buf, F_OK) == 0) + return 0; - return 0; + /* + * If no directory was specified and the file wasn't found, try the + * executable's directory with "persistent-data" appended. + */ + if (!dirname) { + struct sandbox_state *state = state_get_current(); + const char *prog; + char *slash; + + prog = state->prog_fname ? state->prog_fname : state->argv[0]; + assert(prog); + slash = strrchr(prog, '/'); + if (slash) { + snprintf(buf, maxsize, "%.*s/persistent-data/%s", + (int)(slash - prog), prog, fname); + if (access(buf, F_OK) == 0) + return 0; + } + } + + return -ENOENT; } int os_mktemp(char *fname, off_t size) From patchwork Wed Dec 31 22:29:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1140 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=1767220241; bh=fBvBimDeSWzI5XAMYv5351giwEM9a0dRn20QHHS6dtE=; 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=oX3YupOx6q7D4uZmypxKCq+Pm0N84BPMWOc+hMa7RsMwU9wml1MqqcEKVKBd+eWht IaiBxyBzqaAeQCrO2MDERDp2cwnWUg4pliLBfBOvnBEoMNBUlF3GdZwHixCqvlppcW 11zHR+R5YgA/NvaO3n4h9swRcT6NIOeqs4GrUwatN/gKffeyAh/sViu64QFjeOIzDG HET01GIM7IqMKq2E0iZnmKKABS5DMWjpf4/nT+AHSGGxUgKF46Yp65OsiElhfRgZod cyt86wV+qVsCNQ/0/h2ub5XaODvui/rN1Lksbe2L3FJ2VI7ZSB8G73wC1gDqD4Qxod bCd3jtiKt70bA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6BC8F68FD3 for ; Wed, 31 Dec 2025 15:30:41 -0700 (MST) 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 Te6LVnyA6oVH for ; Wed, 31 Dec 2025 15:30:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220241; bh=fBvBimDeSWzI5XAMYv5351giwEM9a0dRn20QHHS6dtE=; 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=oX3YupOx6q7D4uZmypxKCq+Pm0N84BPMWOc+hMa7RsMwU9wml1MqqcEKVKBd+eWht IaiBxyBzqaAeQCrO2MDERDp2cwnWUg4pliLBfBOvnBEoMNBUlF3GdZwHixCqvlppcW 11zHR+R5YgA/NvaO3n4h9swRcT6NIOeqs4GrUwatN/gKffeyAh/sViu64QFjeOIzDG HET01GIM7IqMKq2E0iZnmKKABS5DMWjpf4/nT+AHSGGxUgKF46Yp65OsiElhfRgZod cyt86wV+qVsCNQ/0/h2ub5XaODvui/rN1Lksbe2L3FJ2VI7ZSB8G73wC1gDqD4Qxod bCd3jtiKt70bA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 53C1E68FCD for ; Wed, 31 Dec 2025 15:30:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220240; bh=smveTZ7RX1OiRVPJhTbtUw4vNJ22qZNzfs+hLvf7kV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G6HaeX0fDoasnsOo6JQhiW/PbBgobqJv2nh2MvaLzKNJDiT/GFKpaE6qq1r6WQbRJ nHcKILAsHZ8jLeB6GE0CulzlffYrB1H8jbzTmPIAvBxg1KE8h0Zy9pJavgXrmwyh/b P+8D7b+vdUYyIxE5FdAQrDuxyqsxIbctFBik3sTANwPbVAFsL8oVrS3avzHsUPQyEX HrT0dTrRyZjR/frdsz9T+FljUMCRAoxTdPW95XE+Es1eNAGdhJ4C1TSFWL+/fXB2w2 LKAHpOdrXFIOkaSeYDExxKeWDomlT6I4g265Zwrln6UGCUEAP1/mCOZYkB6V5/R8m7 kcEoiUEHgwI4Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5753C68F65; Wed, 31 Dec 2025 15:30:40 -0700 (MST) 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 2X3oC2EzlTYx; Wed, 31 Dec 2025 15:30:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220236; bh=cqkwKCTB/EVWibUZ4WS39zYO7l0YgI9M6QAyLTkt3AU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVc/OsABgWixUufYeu6SUXUdo3b0sM/CtypRUPVOdQDYl8iLGnpZMqTBYXTusCVy3 Oe7QIWvqqApPyRLNTBZOpon+fw6jHdXorEHyWxeW91o7k2nSeARlsL3VThxyQM17uX ONx7Cs88HsYxNf+TxymNcE/mKNnjiK+VEpj5t0as94vufw2n2OswIt9pceSuwQaW9c B+Jpgl0mE4f1lYMgBQCOKvG9qtrPo5btXvfPDLQYG+rAEBbzzXld2vmEvYcZEFWCbz F4th3aVmyvKqGOw/bFB7NcE5HSvRrwCPu/SAiuVmaeMiw8wefOzjuApIa6J8VncBO2 9xRZ6DaIhXATw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E7CBE68C5D; Wed, 31 Dec 2025 15:30:35 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:35 -0700 Message-ID: <20251231223008.3251711-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FL2Q546WBTGQEFATVSATFQJMJVLO2XMW X-Message-ID-Hash: FL2Q546WBTGQEFATVSATFQJMJVLO2XMW 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/26] sandbox: Add --quiet_vidconsole option to speed up output 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 When running sandbox with lots of console output, the vidconsole slows things down significantly since it renders truetype fonts to the internal framebuffer. Add a -Q/--quiet_vidconsole command-line option that removes vidconsole from stdout and stderr, using only the serial console. This can provide a ~300x speedup for output-heavy operations. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- arch/sandbox/cpu/start.c | 10 ++++++++++ arch/sandbox/include/asm/state.h | 1 + board/sandbox/sandbox.c | 16 ++++++++++++++++ doc/arch/sandbox/sandbox.rst | 7 +++++++ test/py/tests/test_event_dump.py | 1 + 5 files changed, 35 insertions(+) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 30d4f83b6ee..1a5ca97e15e 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -476,6 +476,16 @@ static int sandbox_cmdline_cb_no_term_present(struct sandbox_state *state, SANDBOX_CMDLINE_OPT_SHORT(no_term_present, 'A', 0, "Assume no terminal present (for pager testing)"); +static int sandbox_cmdline_cb_quiet_vidconsole(struct sandbox_state *state, + const char *arg) +{ + state->quiet_vidconsole = true; + + return 0; +} +SANDBOX_CMDLINE_OPT_SHORT(quiet_vidconsole, 'Q', 0, + "Don't use vidconsole for stdout/stderr"); + static int sandbox_cmdline_cb_upl(struct sandbox_state *state, const char *arg) { state->upl = true; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 6a89f0ca5ef..ff7493ec5d6 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -177,6 +177,7 @@ struct sandbox_state { bool soft_fail; /* Continue on failure */ bool pager_bypass; /* Enable pager-bypass mode */ bool no_term_present; /* Assume no terminal present */ + bool quiet_vidconsole; /* Don't use vidconsole for stdout */ int video_test; /* ms to wait before next assert */ const char *video_frames_dir; /* Directory to write video frames */ int video_frame_count; /* Number of frames written */ diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c index d97945e58fc..78b2b7b1f47 100644 --- a/board/sandbox/sandbox.c +++ b/board/sandbox/sandbox.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -19,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -185,3 +188,16 @@ void fwu_plat_get_bootidx(uint *boot_idx) *boot_idx = 0; } #endif + +static int sandbox_settings(void) +{ + struct sandbox_state *state = state_get_current(); + + if (state->quiet_vidconsole) { + env_set("stdout", "serial"); + env_set("stderr", "serial"); + } + + return 0; +} +EVENT_SPY_SIMPLE(EVT_SETTINGS_R, sandbox_settings); diff --git a/doc/arch/sandbox/sandbox.rst b/doc/arch/sandbox/sandbox.rst index b2f4d8913d2..90c3dfa837e 100644 --- a/doc/arch/sandbox/sandbox.rst +++ b/doc/arch/sandbox/sandbox.rst @@ -208,6 +208,13 @@ available options. Some of these are described below: -P, --pager_bypass Enable pager bypass mode for testing. +-Q, --quiet_vidconsole + Don't use vidconsole for stdout/stderr. By default, sandbox outputs to both + serial and vidconsole. This can be slow when there is a lot of output, due to + truetype font rendering to the internal framebuffer. Use this option to use + only serial output, which can provide a significant speedup for output-heavy + operations. + -r, --read Read driver state from a dtb file. In conjunction with `-w`, this allows sandbox to save and restore emulated hardware state (such as a TPM) across diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py index 3ddd60198fe..ff0da82196b 100644 --- a/test/py/tests/test_event_dump.py +++ b/test/py/tests/test_event_dump.py @@ -22,5 +22,6 @@ EVT_LAST_STAGE_INIT efi_block_device_create .*lib/efi_driver/efi_block EVT_LAST_STAGE_INIT install_smbios_table .*lib/efi_loader/efi_smbios.c:.* EVT_LAST_STAGE_INIT last_stage_init .*arch/sandbox/cpu/start.c:.* EVT_MISC_INIT_F sandbox_early_getopt_check .*arch/sandbox/cpu/start.c:.* +EVT_SETTINGS_R sandbox_settings .*board/sandbox/sandbox.c:.* EVT_TEST h_adder_simple .*test/common/event.c:''' assert re.match(expect, out, re.MULTILINE) is not None From patchwork Wed Dec 31 22:29:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1141 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=1767220246; bh=JyeDtAHObaKcWQGCj3fmjNABcCsWjigbbvOJ6q45Ojw=; 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=oymKhlwSGQ1ZbJrkvO4r7+AhJFNzJUjl06+pe6HtwM9NSIZTQf3DDspsmab4AFRtS Nl1VLID3SiFaPfe/mSdbJc8yNTjUOaISfxMHBTMGSFaHwp3pE4Qfc0O8/WXbkL180g KvF00sC132SdRvDJHk4AzCU1CpB/iabG3DjpTNbKEp7UEnGPuywoiXydYY+rKoCiXB Eh/xNt4erRZrRnsDYHavnm0fEi//mIXJC8Pm06Klevocn1J8LF1V6W4+LL4xH97XYG keJlGngs+FyyOcCX3lkwDq9Pczwqhliu0W/KFast8dqCPAD0bSDgHIsC0ipXwzQ6Ub xeSrn+c7PuT0g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DC3EB68FD3 for ; Wed, 31 Dec 2025 15:30:46 -0700 (MST) 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 Nxde5db12Ukj for ; Wed, 31 Dec 2025 15:30:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220246; bh=JyeDtAHObaKcWQGCj3fmjNABcCsWjigbbvOJ6q45Ojw=; 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=oymKhlwSGQ1ZbJrkvO4r7+AhJFNzJUjl06+pe6HtwM9NSIZTQf3DDspsmab4AFRtS Nl1VLID3SiFaPfe/mSdbJc8yNTjUOaISfxMHBTMGSFaHwp3pE4Qfc0O8/WXbkL180g KvF00sC132SdRvDJHk4AzCU1CpB/iabG3DjpTNbKEp7UEnGPuywoiXydYY+rKoCiXB Eh/xNt4erRZrRnsDYHavnm0fEi//mIXJC8Pm06Klevocn1J8LF1V6W4+LL4xH97XYG keJlGngs+FyyOcCX3lkwDq9Pczwqhliu0W/KFast8dqCPAD0bSDgHIsC0ipXwzQ6Ub xeSrn+c7PuT0g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C87AF68FCD for ; Wed, 31 Dec 2025 15:30:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220245; bh=OhUB3xVOjpI7BGpgpJx9rFm27zptJxDTaLWsHkbz1vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwUIrRzS6K5qAQj4ATi1mTXL9KGC6xRTZIG9ty2mz9rji253Ka/81Zf6N4lK9RbIg sV5O5YpSdSkKVMsjYTX/dBGx3xUx7vaJ/MtkZhuqsL+msS8gJ0R/Izjyn60t0WBIp+ dsJ6NSW/SiNb7Op4eQHp9XBJrUkw0+Ao7JJKVSJ4pdSUYJoo7olFmyEFSJmVGm+E6A BwtsVvi8khZ+A6moRgV25Xq9OfGuBMbVhupRUaJMg7x6lUNPKqhgGMBkilA2rBCiq6 Wb1OJUV3CaEGjXA3TdpY8dGvLpDvIpPTf9iag33YtifneI/KFsesY7NpuqMi18z6kr m0FW/AQPlCU6Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3CC7868F65; Wed, 31 Dec 2025 15:30:45 -0700 (MST) 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 w9NH5lb2ZM6v; Wed, 31 Dec 2025 15:30:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220240; bh=nkA0WBnzDONS6l2hlzQ7lZJs4NHnlDev74IAtH4ETyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbl0DpEmbPStZfatVTZi+ObUc7Q4iWP6DjtFNGAKlJX7K87I9NiN6IrlOLYfxcPnt H1QHTEfo0k3SMZ78gKxjlDn1cT+NNfiA3A9Wvy1YpnMl/7vN75FxsTDfJwGPLP88Tu VpoQa4i6SpIGBcgBcrP514Oawj5K3hStnZ1we8heZFOY9SwCm1L1NDBb423Ka82E+6 7ajaYqSdyWVorcE5MDdnusFKCQVoxF69MZrJHVFv3FExjC58lWJ2aRSU1Xrd/0nBpZ T81Fvy7ou67rcoY0xpBuCRUhYA2H2lJ9IRerS62simFz+G6AugZirgkz5aMIUplxBK Qk9uSZWpVn/OA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 99BFD68C5D; Wed, 31 Dec 2025 15:30:40 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:36 -0700 Message-ID: <20251231223008.3251711-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: RU47VIP2AJL73KQ4S5GNFVCM4334LIVZ X-Message-ID-Hash: RU47VIP2AJL73KQ4S5GNFVCM4334LIVZ 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/26] doc: Correct the U-Boot logo 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 Update the ReadTheDocs documentation to use the correct U-Boot logo from the original 2023 website, stickers and coins. This includes the project name. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- doc/conf.py | 2 +- tools/logos/u-boot-logo-text.svg | Bin 0 -> 8552 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 tools/logos/u-boot-logo-text.svg diff --git a/doc/conf.py b/doc/conf.py index 348f0132ffc..498893ad669 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -257,7 +257,7 @@ except ImportError: # The name of an image file (relative to this directory) to place at the top # of the sidebar. -html_logo = '../tools/logos/u-boot_logo.svg' +html_logo = '../tools/logos/u-boot-logo-text.svg' # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 diff --git a/tools/logos/u-boot-logo-text.svg b/tools/logos/u-boot-logo-text.svg new file mode 100644 index 0000000000000000000000000000000000000000..55b7f5c6e2a7e14067c28136238977d81a4a8810 GIT binary patch literal 8552 zcmd5?YjfMS68)ZEfhyBZJ24+1DN3XzwN5;p+nMxEr*5aWA1M-&SW^Tq2w75o{oMr# zKJ;*u*w=|Xj>X06?C!zt63FDo-8v%=Oq40lrvqx*1H$r{CuzQ%4*vY(XJb4drHt|< z%6QJEgPae3oV}WSV;JP_x7+_1@6(v&B{P0WST55=%0x)sy))kaZQR`$o@o=qn7yj{ zzvIPTq|22g-^V`?$EM>e@-LR=B8^w%E?#ZoRU{HgCcAwhcy2DU;{K=QdS@nVR!>tt zEME~qwrL_)fOhN;@Nva(*7o@!W!txWHyzl-CeR6gRmU`$4qysLJ#>_&Rcn4<#!#6rA`hd6dGE8etr-PN0 zMQB;u?bg&nlZ&N=kjf&8S!rpxf?ti-`ZnXWz%2Pj#B2dmFf(V;y8YwU(v5~~CNgQK zX-4DfTUV{?*tTtHTh)s_024bn&-WC`;#5x>1c7Bcmg5-E!zlN;jCMv|zHXs}aomiI z1&d_*z+%2$^SrFg(d(SFor{ggRF5RKSjN_{2}+Ba)EdlynG>1Hj3Gq{LGGzX*B;FN zG~NO|$a|p2#8Oh#ea&Q)L^5heXo*YJgfJzj5dMDqGxo>NB#y(sxVWz$L4qBkIp4sB zsK=;&NgRS(){&g0>uAZ)$Zx>F6RT}#=9qv??u!~Z4zH#atnzPTtFHPj;P%$3=^-vgFMY z9M~0hVV{as-(~XpI9z?Vl-J6zjcb(&;h%{G${nntdL98na{(9F?AK^d99qgN6*5(4 zC9iFxW<&;P*vN=FD!1nAkfPp7ms(CwTN$We0=!(d6Q3c*so7!2{mvk=C!1J8w(0u> zKtFNr+q9G-oo`OgE!clIDbV+Gf&ZIJVB`_xr%rn#&qIEyIhaTvR3Jlgl+ORr{Se<}1v2;Ac#!12!wL>sC;*%59I43%3gqVpE%;=Tt3J5DP&$yTl zUN6)~MR7vrTqI2BCSQGeO&ro01SlvIYB8Vx!(u6U#zd6IkhG~?w=4w|7^mc$G-0P2 zbdC%WUbB#%uGd>chXzw*@pq6O%vxZfaS+V$@i8+S~^Ta|4EAKUR5{f^XhpOJ} zcqxnKESnDABO-EyWhwZkSn~wPq`+!x!J0MrdRN4$h;?N^pupZ|Fa&DBEPQR-p6C15 z_+Zpj3h6b(Hh#~-9E$Mzd&QJc8?CA^ib$@;uC_HH%9U;n10KL=b z671&sIp9z__ck+Zyy@PaTB0=9(8>Ke<=LA#_+3B-bdxBeMPnM)K=Q} zM4-K=w12wtU<4g+AsVwRON+9p`Ff5`k{}okKf|%-><&xo*j14fyxKSmS?bXyE2OH+N*2c>B zFUG>57eKJmUc;#FwouUBVr)M3nn+_378?11*2bljfixF&x)CiS2 zmqLBiyq8p)9zcaMLW9B3^ii-aEfiQx^)F{vqhrcTz;^Z5Bf-^Jptfw+M#N4c+-c&`s{jvl7~p7Q7(J3t-AE;iQtTY$#~V5!O=?S4o%ng zhQ;nWOLJya**Ubot!7_D>onVk@1iW7i}c#iul|NwyDV4?_j)lLCGx!KlrbrpFi;)1 zDGY6xdJ6||JwbJxQ617<{OahKf#=u=wL0-I5HZ}!g>bMdyRv_Hnul-}&4iXVhb2ui zg7EHnrst2lH7KS>A5ytzkJ=Ij-&4_7u4g-g*+hb3x%L})N8j%WI244V9DvlUQQz#~ z02thomynaI6LNC>0|qFkxp28RKJXbeouSrOm0e+DFny~87fJ|b27f`J`n>7u;2|BE zBkw??r?3#UGJv+rJcL_lq{1bhnBQh3j75 z8~K4gzOAS-GROAFr>(H1st1>XpGH-n+IG40Fz{5@&Et; literal 0 HcmV?d00001 -- 2.43.0 _______________________________________________ Concept mailing list -- concept@u-boot.org To unsubscribe send an email to concept-leave@u-boot.org From patchwork Wed Dec 31 22:29:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1142 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=1767220249; bh=myalJPx7jwblfAHH8qcBpx3Ds2EyqAnbHt6WUWEZ1c0=; 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=pECGUi2rgORMIfOYBDzJlDVEvsBRgbDV/UuwCM/2vOik3RrBOyi3VRn1P10w9rhV/ 2o8uh8ua05OIleWCkqyFOsKzsS54ZEO3BFrwuQBWZqfe7HYSIw2CccD/peqTYnh+Oj jy+m1ggeATCZrn9SqVuDfjSm6Xz4K51j2g4Ycb73/WTeLD9vIf47XsEi7WXc7+SqZ0 DKfA7Wh8zDTpF+qg+2p6GSaIfnlGqqj6HAcCtIgRepkPb5wqWFlNcHWJV072qCCOD6 DEZZU6IUxxgZx8h3gnrIedOsCyTrc+Zy1Yd/YetDmZoaDfFY0wKdB/0VcSdwTJrUMp G57MaAEJr9iEw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 44D1F68F65 for ; Wed, 31 Dec 2025 15:30:49 -0700 (MST) 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 Ldk2NBngW4xl for ; Wed, 31 Dec 2025 15:30:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220248; bh=myalJPx7jwblfAHH8qcBpx3Ds2EyqAnbHt6WUWEZ1c0=; 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=Ggqqq3k/SWe9sPVylA7KlV5Rm/36uwA3jLMqRY33qfxYfHPEfpsCoTjqlcSYJ+6xl QowdDUJB3AOv3iXV5ZlRvPifUYaA8VEO16bAr/OXcx23cF9vwst6cdW8oFcNGEPUTh i/KuQ3JsFY7qQHtLVY5rH7xje8HFsVhNon2n4zEQ18EEIMPV5MLGJz43rFtzV5/sR6 MYqci1CGAq9KDscrhDYUMrj5a0E+aZ7wHh4aMO6fYkj07+tI6SOU3ZXlDCMRSuFseX aP/jSZgIqnRJgNquA1pgz8Df6V2QdUycQVSE06Pd6gp0uuXqi5LAF+nyPyJ2fyk1VD x6pXcCfe1jcWQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3FD8368FCB for ; Wed, 31 Dec 2025 15:30:48 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220246; bh=i3n/ty9etcTby4mktSrRdtazZL+JjL3aq+4YjQtzh1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b1hN7nFVbtKHU90v+RloZzhaorCYr6pMnaRN41HhCacxZw/CdFixpBSzhFuxtfXJg WY0wUTQVrQwAHNDzaF1X6yvuXvRWZyfiij4cp0iW4Uo/KGNEy4uFGb+OUmiuL6PQUF Wg/g85Q8q6Blw0Qyigpt1+cYEuzqBcjS6/tLirTl6wXJcJt53Q7vKEIb0P/ISz0kWS gpbTpFDYJX9RSyfl7c2MKKkFGfy95urOFXji3e5K5T0gLxSU/sc73pBw0vNjNSe6DX CWdgQUpU2lCTTwz2xQtb22Lmh5rFJn3xr9+OAGvwRxq1qM2Q7TCrhhXaHNN5UOI36e U9QesR0a6jBTw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1563268FC2; Wed, 31 Dec 2025 15:30:46 -0700 (MST) 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 gRMDZzz461tA; Wed, 31 Dec 2025 15:30:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220245; bh=X7RoNpkuX1l33/44F2sRKYxQWkQNerN/t60bqYvl7SY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K2+i/w2LT9ulmuEyk3GNUqRgWTgiVoU6kW6Gz+tZfbSsBJ5KD2t69Sjvp4rjmU/Gr 99N1ychwfVe7LnCR2pdg21vtsp6pzZj0cJZljwcJ7V5SrfjAa3Wrak/guqnMIZRRf3 CGdIXxE7CaAyFsnz4lA1TQiSesj1dz2ihWGg0CuMaqvNuQ+IZBNqsLGWCJebaxI5bp 3xHQC5MytVUmO5ykjVUKkqdjZ8FtYmhjBRlujJnog+c6wGwWiHysv7uYqP8Mxpswlq f85BG7lh7anGS0WlGPbptVH1+KqrwCySxG438hlqjnkZxeRLUwvwTqh27YxRdfrT1C IiCSKrs0uPcUA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6F06568C5D; Wed, 31 Dec 2025 15:30:45 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:37 -0700 Message-ID: <20251231223008.3251711-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: P6FA7Q2Z2XBGTTEA5RV3S4HS6AIUBGBJ X-Message-ID-Hash: P6FA7Q2Z2XBGTTEA5RV3S4HS6AIUBGBJ 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/26] blkmap: Handle read-only slices in write path 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 Some blkmap slices (like blkmap_crypt) don't support writes and have their write function set to NULL. The blkmap_blk_write_slice() function calls the write function without checking if it's NULL, causing a crash when attempting to write to such slices. Add a NULL check before calling the write function. When the slice doesn't support writes, return 0 to indicate no blocks were written. Co-developed-by: Claude Signed-off-by: Simon Glass --- drivers/block/blkmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 14aa1e4d088..bd55bdf24b7 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -281,6 +281,9 @@ static ulong blkmap_blk_write_slice(struct blkmap *bm, struct blkmap_slice *bms, { lbaint_t nr, cnt; + if (!bms->write) + return 0; + nr = blknr - bms->blknr; cnt = (blkcnt < bms->blkcnt) ? blkcnt : bms->blkcnt; return bms->write(bm, bms, nr, cnt, buffer); From patchwork Wed Dec 31 22:29:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1143 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=1767220252; bh=RMPORJiZdlKWAPBMnOdm/Ew9dL3z36SNrb3hqwHLu+Q=; 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=urCQbEU04FRGuf4dW+ndo2SRa3Ppv1f4SXTnlEmdf/BNQR1AlY5iFD2CgfI3sAtGR UZX3qRPvTzDDU7PFryCC0ho3ge5VtifbMQvW8lk4M3eR9J5GIqXm0j+bHGQICRZebf NXdjHKLejhh4ZsAzt0ji2Ly8NYOj5nI++8n26k61SbgTZCkSfdMF9hrnoVkO7U8QDq mEiWgSgTDk5WyS5HiK5R5vv1JezpmORYsV02MBgAPb67xrJRKfdlqNShcIjCTSbm1l J0wyCPwCXOYqZtk8gJ4R5lk951CYlF1HBWKqYkvKrbymXA4B4Uj68MHM+azrLv+fqv 7+2bsNgNOMPxA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BA4EB68C5D for ; Wed, 31 Dec 2025 15:30:52 -0700 (MST) 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 XuojbRUqvdo4 for ; Wed, 31 Dec 2025 15:30:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220252; bh=RMPORJiZdlKWAPBMnOdm/Ew9dL3z36SNrb3hqwHLu+Q=; 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=urCQbEU04FRGuf4dW+ndo2SRa3Ppv1f4SXTnlEmdf/BNQR1AlY5iFD2CgfI3sAtGR UZX3qRPvTzDDU7PFryCC0ho3ge5VtifbMQvW8lk4M3eR9J5GIqXm0j+bHGQICRZebf NXdjHKLejhh4ZsAzt0ji2Ly8NYOj5nI++8n26k61SbgTZCkSfdMF9hrnoVkO7U8QDq mEiWgSgTDk5WyS5HiK5R5vv1JezpmORYsV02MBgAPb67xrJRKfdlqNShcIjCTSbm1l J0wyCPwCXOYqZtk8gJ4R5lk951CYlF1HBWKqYkvKrbymXA4B4Uj68MHM+azrLv+fqv 7+2bsNgNOMPxA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A737E68FCB for ; Wed, 31 Dec 2025 15:30:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220251; bh=QqRLzzD3qY93rfsOjAuKSNB/rFDySMQn8xMoIzAe3FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pv+8Fa89WtKNavoLTouYqvfqgf9+6mwYHCe2vimFLQBrJlYZshzCmzn/jbV7nn876 0vtjL+UqWNo0DkdSSuO3MSdG636a6tLR2RHgF5UCEcEOlAf8MR/nLlXiKwQna5EVsj E+J5tNrOZdCNAmatiuOoNWcRUgPYWTahV3umqJ3fWje6grsBHUJCVTNB8xbSdeJv+T LSF8kjK/daIdPhd1X90BgeMTLC/u4ifx/J0X3lwlFxYeLE149GvNRo9qR6O5wB47uB B9JzpLZTSMzk/9XxCz7VGydyPodaxh5rwKBgtSwx7NqqHF/My9YotokXk66GwZLbal 3fkw8GoyPYvDg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B173768FC2; Wed, 31 Dec 2025 15:30:51 -0700 (MST) 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 D68AOGIYjBnd; Wed, 31 Dec 2025 15:30:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220246; bh=zKwRkI4jC3zhLsledkLrLb/qxwnbtNRX5jTjpU1d5YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rn67Gy3Cxztdj2nuCdEhtERgq2mxAD5lE/u/HoojnKacgEFiKWmBvKt7vggrxOJuW MpruCL3rJGtGeKoXPVKc+eQJ1LxNTJw23H8uXz2qQsghxd43uQzQtAK4+ajUWF6j9v Q1Trj0m6IEGurLSNOVqr64oT6gQ9QvtWKOXR9b2vRS2UCFfXfq5W+IvDUn0nLgw+Ul mVcaz6uD1Sii92ZsZatUiK2yFIOeZXvX6NaaSjGy3AoeRtZNOqc5660+D2ywbO5yNg ugCnh0EetVgCChljOEiH6Asb0IkFJKMdotpQ5KOmHBETp23hDOkT7KSalq72BuBQFT 57LH+4/q2Y4VQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 574A468C5D; Wed, 31 Dec 2025 15:30:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:38 -0700 Message-ID: <20251231223008.3251711-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KMPX3VZLOQFFSSKSA2OUDIEF75EMFKQL X-Message-ID-Hash: KMPX3VZLOQFFSSKSA2OUDIEF75EMFKQL 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/26] mcheck: Add Kconfig option for caller string length 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 The mcheck heap protection stores a caller string in each allocation header for debugging purposes. The length is hard-coded to 48 bytes in mcheck_core.inc.h Add a CONFIG_MCHECK_CALLER_LEN Kconfig option to make this configurable, allowing users to adjust the trade-off between the amount of debugging context and the memory overhead per allocation. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- Kconfig | 11 +++++++++++ common/mcheck_core.inc.h | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Kconfig b/Kconfig index c28fddf5016..3b89f2c48dd 100644 --- a/Kconfig +++ b/Kconfig @@ -355,6 +355,17 @@ config MCHECK_HEAP_PROTECTION significantly increases memory overhead and should only be used for debugging. +config MCHECK_CALLER_LEN + int "Length of caller string in mcheck header" + depends on MCHECK_HEAP_PROTECTION + default 48 + help + Sets the maximum length of the caller string stored in each + allocation header. This string records the function/file/line + that allocated the memory, useful for debugging memory leaks. + Larger values provide more context but increase memory overhead + per allocation. + config SPL_SYS_MALLOC_F bool "Enable malloc() pool in SPL" depends on SPL_FRAMEWORK && SYS_MALLOC_F && SPL diff --git a/common/mcheck_core.inc.h b/common/mcheck_core.inc.h index 598a5d018ab..fa152790d45 100644 --- a/common/mcheck_core.inc.h +++ b/common/mcheck_core.inc.h @@ -73,7 +73,6 @@ // Full test suite can exceed 10000 concurrent allocations #define REGISTRY_SZ 12000 #define CANARY_DEPTH 2 -#define MCHECK_CALLER_LEN 48 // avoid problems with BSS at early stage: static char mcheck_pedantic_flag __section(".data") = 0; @@ -89,7 +88,7 @@ struct mcheck_hdr { size_t size; /* Exact size requested by user. */ size_t aln_skip; /* Ignored bytes, before the mcheck_hdr, to fulfill alignment */ mcheck_canary canary; /* Magic number to check header integrity. */ - char caller[MCHECK_CALLER_LEN]; /* caller info for debugging */ + char caller[CONFIG_MCHECK_CALLER_LEN]; /* caller info for debugging */ }; static void mcheck_default_abort(enum mcheck_status status, const void *p) @@ -212,7 +211,7 @@ static void *mcheck_allocated_helper(void *altoghether_ptr, size_t customer_sz, for (i = 0; i < CANARY_DEPTH; ++i) hdr->canary.elems[i] = MAGICWORD; if (caller) - strlcpy(hdr->caller, caller, MCHECK_CALLER_LEN); + strlcpy(hdr->caller, caller, CONFIG_MCHECK_CALLER_LEN); else hdr->caller[0] = '\0'; From patchwork Wed Dec 31 22:29:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1144 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=1767220257; bh=FeXATdr8DDASgB29ipqNA0ZMfOU0lNW+nAW5oJRIBbo=; 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=w4R8g6z6xhcXKgzDWBT1GwU5t6nInLPlM14+Od15gS9W/mMfMSBXpJW19unp9WnES DjeugWae0kU3DsYVHozoKErB5FnxO105DlqkKCF+UphdICBZOqZsw70HL4GAvWs7YH YEVzdy3JRq2V0ZRTi2ai8iGDSOVJbxL93eZf865naKwyxp6lRzrsmz9RspB+xC3xgG lOfSwJvN+EXNwDgLSAHFJd1/gpDWJUP4OwIHVUagDeXvs7axrS8bTwvvlx7pLfJUk2 cpIWXjgjSrqQnf7hZAGejmDFGlWIM+M4mtLsRGxkdHKoljwvbNUGLi3eTbESBxtRDG eQC8ds4JN9Xmw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2441E68FC2 for ; Wed, 31 Dec 2025 15:30:57 -0700 (MST) 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 p2S-XH2Fn_UJ for ; Wed, 31 Dec 2025 15:30:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220257; bh=FeXATdr8DDASgB29ipqNA0ZMfOU0lNW+nAW5oJRIBbo=; 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=w4R8g6z6xhcXKgzDWBT1GwU5t6nInLPlM14+Od15gS9W/mMfMSBXpJW19unp9WnES DjeugWae0kU3DsYVHozoKErB5FnxO105DlqkKCF+UphdICBZOqZsw70HL4GAvWs7YH YEVzdy3JRq2V0ZRTi2ai8iGDSOVJbxL93eZf865naKwyxp6lRzrsmz9RspB+xC3xgG lOfSwJvN+EXNwDgLSAHFJd1/gpDWJUP4OwIHVUagDeXvs7axrS8bTwvvlx7pLfJUk2 cpIWXjgjSrqQnf7hZAGejmDFGlWIM+M4mtLsRGxkdHKoljwvbNUGLi3eTbESBxtRDG eQC8ds4JN9Xmw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 08A3D68FCB for ; Wed, 31 Dec 2025 15:30:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220255; bh=9xgCdJWlgeG70GTLTrnMHgOqNLuPrR8e3e7gRaRpPOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vZG1FLy7FPeW3Iq3jCKVSF5nC62EjFxBBNgmNIr6sBFZVV0LmqJsBbuMUJmKSE/lh f6uM6XR+CAroX7FGk5nkBQEVngT9aVhXzRVnJwbbnU1FavxFOyqDYPlZHOXMJD9Csk P1tf+d58safvpgsqAodZjNzNuNZfAW3A4YUdgXNe1kgC5AKKjlHsixzP7auyWeiZVa zbHoVRnUWLrTriHvfdwdASeYgz581sHDlk/ORYIWYQ8lNYVgkoWzypIz4U/JEEpAGq qja6HCCGqtEPha8+vtdb84bocnBkVpd8O4E97Jr/gnAfgphZ7v/qmI9bXwoTdQQ+xJ rqKUkR+p345cQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9B73268C5D; Wed, 31 Dec 2025 15:30:55 -0700 (MST) 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 Fgs5RFAs_Q_4; Wed, 31 Dec 2025 15:30:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220251; bh=gWl8QKzAWQoDuLev28HsH8Y8oPSe6cKsgR1uwA8uOsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lJ65W2lC+U61hjIat9bxQrV9CIZIG5edeV5lzHmgjFLhD3MqbNUgPLE0QERXRVZHo 5GOU3V3cXnFUg1SO1GyaDyEKLErf1gQlJIPVAWkopyMJRB9blYyL0XyNtOtYNRTdHa JKk1bttMXhNeqnZiA6WoQ9jqiHfcX+7Uk7TS4Wccfub7E6maSzmL0rnJV+sB4Zcl3h 5QWQinOJZdsl1ySoSWhIEqpm2qbqWIRGqbRG0FBivdelPWhZ+7l4fFLrMkpGM62P61 SgZ3X6R2vvwuKWbnzYiocOPKAIk1P8UBPsNifBVn1EnDgrzn1ehyH20pAsC5JZ/OIM bkM2ZVjmC51HQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2C73168F65; Wed, 31 Dec 2025 15:30:51 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:39 -0700 Message-ID: <20251231223008.3251711-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: HHQUO4QNESFMHMROTWQBVZI775TAVP5X X-Message-ID-Hash: HHQUO4QNESFMHMROTWQBVZI775TAVP5X 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 06/26] mcheck: Skip mcheck overhead for pre-relocation allocations 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 When mcheck heap-protection is enabled, each allocation adds quite a bit of overhead for headers and canaries. While this is needed for the full allocator, it serves no purpose for pre-relocation allocations, since: 1. Simple malloc is a bump allocator that cannot free memory 3. Mcheck's corruption-detection provides no benefit for non-freeable memory Since the pre-relocation heap space is limited (typically <16KB), this overhead can exhaust the heap, causing boot failures. Fix this by bypassing mcheck hooks in dlmalloc(), dlfree(), dlmemalign() and dlcalloc() when called before relocation, directly calling the simple malloc functions instead. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- common/dlmalloc.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 62e1e0a77da..5069a95d9b3 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -5984,6 +5984,15 @@ static const char *mcheck_caller(void) void *dlmalloc(size_t bytes) { + /* + * Skip mcheck for simple malloc (pre-relocation). Simple malloc is a + * bump allocator that can't free, so mcheck overhead is useless and + * wastes the limited pre-relocation heap space. + */ + if (CONFIG_IS_ENABLED(SYS_MALLOC_F) && + !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) + return malloc_simple(bytes); + mcheck_pedantic_prehook(); size_t fullsz = mcheck_alloc_prehook(bytes); void *p = dlmalloc_impl(fullsz CALLER_NULL); @@ -5993,7 +6002,15 @@ void *dlmalloc(size_t bytes) return mcheck_alloc_posthook(p, bytes, mcheck_caller()); } -void dlfree(void *mem) { dlfree_impl(mcheck_free_prehook(mem)); } +void dlfree(void *mem) +{ + if (CONFIG_IS_ENABLED(SYS_MALLOC_F) && + !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { + dlfree_impl(mem); + return; + } + dlfree_impl(mcheck_free_prehook(mem)); +} void *dlrealloc(void *oldmem, size_t bytes) { @@ -6020,6 +6037,10 @@ void *dlrealloc(void *oldmem, size_t bytes) void *dlmemalign(size_t alignment, size_t bytes) { + if (CONFIG_IS_ENABLED(SYS_MALLOC_F) && + !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) + return memalign_simple(alignment, bytes); + mcheck_pedantic_prehook(); size_t fullsz = mcheck_memalign_prehook(alignment, bytes); void *p = dlmemalign_impl(alignment, fullsz); @@ -6033,6 +6054,16 @@ void *dlmemalign(size_t alignment, size_t bytes) void *dlcalloc(size_t n, size_t elem_size) { + if (CONFIG_IS_ENABLED(SYS_MALLOC_F) && + !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { + size_t sz = n * elem_size; + void *p = malloc_simple(sz); + + if (p) + memset(p, '\0', sz); + return p; + } + mcheck_pedantic_prehook(); /* NB: no overflow check here */ size_t fullsz = mcheck_alloc_prehook(n * elem_size); From patchwork Wed Dec 31 22:29:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1145 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=1767220263; bh=RpPw17NV3vYjfPi/o8622Mf2n0JRjKZFiRJh1EM0H+U=; 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=PUcuUS8Yq6rCjIwN9iR09VMvkrZIODEb7ujLm7zM/uKCOaI6unZ3q84oM6UWEpyLx SrjgDNuin9kC5ZwI0JjymALQQLtwJjnfHF6Bn6PwPErD1ocbTy2HFv5J+h15/Xf3D4 heRh60v1kH5CWjztplRimQ5mpQctRJeaVuS0wckFeCjinsqhNFB3swU/v11iyvAdiP m4tm4yUP8p2Xdb5bXfXLFnaUac7d45fAdNrjnOCAzxO+AFfM3UBt6lPEegxp3t8fTV 9bKB3MuHmzA5sCkGConKOOXCJ/JhXlx6dNj3Zu44ok6UnXNi64kxhXGt9wBZ82Oq2y h48RVcTiBDlCw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 347FA68FCF for ; Wed, 31 Dec 2025 15:31:03 -0700 (MST) 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 q_JhMUIMgDot for ; Wed, 31 Dec 2025 15:31:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220263; bh=RpPw17NV3vYjfPi/o8622Mf2n0JRjKZFiRJh1EM0H+U=; 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=PUcuUS8Yq6rCjIwN9iR09VMvkrZIODEb7ujLm7zM/uKCOaI6unZ3q84oM6UWEpyLx SrjgDNuin9kC5ZwI0JjymALQQLtwJjnfHF6Bn6PwPErD1ocbTy2HFv5J+h15/Xf3D4 heRh60v1kH5CWjztplRimQ5mpQctRJeaVuS0wckFeCjinsqhNFB3swU/v11iyvAdiP m4tm4yUP8p2Xdb5bXfXLFnaUac7d45fAdNrjnOCAzxO+AFfM3UBt6lPEegxp3t8fTV 9bKB3MuHmzA5sCkGConKOOXCJ/JhXlx6dNj3Zu44ok6UnXNi64kxhXGt9wBZ82Oq2y h48RVcTiBDlCw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0E76568FC2 for ; Wed, 31 Dec 2025 15:31:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220260; bh=JV3IJ4ccGhErJbmpJPJzoos9OU8dpFtjH/2NJnUIv2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=djA4j7OM9eU2qwgLb8xmCtOIOe3dHATauq24I2V1LB2Sh4p9o6U0Lfth1pM01AlCQ UM+gn8pgIRt7c7xMj08aJ1jZuh6UNEgZb7pioZZt+D1QPACkgW63VvruKuQ1fgsjKK 9ObQVZgSPSZYKCiqwHx8moPsrfFOqf0mo5hsPA4O/4uDbYsfeRkyRFiSTe0VSusKxj isPHduY92CzjXdLXD1hOLn2VLmh4Wlv4124EZQ+iI9vSV4YaZGfZrq+Tk0C3pweD0W kH61ilEdAVFGQCv95bz0aKaFnH/oh6pFvO43jnQdMPO2v9zT+rpAoZp8emtsSZGYZ/ laD3yBJpN8sRA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 52DDE68C5D; Wed, 31 Dec 2025 15:31:00 -0700 (MST) 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 aEd-J_pvRdgh; Wed, 31 Dec 2025 15:31:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220256; bh=gLIYM+OEpj4SvZJef/yw5UDI5cPfjTVM4IZFkzewuig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FROqDo8wyYhO2Z76jqoibQLzIhPb95gVUtF8sJLCuxtkcgsPynpPkornpHk0L1vVV 50TQqghbXahXC5T3Kqd2De+1SVI7pRNNun4+R3NqcOMDB8I8ZBzcquG2YCSxKAXsje p/tlc4ArTQgvJwR3fhZYvbiozM1X2hqqjtFyQXElifm8OPaUtqrnXySrXAb/wAI5SG pGgr1FiUiF5grvYw6PGHB2XpA4/RiWKzkfZ8xL89XJbWFF6BOTarR0s3TYoMbhZV4f g5NSekv1GO7j8UFaOueXXZCRQr4AUZ9XueutCtZmUwVkf6/REabKeRWNF2jpRRGKgB 3yKABvWPFrPBA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D5CBD68F65; Wed, 31 Dec 2025 15:30:55 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:40 -0700 Message-ID: <20251231223008.3251711-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 42I6NFR76LEGPFKNTGLDJHYWK5D3FEIK X-Message-ID-Hash: 42I6NFR76LEGPFKNTGLDJHYWK5D3FEIK 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: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/26] Revert "lib: Add CONFIG_LIB_KMEM_CACHE for full kmem_cache support" 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 The memory leaks were in fact not coming from the kmem cache, so let's drop this unnecessary feature. This reverts commit e63fc511c3dadbc99b53611cea304bc2bb565888. Signed-off-by: Simon Glass --- include/linux/slab.h | 27 +++++++++++---------------- lib/Kconfig | 8 -------- lib/Makefile | 1 - lib/kmem_cache.c | 20 -------------------- 4 files changed, 11 insertions(+), 45 deletions(-) delete mode 100644 lib/kmem_cache.c diff --git a/include/linux/slab.h b/include/linux/slab.h index caaaa3d9e16..2b374641534 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -84,19 +84,24 @@ static inline void *krealloc(const void *p, size_t new_size, gfp_t flags) void *kmemdup(const void *src, size_t len, gfp_t gfp); -/* kmem_cache implementation / stubs */ +/* kmem_cache stubs */ struct kmem_cache { int sz; }; struct kmem_cache *get_mem(int element_sz); -#define kmem_cache_create(a, sz, c, d, e) get_mem(sz) +#define kmem_cache_create(a, sz, c, d, e) ({ (void)(a); (void)(e); get_mem(sz); }) void *kmem_cache_alloc(struct kmem_cache *obj, gfp_t flag); -#if CONFIG_IS_ENABLED(LIB_KMEM_CACHE) -void kmem_cache_free(struct kmem_cache *cachep, void *obj); -void kmem_cache_destroy(struct kmem_cache *cachep); -#else +static inline void *kmem_cache_zalloc(struct kmem_cache *obj, gfp_t flags) +{ + void *ret = kmem_cache_alloc(obj, flags); + + if (ret) + memset(ret, 0, obj->sz); + return ret; +} + static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj) { free(obj); @@ -106,15 +111,5 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep) { free(cachep); } -#endif - -static inline void *kmem_cache_zalloc(struct kmem_cache *obj, gfp_t flags) -{ - void *ret = kmem_cache_alloc(obj, flags); - - if (ret) - memset(ret, 0, obj->sz); - return ret; -} #endif /* _LINUX_SLAB_H */ diff --git a/lib/Kconfig b/lib/Kconfig index 5ddf8125766..9c7eb27c392 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -396,14 +396,6 @@ config TPL_TINY_MEMSET config RBTREE bool -config LIB_KMEM_CACHE - bool "Enable full kmem_cache implementation" - help - Provide a proper kmem_cache implementation in lib/linux_compat.c - that tracks allocated objects. This is needed by subsystems like - ext4 that require cache management. When disabled, simple inline - stubs are used instead. - config BITREVERSE bool "Bit reverse library from Linux" diff --git a/lib/Makefile b/lib/Makefile index 3890a827d1c..e770c273a8c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -136,7 +136,6 @@ obj-$(CONFIG_$(PHASE_)OF_LIBFDT) += fdtdec.o fdtdec_common.o fdt_print.o obj-y += hang.o obj-y += linux_compat.o obj-y += linux_string.o -obj-$(CONFIG_$(PHASE_)LIB_KMEM_CACHE) += kmem_cache.o obj-$(CONFIG_$(PHASE_)LMB) += lmb.o obj-y += membuf.o obj-$(CONFIG_REGEX) += slre.o diff --git a/lib/kmem_cache.c b/lib/kmem_cache.c deleted file mode 100644 index bff9329aa53..00000000000 --- a/lib/kmem_cache.c +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * kmem_cache implementation for U-Boot - * - * Copyright 2025 Canonical Ltd - * Written by Simon Glass - */ - -#include -#include - -void kmem_cache_free(struct kmem_cache *cachep, void *obj) -{ - free(obj); -} - -void kmem_cache_destroy(struct kmem_cache *cachep) -{ - free(cachep); -} From patchwork Wed Dec 31 22:29:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1146 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=1767220270; bh=y3u0I/IQ0qq6uPFMIoq5N9dtbakOGgdl7hG4XiamZTo=; 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=ZZbpvqJqL3J9Dhc+aSgjqiB1FE1PoiPoMxTjV7RtuUiDvF02nLyOFloSDNY0/0W98 mDg3FxTy75UPjpua7arwNUQqnwuvj8N1BTKNE737dgpQpqcqfmKa/R94xMWzImDZ1A He2fCaKqJO5djD6H0uHBa6w2Yy5xtfplQGQv1KhFTNeNhxWs4gpjqsrL2FH5A+sDxj cuLTZQBehS8PtnQRLNr+DANpwbwaU9WOz4KZluM1Vfhm+NfJbYviQXjXhBqozzu1O2 tpOf4nLCBI2yo9fS66Sq5j3Nr4jmu7qOmF+aOJMHi+CDRCEYurLaiaHxa2kQCxiNBi jZzW0E8lAh1Cw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 64BD968FCB for ; Wed, 31 Dec 2025 15:31:10 -0700 (MST) 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 bo7hgmvsskMp for ; Wed, 31 Dec 2025 15:31:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220270; bh=y3u0I/IQ0qq6uPFMIoq5N9dtbakOGgdl7hG4XiamZTo=; 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=ZZbpvqJqL3J9Dhc+aSgjqiB1FE1PoiPoMxTjV7RtuUiDvF02nLyOFloSDNY0/0W98 mDg3FxTy75UPjpua7arwNUQqnwuvj8N1BTKNE737dgpQpqcqfmKa/R94xMWzImDZ1A He2fCaKqJO5djD6H0uHBa6w2Yy5xtfplQGQv1KhFTNeNhxWs4gpjqsrL2FH5A+sDxj cuLTZQBehS8PtnQRLNr+DANpwbwaU9WOz4KZluM1Vfhm+NfJbYviQXjXhBqozzu1O2 tpOf4nLCBI2yo9fS66Sq5j3Nr4jmu7qOmF+aOJMHi+CDRCEYurLaiaHxa2kQCxiNBi jZzW0E8lAh1Cw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4FA3068FCF for ; Wed, 31 Dec 2025 15:31:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220267; bh=1IMo+OI2LfHlEjFSeo4xOjaGN6R82szU9OQ/kE+LDJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LCIFTOXdpTqbEC+am3LsglyJq4KoTpjYMZxovXl3ZAuFBH5BL5LUtyH817njjmQlE tCirLJ4hbtmJzfHnyKgZicNIMEjWQhiiQIcqGDatazv6rFbV9+VVgiNYhJVwec5Sx0 r92T2coTeczLjgkVV9cje+qdZ7OIMm5oJZaFIOh01XFjuQB71A4PIs2/NVnuXnupMN lAIjn9a1i68DoOfKYvpYTI/TH5osGt8+WWoXEugkIW6jvzxiOhuB5lQN/m7XvqbE6u a97Vhz8WP2RDEpFryJJsO+kCMrAX4Q2fMSGa4/RpzEik4QXJ21OA0n19ZeJ6nKGcQH uivhbq3pbzN6g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DBB7868FCB; Wed, 31 Dec 2025 15:31:07 -0700 (MST) 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 1RJTKnEB5hdr; Wed, 31 Dec 2025 15:31:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220260; bh=gTzf6RpmaHEfr5sISaHsBrr3xXvDKb5SHVy7MwyI6jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q8XO9u/oCGAjydK6l0mLy9Qp9Irt+0NuchTrJvuqd1k/XgcVq9a+RU2Wspxuy0mAj o1SJ3Rg06in93+sk35Xd+rN5QeVig90yh3zJvFigumVtu0adYConh/wKSLYoAtEFTV Bm5c4nyWFr6HlO+0YYliBH323TmkuhsJoI3w7/qLDrKsa0vs6wfjBqRCQN55Uj+Ga8 X4raeCX5Tiz1Y7+TqSMyKCjzLIl5/lH7OmgC2DS7UAIN6nZ0LsCZ6i9jGYVe53v56u M53+lfcaFupvS6IqLSi5ExeSiBBWdBaB6xR1Y8eWSZgZa+qt5zHjFT1PuLmsjKNHvP /Z55lKIudq4Xw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 86A5468F65; Wed, 31 Dec 2025 15:31:00 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:41 -0700 Message-ID: <20251231223008.3251711-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: W3COXNPMDDIAADPF327WU4LP4R2GPBDL X-Message-ID-Hash: W3COXNPMDDIAADPF327WU4LP4R2GPBDL 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 08/26] ext4l: Move message buffer functions to support.c 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 Move the message buffer functions from interface.c to support.c since they are internal support code rather than filesystem-interface functions. This keeps interface.c focused on functions called from the U-Boot filesystem layer. Functions moved: - ext4l_msg_init() - ext4l_record_msg() - ext4l_get_msg_buf() - ext4l_print_msgs() Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 6 +++-- fs/ext4l/interface.c | 51 ------------------------------------------- fs/ext4l/support.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 087d8394ab6..37a4abb537f 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2892,12 +2892,14 @@ void bh_cache_clear(void); int bh_cache_sync(void); int ext4l_read_block(sector_t block, size_t size, void *buffer); int ext4l_write_block(sector_t block, size_t size, void *buffer); +void ext4l_msg_init(void); +void ext4l_record_msg(const char *msg, int len); +struct membuf *ext4l_get_msg_buf(void); +void ext4l_print_msgs(void); /* ext4l interface functions (interface.c) */ struct blk_desc *ext4l_get_blk_dev(void); struct disk_partition *ext4l_get_partition(void); -void ext4l_record_msg(const char *msg, int len); -struct membuf *ext4l_get_msg_buf(void); #define sb_is_blkdev_sb(sb) ({ (void)(sb); 0; }) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 7c37c99488a..aebcc17fd3a 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -24,9 +23,6 @@ #include "ext4_uboot.h" #include "ext4.h" -/* Message buffer size */ -#define EXT4L_MSG_BUF_SIZE 4096 - /* Global state */ static struct blk_desc *ext4l_dev_desc; static struct disk_partition ext4l_part; @@ -42,10 +38,6 @@ static int ext4l_open_dirs; /* Global super_block pointer for filesystem operations */ static struct super_block *ext4l_sb; -/* Message recording buffer */ -static struct membuf ext4l_msg_buf; -static char ext4l_msg_data[EXT4L_MSG_BUF_SIZE]; - /** * ext4l_get_blk_dev() - Get the current block device * @@ -150,49 +142,6 @@ void ext4l_clear_blk_dev(void) ext4l_mounted = 0; } -/** - * ext4l_msg_init() - Initialize the message buffer - */ -static void ext4l_msg_init(void) -{ - membuf_init(&ext4l_msg_buf, ext4l_msg_data, EXT4L_MSG_BUF_SIZE); -} - -/** - * ext4l_record_msg() - Record a message in the buffer - * - * @msg: Message string to record - * @len: Length of message - */ -void ext4l_record_msg(const char *msg, int len) -{ - membuf_put(&ext4l_msg_buf, msg, len); -} - -/** - * ext4l_get_msg_buf() - Get the message buffer - * - * Return: Pointer to the message buffer - */ -struct membuf *ext4l_get_msg_buf(void) -{ - return &ext4l_msg_buf; -} - -/** - * ext4l_print_msgs() - Print all recorded messages - * - * Prints the contents of the message buffer to the console. - */ -static void ext4l_print_msgs(void) -{ - char *data; - int len; - - while ((len = membuf_getraw(&ext4l_msg_buf, 80, true, &data)) > 0) - printf("%.*s", len, data); -} - int ext4l_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) { diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 72bf819c3d6..1fc0bc0aa21 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -19,6 +20,13 @@ #include "ext4_uboot.h" #include "ext4.h" +/* Message buffer size */ +#define EXT4L_MSG_BUF_SIZE 4096 + +/* Message recording buffer */ +static struct membuf ext4l_msg_buf; +static char ext4l_msg_data[EXT4L_MSG_BUF_SIZE]; + /* * Global task_struct for U-Boot. * This must be a single global instance shared across all translation units, @@ -46,6 +54,49 @@ u32 ext4l_crc32c(u32 crc, const void *address, unsigned int length) return crc32c_cal(crc, address, length, ext4l_crc32c_table); } +/** + * ext4l_msg_init() - Initialise the message buffer + */ +void ext4l_msg_init(void) +{ + membuf_init(&ext4l_msg_buf, ext4l_msg_data, EXT4L_MSG_BUF_SIZE); +} + +/** + * ext4l_record_msg() - Record a message in the buffer + * + * @msg: Message string to record + * @len: Length of message + */ +void ext4l_record_msg(const char *msg, int len) +{ + membuf_put(&ext4l_msg_buf, msg, len); +} + +/** + * ext4l_get_msg_buf() - Get the message buffer + * + * Return: Pointer to the message buffer + */ +struct membuf *ext4l_get_msg_buf(void) +{ + return &ext4l_msg_buf; +} + +/** + * ext4l_print_msgs() - Print all recorded messages + * + * Prints the contents of the message buffer to the console. + */ +void ext4l_print_msgs(void) +{ + char *data; + int len; + + while ((len = membuf_getraw(&ext4l_msg_buf, 80, true, &data)) > 0) + printf("%.*s", len, data); +} + /* * iget_locked - allocate a new inode * @sb: super block of filesystem From patchwork Wed Dec 31 22:29:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1147 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=1767220272; bh=c/WrpaXLreMKnRmZNxgVL9YjTUNrmMEKVvhjcOUy5gA=; 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=ovKuKU0PLDOKvxvRcJDzY9lI4ab4GLuW3w3AC4EdK/sHr8FJJi8pWy92fLcDCKnAX HkhbNb+Lv0/BXyLtcAWv6dWkm6MoWDFAkey3szc8jyvvybp5fMFWRQQ3CgCggNJbNk 7TVWkMQakWgCgxQs5Cvnn3ktU1IkqLtLjN9N62ZKtKdhzbjEJ8e5Y89XxzrMjQ5E6t kY/q2JvZ0dOdTtfYWUMaIptn5dvW5ptVBMkDYukK3BkdGgI7Kr1MAcd3MGorM88AGQ SD/Ljc4UPfKG9SkkZsQ8EIa4goR0+fb6bhrOSbIsFtphE4lyMRYpBZZor1L4YzZQIl 9nNM6GBJ1ltoA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4F0B268F61 for ; Wed, 31 Dec 2025 15:31:12 -0700 (MST) 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 qY1dyamwA6FN for ; Wed, 31 Dec 2025 15:31:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220272; bh=c/WrpaXLreMKnRmZNxgVL9YjTUNrmMEKVvhjcOUy5gA=; 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=ovKuKU0PLDOKvxvRcJDzY9lI4ab4GLuW3w3AC4EdK/sHr8FJJi8pWy92fLcDCKnAX HkhbNb+Lv0/BXyLtcAWv6dWkm6MoWDFAkey3szc8jyvvybp5fMFWRQQ3CgCggNJbNk 7TVWkMQakWgCgxQs5Cvnn3ktU1IkqLtLjN9N62ZKtKdhzbjEJ8e5Y89XxzrMjQ5E6t kY/q2JvZ0dOdTtfYWUMaIptn5dvW5ptVBMkDYukK3BkdGgI7Kr1MAcd3MGorM88AGQ SD/Ljc4UPfKG9SkkZsQ8EIa4goR0+fb6bhrOSbIsFtphE4lyMRYpBZZor1L4YzZQIl 9nNM6GBJ1ltoA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 364AD68F65 for ; Wed, 31 Dec 2025 15:31:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220269; bh=aSdn5Rt/FbKlc4/FBOuHe8DHZun4kh5BWIFzL9WFvbc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I0vUrJwu374wh9HLnYEvvkZ7GmxYWPC8bM2LZZQHDRDL/MFyVdCppxjNZqijr+uZn 9xM8MzkqAJDC3ZkfLfhAf9x2Nc8Kuya9O5f05pRvzBT3MBn7+2E9TmBiyI6wkifU85 v4uvY0spT4No9Suosr9NtGG0eiVxGQPY6W65lFgaPRmoax4IIv1K9tSV+R64GiHnww hEdmzuadlzQVQ2lnXfui/xs4y1oqNOJnPNOQ1fiUBc2H2Kcdh0vboAQ522XvCinIPB FoN80QmgpoU4HpFD+m39g+NyEDy2rkaRsItJIR001MMfnOD0xjSFvldHezSFNj4p0j aTOlEVtHSbu6Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C726268F65; Wed, 31 Dec 2025 15:31:09 -0700 (MST) 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 K1qA85rjMrOx; Wed, 31 Dec 2025 15:31:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220265; bh=raPzOAhQoayBlIcrgTyx4FYWmunATYXK8Zp6AWjQ7eQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XQR16y3ifMUQU4zs2I4joKzWcVno6Sth6ogLWVFbUOYHtQEviOIIIP7hnOd5GT4Td jSR/L/tokdoLPmhUt1UqsAmO8EA5EhR8RWKLxOeRJ/ylzAOx/QctwfR+YTyzue3Y/I lYOS5eETUr1InQ+tHD5dPnNUmOwazYzEkDP+z1X9j5iGiF3UQaPRRrR5vtSlYDIWoa Tucz83gI7qwabucMlXsiz5pAmb+sTUEok67vvY1EtI8BxiMwKI1u1vJlfqWF9YzEp7 Sg9v29F+a08wjEkYNGfSDTB/3MYvy8s/2cApjgo0qRPhzniiq2dSq8ywcuKv+tjISK R/3wcvwKnSIgg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 52BA068C5D; Wed, 31 Dec 2025 15:31:05 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:42 -0700 Message-ID: <20251231223008.3251711-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: CLNV24MDDKMCROHKLE7QGEND3UWLWUVJ X-Message-ID-Hash: CLNV24MDDKMCROHKLE7QGEND3UWLWUVJ 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/26] ext4l: Add inode-tracking lists 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 U-Boot does not track allocated inodes, causing memory leaks when remounting filesystems. Add s_inodes list to super_block and i_sb_list to inode structures to track all allocated inodes, allowing proper eviction on unmount. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 6 ++++++ fs/ext4l/support.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 37a4abb537f..78d44faa0db 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -682,6 +682,9 @@ struct super_block { const struct export_operations *s_export_op; const struct xattr_handler * const *s_xattr; struct dentry *d_sb; /* Parent dentry - stub */ + + /* U-Boot: list of all inodes, for freeing on unmount */ + struct list_head s_inodes; }; /* Block device read-only check - stub */ @@ -859,6 +862,9 @@ struct inode { struct rw_semaphore i_rwsem; /* inode lock */ const char *i_link; /* Symlink target for fast symlinks */ unsigned short i_write_hint; /* Write life time hint */ + + /* U-Boot: linkage into super_block s_inodes list */ + struct list_head i_sb_list; }; /* Inode time accessors */ diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 1fc0bc0aa21..7f2bea4ca06 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -126,6 +126,10 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino) inode->i_mapping = &inode->i_data; inode->i_data.host = inode; INIT_LIST_HEAD(&ei->i_es_list); + INIT_LIST_HEAD(&inode->i_sb_list); + + /* Add to superblock's inode list for eviction on unmount */ + list_add(&inode->i_sb_list, &sb->s_inodes); return inode; } @@ -154,6 +158,10 @@ struct inode *new_inode(struct super_block *sb) inode->i_mapping = &inode->i_data; inode->i_data.host = inode; INIT_LIST_HEAD(&ei->i_es_list); + INIT_LIST_HEAD(&inode->i_sb_list); + + /* Add to superblock's inode list for eviction on unmount */ + list_add(&inode->i_sb_list, &sb->s_inodes); return inode; } From patchwork Wed Dec 31 22:29:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1148 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=1767220275; bh=179rUNxeOghgYhKIC0OFBikzmuRL2EJntGQbyZUixDc=; 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=Y9eT5ib6/QCxy8T3MsQLf19uZOR4j6CORjq1LY+4b+GlMB7iDziYjmjE4So/oqijx Rb+sKwtAyLXUovtxTC2Bk9I8UuoGQ1EZ5cxOWT7X8JGnZqFI6O3qOIlsa40amZAmGC YxTNKNbfmBifk8fxntW9w2PbjmDKQEHWA7wFQsH6fiZhD29g6ogNwgA6Vs/VBhLbpJ 0YJYD1WmqHtl+SLlqxEKLJhP1okJtxD89YTp10Pn81l36Jx0L8iTo/OWGw2pnsoIYF lIKdh+8RiK3d3q7jlaMrO9Hx9GoImwPSNY0Hz5FRXdLlMnY5lXWWpmpWMCgFXcNjEA il9ZB/nkDtzCQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3540868FD3 for ; Wed, 31 Dec 2025 15:31:15 -0700 (MST) 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 7FgN_g5oIAeK for ; Wed, 31 Dec 2025 15:31:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220273; bh=179rUNxeOghgYhKIC0OFBikzmuRL2EJntGQbyZUixDc=; 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=kCrK+e27UcSBpsiwoOvKle5bG6IMmjQkk5xBeOl/pdkmTpeddrcjldOmnFEWTCnml akkUF9VTxakfWS8QzURpRSf1A3gL9RN65yYzyxnbybs2+S4bzl7PhbBbYpn9w5nINg o5eB4TR05Lt2aQXHHHqIf0vv5QKX6wlYXF6yFYBLHa4k7tbKrYuLaVYuOUDnZAwCwn Wf8E3DWWB49VeTtG7oeBTU7ZyfKm7L4j1NjGZ6snoROnOn2+2RdEsrDoen1ntVbcWa QE8pCRKqZL5QeT6BiW2n5ZKNbEHy9AO/C+7reRFbpcAc0vm8RTsptjwov8SAFHjT4w 1wi7vYy+v6jRA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 38CA368F61 for ; Wed, 31 Dec 2025 15:31:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220270; bh=IlBijvSFUSLa6oZEdWHJ8L/Z/DEgmFJ3U3n3cPya5Po=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lT0Oy/H79r7BAOvedDaBZZo4nKry1hAvqSpNcxi5OphyFwa7quAwgM5KHp+EFtdsE Z9vX2MFU1OIjiKZis6irrKwdFrvcJDShSUgugWTmFtUoIrpJEV83YKR3FDjMEKlyO2 0+8kTtFcLqkw1FReNIksffQjZq40Q+Uhh7g5MegXYiRGNpr/4CYr/dIYSVQ21E+wqy TUtDpXxKL7oglidJsolmqo6RrMFF9OZW+stF6FWMefwGPmUD3J/TadQXTysQytox4O Tl9O9PFg8pJ3gqMEvW9gy9vFXXLj2DOlZ5msGRblzdNK3nttemMOSnyX0qrwmIWrIq ZLcdKseLne5og== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E917268FD3; Wed, 31 Dec 2025 15:31:10 -0700 (MST) 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 yOPH_HySSiA5; Wed, 31 Dec 2025 15:31:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220270; bh=jQ1x1xzdGGIkKIklF8R67MBQ/EeAn0IVP49IToPce94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THjNPQhKEuTw31XLr2kXEfcKUdCTGbrkcqCevMl5qK1GUjXsM3AuaOXtSmLNt4n00 mkqmVGUeY23qAXNU/JAvhtyLZY9yZKfN8jf/tPmi8crJ351fhsvnK1uyTHMV2YiQhC aeIbGAl/GwXURiuqThsz0/ajNsMhCuIQLkPSLAnAIwgR42VDnYIpSYwOTF/3INOt+Y I8AK25fdL8ztxoE0KYr8pUKgJMuRiC52iqJbcoxMEO1CHnzwe8Z/2A1/AJInYivgIw BqP2gIuNj/P2S4E0OdTUtJOHBgW/FSjBEMRxfEoL8N3TAf2f/qaUPSlo6fJM1iCrGU LvHhpwKml9fMA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0EC5268C5D; Wed, 31 Dec 2025 15:31:10 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:43 -0700 Message-ID: <20251231223008.3251711-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GSMVC6RPYNJMS2DAUIGAZVM6E5H7XU4N X-Message-ID-Hash: GSMVC6RPYNJMS2DAUIGAZVM6E5H7XU4N 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/26] ext4l: Fix a few problems with handling bh_cache 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 Several buffer cache issues cause problems when remounting: 1. bh_cache_insert() only checks block number, but the same block can be read with different sizes (e.g. superblock at 1K vs 4K). Check both block number and size when determining if already cached. 2. bh_cache_clear() leaves stale buffer references, causing memory leaks. Force the reference count to 1 before releasing since ext4 code won't access these buffers after unmount. 3. brelse() calls free_buffer_head() when the reference count reaches zero. However, buffer heads remain in the cache and are freed by bh_cache_clear() during unmount. This causes a double-free. Fix this by having brelse() only decrement the count, without freeing. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/support.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 7f2bea4ca06..3133a4ebead 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -258,9 +258,10 @@ static void bh_cache_insert(struct buffer_head *bh) unsigned int hash = bh_cache_hash(bh->b_blocknr); struct bh_cache_entry *entry; - /* Check if already in cache */ + /* Check if already in cache - must match block AND size */ for (entry = bh_cache[hash]; entry; entry = entry->next) { - if (entry->bh && entry->bh->b_blocknr == bh->b_blocknr) + if (entry->bh && entry->bh->b_blocknr == bh->b_blocknr && + entry->bh->b_size == bh->b_size) return; /* Already cached */ } @@ -316,7 +317,12 @@ void bh_cache_clear(void) struct buffer_head *bh = entry->bh; bh_clear_stale_jbd(bh); - /* Release the cache's reference */ + /* + * Force count to 1 so the buffer will be freed. + * On unmount, ext4 code won't access these + * buffers again, so extra references are stale. + */ + atomic_set(&bh->b_count, 1); if (atomic_dec_and_test(&bh->b_count)) free_buffer_head(bh); } @@ -629,14 +635,24 @@ struct buffer_head *sb_bread(struct super_block *sb, sector_t block) /** * brelse() - Release a buffer_head * @bh: Buffer head to release + * + * Decrements the reference count on the buffer. Buffer heads are cached + * and only freed by bh_cache_clear() on unmount, so this just decrements + * the count without freeing. */ void brelse(struct buffer_head *bh) { if (!bh) return; - if (atomic_dec_and_test(&bh->b_count)) - free_buffer_head(bh); + /* + * If buffer has JBD attached, don't let ref count go to zero. + * The journal owns a reference and will clean up properly. + */ + if (buffer_jbd(bh) && atomic_read(&bh->b_count) <= 1) + return; + + atomic_dec(&bh->b_count); } /** From patchwork Wed Dec 31 22:29:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1149 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=1767220278; bh=5Fv1+ir0Gf/HPKj2ggiRkrQ5wYCAR+vXphZ7oi/LliU=; 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=ZQ/3x3tLtHXmV2PnLLm7oZa4WKBM6nUFMEEOctig2gVeI1kRIF2j8Eq1ZieiFG9fS Kt8AoHs9oZwNHYMHjUM/mn1iJntJK/Dtz46pKEhDCJbL5asOszhaMbDSYJsQVYKfhq sdTooS2Ae7lCjUxIV0DHrIdhjtFsCm8s0fKOe9c1/T3xb4uuPw9zrUucW7zdF2wwQy kuy3k/dOgZwocurpsYSoF5Afs6RCifD5GoOpObbe7AAwyzPvfdWZKV/pwr3cAtvWp8 xZOQCtPeZm/r7RRBoVN7BCOxSVeZrfwW36EX1rUvQFoPX/2sUqMDlReda2cks3WYAH mVOqHMaZZzJ2g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4F57C68FD3 for ; Wed, 31 Dec 2025 15:31:18 -0700 (MST) 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 vG-B7ck7ubla for ; Wed, 31 Dec 2025 15:31:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220278; bh=5Fv1+ir0Gf/HPKj2ggiRkrQ5wYCAR+vXphZ7oi/LliU=; 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=ZQ/3x3tLtHXmV2PnLLm7oZa4WKBM6nUFMEEOctig2gVeI1kRIF2j8Eq1ZieiFG9fS Kt8AoHs9oZwNHYMHjUM/mn1iJntJK/Dtz46pKEhDCJbL5asOszhaMbDSYJsQVYKfhq sdTooS2Ae7lCjUxIV0DHrIdhjtFsCm8s0fKOe9c1/T3xb4uuPw9zrUucW7zdF2wwQy kuy3k/dOgZwocurpsYSoF5Afs6RCifD5GoOpObbe7AAwyzPvfdWZKV/pwr3cAtvWp8 xZOQCtPeZm/r7RRBoVN7BCOxSVeZrfwW36EX1rUvQFoPX/2sUqMDlReda2cks3WYAH mVOqHMaZZzJ2g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3C97268FCB for ; Wed, 31 Dec 2025 15:31:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220277; bh=SYaLloNQq+r9LPtJDoUDPkIQRFI0fIO8FTGa5YPHeiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZpS3vRmie60LwgyXNgwfBDt9nZu+45jTyReV0ic5XO7ahIeBF8opE9PoKnA/xeWw 5dCKqXI0Im006LXSqPzWo5zkmNaXOK3QSRdQMi9ezBlolN+q1k+RGoswSjOlikqJz6 MyZze5V9Edb7wVDI/VHlCYH/hO0LhvC9eLEhWJ89mE7RgfHtr7q4w2C0TkLOCXom11 Q+upTOH+hyldOT68bjjjBTebW6xonqbLQ3womHdOmFh8cUlPYvIxB5H4ycn3YY1U5U YvpbUqvdkgOtkHmXXte1eiYcBM1Rda6TBAOruS2g05+7udKnrWv71c73tXbjBJ0a4M 5uzHsF7vpRJGg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8882368F65; Wed, 31 Dec 2025 15:31:17 -0700 (MST) 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 bEo1euPeLnuO; Wed, 31 Dec 2025 15:31:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220271; bh=ae3j/GT/z+YZeDCFWt53Ocz6iAZIYaalBHpkWIgzLrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XReBrzI6TSvsEwDVBe4cT/Q/OrzVo4PRUIZPsDZyGFvGPFUbX+GxVMIcjoHsIKUZx DPpRiLm1yF7EM1p+w7scN3hWXp4GfrLxxm2/zvYb2cZapdjRDeoAJ9iF8jybELqF8v s0upPk4Vr5jfN6f7U8P+KIG9kdiIsLPZT3cX9YaO+0lJPSKlOfR02ETenNpOYOiSEZ 6Tmb2EYqnO40VP8gHjovXtMsxkGZ5bY7/MuAk6r3kvPBfNpSvQ2oLnPiJa+4jWGP63 pBggskZOz4B/GwH/dZGd5QEHUdhfiBeYm68eUnzqGFwGto07t1iYLkDon50t5GWlzq WpiSNErde7Q5w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 330F068C5D; Wed, 31 Dec 2025 15:31:11 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:44 -0700 Message-ID: <20251231223008.3251711-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GJ7HJO5LZ7SUIS3B5UKJY435JDLADBQL X-Message-ID-Hash: GJ7HJO5LZ7SUIS3B5UKJY435JDLADBQL 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/26] ext4l: Clean up fully when unmounting 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 Resources are not properly released on unmount, causing memory leaks in long-running U-Boot sessions that remount filesystems. Add ext4l_free_sb() to release all resources on unmount: - Destroy journal and commit superblock - Release superblock buffer and unregister lazy init - Free mballoc data and release system zone - Destroy xattr caches - Free group descriptors and flex groups - Evict all tracked inodes - Free root dentry, sbi, and superblock structures Also: - Init the s_inodes list when allocating superblock - Free mount context (ctx, fc) after successful mount - Call destroy_inodecache() during global cleanup Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4.h | 6 ++ fs/ext4l/ext4_uboot.h | 1 + fs/ext4l/interface.c | 135 ++++++++++++++++++++++++++++++++++++++++++ fs/ext4l/super.c | 25 ++++++-- 4 files changed, 162 insertions(+), 5 deletions(-) diff --git a/fs/ext4l/ext4.h b/fs/ext4l/ext4.h index 669d5522f27..a1c80dd7cdf 100644 --- a/fs/ext4l/ext4.h +++ b/fs/ext4l/ext4.h @@ -3947,4 +3947,10 @@ extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, #define EFSBADCRC EBADMSG /* Bad CRC detected */ #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ +/* Cleanup functions exported from super.c */ +void ext4_group_desc_free(struct ext4_sb_info *sbi); +void ext4_flex_groups_free(struct ext4_sb_info *sbi); +void ext4_destroy_lazy_init(void); +void destroy_inodecache(void); + #endif /* _EXT4_H */ diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 78d44faa0db..abe54e67aa4 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2086,6 +2086,7 @@ struct fs_context { /* ext4 superblock initialisation and commit */ int ext4_fill_super(struct super_block *sb, struct fs_context *fc); int ext4_commit_super(struct super_block *sb); +void ext4_unregister_li_request(struct super_block *sb); /* fs_parameter stubs */ struct fs_parameter { diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index aebcc17fd3a..ceedabdb727 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -22,6 +22,8 @@ #include "ext4_uboot.h" #include "ext4.h" +#include "ext4_jbd2.h" +#include "xattr.h" /* Global state */ static struct blk_desc *ext4l_dev_desc; @@ -142,6 +144,134 @@ void ext4l_clear_blk_dev(void) ext4l_mounted = 0; } +/** + * ext4l_free_sb() - Free superblock and associated resources + * @sb: Superblock to free + * @skip_io: If true, skip all I/O operations (for forced close) + * + * Releases all resources associated with the superblock including the journal, + * caches, inodes, and the superblock structure itself. + */ +static void ext4l_free_sb(struct super_block *sb, bool skip_io) +{ + struct ext4_sb_info *sbi = EXT4_SB(sb); + + /* + * Destroy journal first to properly clean up all buffers. + * If skip_io is set, the device may be invalid so skip + * journal destroy entirely - it will be recovered on next mount. + */ + if (sbi->s_journal && !skip_io) + ext4_journal_destroy(sbi, sbi->s_journal); + + /* Commit superblock if device is valid and I/O is allowed */ + if (!skip_io) + ext4_commit_super(sb); + + /* Release superblock buffer */ + brelse(sbi->s_sbh); + + /* Unregister lazy init and free if no longer needed */ + ext4_unregister_li_request(sb); + ext4_destroy_lazy_init(); + + /* Free mballoc data */ + ext4_mb_release(sb); + + /* Release system zone */ + ext4_release_system_zone(sb); + + /* Destroy xattr caches */ + ext4_xattr_destroy_cache(sbi->s_ea_inode_cache); + sbi->s_ea_inode_cache = NULL; + ext4_xattr_destroy_cache(sbi->s_ea_block_cache); + sbi->s_ea_block_cache = NULL; + + /* Free group descriptors and flex groups */ + ext4_group_desc_free(sbi); + ext4_flex_groups_free(sbi); + + /* Evict all inodes before destroying caches */ + while (!list_empty(&sb->s_inodes)) { + struct inode *inode; + struct ext4_inode_info *ei; + + inode = list_first_entry(&sb->s_inodes, + struct inode, i_sb_list); + list_del_init(&inode->i_sb_list); + /* Clear extent status and free the inode */ + ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS); + ei = EXT4_I(inode); + kfree(ei); + } + + /* Free root dentry */ + if (sb->s_root) { + kfree(sb->s_root); + sb->s_root = NULL; + } + + /* Free sbi */ + kfree(sbi->s_blockgroup_lock); + kfree(sbi); + + /* Free structures allocated in ext4l_probe() */ + kfree(sb->s_bdev->bd_mapping); + kfree(sb->s_bdev); + kfree(sb); +} + +/** + * ext4l_close_internal() - Internal close function + * @skip_io: If true, skip all I/O operations (for forced close) + * + * When called from the safeguard in ext4l_probe(), the device may be + * invalid (rebound to a different file), so skip_io should be true to + * avoid crashes when trying to write to the device. + */ +static void ext4l_close_internal(bool skip_io) +{ + struct super_block *sb = ext4l_sb; + + if (ext4l_open_dirs > 0) + return; + + if (sb) + ext4l_free_sb(sb, skip_io); + + ext4l_dev_desc = NULL; + ext4l_sb = NULL; + + /* + * Force cleanup of any remaining journal_heads before clearing + * the buffer cache. This ensures no stale journal_head references + * survive to the next mount. This is critical even when skip_io + * is true - we MUST disconnect journal_heads before freeing + * buffer_heads to avoid dangling pointers. + */ + bh_cache_release_jbd(); + + ext4l_clear_blk_dev(); + + /* + * Clean up ext4 and JBD2 global state so it can be properly + * reinitialised on the next mount. This is important in U-Boot + * where we may mount/unmount filesystems multiple times in a + * single session. + * + * Even when skip_io is true (journal wasn't properly destroyed), + * we must destroy the caches to free all orphaned journal_heads. + * The next mount will reinitialise fresh caches. + */ + ext4_exit_system_zone(); + ext4_exit_es(); + if (IS_ENABLED(CONFIG_EXT4_WRITE)) + ext4_exit_mballoc(); + if (IS_ENABLED(CONFIG_EXT4_JOURNAL)) + jbd2_journal_exit_global(); + destroy_inodecache(); +} + int ext4l_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) { @@ -192,6 +322,7 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, ret = -ENOMEM; goto err_exit_es; } + INIT_LIST_HEAD(&sb->s_inodes); /* Allocate block_device */ sb->s_bdev = kzalloc(sizeof(struct block_device), GFP_KERNEL); @@ -279,6 +410,10 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, /* Store super_block for later operations */ ext4l_sb = sb; + /* Free mount context - no longer needed after successful mount */ + kfree(ctx); + kfree(fc); + /* Print messages if ext4l_msgs environment variable is set */ if (env_get_yesno("ext4l_msgs") == 1) ext4l_print_msgs(); diff --git a/fs/ext4l/super.c b/fs/ext4l/super.c index 9ed6f907b7a..48c87eb0e97 100644 --- a/fs/ext4l/super.c +++ b/fs/ext4l/super.c @@ -48,7 +48,6 @@ static int ext4_unfreeze(struct super_block *sb); static int ext4_freeze(struct super_block *sb); static inline int ext2_feature_set_ok(struct super_block *sb); static inline int ext3_feature_set_ok(struct super_block *sb); -static void ext4_unregister_li_request(struct super_block *sb); static void ext4_clear_request_list(void); static struct inode *ext4_get_journal_inode(struct super_block *sb, unsigned int journal_inum); @@ -1228,7 +1227,7 @@ static void ext4_percpu_param_destroy(struct ext4_sb_info *sbi) percpu_free_rwsem(&sbi->s_writepages_rwsem); } -static void ext4_group_desc_free(struct ext4_sb_info *sbi) +void ext4_group_desc_free(struct ext4_sb_info *sbi) { struct buffer_head **group_desc; int i; @@ -1241,7 +1240,7 @@ static void ext4_group_desc_free(struct ext4_sb_info *sbi) rcu_read_unlock(); } -static void ext4_flex_groups_free(struct ext4_sb_info *sbi) +void ext4_flex_groups_free(struct ext4_sb_info *sbi) { struct flex_groups **flex_groups; int i; @@ -1484,7 +1483,7 @@ static int __init init_inodecache(void) return 0; } -static void destroy_inodecache(void) +void destroy_inodecache(void) { /* * Make sure all delayed rcu free inodes are flushed before we @@ -3708,7 +3707,7 @@ static void ext4_remove_li_request(struct ext4_li_request *elr) kfree(elr); } -static void ext4_unregister_li_request(struct super_block *sb) +void ext4_unregister_li_request(struct super_block *sb) { mutex_lock(&ext4_li_mtx); if (!ext4_li_info) { @@ -3722,6 +3721,22 @@ static void ext4_unregister_li_request(struct super_block *sb) mutex_unlock(&ext4_li_mtx); } +/* + * ext4_destroy_lazy_init() - Free lazy init info if no longer needed + * + * In U-Boot, there is no lazy init thread, so this must be called after + * ext4_unregister_li_request() to free ext4_li_info when the list is empty. + */ +void ext4_destroy_lazy_init(void) +{ + mutex_lock(&ext4_li_mtx); + if (ext4_li_info && list_empty(&ext4_li_info->li_request_list)) { + kfree(ext4_li_info); + ext4_li_info = NULL; + } + mutex_unlock(&ext4_li_mtx); +} + static struct task_struct *ext4_lazyinit_task; /* From patchwork Wed Dec 31 22:29:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1150 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=1767220282; bh=MJuyMakNpjZA5uW76FcJEjqcpHVNPFrpTTICMW4t3V0=; 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=CZXf73y4sR6aWmchWBeP8g4/SHfFl8DlvAfmODRpdMfdtlHs1pDciKbIn2XPv9QdU bk3dhtW7IO2aXQQ3598fyMPixqpRQyUMLAsx4KWWv1ITKGnzBgdF07wzh9OU1nJhOU qxjYITebABvcxEkE7K7iUuS4nWBZaTJG5v71BLVIs6zgp4wZPH5WcRy+UKobqh3bec Qlw5s5RU+uK7ukY7/LB+jnOlTwq/ipykD18Yq+LIRDI8PCPEOIHbQn+OUTW075hZo9 ZYizyFQM72ynPv1rwtTMz5V2Dqy2jImhlE7iPFEyruwNl/EZKrs/v1lF+dGKP34WaF 5VCbRt8iainCA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 061FC68F65 for ; Wed, 31 Dec 2025 15:31:22 -0700 (MST) 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 ek5PhVjNdkJA for ; Wed, 31 Dec 2025 15:31:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220281; bh=MJuyMakNpjZA5uW76FcJEjqcpHVNPFrpTTICMW4t3V0=; 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=vkvY3Qu4fUbJjlqLjsCvKgp+I33GfD8hi1pCa1mw5yKW+gKbMUncEMb8518lYUfsI y3ELQ0nFymumKLsf221ZWtYXu8mMpR2KSE/YXNxujj0vHWU83+MKMpIMlfq0OO6Ptj mRIGldm/F59To8/4IWQNXlVpfPsLR7Gq4YqIvbp8QN4DnL6sHsW5Ky8RB8IMTzAe3g HXlIvHlJShQq1H1qV2Z9+XPpmIi2KeTmRcIDKVajdiyY0+NX1NLhf24DwYdCnofPgp wt7FoQ8p8EyUL6NMqFjjJ1oymrEnhsMSDMJbXoiLYXxSm+DJQKIfChAtWwtWcqttrz KgalY8y77gNYg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E579068FCB for ; Wed, 31 Dec 2025 15:31:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220280; bh=XzzR7Wy1g8pKNXsGI3Pq7JPMRXrjcUxV2fReENeIBjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ytavq6PokJFYBpHFyTUknS+JufNQGqZhaDZBuii3am53VkeFRlH2KQDwzHQIIoPlq rwXpw6ob47shOi7m2HDFW5epOR8N4PlaDFXtx38HHKOgvF8BmBIqviBZVPrdeLHz9A UBZZBOPHx0/cAsbuWQQCM16JPYqXceVUssDv3+D7STdcgi0dwpAR8HTnlz+Vs/lU9d CVttQ2rSDxqcV9q1SKx5HAP8+gI8Xo1SuwT0PlmZlmjrkGeO+8ek1Ng+uAp7RSaNj3 qmI1y2Y9j/qn7mrLpixG0z2HVDNYxiup76F3blXKsQBSm3YW6UFq/pXtbm7a3SyfqB hO9S4w0TnHjkQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4D15A68C5D; Wed, 31 Dec 2025 15:31:20 -0700 (MST) 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 hbBvMAZTHUsx; Wed, 31 Dec 2025 15:31:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220276; bh=QCfT4vLI2kxS1BLen1r8F84/GBlJZP4S3qhbmJbUNvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s23dvhiO5J2IKcwppBghdmgBZw0I9rCT3NtIFwgfQjAY/k/e6D1UUzQkOQsN9cGYk Xv4cSSw/MXf4agE+YvyHr6qayBRjZ6Dj0065x8W715Hu81Pg3rxeKy58qcyELJTUEq OrD2YxIVbIHRUB0BKVKE1LuLZmm/ZIL+9uxVyZl8tAkhXHBX/TOk6K+Ovm3fMcBaxQ NlYGPDUKl0Qg+Jvzp0WgT2vfL4Keq38PPktKId+bVUyBe38/PjMmxy7wiN4IA8sLHl r/tZgKKiKWEW9Y/rv7EfChUbbSIcKCU2KJriWe8C4Hb0BiXuzi3ZYe+pUOOEP/PQmh U/crvKcga98dg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E3DE368F61; Wed, 31 Dec 2025 15:31:15 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:45 -0700 Message-ID: <20251231223008.3251711-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5QCXZUJUVLRPNSO7ESTXCDCHPZ4EYXGD X-Message-ID-Hash: 5QCXZUJUVLRPNSO7ESTXCDCHPZ4EYXGD 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 12/26] ext4l: Remove duplicate atomic_add declarations 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 The atomic_add() and atomic64_add() functions are now provided by asm-generic/atomic.h so remove the duplicate declarations from ext4_uboot.h and the implementation from stub.c Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 4 ---- fs/ext4l/stub.c | 8 +------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index abe54e67aa4..df26c02b54d 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2310,10 +2310,6 @@ void *kvzalloc(size_t size, gfp_t flags); #define kvmalloc(size, flags) kvzalloc(size, flags) unsigned long roundup_pow_of_two(unsigned long n); -/* Atomic operations - declarations for stub.c */ -void atomic_add(int val, atomic_t *v); -void atomic64_add(s64 val, atomic64_t *v); - /* Power of 2 check - declaration for stub.c */ int is_power_of_2(unsigned long n); diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index f072cb5713f..d328c6821a9 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -617,13 +617,7 @@ int percpu_init_rwsem(struct percpu_rw_semaphore *sem) return 0; } -/* Atomic operations */ -void atomic_add(int val, atomic_t *v) -{ - v->counter += val; -} - -/* atomic64_add is now a macro in ext4_uboot.h */ +/* atomic_add and atomic64_add are now in asm-generic/atomic.h */ /* Discard */ unsigned int bdev_max_discard_sectors(struct block_device *bdev) From patchwork Wed Dec 31 22:29:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1151 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=1767220287; bh=wTuaCzUxq67U3bSGt8DrPEZqKVlOe3+l998CWn9W31k=; 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=ob/3wZrujsjbcjjRAvtVW0xhxnfSYrvZjPI0zVi3WQ8Xkp1uLDa4kgRuXH9RiUiIv 8kJwRaZ9rRr1BK+S0L+R/lQL4KBVMWDIZopBDoMXmFxOpp3efWSNU9CocwpYG6dQK/ 4/BS5HLisRWtkkUhcpB95xcnWX3cXkmcvZLITi4hcU4XS+xvO8TbgvCpoFNiKTX+on NNt3iCVqcROe0H9nVHp72si+SrGJcLCVbVYrk9x8bYuFJRhI6+75cNAjxjlsB6DrqH 55TdEUI3Xoizv1TLuIA8QT/7thOVejVkh4udEgddPFR+2tys94P26xO92PcYJPHCKu BzK0MxLy4Ua7w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 022DD68F65 for ; Wed, 31 Dec 2025 15:31:27 -0700 (MST) 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 3Ceb3-vnJroo for ; Wed, 31 Dec 2025 15:31:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220286; bh=wTuaCzUxq67U3bSGt8DrPEZqKVlOe3+l998CWn9W31k=; 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=Gck/Q8wHP8Eeqxe+SqoSxenpruZscjMtP82Rwk34gpCqQaPhNF8QsRwSIefnRP4uV KLER4FlB4iKKhcH6vG6oI+nOB9NmPkdAxWBSdsI34XRoWTe2f162YOH2fjfetZD7l3 LgY2BMUMEvWzxGxZpO+5si+YdXUI/S1IwkrP9oMYzeAMzinc2nPUvu/Th/wWwYbGTM RhHcKnoglD8iY5nR6dTm+djZlXF4d0vLMIPKJI9NS5ZMDh4cfpgezz2sNkJKowcGEq 9Pym7+UmwhNKKHDOyC/XgRn04Q9khXYPUyLUj5DkZPhEOKg+1Z4NbXlOFj1weeBGY2 zh8aJ+Bg+S7MA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DE28068C5D for ; Wed, 31 Dec 2025 15:31:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220284; bh=RvyzsIhlq4FUPMa5Uhcx4BdB2kdRZMmI1HX4II5iF6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XKYNWA+bj3pbGgqUUdT27VzR7CgOM+EgFh5Pqli28B4rPE+Z9rE9e0qPmQ+SlEOFJ QmLHuha2Q75rNyyu7D/NIWK+PrFxQFdlYi0n6NsPgHKnp/1olDqX2d8zJJPDIdnVf5 3cgmyvKwXOnAS4MgvIkQpQn8u+5e5wnewQvxX+78Nd+LAhSMvnvNSlGnqM52s0VUvQ sTjBwJ5diexEgdkn+ieGMG6djq0LEphD26XHFM+7InFnnFlJVeKtCs/4qmbhJ1D87C 3M+t5N/g4jDMseEk35EGTZWGFK0wagxeZyiJUvDbRHdw1mm/7LYHRx2eA/KPKqjVgz jm5ccn0di+Sdg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E758668C5D; Wed, 31 Dec 2025 15:31:24 -0700 (MST) 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 M93tP2Jdr50Y; Wed, 31 Dec 2025 15:31:24 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220280; bh=RnX+Ze3ayBAw8NDG0s8Ux8awWlsvZ6vaUVFOMbbSx+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R5VXKUbwGiQ7I7uVdV+vPgxdZM++UfO6V5HqcgmoVlBn4FA/L1tSEs7WREuwfIU9W AFpM5cTOrJruinKdslfkp3Hhjrz5boqrhnDbk6ZMPQmshGZAFezLQIb1Yzvt6nmXUU zaW/n0GxljviHkhOACCB5r2/X+OdrhbmA42j2H2yZ1L+d1WWNiAuVVIMOvoTlMkg7O 3zBZDHk+YEKEe7vfvsvPM0Geb+jA6yxgubM0kLFHS3WqKb9rpwgcrqfsSM6PIT+QZW 4gODLCfvjjk7zf8ImPrdZErYr/psIIOYgrGJ5eRkha/CvZNmV0CHNMtSh0RQRhGErm KnuJfEN7ggpSw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8F0AC68F61; Wed, 31 Dec 2025 15:31:20 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:46 -0700 Message-ID: <20251231223008.3251711-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5VXJ6L2O3G4XALDE45YJSXQ5SWPPGMNR X-Message-ID-Hash: 5VXJ6L2O3G4XALDE45YJSXQ5SWPPGMNR 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 13/26] ext4l: Use the real crc16 implementation 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 The crc16() stub always returns 0, which causes group-descriptor checksum-verification to fail for filesystems using the old CRC16 checksum algorithm (gdt_csum feature without metadata_csum). Replace the stub with U-Boot's real CRC16 implementation to allow mounting these filesystems. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index df26c02b54d..ba4b4266daa 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2143,8 +2143,8 @@ struct fs_parse_result { /* ctype */ #include -/* crc16 */ -#define crc16(crc, buf, len) (0) +/* crc16 - use U-Boot's implementation */ +#include /* Timer and timing stubs */ #define HZ 1000 From patchwork Wed Dec 31 22:29:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1152 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=1767220291; bh=bgBXgmdKjphbEDpXJrEohfk/f2Yxn5aEEyqYkUHe7h0=; 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=iBqUr79KU5d4rf51QLCD9Lkafsq03j4PPC3XXxvMaccliUtYX46Hc12ZVTSvEtxDB mmvtGo6jKyNl6Hkf69UqiJ8gzsA1OGsTuHLc8h0HokRm5Ua1inRRWCtIqhkZJtmERy uOHBmHIAqqkC3K+TgA02FsSmMCr6ikPG85JX468zO3RRhk1aqJbSAx1pBA/+YA6ys+ ZplXkn07yPUCJoFm3wBzYoQqXoVAUm1QgGHCRFoYy8aWkRdSUbpZmYKEjPr+qaSB/k E5NExG6aOvytZBXC6SmcdlL5hwPaxV9LsbIsU9PzXshjBv8pvvorrXT+oCEcRkGTGb XtzIh+ikBHkog== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BD1D868FDF for ; Wed, 31 Dec 2025 15:31:31 -0700 (MST) 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 Oxmpd63mKjen for ; Wed, 31 Dec 2025 15:31:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220291; bh=bgBXgmdKjphbEDpXJrEohfk/f2Yxn5aEEyqYkUHe7h0=; 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=iBqUr79KU5d4rf51QLCD9Lkafsq03j4PPC3XXxvMaccliUtYX46Hc12ZVTSvEtxDB mmvtGo6jKyNl6Hkf69UqiJ8gzsA1OGsTuHLc8h0HokRm5Ua1inRRWCtIqhkZJtmERy uOHBmHIAqqkC3K+TgA02FsSmMCr6ikPG85JX468zO3RRhk1aqJbSAx1pBA/+YA6ys+ ZplXkn07yPUCJoFm3wBzYoQqXoVAUm1QgGHCRFoYy8aWkRdSUbpZmYKEjPr+qaSB/k E5NExG6aOvytZBXC6SmcdlL5hwPaxV9LsbIsU9PzXshjBv8pvvorrXT+oCEcRkGTGb XtzIh+ikBHkog== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC40468FCB for ; Wed, 31 Dec 2025 15:31:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220289; bh=E4Wp3ngFz+k5twnLEut703S5y1tnru9UW7zkvBfHZK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D/5q/Nl8TZtkspbATWD5/8gVolonMZaVaP5MWA8JYuDXXnbS3RgaMpzounRw38WpH lpOjtffNdOzeONewaDuBJJWqmYbyRUYnu5HpykHvYlSPT8q9/34Izhl1Uz4JS6mYtQ mJBSFo79HvW/oIAGJgjLbchsKLuwrEoOFntD4SvLFZFsUwky75NNspcs35kF/XXaTc LrWi7/dASlgA7jOM66vMnUAlVkRccXuB952MqIN0fMEMLPygJT0WehLfF/6A91okCg LP7pbxkwVTjkUCXxOwy5hXsCOQHxkXvRVjWHcTkftHM7myBMZxHQLB/KH3OjxENVtS 0UcaeLETqOq7w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B8A6368F65; Wed, 31 Dec 2025 15:31:29 -0700 (MST) 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 Vcficc4lyg-T; Wed, 31 Dec 2025 15:31:29 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220285; bh=FMoM9cmv1X7g3AoPwN6RBkFt+06WTzrlPQ+9P0pkH1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DJ3TN6RpElrESkgEeAtm+gvnIv8bhc3wUS5TZU6TRUDsc3cTkk9Y/WXD0NoQ652NS M2YWNPsDOGQG2VmTxOCR830wzc4XJtNCBiDae0dveuaof/Qt5hKsA8CuSCkFxVRanO Kuu4gRAhK/OxaAi7dW9EiFWHRKc8BaaKRE1Fo0E4o0QNt2EzakmmOZQnHnWl+eXFmV jRbQpXlj6C6YRMho3s32w1MvOxs71KfgzIdEWeVst6RLIH3ELyBnLeOslvU6ESLtd9 g0jFK1asKfy9LmP6ucVfmdtnBvEZuRaXuKeO+i6RNj5LLMQ2VRI5PD1hkxXnIOIfLz pfcJp26PNkmow== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 60D2F68F61; Wed, 31 Dec 2025 15:31:25 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:47 -0700 Message-ID: <20251231223008.3251711-15-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 36H24FBJL3L2JIA6U6EG3GQ2UHR4DEC3 X-Message-ID-Hash: 36H24FBJL3L2JIA6U6EG3GQ2UHR4DEC3 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 14/26] ext4l: Add a few Kconfig dependencies 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 The ext4l driver requires the filesystem framework (FS) and rbtree library (RBTREE) to build correctly. Add the first as an explicit dependency and 'select' the second, to prevent build failures when ext4l is enabled. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/Kconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4l/Kconfig b/fs/ext4l/Kconfig index 998f0f45474..be989208ec5 100644 --- a/fs/ext4l/Kconfig +++ b/fs/ext4l/Kconfig @@ -5,6 +5,9 @@ config FS_EXT4L bool "Enable ext4 filesystem support (Linux port)" + depends on FS + select RBTREE + select CRC32C help This provides support for reading images from the ext4 filesystem, using code ported from Linux. This is mutually exclusive with From patchwork Wed Dec 31 22:29:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1153 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=1767220295; bh=j6SPQgm28reDuQ3vwaxwgavO+jxUOvhYvmHJJJB6vbc=; 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=jJvEg+bjHJ3ifHlg4Yt2C/WZcWTVSgJcXTdm/pWpo1nbfi7Vwm0Al4jXwkEHP7mG/ y2HHdbA4IdFVyej8kd9TNlcp3sbnP3q+d+MMnuVbfxYEFou/0s+UXCj8+ic1s8WM/D r+nkdIdJ+gurUkj/O815Dq2vs74TicM1b4Tur6UysqIE5WlAOeqESyuRpPVa46gUaT Q9NpirKacTnyzL3t1zW56Wl8xpxVo/SibQ5XJ24ArfQP0cPw1onmPsAjnNPplIKbgF d+XMhu0ZMDM8tmex8NSiVPvB9BiXmb+MVdO9qNfkA8Swe8hO7e1rNe45rgIyMPA9mi MfwgJNU49g9CQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 93FB668FE6 for ; Wed, 31 Dec 2025 15:31:35 -0700 (MST) 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 6crjM480431k for ; Wed, 31 Dec 2025 15:31:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220295; bh=j6SPQgm28reDuQ3vwaxwgavO+jxUOvhYvmHJJJB6vbc=; 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=jJvEg+bjHJ3ifHlg4Yt2C/WZcWTVSgJcXTdm/pWpo1nbfi7Vwm0Al4jXwkEHP7mG/ y2HHdbA4IdFVyej8kd9TNlcp3sbnP3q+d+MMnuVbfxYEFou/0s+UXCj8+ic1s8WM/D r+nkdIdJ+gurUkj/O815Dq2vs74TicM1b4Tur6UysqIE5WlAOeqESyuRpPVa46gUaT Q9NpirKacTnyzL3t1zW56Wl8xpxVo/SibQ5XJ24ArfQP0cPw1onmPsAjnNPplIKbgF d+XMhu0ZMDM8tmex8NSiVPvB9BiXmb+MVdO9qNfkA8Swe8hO7e1rNe45rgIyMPA9mi MfwgJNU49g9CQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8321B68FD3 for ; Wed, 31 Dec 2025 15:31:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220294; bh=+bi/dR+ir7ssEIOl6ngft4hZHlljKXAmPId3zpWM2s8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NTTsLj/7Q7543+U26fqoDvtgcUs6G9m5v/QY3P8wTnLsYz3Tejdx9M8kUHe2XZ4UE c5EH23xK0rg8V+lFpR+2z3CrDuNBG57YyUV5OegCpNU1avcEPFxuwLwFeAlBqzVsoK z+eRtPzVRgbQh621vodAoeERix07bwQQaZH01fv/QJMr4sKtbbV82X4bkrSpBuqBWh VXOMLY/v7RQkhlPIKXOWf7jm6EecKu+8bssHlc8U6UjfVpTwHNPyFwUQ+ufNUVnOD4 zC594u2DlNlIFllAjHJJc+9DTWKuErJaC43A54mNggrK57zxBhC9HWrdz+VZcW0kU7 55K8cjKtibqJQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6904668F65; Wed, 31 Dec 2025 15:31:34 -0700 (MST) 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 im6cSqmYiBTy; Wed, 31 Dec 2025 15:31:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220290; bh=x8Xv4zk8OpYLgPgQ8SshF6mFni7sZAxU/RrRt7sM3OM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CszanSYuLUb5pJ/5++TjeiKtsKKV3YYntTHy0Vk4Sx3UfNzycFj/e81D2u5LFChfS uSBzwtDXVgCH5nl36r3dE3Wpp8SSVR50hgd8QHnEKDkumd4ydmHdQnodrfX4Ye35Mq KWcs/WPhflBUZtN3fls4j3g53e8M8BzhUiVdDCDIRGANQSInd77YjAAGQp8ovK1FaM jbMGlgPNKLy9VOhgoR6NejlHH/qcNOX1qWUKHt5WJ68LO8d1P0+vwjOVBMdmygKTfe jJ28eMk7pMuXHc926M4tIRJRJCjm5tRcvufCCKsi15Nxcg4xG6muqX5/fB5rYRNZe5 GQo2LHCr5Duzg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0CE1E68F61; Wed, 31 Dec 2025 15:31:29 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:48 -0700 Message-ID: <20251231223008.3251711-16-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QNWKPVLNMY7BVMSMJNPC4KKZZS5CPVGP X-Message-ID-Hash: QNWKPVLNMY7BVMSMJNPC4KKZZS5CPVGP 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 15/26] ext4l: Add bh_cache_release_jbd() to clean up journal references 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 bh_cache_release_jbd() to forcibly release any journal_heads still attached to buffer_heads after journal destroy. This must be called after journal destroy but before bh_cache_clear() to ensure all journal_heads are properly released, even if journal destroy did not fully clean up (e.g., on abort). The function clears b_bh in each journal_head to prevent use-after-free when the buffer_head is later freed, and resets transaction pointers. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 1 + fs/ext4l/support.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index ba4b4266daa..00419fe834e 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2891,6 +2891,7 @@ void free_buffer_head(struct buffer_head *bh); /* ext4l support functions (support.c) */ void ext4l_crc32c_init(void); +void bh_cache_release_jbd(void); void bh_cache_clear(void); int bh_cache_sync(void); int ext4l_read_block(sector_t block, size_t size, void *buffer); diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 3133a4ebead..aaaf89092eb 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -332,6 +332,42 @@ void bh_cache_clear(void) } } +/** + * bh_cache_release_jbd() - Release all JBD references from buffer cache + * + * This must be called after journal destroy but before bh_cache_clear(). + * It ensures all journal_heads are properly released from buffer_heads + * even if the journal destroy didn't fully clean up (e.g., on abort). + */ +void bh_cache_release_jbd(void) +{ + int i; + struct bh_cache_entry *entry; + + for (i = 0; i < BH_CACHE_SIZE; i++) { + for (entry = bh_cache[i]; entry; entry = entry->next) { + if (entry->bh && buffer_jbd(entry->bh)) { + struct buffer_head *bh = entry->bh; + struct journal_head *jh = bh2jh(bh); + + /* + * Forcibly release the journal_head. + * Clear b_bh to prevent use-after-free when + * the buffer_head is later freed. + */ + if (jh) { + jh->b_bh = NULL; + jh->b_transaction = NULL; + jh->b_next_transaction = NULL; + jh->b_cp_transaction = NULL; + } + clear_buffer_jbd(bh); + bh->b_private = NULL; + } + } + } +} + /** * bh_cache_sync() - Sync all dirty buffers to disk * From patchwork Wed Dec 31 22:29:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1154 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=1767220298; bh=ni9mZ2AKOfJ6YSwLGVJ517XBH0cIvM8frDHa5TTZlmY=; 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=uDpDamKq37Qnhmcq7nf+D4fWt9udOZ/veM5nCCsJS12+02W10oAZuoUJUeNLi8WWF mddmt/Uf51cDEB1JDSRly5DPSrnM/1GTX+k2Y9Z3pzWAtQ5fDWms/IdB3DmuqIBgpn vXkll1MfYsGUWV8V58/JoAQwWqhfebodZIQVwQ53DyWFrin6tSMS46gxAZ9IBlSILv 1H7QL6YyMf3+pF/uuAYkYmPYBEaV/894J0R1YKchyf/B1bhv4Nv9hnnMhmFKbhbGVs aBwW5Z+8leSOZc3yXEJzjY4ZVAWzd/UnQKycJfoxEsO55t/hvMeVtnBwagMlvWSQxh HmZU31726SWdw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0078168FEA for ; Wed, 31 Dec 2025 15:31:38 -0700 (MST) 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 GKHnrhLqTnU2 for ; Wed, 31 Dec 2025 15:31:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220296; bh=ni9mZ2AKOfJ6YSwLGVJ517XBH0cIvM8frDHa5TTZlmY=; 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=MC0EzXpzK08XL02rHTF+VbvertWJjE1ot+QMyr80r3aM4+cO/Sd5KsaZc3EInpbfA XxUsIYCjBYja0PED/1a4gNhnBJk9Kyt7O1yPIdq9QuJPJ0Dqw/uwaFoFXvRUuO/cdU r/C7POYn81JXBs53ue4gzp/bOhB/5UucbYjNtkebNpgAtjnwZsqKhIsTPkOW0VXNrN ce7e5oV/9kNxelmOI7+vu8dpxS7V+1Pn5MlbtgnyT7U4y4c/X0wtRgzuSja3b2f+o8 /T6NtwqhoYY66xdO1cBZGbBobkwGdrvT3TUmrLQy2jODXyWHVlxVb+r47fCTRuaTvL urIkXYlLXPvxA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ED15F68F65 for ; Wed, 31 Dec 2025 15:31:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220295; bh=4JbotGJE8pNdXCvcB1y6k99TdYLZ2/0w97LPB2LSrLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uZpoVY6pQXVGsEPz+VQSQFHp86kNRZy/0jHKkGROLuAZGqFFmIgLWSb4v/Dpi/3de j+P6JTwVy8D8eosIgqiGCdjD0o0DLPeu8+eaQwWsun/EU/vUvf7cTyJPzDYPgUtWDS Z6BToGjDE+QmsHSFyPZWFE1kjqDIebUx8npkKwBX7go7yUwD58RUydwCgrFLdDH4sH tI3QaUPbIltWWf5He9A9aAP495biqlyJs84HikG0hrP4luylcRHxbfxDUZcqrEBa6n rGW3WpIbU/rAUsCtb4PIEVPJ0YCxa7v57Rzj8Tx8taY/eyqrxB8ZL00frK7Kz2GvPK 8YZ5jUXMsPUwg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4BA6368FCB; Wed, 31 Dec 2025 15:31:35 -0700 (MST) 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 FG6PSjNBp8ZD; Wed, 31 Dec 2025 15:31:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220295; bh=85IK569qU4Bbx/S/INjLEOj69VxLGTvfMawi1T/V6Lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AG9OkUHwz7deQ9ZHhLb697uiSppowKWRaoff6oUxwjlC1d6jzniDVxRrnCYZEkpmc YpSTGO+z3+KTrdhWIysPh5SUihvXhroW/5zQSVKboKmD8iqM88Yu0kn4891otAoD+c AzoIlgKkO8Q4eyVnD2i0zyrpjkvv1vaUnDQDIksCAPflqu2OzZgLKu0TMw8EfEYxSg he96M16csk29ZNbU4Gc8yBFj7tGzw/MRBWFpR0MwytG2dR0O12zMlXE3pbaSnHU7VB Jc/O5jDuHT1UcQ4eyBgOAhbAyRXp2W0AVms/cFXIm+YJ3b2FxtlHjchfEtXWVtYZ36 tkr0l1ZtDYrkA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A54BC68F61; Wed, 31 Dec 2025 15:31:34 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:49 -0700 Message-ID: <20251231223008.3251711-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: EYODYMZAFBCAQEUI2GXBTSKI2NT7OG6P X-Message-ID-Hash: EYODYMZAFBCAQEUI2GXBTSKI2NT7OG6P 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 16/26] ext4l: Add safeguard to close previous mount in probe 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 When running multiple filesystem tests in sequence, probe may be called without an explicit close of the previous mount. The old device may have been rebound to a different file, making I/O to it invalid. Add a new ext4l_close_internal() function with a skip_io parameter to handle this case. When skip_io is true, it skips journal-destroy entirely since the device may be invalid. It will be recovered on next mount. Also call the ext4- and JBD2- cleanup functions to properly reset the global state for subsequent mounts: ext4_exit_system_zone(), ext4_exit_es(), ext4_exit_mballoc(), and jbd2_journal_exit_global() This ensures the caches are destroyed, thus freeing all orphaned journal_heads, even when skip_io is true. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index ceedabdb727..301e28af3b8 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -286,6 +286,17 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, if (!fs_dev_desc) return -EINVAL; + /* + * Ensure any previous mount is properly closed before mounting again. + * This prevents resource leaks if probe is called without close. + * + * Since we're being called while a previous mount exists, we can't + * trust the old device state (it may have been rebound to a different + * file). Use skip_io=true to skip all I/O during close. + */ + if (ext4l_sb) + ext4l_close_internal(true); + /* Initialise message buffer for recording ext4 messages */ ext4l_msg_init(); @@ -855,12 +866,7 @@ int ext4l_read(const char *filename, void *buf, loff_t offset, loff_t len, void ext4l_close(void) { - if (ext4l_open_dirs > 0) - return; - - ext4l_dev_desc = NULL; - ext4l_sb = NULL; - ext4l_clear_blk_dev(); + ext4l_close_internal(false); } /** From patchwork Wed Dec 31 22:29:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1155 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=1767220302; bh=OoOLEtPg9nRElHmGosGY1GWG4HA/OT0kOJqYnQO2MN4=; 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=rCvDTTceiXLsAGhuogbInfHyx1BJzKXh5PTvrnHHz3qYheBqbMQO0H4KWJTMSu6Af 3Fw2H7XugxaIaAugakAv+1251Pa7nzK5qIq6Pa/MfutZrTxlFsemNcIvXpMuHUpyRX zS8U/Oc8oSN409xuH6LNAe/YLzzCJiiQdIb3YVi54GvAD2zotzuru53aHkvMMI6P8x E33okSiqdDsQfi/JobKk2lzQqXufrdypnxDaF3pkS2kBJWAnJjdFCjD7Okd8Ghr9iV nHNQaPi9lSlo2EmbxNhldZvfRaIN+85r/wsIrP88In+dNFTnavNnVQUaEdwaaKPyjZ U/xRPPwodN4Sg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7372F68FE5 for ; Wed, 31 Dec 2025 15:31:42 -0700 (MST) 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 vK0zz3sy9cvT for ; Wed, 31 Dec 2025 15:31:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220302; bh=OoOLEtPg9nRElHmGosGY1GWG4HA/OT0kOJqYnQO2MN4=; 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=rCvDTTceiXLsAGhuogbInfHyx1BJzKXh5PTvrnHHz3qYheBqbMQO0H4KWJTMSu6Af 3Fw2H7XugxaIaAugakAv+1251Pa7nzK5qIq6Pa/MfutZrTxlFsemNcIvXpMuHUpyRX zS8U/Oc8oSN409xuH6LNAe/YLzzCJiiQdIb3YVi54GvAD2zotzuru53aHkvMMI6P8x E33okSiqdDsQfi/JobKk2lzQqXufrdypnxDaF3pkS2kBJWAnJjdFCjD7Okd8Ghr9iV nHNQaPi9lSlo2EmbxNhldZvfRaIN+85r/wsIrP88In+dNFTnavNnVQUaEdwaaKPyjZ U/xRPPwodN4Sg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 60C9F68FE3 for ; Wed, 31 Dec 2025 15:31:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220300; bh=5KhIpuQUmswOxedCwSC1sgLqmAOVIoxoSjjlj8sOzoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uALhrEfTz0/2A544a6CI9njiSIKohIk0VmV/KdPoDLDhwjghQDjpS5iTowOMeoyZv B8AAGzAUEQPn2IfayacT7mao5yyVqyU0WErSnkkCwaV97Sa6VqhA9uZkdMYvMu4v4X svkkL07H5vj28rLknvt56VgrH4Q28xE0zXxzFsjnrbHBClmkLle+Ix7fPDjU0ORuSB qytl+HW/W9moGX9T9nV8KkNuFoaq4R0DxQ0phgm8YLtnBZDNqF/kXn2/cpJeVUWE9K LPhH/Jn5rbUPSCXBkFIdK9MGsZ/Yr9l728NrU8NvUDqQqIR75lxaT3Xng878MYsFul G7yFrr5oU5/Fw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4D56F68F61; Wed, 31 Dec 2025 15:31:40 -0700 (MST) 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 TIc1TTI0_zFr; Wed, 31 Dec 2025 15:31:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220295; bh=YGAZ+1mJJtgC3r6xCokqi8Wxn8H026ghdyl9G2jQtBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TCghiHyaxe0Od2OMyTg0nDxlOjoFyD8WlBg5OqkvrNcLJ47OyTmX6yRH3ITmsPn10 /AoFA1nfE3VwL7oqxYJSUE9H3CvxAzGPtlUgIdc1APDWgruiVETyg1k6tITNifnswW 68pPebbtUq7lbpbUC3m/Vhopt7ztsSbYQ9JN0Jdhz7teBGTEa4NZuXpZLLNVrLBpa0 oRRu7g/epenmU2iw9IzbZL5RhwH+15Swljj/0BfFM7LCrlsyxpfLEDZ1YR5oWg9LKz mKiLUOIF+coJ9fuGyp/E3m8VRqPfmfhiFtahtLVm6Y7tui8Nco1vS8OXRS+0CGsEOl Vl99dDTahKxqg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 871AD68FE3; Wed, 31 Dec 2025 15:31:35 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:50 -0700 Message-ID: <20251231223008.3251711-18-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KBVGAHTJI6IEVAJPCLEUAPUZRKCA7TTT X-Message-ID-Hash: KBVGAHTJI6IEVAJPCLEUAPUZRKCA7TTT 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 17/26] ext4l: Prevent freeing buffer_heads with active journal_heads 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 When running filesystem tests back-to-back, buffer_heads could be freed while journal_heads still reference them. This causes use-after-free crashes when the journal code later accesses the stale b_bh pointer. Add protection in free_buffer_head() to skip buffers with JBD attached, since the journal owns a reference and will clean them up properly. Also add protection in brelse() to prevent the ref count from dropping to zero while JBD is still attached. Update comments in ext4l_close_internal() to clarify why cache cleanup is critical even during skip_io mode. Fixes crashes when test_fs13 runs after test_fs11 in the same session. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/support.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index aaaf89092eb..3be40b6fca2 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -466,6 +466,15 @@ void free_buffer_head(struct buffer_head *bh) if (!bh) return; + /* + * Never free a buffer_head that has a journal_head attached. + * This would cause use-after-free when the journal tries to access it. + * The journal owns a reference and the buffer will be cleaned up when + * the journal_head is properly released. + */ + if (buffer_jbd(bh)) + return; + /* * Shadow buffers (b_private != NULL) share their folio with the * original buffer. Don't free the shared folio. From patchwork Wed Dec 31 22:29:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1156 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=1767220304; bh=NpdfDkEw/grtyabkYE9Auw2Tn13ZYbrM2ddRWdc6jEA=; 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=pFuKesDAlFI2AlbOSiUlwXe4CwFKuVEHO8FWZCWVL3zc55ncD6dhR56UcXOqCZbo/ C+jcyv4GjbDTDA3NIfkjdX8G0RjfFUI2+A5NLdv4DmLkq+DIQy4VouUyPvoES63p5b Hw2f8+tDQezTX4VGfFXfb4aiqNOjKeY8v0Eh+vj0yKrgg0AfSWpPzWaKX0ydjdFVWF iMTi+4BSupIP/1xYlkXrAS5A4+pKItSCG+fkO2790QKf9/+YgYVOwsYEe2O4wzG2xC /6vuf5nPXXti0V2y5h78D9fFgAtX08XL0509O11AMG5LJEsvCXcTTHSoc1YPhCaqv8 klkYkzeurTIcQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D760368FE9 for ; Wed, 31 Dec 2025 15:31:44 -0700 (MST) 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 ieugnH6GABZy for ; Wed, 31 Dec 2025 15:31:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220302; bh=NpdfDkEw/grtyabkYE9Auw2Tn13ZYbrM2ddRWdc6jEA=; 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=hM0ceN/0XN5fdJD896cVBRzqXP5cC2wpJ5w1RioSyvy9/P3EouRbHVrcERbBiYa7L IJVWHVvilKToIrVBgakVIYqgZgyOrepEwd1Fetbfqa1sM55HSxEf0Miu3i2Cx21syO wRTZYMWBBvl2IPhxIoz/gzShWhMkhb8RaV1HdRZYfCus2oJktmFyQNmdGh7CI0pos4 S063f3eIOgE4xuLOlmTy8zt39l1BD3prqynTMzc/+jdNFxMfhe7s1CQnJaP4xyMcEB AIW/Bq1H48UvATfMDJgZOMCsjyOxHFH3+4i4X+bW5HX3smJe8N3S7GjtXwPMQgTzO1 tPR8TjNWF8XaQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D1B1268FE3 for ; Wed, 31 Dec 2025 15:31:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220301; bh=1sJfDaF46I6M3in63PXT9NP5pQXeuX+aQqAoIv+w7W0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxmhxBilJ3b43znqXy2s8zE1/N1JmhuOeGrJXI4RpD+E95lNAzQKzW0ehuqiCHJp9 dvIEeoTyv9dEdkg04ckBMczf/GKfM7vKgRihFd0KpdGG9Fwl13ixXiv9KpA8c7tLUy 4HfEmWPsyqHqjYhGxxNFVTFyM069chf9NITK8UGrQV4c66jXkxZB8tFz/eep361zqo KYmAAJ8MV3/3oLcN3K/Te4Nf8sYgkWtdAtxT7CqaLEmDPKkupvgvYgsfanDe7fDaGU EgZJvc5/nyXCuiPc7lqCdeBDVNSL02ogSzLniwjx/FsSoka9WxaWAOOdBwpz8YoIGV 8HOWpvFkl57Iw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0BE5C68FCB; Wed, 31 Dec 2025 15:31:41 -0700 (MST) 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 UUM9G_rGy0xT; Wed, 31 Dec 2025 15:31:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220300; bh=9IkpGkEaYnzDYbZ2SLmiqa50hXyLmr/gU6u3WOQ5RTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NyYH7dnIo40NZ5iYAdgO3/MR+YE6FC+UUy0O/ujir5rdBP9pLBJH62P4sklpWmOqD DNbZf03VT7yBk2oL9BrstZynojxr+oWaka5XtqPXiw7hrBmO3TEkkg/hOc1RC+oR1q M19+pCmqN7RWqKIALNnfjng/u+ekUNcfydAsl3BpuO7r2/H/YPaWZ4dXiE1ZUljeDh 760sp9ODkrvBay02d9+mt8TH6IqzRvs83nWj5j1I6RhiyOMQBwW1gcAlCKMtglof5+ aJfZak8UQjUVXRwjXEWT21P+qjp6Ukm5GvsEb0znV7IJB/9Qd5X+PN8Y8EQ8dke7l+ XTtysgNADfMsQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 62DF468F65; Wed, 31 Dec 2025 15:31:40 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:51 -0700 Message-ID: <20251231223008.3251711-19-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: AEG6VDAEHJS7O4IMUKILSPGTDNJJDB2L X-Message-ID-Hash: AEG6VDAEHJS7O4IMUKILSPGTDNJJDB2L 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 18/26] ext4l: Add support for read-only devices 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 Some block devices, such as LUKS-encrypted volumes mounted via blkmap_crypt, only support read access. When ext4l attempts to write the superblock during mount, the write fails and causes mount to fail. Add a way to detect this read-only device detection: - Test writes during mount by writing back the superblock data; if the write fails, mark the device as read-only - Update bdev_read_only() to return the actual read_only status - Update sb_rdonly() to check the SB_RDONLY flag This allows ext4l to successfully mount read-only devices like LUKS volumes for read access. We could perhaps have a read-only flag in the block device, but that is left for another day. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 8 ++++---- fs/ext4l/interface.c | 14 ++++++++++++-- include/linux/fs.h | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 00419fe834e..da59956eee8 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -315,8 +315,8 @@ extern struct user_namespace init_user_ns; /* might_sleep - stub */ #define might_sleep() do { } while (0) -/* sb_rdonly - U-Boot mounts filesystems read-write */ -#define sb_rdonly(sb) 0 +/* sb_rdonly - check if filesystem is mounted read-only */ +#define sb_rdonly(sb) ((sb)->s_flags & SB_RDONLY) /* Trace stubs */ #define trace_ext4_journal_start_inode(...) do { } while (0) @@ -687,10 +687,10 @@ struct super_block { struct list_head s_inodes; }; -/* Block device read-only check - stub */ +/* Block device read-only check */ static inline int bdev_read_only(struct block_device *bdev) { - return 0; + return bdev ? bdev->read_only : 0; } /* kuid_t and kgid_t - from linux/cred.h */ diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 301e28af3b8..c60ea7db684 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -401,8 +401,6 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, goto err_free_buf; } - free(buf); - /* Save device info for later operations */ ext4l_dev_desc = fs_dev_desc; if (fs_partition) @@ -411,6 +409,18 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, /* Set block device for buffer I/O */ ext4l_set_blk_dev(fs_dev_desc, fs_partition); + /* + * Test if device supports writes by writing back the same data. + * If write returns 0, the device is read-only (e.g. LUKS/blkmap_crypt) + */ + if (blk_dwrite(fs_dev_desc, + (part_offset + BLOCK_SIZE) / fs_dev_desc->blksz, + 2, buf) != 2) { + sb->s_bdev->read_only = true; + sb->s_flags |= SB_RDONLY; + } + free(buf); + /* Mount the filesystem */ ret = ext4_fill_super(sb, fc); if (ret) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 0bf0d3b0379..54c0148ee72 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -76,6 +76,7 @@ struct block_device { void *bd_disk; struct super_block *bd_super; dev_t bd_dev; + bool read_only; }; /* errseq functions - stubs */ From patchwork Wed Dec 31 22:29:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1158 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=1767220312; bh=xKBfBeZBaZ4JgjtrO63EK7c/HsZU+x0FSs5yg8suDfE=; 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=W5sN587E4XG4DpbwK62UCFBI62ODIPUNIIXhACcKS4NzXpqmNZriEc1b7P+xfIgJ6 t5AHSCslb8L9fGc+/8dE5QudPzS2Ti0rrj7grUarTh9VtQ/7aaiGxsE2+Urgcf/QPu VqIvkqXWopLgIpcoIxBkRwuEtxMMBVvRtPhZS5agpCFfb0Nc1dG63zRgkDoWgrIyae g09nV5yiMC8n+h+mijwx76QgtlsssV1CbgCM2tP3rtJ53Trphna8IjzX8Kmh1YcorG in7oiCKrJv5LU02OwIXngNpOvquOf/0qttk0798Ubniit/AT9qzvv/UL3eW8m296h0 /HcbPsv3caBHg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E042868F51 for ; Wed, 31 Dec 2025 15:31:52 -0700 (MST) 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 4hJAlfIV9W4S for ; Wed, 31 Dec 2025 15:31:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220310; bh=xKBfBeZBaZ4JgjtrO63EK7c/HsZU+x0FSs5yg8suDfE=; 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=WOtye7ztVjkDAwXWjVMkSNnkjP2gIkPveopHymHq4LQxRBJ27A0TbNUk70HwIi13f q3TLUoYignNADJeHkcBf+cOUQd4hhINZSy/NHzOkEBiUtIDeWfU2gQgjs7BZw1HG97 SGEwnytkKM0mnrJQMk3YLitIMweGdMADiJV0YUdwvDe3oRjR+OOJs1yW50WpDcLRgQ ebHl1UPhSiG8YAra2+kvNyujdJmcc3qif6bHNIkrZGiLwlYHvglW4UJv7ZC0f89l+D S+hJ01Ew6duSUglHDhIWnPqvEJh7KK1wjxBygIffZguWI9lyOvgX/KuWPjjugifjPP qHW1r6DPS9OMw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DD3DA68FCB for ; Wed, 31 Dec 2025 15:31:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220307; bh=dQyzmmg/amSVcNt0D0Q8GuHVjo5rFV2fO+By+H47ePA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jtp46EQPdsPZQw4YqoQiLLZKZvpDJU2qalKwBt4/p/0IjmrUytqHymZpbCdCUMdhw MvaoSq9OBcs11jd5uZug619Sq4En/l5pPFftjieqLenM7Kq07g8eAqr1QkKZLAgyNa nxvWbi6ouHIODaIrh9jJvprQVpMwz7FJHVEGOIhSh+kT3pNB0+TXlS8CRXC3HmngDz sc+17P6ADGBkIwYimqPSjLQXu9PgYtOkewC4UvsoRiqYWHiN0XAOxXJe2CZSyIH6/L EwmSAGb2/+pl0L56WZc+AW6Ix3BHsTpqZeaFsMm8WX0+KbzqvBiTIBTqQzLJiYxENK CQVdN+iYiSs6w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3995768FCB; Wed, 31 Dec 2025 15:31:47 -0700 (MST) 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 Cfu-mxIvFoS3; Wed, 31 Dec 2025 15:31:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220301; bh=xtAIB4mBJQcAMsSg2BvcoHc0yJlVcSPNOm3xNb7Q2Y0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZEzP9xuJtRnAITpDdp4v/Vyd7YEYKl0OFbhO2gUnXlab39N43n6Z3Ka7JQDrwlJPF Z4XmQIxMd6/eeT9kSFYv+dmq1/eQhh8c75F8M2JXundkp7iTD7WSMR3eSe8Fhm4rC2 WKaMtMvlAMECnjzJHExiSKhQ/KZW8M5d0IET9wGlMqhpHlXdAnm/PxuyGnLMTMH/5m WkLxeUYx1kA7GEBoduFwS4Skjm47etgjIxSNk01DmnuOFRi4GYj4qQhyusXDn8o4zD kx7ZV8kIFSR10Ec9j/mpoDldZztDWDxZTakG0EX5BK0xqQiRjNnOiDO2ycZrt8rS7Y A5QlnenFls2kw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5111F68F65; Wed, 31 Dec 2025 15:31:41 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:52 -0700 Message-ID: <20251231223008.3251711-20-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: VJCOUW4F4RSIHRTSR4FHNESA4NVDF7JM X-Message-ID-Hash: VJCOUW4F4RSIHRTSR4FHNESA4NVDF7JM 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 19/26] ext4l: Add write support 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 the ability to write files to ext4 filesystems using the ext4l driver. This enables the 'save' command to work with ext4l. The implementation uses the jbd2 journal for crash safety: - ext4l_write() creates files if needed and writes data - Journal transactions commit synchronously for durability - Buffer cache syncs dirty buffers after write operations The write path consists of the following steps: 1. Lookup or create file via ext4_create() 2. Start journal transaction 3. For each block: get/allocate block, copy data, sync to disk 4. Update inode size and commit transaction 5. Sync all dirty buffers Add an ext4l_op_ptr() macro to select between a write operation and a fallback based on CONFIG_EXT4_WRITE, avoiding #ifdefs in fstypes[]. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 271 ++++++++++++++++++++++++++++ fs/fs_legacy.c | 2 +- include/ext4l.h | 23 +++ test/fs/ext4l.c | 42 +++++ test/py/tests/test_fs/test_ext4l.py | 5 + 5 files changed, 342 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index c60ea7db684..94bfd71bfb5 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -874,6 +874,277 @@ int ext4l_read(const char *filename, void *buf, loff_t offset, loff_t len, return 0; } +static int ext4l_write_file(struct inode *dir, const char *filename, void *buf, + loff_t offset, loff_t len, loff_t *actwrite) +{ + struct dentry *dir_dentry, *dentry, *result; + handle_t *handle = NULL; + struct buffer_head *bh; + struct inode *inode; + loff_t pos, end; + umode_t mode; + int ret; + + /* Create dentry for the parent directory */ + dir_dentry = kzalloc(sizeof(struct dentry), GFP_KERNEL); + if (!dir_dentry) + return -ENOMEM; + dir_dentry->d_inode = dir; + dir_dentry->d_sb = dir->i_sb; + + /* Create dentry for the filename */ + dentry = kzalloc(sizeof(struct dentry), GFP_KERNEL); + if (!dentry) { + kfree(dir_dentry); + return -ENOMEM; + } + + /* Initialize dentry (kzalloc already zeros memory) */ + dentry->d_name.name = filename; + dentry->d_name.len = strlen(filename); + dentry->d_sb = dir->i_sb; + dentry->d_parent = dir_dentry; + + /* Lookup file */ + result = ext4_lookup(dir, dentry, 0); + + if (IS_ERR(result)) { + ret = PTR_ERR(result); + goto out_dentry; + } + + if (result && result->d_inode) { + /* File exists - use the existing inode for overwrite */ + inode = result->d_inode; + if (result != dentry) { + /* Use the result dentry instead */ + kfree(dentry); + dentry = result; + } + } else { + /* ext4_lookup returned NULL or a dentry with NULL inode */ + if (result && result != dentry) { + /* Free the result dentry since it doesn't have an inode */ + kfree(result); + } + /* Keep using our original dentry */ + dentry->d_inode = NULL; + + /* File does not exist, create it */ + /* Mode: 0644 (rw-r--r--) | S_IFREG */ + mode = S_IFREG | 0644; + ret = ext4_create(&nop_mnt_idmap, dir, dentry, mode, true); + if (ret) + goto out_dentry; + + inode = dentry->d_inode; + } + if (!inode) { + ret = -EIO; + goto out_dentry; + } + + /* + * Attach jinode for journaling if needed (like ext4_file_open does). + * This is required for ordered data mode. + */ + ret = ext4_inode_attach_jinode(inode); + if (ret < 0) + goto out_dentry; + + /* + * Start a journal handle for the write operation. + * U-Boot uses a synchronous single-transaction model where + * ext4_journal_stop() commits immediately for crash safety. + */ + handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, + EXT4_DATA_TRANS_BLOCKS(inode->i_sb)); + if (IS_ERR(handle)) { + ret = PTR_ERR(handle); + handle = NULL; + goto out_dentry; + } + + /* Write data to file */ + pos = offset; + end = offset + len; + while (pos < end) { + ext4_lblk_t block = pos >> inode->i_blkbits; + uint block_offset = pos & (inode->i_sb->s_blocksize - 1); + uint bytes_to_write = inode->i_sb->s_blocksize - block_offset; + int needed_credits = EXT4_DATA_TRANS_BLOCKS(inode->i_sb); + + if (pos + bytes_to_write > end) + bytes_to_write = end - pos; + + /* + * Ensure we have enough journal credits for this block. + * Each block allocation can use up to EXT4_DATA_TRANS_BLOCKS + * credits. Try to extend, or restart the transaction if needed. + */ + ret = ext4_journal_ensure_credits(handle, needed_credits, 0); + if (ret < 0) + goto out_handle; + + bh = ext4_getblk(handle, inode, block, 0); + + if (IS_ERR(bh)) { + ret = PTR_ERR(bh); + goto out_handle; + } + if (!bh) { + /* Block doesn't exist, allocate it */ + bh = ext4_getblk(handle, inode, block, + EXT4_GET_BLOCKS_CREATE); + if (IS_ERR(bh)) { + ret = PTR_ERR(bh); + goto out_handle; + } + if (!bh) { + ret = -EIO; + goto out_handle; + } + } + + /* Get write access for journaling */ + ret = ext4_journal_get_write_access(handle, inode->i_sb, bh, + EXT4_JTR_NONE); + if (ret) { + brelse(bh); + goto out_handle; + } + + /* Copy data to buffer */ + memcpy(bh->b_data + block_offset, buf + (pos - offset), + bytes_to_write); + + /* + * In data=journal mode, file data goes through the journal. + * In data=ordered mode, write directly to disk. + */ + if (ext4_should_journal_data(inode)) { + /* data=journal: write through journal */ + ret = ext4_handle_dirty_metadata(handle, inode, bh); + if (ret) { + brelse(bh); + goto out_handle; + } + } else { + /* data=ordered: write directly to disk */ + mark_buffer_dirty(bh); + ret = sync_dirty_buffer(bh); + if (ret) { + brelse(bh); + goto out_handle; + } + } + + brelse(bh); + pos += bytes_to_write; + } + + /* Update inode size */ + if (end > inode->i_size) { + i_size_write(inode, end); + /* + * Also update i_disksize in ext4_inode_info - this is what gets + * written to disk via ext4_fill_raw_inode -> ext4_isize_set + */ + EXT4_I(inode)->i_disksize = end; + /* Mark inode dirty to update on disk */ + ext4_mark_inode_dirty(handle, inode); + } + + *actwrite = len; + ret = 0; + +out_handle: + /* Stop handle - this commits the transaction synchronously in U-Boot */ + if (handle) { + int stop_ret = ext4_journal_stop(handle); + + if (stop_ret) { + if (!ret) + ret = stop_ret; + } + } + +out_dentry: + /* + * Free our manually allocated dentries. In U-Boot's minimal dcache, + * these won't be cached elsewhere. + */ + kfree(dir_dentry); + kfree(dentry); + return ret; +} + +int ext4l_write(const char *filename, void *buf, loff_t offset, loff_t len, + loff_t *actwrite) +{ + struct inode *parent_inode = NULL; + char *parent_path = NULL; + const char *basename; + char *path_copy; + char *last_slash; + int ret; + + if (!ext4l_sb) + return -ENODEV; + + if (!filename || !buf || !actwrite) + return -EINVAL; + + /* Check if filesystem is mounted read-write */ + if (ext4l_sb->s_flags & SB_RDONLY) + return -EROFS; + + /* Parse filename to get parent directory and basename */ + path_copy = strdup(filename); + if (!path_copy) + return -ENOMEM; + + last_slash = strrchr(path_copy, '/'); + + if (last_slash) { + *last_slash = '\0'; + parent_path = path_copy; + basename = last_slash + 1; + if (*parent_path == '\0') /* Root directory */ + parent_path = "/"; + } else { + parent_path = "/"; + basename = filename; + } + + /* Resolve parent directory inode */ + ret = ext4l_resolve_path(parent_path, &parent_inode); + if (ret) { + free(path_copy); + return ret; + } + + if (!S_ISDIR(parent_inode->i_mode)) { + free(path_copy); + return -ENOTDIR; + } + + /* Call write implementation */ + ret = ext4l_write_file(parent_inode, basename, buf, offset, len, + actwrite); + + /* Sync all dirty buffers - U-Boot has no journal thread */ + if (!ret) { + int sync_ret = bh_cache_sync(); + + if (sync_ret) + ret = sync_ret; + } + + free(path_copy); + return ret; +} + void ext4l_close(void) { ext4l_close_internal(false); diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 155092519dd..66545834928 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -283,7 +283,7 @@ static struct fstype_info fstypes[] = { .exists = ext4l_exists, .size = ext4l_size, .read = ext4l_read, - .write = fs_write_unsupported, + .write = ext4l_op_ptr(ext4l_write, fs_write_unsupported), .uuid = ext4l_uuid, .opendir = ext4l_opendir, .readdir = ext4l_readdir, diff --git a/include/ext4l.h b/include/ext4l.h index 9cfe4867ffa..5dfb671690c 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -15,6 +15,13 @@ struct fs_dir_stream; struct fs_dirent; struct fs_statfs; +/* Select op when EXT4_WRITE is enabled, fallback otherwise */ +#if CONFIG_IS_ENABLED(EXT4_WRITE) +#define ext4l_op_ptr(op, fallback) op +#else +#define ext4l_op_ptr(op, fallback) fallback +#endif + /** * ext4l_probe() - Probe a block device for an ext4 filesystem * @@ -69,6 +76,22 @@ int ext4l_size(const char *filename, loff_t *sizep); int ext4l_read(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread); +/** + * ext4l_write() - Write data to a file + * + * Creates the file if it doesn't exist. Overwrites existing content. + * + * @filename: Path to file + * @buf: Buffer containing data to write + * @offset: Byte offset to start writing at + * @len: Number of bytes to write + * @actwrite: Returns actual bytes written + * Return: 0 on success, -EROFS if read-only, -ENODEV if not mounted, + * -ENOTDIR if parent is not a directory, negative on other errors + */ +int ext4l_write(const char *filename, void *buf, loff_t offset, loff_t len, + loff_t *actwrite); + /** * ext4l_get_uuid() - Get the filesystem UUID * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index 43801f252f7..82587a87894 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -396,3 +396,45 @@ static int fs_test_ext4l_statfs_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_statfs_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_write_norun() - Test ext4l_write function + * + * Verifies that ext4l can write file contents to the filesystem. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_write_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + const char *test_data = "test write data\n"; + size_t test_len = strlen(test_data); + loff_t actwrite, actread; + char read_buf[32]; + loff_t size; + + ut_assertnonnull(fs_image); + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY)); + + /* Write a new file */ + ut_assertok(ext4l_write("/newfile.txt", (void *)test_data, 0, + test_len, &actwrite)); + ut_asserteq(test_len, actwrite); + + /* Verify the file exists and has correct size */ + ut_asserteq(1, ext4l_exists("/newfile.txt")); + ut_assertok(ext4l_size("/newfile.txt", &size)); + ut_asserteq(test_len, size); + + /* Read back and verify contents */ + memset(read_buf, '\0', sizeof(read_buf)); + ut_assertok(ext4l_read("/newfile.txt", read_buf, 0, 0, &actread)); + ut_asserteq(test_len, actread); + ut_asserteq_str(test_data, read_buf); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_write_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }); diff --git a/test/py/tests/test_fs/test_ext4l.py b/test/py/tests/test_fs/test_ext4l.py index 25d09dca889..e953be379eb 100644 --- a/test/py/tests/test_fs/test_ext4l.py +++ b/test/py/tests/test_fs/test_ext4l.py @@ -118,3 +118,8 @@ class TestExt4l: """Test that fsinfo command displays filesystem statistics.""" with ubman.log.section('Test ext4l fsinfo'): ubman.run_ut('fs', 'fs_test_ext4l_fsinfo', fs_image=ext4_image) + + def test_write(self, ubman, ext4_image): + """Test that ext4l can write file contents.""" + with ubman.log.section('Test ext4l write'): + ubman.run_ut('fs', 'fs_test_ext4l_write', fs_image=ext4_image) From patchwork Wed Dec 31 22:29:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1157 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=1767220310; bh=gouPez5b5DiNLjRK4Fuo6HQeD3ufBJap9Bfst2zkxzk=; 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=w2rN3vEqj7bDsZjRWL2rE6RDDXk8S0hmdCI6lbL8HZMAn+X9/zICUwIcg4zBfkK6i 7jYzIIQXr4m4uzh9KW3iSnUAd90PIVRtkNC+AcGEhpgfZ5IFNiaBaymLadoirubXgO ka2SdWtYrsJHIr0+l6tZuGXnBU8qW3NG2PAhW//W38fwfFUdr8M4AiUVF6QLJ9hMu3 fIpwNg2nr2PQA/6LFFXqkaSxVMwEfo1jKyFBBm8K+EL61re0BFTh1H/UZp18YHt2Oe H1CE9XqbwYnTcT8sgQ4zEPI4VW8SzehRLFs0SW3mrr5VrUB6l7GSXpa5oXki9DxTAt gGx/ZiQ36BEGA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 72EEC68FD3 for ; Wed, 31 Dec 2025 15:31:50 -0700 (MST) 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 llzrheWj7DxI for ; Wed, 31 Dec 2025 15:31:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220310; bh=gouPez5b5DiNLjRK4Fuo6HQeD3ufBJap9Bfst2zkxzk=; 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=w2rN3vEqj7bDsZjRWL2rE6RDDXk8S0hmdCI6lbL8HZMAn+X9/zICUwIcg4zBfkK6i 7jYzIIQXr4m4uzh9KW3iSnUAd90PIVRtkNC+AcGEhpgfZ5IFNiaBaymLadoirubXgO ka2SdWtYrsJHIr0+l6tZuGXnBU8qW3NG2PAhW//W38fwfFUdr8M4AiUVF6QLJ9hMu3 fIpwNg2nr2PQA/6LFFXqkaSxVMwEfo1jKyFBBm8K+EL61re0BFTh1H/UZp18YHt2Oe H1CE9XqbwYnTcT8sgQ4zEPI4VW8SzehRLFs0SW3mrr5VrUB6l7GSXpa5oXki9DxTAt gGx/ZiQ36BEGA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6034A68F65 for ; Wed, 31 Dec 2025 15:31:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220307; bh=nRp9lQeab0p9Kxo1yMO0uoQUEE1iP3OpgSXyxLR4PLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nDNCLJYldyPkT5cechVM/BPBWIuDw6zvwY7RWJPkJK/WQGBrmfpj6BNIwFcHJTO+n O6oZFtOL9BVwZJSyox1g6YhSoGDCy2XDoAWmO0u0pHY+MX2ziIAIl/xOn4LGDPskPl oHBb0+NdSW27TVSjV55RnZMM0oiOaSZAr+GM0g/p6gJW6ws6oVnqsYJjmxMaJcR4S9 E6/IntUD+QNIaDn+PqzPtIYRLpdHFVOSq8D1BDLrglXqzeDYOfQ2GxifYv5V5IOK4p NyYJOsQ207dYadEXgYv0c7WhB+/BYHGMZC3ucGCq387awa+wEcWGn9oC5WY5yCC6yE ugOsCezTz5JSA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3A39468FD3; Wed, 31 Dec 2025 15:31:47 -0700 (MST) 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 pjPWctHii6VL; Wed, 31 Dec 2025 15:31:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220306; bh=YV2DH35rytbvVfNVsgq6nWfbS7MRGg4aa/xbhIlGBwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hLilyOdN8LGs4jq2XOGELlDOgAUqpTvi2/hAdHGxMv0nHonUK3u+YHw+GHXTFaRtf GQqV2vvfVmNC9su10E8netndh3URdjoFXN6yPoolP+xDuhZV/f8MUWeVaUc2oas1F0 VlKonqBdDs1C/2KO1z4gDoMbKhKdd0P/9gqFaq3rPZKWUbgqWhSFRKRVFQrYMvAPHk imaKKFVFm2p7nn8Uy3ZbBhESRfJSjeVs7dSI9oWkWFPNHuxy6F9vP3AQbTaa5TQVav nDininf1F/zprgiLn/gDi50QIPj5g15+ns4b5JZAdNP/nhSuthxYfGBY3pcUDy33iL 9mzgMtG3Bbv+Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 24FA568F61; Wed, 31 Dec 2025 15:31:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:53 -0700 Message-ID: <20251231223008.3251711-21-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: EFU5HGULMTTWH7YO3JS2RI3ORA4AMHLT X-Message-ID-Hash: EFU5HGULMTTWH7YO3JS2RI3ORA4AMHLT 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 20/26] ext4l: Add unlink support for file deletion 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 Implement ext4l_unlink() to delete files from ext4 filesystems. This enables the 'rm' command to work with ext4l. The implementation: - Resolves the parent directory and target file - Verifies the target is not a directory (use rmdir for that) - Calls ext4_unlink() to remove the directory entry - Uses journal transactions for crash safety Add ext4l_op_ptr() macro to select between ext4l_unlink() and the fallback based on CONFIG_EXT4_WRITE Call ext4_commit_super() to ensure the changes are written to disk. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 251 +++++++++++++++++----------- fs/fs_legacy.c | 2 +- include/ext4l.h | 9 + test/fs/ext4l.c | 41 +++++ test/py/tests/test_fs/test_ext4l.py | 5 + 5 files changed, 212 insertions(+), 96 deletions(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 94bfd71bfb5..442617a0d3e 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -874,75 +874,131 @@ int ext4l_read(const char *filename, void *buf, loff_t offset, loff_t len, return 0; } -static int ext4l_write_file(struct inode *dir, const char *filename, void *buf, - loff_t offset, loff_t len, loff_t *actwrite) +/** + * ext4l_resolve_file() - Resolve a file path for write operations + * @path: Path to process + * @dir_dentryp: Returns parent directory dentry (caller must kfree) + * @dentryp: Returns file dentry after lookup (caller must kfree) + * @path_copyp: Returns path copy (caller must free) + * + * Common setup for write operations. Validates inputs, checks read-write + * mount, parses path, resolves parent directory, creates dentries, and + * performs lookup. + * + * Return: 0 on success, negative on error + */ +static int ext4l_resolve_file(const char *path, struct dentry **dir_dentryp, + struct dentry **dentryp, char **path_copyp) { + char *path_copy, *dir_path, *last_slash; struct dentry *dir_dentry, *dentry, *result; - handle_t *handle = NULL; - struct buffer_head *bh; - struct inode *inode; - loff_t pos, end; - umode_t mode; + struct inode *dir_inode; + const char *basename; int ret; - /* Create dentry for the parent directory */ + if (!ext4l_sb) + return -ENODEV; + + if (!path) + return -EINVAL; + + /* Check if filesystem is mounted read-write */ + if (ext4l_sb->s_flags & SB_RDONLY) + return -EROFS; + + /* Parse path to get parent directory and basename */ + path_copy = strdup(path); + if (!path_copy) + return -ENOMEM; + + last_slash = strrchr(path_copy, '/'); + if (last_slash) { + *last_slash = '\0'; + dir_path = path_copy; + basename = last_slash + 1; + if (*dir_path == '\0') + dir_path = "/"; + } else { + dir_path = "/"; + basename = path; + } + + /* Resolve parent directory */ + ret = ext4l_resolve_path(dir_path, &dir_inode); + if (ret) { + free(path_copy); + return ret; + } + + if (!S_ISDIR(dir_inode->i_mode)) { + free(path_copy); + return -ENOTDIR; + } + + /* Create dentry for parent directory */ dir_dentry = kzalloc(sizeof(struct dentry), GFP_KERNEL); - if (!dir_dentry) + if (!dir_dentry) { + free(path_copy); return -ENOMEM; - dir_dentry->d_inode = dir; - dir_dentry->d_sb = dir->i_sb; + } + dir_dentry->d_inode = dir_inode; + dir_dentry->d_sb = dir_inode->i_sb; - /* Create dentry for the filename */ + /* Create dentry for the file */ dentry = kzalloc(sizeof(struct dentry), GFP_KERNEL); if (!dentry) { kfree(dir_dentry); + free(path_copy); return -ENOMEM; } - - /* Initialize dentry (kzalloc already zeros memory) */ - dentry->d_name.name = filename; - dentry->d_name.len = strlen(filename); - dentry->d_sb = dir->i_sb; + dentry->d_name.name = basename; + dentry->d_name.len = strlen(basename); + dentry->d_sb = dir_inode->i_sb; dentry->d_parent = dir_dentry; - /* Lookup file */ - result = ext4_lookup(dir, dentry, 0); - + /* Look up the file */ + result = ext4_lookup(dir_inode, dentry, 0); if (IS_ERR(result)) { - ret = PTR_ERR(result); - goto out_dentry; + kfree(dentry); + kfree(dir_dentry); + free(path_copy); + return PTR_ERR(result); } - if (result && result->d_inode) { + *dir_dentryp = dir_dentry; + *dentryp = dentry; + *path_copyp = path_copy; + + return 0; +} + +static int ext4l_write_file(struct dentry *dir_dentry, struct dentry *dentry, + void *buf, loff_t offset, loff_t len, + loff_t *actwrite) +{ + struct inode *dir = dir_dentry->d_inode; + handle_t *handle = NULL; + struct buffer_head *bh; + struct inode *inode; + loff_t pos, end; + umode_t mode; + int ret; + + if (dentry->d_inode) { /* File exists - use the existing inode for overwrite */ - inode = result->d_inode; - if (result != dentry) { - /* Use the result dentry instead */ - kfree(dentry); - dentry = result; - } + inode = dentry->d_inode; } else { - /* ext4_lookup returned NULL or a dentry with NULL inode */ - if (result && result != dentry) { - /* Free the result dentry since it doesn't have an inode */ - kfree(result); - } - /* Keep using our original dentry */ - dentry->d_inode = NULL; - /* File does not exist, create it */ /* Mode: 0644 (rw-r--r--) | S_IFREG */ mode = S_IFREG | 0644; ret = ext4_create(&nop_mnt_idmap, dir, dentry, mode, true); if (ret) - goto out_dentry; + return ret; inode = dentry->d_inode; } - if (!inode) { - ret = -EIO; - goto out_dentry; - } + if (!inode) + return -EIO; /* * Attach jinode for journaling if needed (like ext4_file_open does). @@ -950,7 +1006,7 @@ static int ext4l_write_file(struct inode *dir, const char *filename, void *buf, */ ret = ext4_inode_attach_jinode(inode); if (ret < 0) - goto out_dentry; + return ret; /* * Start a journal handle for the write operation. @@ -959,11 +1015,8 @@ static int ext4l_write_file(struct inode *dir, const char *filename, void *buf, */ handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, EXT4_DATA_TRANS_BLOCKS(inode->i_sb)); - if (IS_ERR(handle)) { - ret = PTR_ERR(handle); - handle = NULL; - goto out_dentry; - } + if (IS_ERR(handle)) + return PTR_ERR(handle); /* Write data to file */ pos = offset; @@ -1063,84 +1116,92 @@ out_handle: if (handle) { int stop_ret = ext4_journal_stop(handle); - if (stop_ret) { - if (!ret) - ret = stop_ret; - } + if (stop_ret && !ret) + ret = stop_ret; } -out_dentry: - /* - * Free our manually allocated dentries. In U-Boot's minimal dcache, - * these won't be cached elsewhere. - */ - kfree(dir_dentry); - kfree(dentry); return ret; } int ext4l_write(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actwrite) { - struct inode *parent_inode = NULL; - char *parent_path = NULL; - const char *basename; + struct dentry *dir_dentry, *dentry; char *path_copy; - char *last_slash; int ret; - if (!ext4l_sb) - return -ENODEV; - - if (!filename || !buf || !actwrite) + if (!buf || !actwrite) return -EINVAL; - /* Check if filesystem is mounted read-write */ - if (ext4l_sb->s_flags & SB_RDONLY) - return -EROFS; + ret = ext4l_resolve_file(filename, &dir_dentry, &dentry, &path_copy); + if (ret) + return ret; - /* Parse filename to get parent directory and basename */ - path_copy = strdup(filename); - if (!path_copy) - return -ENOMEM; + /* Call write implementation */ + ret = ext4l_write_file(dir_dentry, dentry, buf, offset, len, actwrite); - last_slash = strrchr(path_copy, '/'); + /* Sync all dirty buffers - U-Boot has no journal thread */ + if (!ret) { + int sync_ret = bh_cache_sync(); - if (last_slash) { - *last_slash = '\0'; - parent_path = path_copy; - basename = last_slash + 1; - if (*parent_path == '\0') /* Root directory */ - parent_path = "/"; - } else { - parent_path = "/"; - basename = filename; + if (sync_ret) + ret = sync_ret; } - /* Resolve parent directory inode */ - ret = ext4l_resolve_path(parent_path, &parent_inode); - if (ret) { - free(path_copy); + kfree(dentry); + kfree(dir_dentry); + free(path_copy); + return ret; +} + +int ext4l_unlink(const char *filename) +{ + struct dentry *dentry, *dir_dentry; + char *path_copy; + int ret; + + ret = ext4l_resolve_file(filename, &dir_dentry, &dentry, &path_copy); + if (ret) return ret; + + /* Check if file exists */ + if (!dentry->d_inode) { + ret = -ENOENT; + goto out; } - if (!S_ISDIR(parent_inode->i_mode)) { - free(path_copy); - return -ENOTDIR; + /* Cannot unlink directories with unlink - use rmdir */ + if (S_ISDIR(dentry->d_inode->i_mode)) { + ret = -EISDIR; + goto out; } - /* Call write implementation */ - ret = ext4l_write_file(parent_inode, basename, buf, offset, len, - actwrite); + /* Unlink the file */ + ret = __ext4_unlink(dir_dentry->d_inode, &dentry->d_name, + dentry->d_inode, dentry); - /* Sync all dirty buffers - U-Boot has no journal thread */ + /* + * Release inode - this triggers ext4_evict_inode for nlink=0 inodes, + * which frees the data blocks and inode. + */ + if (dentry->d_inode) { + iput(dentry->d_inode); + dentry->d_inode = NULL; + } + + /* Sync all dirty buffers after inode eviction */ if (!ret) { int sync_ret = bh_cache_sync(); if (sync_ret) ret = sync_ret; + /* Commit superblock with updated free counts */ + ext4_commit_super(ext4l_sb); } +out: + kfree(dentry); + kfree(dir_dentry); free(path_copy); return ret; } diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 66545834928..1eb79b338ee 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -288,7 +288,7 @@ static struct fstype_info fstypes[] = { .opendir = ext4l_opendir, .readdir = ext4l_readdir, .closedir = ext4l_closedir, - .unlink = fs_unlink_unsupported, + .unlink = ext4l_op_ptr(ext4l_unlink, fs_unlink_unsupported), .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, diff --git a/include/ext4l.h b/include/ext4l.h index 5dfb671690c..abcf17f99ad 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -92,6 +92,15 @@ int ext4l_read(const char *filename, void *buf, loff_t offset, loff_t len, int ext4l_write(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actwrite); +/** + * ext4l_unlink() - Delete a file + * + * @filename: Path to file to delete + * Return: 0 on success, -ENOENT if file not found, -EISDIR if path is a + * directory, -EROFS if read-only, negative on other errors + */ +int ext4l_unlink(const char *filename); + /** * ext4l_get_uuid() - Get the filesystem UUID * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index 82587a87894..dec6e3340bb 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -438,3 +438,44 @@ static int fs_test_ext4l_write_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_write_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_unlink_norun() - Test ext4l_unlink function + * + * Verifies that ext4l can delete files from the filesystem. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_unlink_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + const char *test_data = "unlink test\n"; + size_t test_len = strlen(test_data); + loff_t actwrite; + + ut_assertnonnull(fs_image); + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY)); + + /* Create a new file to unlink */ + ut_assertok(ext4l_write("/unlinkme.txt", (void *)test_data, 0, + test_len, &actwrite)); + ut_asserteq(test_len, actwrite); + + /* Verify file exists (same mount) */ + ut_asserteq(1, ext4l_exists("/unlinkme.txt")); + + /* Unlink the file */ + ut_assertok(ext4l_unlink("/unlinkme.txt")); + + /* Verify file no longer exists */ + ut_asserteq(0, ext4l_exists("/unlinkme.txt")); + + /* Verify unlinking non-existent file returns -ENOENT */ + ut_asserteq(-ENOENT, ext4l_unlink("/nonexistent")); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_unlink_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }); diff --git a/test/py/tests/test_fs/test_ext4l.py b/test/py/tests/test_fs/test_ext4l.py index e953be379eb..edea38f7faf 100644 --- a/test/py/tests/test_fs/test_ext4l.py +++ b/test/py/tests/test_fs/test_ext4l.py @@ -123,3 +123,8 @@ class TestExt4l: """Test that ext4l can write file contents.""" with ubman.log.section('Test ext4l write'): ubman.run_ut('fs', 'fs_test_ext4l_write', fs_image=ext4_image) + + def test_unlink(self, ubman, ext4_image): + """Test that ext4l can delete files.""" + with ubman.log.section('Test ext4l unlink'): + ubman.run_ut('fs', 'fs_test_ext4l_unlink', fs_image=ext4_image) From patchwork Wed Dec 31 22:29:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1159 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=1767220317; bh=tPj6GYNalcyFdTl7J4vvbShtZ9XvV+NI2pcUnk/NF04=; 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=Tn5IZBoi9R2JnBa6em4UWrQ+PkFshSBEbXCL0sN1r2Eg6GyKp7uIGuKPZZ6aWIsTo 2xY/TuKpUCvr83t29tmpe3LOb61JVQGAONhmbb1WVdyCCdcQSLYjvlsL6mGZ/lEHHW dX3D2jlfkHJH+fZywNyEDDE1KGef1JED+0Idg6rONChNgdIa5OoK+uYI+WE7EY0PQr GxCFsoKnwjIJcQy5ip7HOvZCc3sDqcwMuIrNu0jG28VPboF0qBCQhaUy/dOrN/dnJJ 02kKpelNJqzBII3KShPeATEl4fY4SW5hcaWdqqtsJKmXEIEbCwq1+cYUnnxjMDYsVV Csufiuhab6Uzw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6506D68FCB for ; Wed, 31 Dec 2025 15:31:57 -0700 (MST) 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 w-I6IQyQxLGp for ; Wed, 31 Dec 2025 15:31:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220317; bh=tPj6GYNalcyFdTl7J4vvbShtZ9XvV+NI2pcUnk/NF04=; 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=Tn5IZBoi9R2JnBa6em4UWrQ+PkFshSBEbXCL0sN1r2Eg6GyKp7uIGuKPZZ6aWIsTo 2xY/TuKpUCvr83t29tmpe3LOb61JVQGAONhmbb1WVdyCCdcQSLYjvlsL6mGZ/lEHHW dX3D2jlfkHJH+fZywNyEDDE1KGef1JED+0Idg6rONChNgdIa5OoK+uYI+WE7EY0PQr GxCFsoKnwjIJcQy5ip7HOvZCc3sDqcwMuIrNu0jG28VPboF0qBCQhaUy/dOrN/dnJJ 02kKpelNJqzBII3KShPeATEl4fY4SW5hcaWdqqtsJKmXEIEbCwq1+cYUnnxjMDYsVV Csufiuhab6Uzw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 53EC068F61 for ; Wed, 31 Dec 2025 15:31:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220315; bh=6X4eUpNK1yNzpzw6QIntoNRI64nY1e1AWk96HTR1qaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ecyKcH0BnVux0YF96hN1cxF3DYRZHDGLFpLKldJqxW5wMo1fK3bINPUDL153Q4JSF fDnuttpkSq5aQdUxVkQkn8e10uhERKAQoF03g/EqWtbALygUm8KE0JdJY0y8FoHc/Z M22pMaseCJ0Vqns6PsxwrHhhUaMxvNTW82hym+PjHPV50G7g9g4j9HNMUKGjqMlV9Q nLDu+i0KPNPMMdtlplP1tR0p1yLIYaSZx38ulcitd142D0cj8tEv6K7IZE82bso6xK JIohZo+mz7Wf+6MT3OsKE/mPpDaqR5xfhX5YP9RkUuU/lvyHApBgkASWAJzKoea6oC RPTdTHrdVPzaw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3B00768F51; Wed, 31 Dec 2025 15:31:55 -0700 (MST) 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 BSLDf-cZ21Jl; Wed, 31 Dec 2025 15:31:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220307; bh=7hFp/OfEvULsA5cG4yRUfr5qVFcH0LkJHYIYcuXqEeI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u8ZdZ4afWPK+YNLZWSP/dWKG6PEv5mSbqBht74Eq8p7nGLHnTUUhReyw03kbez6H3 tEB99Y63hvZvGxYdjMHWYMpsBDWvq8+OqEx7f9HZ6w5gWbvWAenvAHr/5afP4sYFhx zochJBqIecIJTTkfxz4k8OOdPEnWDXTQZGDAURCNakb/UR9F2eyTd7BJdmfgf/4yl6 XGBkh6KE9aYP7yiC6npkp/1MAAvdV5DSJXmEi3RQCa0nvqxSZxti/4A7vjs1aKqSOk SxQLeNswkuvRXrVUgxOzq/7CMSD9pmZsR6rLDcqoVBm15mTK91GeopQMxiAu1FOSoS MEBT5v+PN1GVQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5D49468F61; Wed, 31 Dec 2025 15:31:47 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:54 -0700 Message-ID: <20251231223008.3251711-22-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: K7OFRXHS6VLOR25TLOJEKJAX3ASR4LHI X-Message-ID-Hash: K7OFRXHS6VLOR25TLOJEKJAX3ASR4LHI 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 21/26] ext4l: Add mkdir support for directory creation 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 Implement ext4l_mkdir() to create directories on ext4 filesystems. The function parses the path to extract the parent directory and basename, resolves the parent inode, checks for existing entries, and calls the Linux ext4_mkdir() function to create the directory. Hook ext4l_mkdir into the filesystem layer via the .mkdir callback in fs_legacy.c, enabling the standard 'mkdir' command to work with ext4l filesystems. Add a unit test that verifies directory creation, duplicate detection (-EEXIST), nested directory creation, and error handling for non-existent parent directories (-ENOENT). Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 43 ++++++++++++++++++++++++++++++++++++++++ fs/fs_legacy.c | 2 +- include/ext4l.h | 10 ++++++++++ test/fs/ext4l.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 442617a0d3e..010db3a3631 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -1206,6 +1206,49 @@ out: return ret; } +int ext4l_mkdir(const char *dirname) +{ + struct dentry *dentry, *dir_dentry, *result; + char *path_copy; + int ret; + + ret = ext4l_resolve_file(dirname, &dir_dentry, &dentry, &path_copy); + if (ret) + return ret; + + if (dentry->d_inode) { + /* Directory already exists */ + ret = -EEXIST; + goto out; + } + + /* Create the directory with mode 0755 (rwxr-xr-x) */ + result = ext4_mkdir(&nop_mnt_idmap, dir_dentry->d_inode, dentry, + S_IFDIR | 0755); + if (IS_ERR(result)) { + ret = PTR_ERR(result); + goto out; + } + + ret = 0; + + /* Sync all dirty buffers */ + { + int sync_ret = bh_cache_sync(); + + if (sync_ret) + ret = sync_ret; + /* Commit superblock with updated free counts */ + ext4_commit_super(ext4l_sb); + } + +out: + kfree(dentry); + kfree(dir_dentry); + free(path_copy); + return ret; +} + void ext4l_close(void) { ext4l_close_internal(false); diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 1eb79b338ee..b53d420f279 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -289,7 +289,7 @@ static struct fstype_info fstypes[] = { .readdir = ext4l_readdir, .closedir = ext4l_closedir, .unlink = ext4l_op_ptr(ext4l_unlink, fs_unlink_unsupported), - .mkdir = fs_mkdir_unsupported, + .mkdir = ext4l_op_ptr(ext4l_mkdir, fs_mkdir_unsupported), .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, .statfs = ext4l_statfs, diff --git a/include/ext4l.h b/include/ext4l.h index abcf17f99ad..1a12ba1ac1c 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -101,6 +101,16 @@ int ext4l_write(const char *filename, void *buf, loff_t offset, loff_t len, */ int ext4l_unlink(const char *filename); +/** + * ext4l_mkdir() - Create a directory + * + * @dirname: Path of directory to create + * Return: 0 on success, -EEXIST if directory already exists, + * -ENOTDIR if parent is not a directory, -EROFS if read-only, + * negative on other errors + */ +int ext4l_mkdir(const char *dirname); + /** * ext4l_get_uuid() - Get the filesystem UUID * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index dec6e3340bb..5930e4234ba 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -479,3 +479,50 @@ static int fs_test_ext4l_unlink_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_unlink_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_mkdir_norun() - Test ext4l_mkdir function + * + * Verifies that ext4l can create directories on the filesystem. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_mkdir_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + static int test_counter; + char dir_name[32]; + char subdir_name[64]; + int ret; + + ut_assertnonnull(fs_image); + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY)); + + /* Use unique directory names to avoid issues with test re-runs */ + snprintf(dir_name, sizeof(dir_name), "/testdir%d", test_counter); + snprintf(subdir_name, sizeof(subdir_name), "%s/subdir", dir_name); + test_counter++; + + /* Create a new directory */ + ret = ext4l_mkdir(dir_name); + ut_assertok(ret); + + /* Verify directory exists */ + ut_asserteq(1, ext4l_exists(dir_name)); + + /* Verify creating duplicate returns -EEXIST */ + ut_asserteq(-EEXIST, ext4l_mkdir(dir_name)); + + /* Create nested directory */ + ut_assertok(ext4l_mkdir(subdir_name)); + ut_asserteq(1, ext4l_exists(subdir_name)); + + /* Verify creating directory in non-existent parent returns -ENOENT */ + ut_asserteq(-ENOENT, ext4l_mkdir("/nonexistent/dir")); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_mkdir_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }); From patchwork Wed Dec 31 22:29:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1160 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=1767220328; bh=Og4kyMgeE+lh4MRyjoxcE+6L0FluqrRkXNqohe+BC44=; 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=EIzd1CQ2iNc6qAbKmCDL+WMBReJz9glECJafPYHdlmTftIxb2h7JsqKFi0tGGNxAf E5SSfr4UwPvltlr0BhoI9ZNgmd42oh4VdAYJ3q+YldOEY2sOFvenmxc158FJ/ooC5Z CY9fpP/n61ybuGSQKln+Au5oGIzecFyxax/E+6/rJmnXczghNT4opcVCloUjPX1/TW rlZ9qCyv3J7M5leFhWmcH322f5Hs7pkC7rnAHaHy88kAAyAMf0G2rhn9TojxQve2bh j2CHJmj8Nbaf7JBZyuS285Ir3RAnRy6boJYXpQHR2w3E8F8r145I3JDVEHfl5Eu3/Z 8oawGERRvbG0w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2043168FE5 for ; Wed, 31 Dec 2025 15:32:08 -0700 (MST) 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 k2qLW8n8PiQr for ; Wed, 31 Dec 2025 15:32:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220328; bh=Og4kyMgeE+lh4MRyjoxcE+6L0FluqrRkXNqohe+BC44=; 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=EIzd1CQ2iNc6qAbKmCDL+WMBReJz9glECJafPYHdlmTftIxb2h7JsqKFi0tGGNxAf E5SSfr4UwPvltlr0BhoI9ZNgmd42oh4VdAYJ3q+YldOEY2sOFvenmxc158FJ/ooC5Z CY9fpP/n61ybuGSQKln+Au5oGIzecFyxax/E+6/rJmnXczghNT4opcVCloUjPX1/TW rlZ9qCyv3J7M5leFhWmcH322f5Hs7pkC7rnAHaHy88kAAyAMf0G2rhn9TojxQve2bh j2CHJmj8Nbaf7JBZyuS285Ir3RAnRy6boJYXpQHR2w3E8F8r145I3JDVEHfl5Eu3/Z 8oawGERRvbG0w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0E70C68FD3 for ; Wed, 31 Dec 2025 15:32:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220326; bh=75uxdP2Rl9IrkgXz+DrzTa4xk3X45LN0IhItGUUt9Ig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cGQl7rZr99zJZW+YeZhh4MqgX+KhmD80AuC1JJcwxcmqLh+LywucRYlYU3LEhQsMw WtxIf7f5RduP/nRAyfBDnY9M6lnsVyyFFJVmcmH8tqUbn66H3CgKpoUedQeJT8MW1k j1Pzd7ozscVecA1Ao9G0Wsiq3pI8Fe8M5RNW5UFlx7EeKBRo9mkbpfIHvypsqae6E8 n0uRBTU5B0nrvCHMLO0TgWgO6GC0yCiIRsv60crYQcBzzgt+3slKdYKYOU3ozMYuWA bt5FD0FvtauQ7Ql7kRKDhIIcSca5Q3PjnUv/uq/EikgEzAOYqh7+IWZesyEvgY7Zn7 B9cu15ZE0XPbw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7D76F68F51; Wed, 31 Dec 2025 15:32:06 -0700 (MST) 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 2uMez-7xl0Cl; Wed, 31 Dec 2025 15:32:06 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220322; bh=rXnEHhaMRR9RYKs1HTBp+zEx61herdUEhk75aPEBWkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IamIVPdJI8FHAuR7FnLrET/saa84BMNq+XW2zp6bA1SjrrxmfjwIiOGFOd+kOSDR4 TxUO7XWkozN/5YRiS1ZH1NN+x71PzM9+vi4rgbRY1HmqEydza+SKfraKtFn5/fuBuK rMjRhimG0EwC/Q9WrCroGNCdfggy1nqGvZdEKXqtyMflrcvPLwnZYxvQpFu42v3OB0 2ce29GBortt4b+ToEHBxzKin5rV9yuMm9FPebve925iK7CV+/VCTSknyDF44/cN0Ey Ah4k/EHE7Ke8+0aKjInALED5eYsZRqE7g2pfTyaTZBTI9XUYloB4lNID216P9nOnyY SMONPIO/18zFA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5C10A68FD3; Wed, 31 Dec 2025 15:31:52 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:55 -0700 Message-ID: <20251231223008.3251711-23-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: UXC2TVQJBYVBBQKZMMLMVJ7C4YX36ISF X-Message-ID-Hash: UXC2TVQJBYVBBQKZMMLMVJ7C4YX36ISF 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 22/26] ext4l: Add symlink support 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 ext4l_ln() to create symbolic links. This uses the Linux ext4_symlink() function which supports both fast symlinks (stored in inode) and regular symlinks (stored in data blocks). Fix the fscrypt_prepare_symlink() stub to properly init the disk_link structure with the symlink target, which is required for symlink creation to work correctly. Add some notes about U-Boot's argument ordering with symlinks. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 2 +- fs/ext4l/interface.c | 48 ++++++++++++++++++++++++++++++++++ fs/fs_legacy.c | 2 +- include/ext4l.h | 11 ++++++++ test/fs/ext4l.c | 60 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index da59956eee8..5ea573fcfb8 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -1579,7 +1579,7 @@ static inline char *d_path(const struct path *path, char *buf, int buflen) #define fscrypt_dio_supported(i) (1) #define fscrypt_has_permitted_context(p, c) ({ (void)(p); (void)(c); 1; }) #define fscrypt_is_nokey_name(d) ({ (void)(d); 0; }) -#define fscrypt_prepare_symlink(d, s, l, m, dl) ({ (void)(d); (void)(s); (void)(l); (void)(m); (void)(dl); 0; }) +#define fscrypt_prepare_symlink(d, s, l, m, dl) ({ (void)(d); (void)(m); (dl)->name = (unsigned char *)(s); (dl)->len = (l) + 1; 0; }) #define fscrypt_encrypt_symlink(i, s, l, d) ({ (void)(i); (void)(s); (void)(l); (void)(d); 0; }) #define fscrypt_prepare_link(o, d, n) ({ (void)(o); (void)(d); (void)(n); 0; }) #define fscrypt_prepare_rename(od, ode, nd, nde, f) ({ (void)(od); (void)(ode); (void)(nd); (void)(nde); (void)(f); 0; }) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 010db3a3631..c9dd25dd7b4 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -1249,6 +1249,54 @@ out: return ret; } +int ext4l_ln(const char *filename, const char *linkname) +{ + struct dentry *dentry, *dir_dentry; + char *path_copy; + int ret; + + /* + * Note: The parameter naming follows U-Boot's convention: + * - filename: the target file the link should point to + * - linkname: the path of the symlink to create + */ + if (!filename) + return -EINVAL; + + ret = ext4l_resolve_file(linkname, &dir_dentry, &dentry, &path_copy); + if (ret) + return ret; + + if (dentry->d_inode) { + /* File already exists */ + ret = -EEXIST; + goto out; + } + + /* Create the symlink - filename is what the link points to */ + ret = ext4_symlink(&nop_mnt_idmap, dir_dentry->d_inode, dentry, + filename); + if (ret) + goto out; + + /* Sync all dirty buffers */ + { + int sync_ret = bh_cache_sync(); + + if (sync_ret) + ret = sync_ret; + /* Commit superblock with updated free counts */ + ext4_commit_super(ext4l_sb); + } + +out: + kfree(dentry); + kfree(dir_dentry); + free(path_copy); + + return ret; +} + void ext4l_close(void) { ext4l_close_internal(false); diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index b53d420f279..a325c2631d4 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -290,7 +290,7 @@ static struct fstype_info fstypes[] = { .closedir = ext4l_closedir, .unlink = ext4l_op_ptr(ext4l_unlink, fs_unlink_unsupported), .mkdir = ext4l_op_ptr(ext4l_mkdir, fs_mkdir_unsupported), - .ln = fs_ln_unsupported, + .ln = ext4l_op_ptr(ext4l_ln, fs_ln_unsupported), .rename = fs_rename_unsupported, .statfs = ext4l_statfs, }, diff --git a/include/ext4l.h b/include/ext4l.h index 1a12ba1ac1c..d0e420c8da2 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -111,6 +111,17 @@ int ext4l_unlink(const char *filename); */ int ext4l_mkdir(const char *dirname); +/** + * ext4l_ln() - Create a symbolic link + * + * @filename: Path of symlink to create + * @target: Target path the symlink points to + * Return: 0 on success, -EEXIST if file already exists, + * -ENOTDIR if parent is not a directory, -EROFS if read-only, + * negative on other errors + */ +int ext4l_ln(const char *filename, const char *target); + /** * ext4l_get_uuid() - Get the filesystem UUID * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index 5930e4234ba..1d46a752f32 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -526,3 +526,63 @@ static int fs_test_ext4l_mkdir_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_mkdir_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_ln_norun() - Test ext4l_ln function + * + * Verifies that ext4l can create symbolic links on the filesystem. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_ln_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + static int test_counter; + char link_name[32]; + const char *target = "/testfile.txt"; + loff_t size; + loff_t actread; + char buf[32]; + + ut_assertnonnull(fs_image); + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY)); + + /* Use unique symlink names to avoid issues with test re-runs */ + snprintf(link_name, sizeof(link_name), "/testlink%d", test_counter); + test_counter++; + + /* + * Create a symbolic link. ext4l_ln follows U-Boot's ln command + * convention: ext4l_ln(target, linkname) creates linkname pointing + * to target. + */ + ut_assertok(ext4l_ln(target, link_name)); + + /* Verify symlink exists */ + ut_asserteq(1, ext4l_exists(link_name)); + + /* + * Size through symlink should be target file's size (12 bytes), + * since ext4l_resolve_path follows symlinks (like stat, not lstat) + */ + ut_assertok(ext4l_size(link_name, &size)); + ut_asserteq(12, size); + + /* Verify we can read through the symlink */ + memset(buf, '\0', sizeof(buf)); + ut_assertok(ext4l_read(link_name, buf, 0, 0, &actread)); + ut_asserteq(12, actread); + ut_asserteq_str("hello world\n", buf); + + /* Verify creating duplicate returns -EEXIST */ + ut_asserteq(-EEXIST, ext4l_ln(target, link_name)); + + /* Verify creating symlink in non-existent parent returns -ENOENT */ + ut_asserteq(-ENOENT, ext4l_ln(target, "/nonexistent/link")); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_ln_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }); From patchwork Wed Dec 31 22:29:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1161 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=1767220330; bh=237M7JClVSt5Yp0UfL4WPptafdQ3W1W1KyifOATRU8w=; 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=Evn8+UthLkJ4OG27ehIiPIiGalOjTMBRU8QYmBZaDvdJVdVzwgHxYeKHJgBlHP5NG 7OF+JOOZJz0p7ZBCzSyhHVo92QGxSin46PBFT87PXA4kRgavBZmtEVO7qo0pfGRnnD v0nCHpCc8RF/Bx/iZxXoa/zQWprlJqFwZRgsQexgBPYWUG5ohDeww1AHDqUK4EWIxq XZdwCetqhvOTXcmkxrNPns8llJHqlmB3BKmHjNbBxBrmwW6vbMHkc+oBiLL5vHxDKT ksPrs5Mf9mj61IOvqME4RzwRWeIQj/k2oim9+Cf2fHCDanbIAPE4gesYvu+N08VZ9I 4YA0VTX3QMLzA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CFE5268F65 for ; Wed, 31 Dec 2025 15:32:10 -0700 (MST) 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 wrWEk60D35DR for ; Wed, 31 Dec 2025 15:32:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220329; bh=237M7JClVSt5Yp0UfL4WPptafdQ3W1W1KyifOATRU8w=; 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=F3eT24AzqveBVTdLVdWF3Y5xIlEv+s7x5m2mLPzaNP45Jznp2ebTAcejYtb6my3aJ HJfzdTREVj9dUVzPPwtKFCAWB17JldMTdE5UAJmyHj9eCnBsr6jmoCzbNkRUI0nbXk i3lWZgphV6Cj8xzZNVwAx1/CiE4g275tEyaXaAoKAlFQ1KwKiU/exvG2O5LyozqEwH J83003IMRWupr3gTioBXcCoqnr/Wk8TKTd3nKYoJlnRDp9MV5UyNCasbQBBtLAChZO 0v6UDEDHG6J12mNIt+qsZaBLZqq7/yPLgPN3gzdbJ96ES/VriovwsN6BIHedTQIsIU 73cav1w++79QA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BC1B868FCB for ; Wed, 31 Dec 2025 15:32:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220327; bh=l2Dt9p39ZGfGmiHEIeIGEum3fkmUL3pUP/64W5cPmWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BPUUPfrxOHwSibzwNPaitJK0C41UB1rXFWRj3xE+7hbcxcs/hYsO2ocPAHt3sM/ui OGUAGTNO447v7SLNtH1Y8h1spnxA8ccAa0YL8bbHnxUmASPixg7fHO+BjZG7KEIuqW P+tzW4KW+R9XJMaAUDiBZAgWcNCJczJtBGLNXa6HB/3upKIaInqqPznyoStg/2tW7O 8/UQmevQgKgbpTtdR347I3fVC+p2D3Qnx+aDBnowFQOA/rNcNWlD9tTjRGF3TJlHbz HWji+ifrSlM0Q7nv+3tc8TpdsYy2orUNWtqVpl98pBOaoecQxsUOpPB4qP1LOdi4E/ WiL5UBY0fGoKA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 69E2168F65; Wed, 31 Dec 2025 15:32:07 -0700 (MST) 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 90fbUfyNaoFF; Wed, 31 Dec 2025 15:32:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220327; bh=ZDnBl4+o5jS0XwI12hSHzEm40ilVf32srQdyqelCCok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XV3VYgfIUgZLQY0uxXStZqF52mwv9zn7I92SDKwAYk6dTxYX6+mHhc6xs7qptBjr6 cnRd3Ct4AJAWioLu6HEc2wT4JEGurbsfYJfDXLcUrc4ivCQtgGjO+7pwfthDup8esh Kl7Kkqu1M4HKft50JOQ3fY1GyHcfdtRlR3QlBIAs2mGpbURR3kQC0dcYg4omqmC5sK lPLhN/kyT7CX3Mp8XsA8gDoC3lzYCBOp0yxgXkq6kyeBBIG+gswcOW2cAvrTDK6fYR VOe2+LwLE3go3ReU1kyQyBn7QRuFZuDjetTxRaHVv39SKJFSKNmF5WOfTzQ2tO6R7J H7oYqvjsWnN+Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BD82268F61; Wed, 31 Dec 2025 15:32:06 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:56 -0700 Message-ID: <20251231223008.3251711-24-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 72I3UHKLU3Y3CDWC6XY3I6XCFC2Q5OM7 X-Message-ID-Hash: 72I3UHKLU3Y3CDWC6XY3I6XCFC2Q5OM7 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 23/26] ext4l: Update symlink to replace existing files 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 The ext4l_ln() function returned -EEXIST when creating a symlink where a file already exists. This differs from the old ext4 implementation which deletes any existing file before creating the symlink (like ln -sf behaviour). Update ext4l_ln() to match this behaviour by calling __ext4_unlink() to remove any existing non-directory file before creating the symlink. Directories cannot be replaced with symlinks and return -EISDIR. This allows test_symlink3 to pass. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 18 +++++++++++++++--- include/ext4l.h | 5 ++++- test/fs/ext4l.c | 4 ++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index c9dd25dd7b4..acd9ba5511e 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -1268,9 +1268,21 @@ int ext4l_ln(const char *filename, const char *linkname) return ret; if (dentry->d_inode) { - /* File already exists */ - ret = -EEXIST; - goto out; + /* File already exists - delete it first (like ln -sf) */ + if (S_ISDIR(dentry->d_inode->i_mode)) { + /* Cannot replace a directory with a symlink */ + ret = -EISDIR; + goto out; + } + + ret = __ext4_unlink(dir_dentry->d_inode, &dentry->d_name, + dentry->d_inode, dentry); + if (ret) + goto out; + + /* Release inode to free data blocks */ + iput(dentry->d_inode); + dentry->d_inode = NULL; } /* Create the symlink - filename is what the link points to */ diff --git a/include/ext4l.h b/include/ext4l.h index d0e420c8da2..882a27dad42 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -114,9 +114,12 @@ int ext4l_mkdir(const char *dirname); /** * ext4l_ln() - Create a symbolic link * + * Creates the symlink, replacing any existing file (like ln -sf). + * Refuses to replace a directory. + * * @filename: Path of symlink to create * @target: Target path the symlink points to - * Return: 0 on success, -EEXIST if file already exists, + * Return: 0 on success, -EISDIR if target is a directory, * -ENOTDIR if parent is not a directory, -EROFS if read-only, * negative on other errors */ diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index 1d46a752f32..c1d10dcc816 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -576,8 +576,8 @@ static int fs_test_ext4l_ln_norun(struct unit_test_state *uts) ut_asserteq(12, actread); ut_asserteq_str("hello world\n", buf); - /* Verify creating duplicate returns -EEXIST */ - ut_asserteq(-EEXIST, ext4l_ln(target, link_name)); + /* Verify creating duplicate succeeds (like ln -sf) */ + ut_assertok(ext4l_ln(target, link_name)); /* Verify creating symlink in non-existent parent returns -ENOENT */ ut_asserteq(-ENOENT, ext4l_ln(target, "/nonexistent/link")); From patchwork Wed Dec 31 22:29:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1162 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=1767220333; bh=E7k+1wq8yD44dI9ImAmkMlB/IHdMy/mXXT6b5FU0gic=; 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=XTBWTe6Foalt+2Q5AcCk+qzOMrrg5GrE7ZVrM1CQhO8J7Gvy907Z2vorx4mpIRHq8 afdykWTu1lRvYy4v29XG7pxvVsN6+qyf18IyJhKUXpJXHexgiPHTq1dlGU7zvlciZN Z6+Kz6bUnYN8qVhrZHBZCp9G088hCBhhpFU+t2fhlZ+nSL5b1h5cxfcp6xYMugevwp GP+RQtG9GktIQgIo8nXcw4VkK4pdf3cMOqAsTI9GbZ9easCUSC0xFrCvgKg/GR+2N2 1yW00p84ZsRaBHP4HEBtbOwJ32LFxV34ioXm+32AtWrsmjEUL0Fm913azm0lv9H8kj 1jY3FpbmBnrvA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 32D3D68FE5 for ; Wed, 31 Dec 2025 15:32:13 -0700 (MST) 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 ibnYp6Es9Z5D for ; Wed, 31 Dec 2025 15:32:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220332; bh=E7k+1wq8yD44dI9ImAmkMlB/IHdMy/mXXT6b5FU0gic=; 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=LiYujfU/P8XMjrNFprqHr3BSegK6JO2aXXIzSDGaByJBD9JO5KQbNoK436Ytetm62 Zxd6CJvEvAQWBYCkqOvMK882lZ9+ZSXkqHiDmOLenykp5M8/GPwjM/KOxFt2RYvs3Y INHL+wvyp0G/MnZqPMi2VFFy+6ma9T1lWRJs/Ubp+LjPd4GhMZ2O9TvxfhHpP7rfPj /6uxZngX7GdQ2B5H5UyLO2fmOa3dE2+iWMD5F0e+SR87wAKFVUaSDpyyMESgYjXVxp r43La8HN/fP967UCrr88v7GFMfnWUOsN2W4pTcOgglFggOxtC3+k+57VCBdDwQYILj OIEW5GfJKPthw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D69FD68F65 for ; Wed, 31 Dec 2025 15:32:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220330; bh=ej3orwGJz/HU8LzdAfTNM7w1BYh7cJ/D90Fegs+kCxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vNFADdZTxqemiW4N07u88oPPEA9HcS9+GE7/Tjunzahm2gx+fA7n3MfpwnGBPdhJi qorLkCgIBX1iIOHHKh/l26sMogxLW0Nh6fdTH6Jw2HQQEVx8gsfedaLSl6UHT3/2Ed bEOUgZ6M0t90KFrTLdmF+sEgZZmtbJsM7fKrcIx0xXTq5QARzgVPuo7HbnAxFjYvTK 9DO6kWpZQhmXU/YWpn1oMTPt5oBKhNT3ZfkfLSzst2jrr7TFF/Z+Y9gO268arlxgK7 QSBh/H8U/us0NfoVXojKBpo7bRA55gprPQjs3E1JVztR0MdBXADMZST7BPgwwv6qlb wIJGuU/JqLMJA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BF32A68FF3; Wed, 31 Dec 2025 15:32:10 -0700 (MST) 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 l8Mxm93c6JcL; Wed, 31 Dec 2025 15:32:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220328; bh=N26EpYAENKDZZnSDKnX/DmBkjxHzowMSxYEkqTJtTEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qox20++bvZaR/ntHbkty3D9SW6QNqVvBDHrDriJsaERZBvg3foccQwux6AjmJBA0Q CbML30dL8Wgg4TJLuaidKHyMMPeLnFblVcoQX3kyH4cgTRMlmyPGFsx7PbDzcVu8CV M9lywdXBsHCH6CtoE6Ln6PcaziZJNzWHf50r4IbGu1cOBqAx98P36KKYpLC4yrCj4N d1wKackmVfTBwNqUUKN6DUEJWUonwf8FcZTSDZc5BHaM4is+CvoymbFdzKfbk8Rvgg PF7+6wiRtagTNttmK+5iEpRTqpZYRJDvl6Dqdky26qjcFSTZREOV5u8PHv5esSnVgM gl1SLb2tD80YA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id AB84E68F61; Wed, 31 Dec 2025 15:32:07 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:57 -0700 Message-ID: <20251231223008.3251711-25-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 66D25O53XAONNTN4K2Q5TWQELIUV24X2 X-Message-ID-Hash: 66D25O53XAONNTN4K2Q5TWQELIUV24X2 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 24/26] ext4l: Add rename support 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 ext4l_rename() to rename files and directories, including moves across directories. This uses the Linux ext4_rename() function. Also fix the symlink test to verify reading through symlinks works correctly, since ext4l_resolve_path follows symlinks (stat behavior). Add Python test wrappers for mkdir, ln, and rename tests. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 54 +++++++++++++++++++++++++ fs/fs_legacy.c | 2 +- include/ext4l.h | 11 ++++++ test/fs/ext4l.c | 61 +++++++++++++++++++++++++++++ test/py/tests/test_fs/test_ext4l.py | 15 +++++++ 5 files changed, 142 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index acd9ba5511e..f581c32359e 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -1309,6 +1309,60 @@ out: return ret; } +int ext4l_rename(const char *old_path, const char *new_path) +{ + struct dentry *old_dentry, *new_dentry; + struct dentry *old_dir_dentry, *new_dir_dentry; + char *old_path_copy, *new_path_copy; + int ret; + + /* Check new_path before ext4l_resolve_file checks old_path */ + if (!new_path) + return -EINVAL; + + ret = ext4l_resolve_file(old_path, &old_dir_dentry, &old_dentry, + &old_path_copy); + if (ret) + return ret; + + if (!old_dentry->d_inode) { + /* Source file doesn't exist */ + ret = -ENOENT; + goto out_old; + } + + ret = ext4l_resolve_file(new_path, &new_dir_dentry, &new_dentry, + &new_path_copy); + if (ret) + goto out_old; + + /* Perform the rename */ + ret = ext4_rename(&nop_mnt_idmap, old_dir_dentry->d_inode, old_dentry, + new_dir_dentry->d_inode, new_dentry, 0); + if (ret) + goto out_new; + + /* Sync all dirty buffers */ + { + int sync_ret = bh_cache_sync(); + + if (sync_ret) + ret = sync_ret; + /* Commit superblock with updated free counts */ + ext4_commit_super(ext4l_sb); + } + +out_new: + kfree(new_dentry); + kfree(new_dir_dentry); + free(new_path_copy); +out_old: + kfree(old_dentry); + kfree(old_dir_dentry); + free(old_path_copy); + return ret; +} + void ext4l_close(void) { ext4l_close_internal(false); diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index a325c2631d4..6e1bb449410 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -291,7 +291,7 @@ static struct fstype_info fstypes[] = { .unlink = ext4l_op_ptr(ext4l_unlink, fs_unlink_unsupported), .mkdir = ext4l_op_ptr(ext4l_mkdir, fs_mkdir_unsupported), .ln = ext4l_op_ptr(ext4l_ln, fs_ln_unsupported), - .rename = fs_rename_unsupported, + .rename = ext4l_op_ptr(ext4l_rename, fs_rename_unsupported), .statfs = ext4l_statfs, }, #endif diff --git a/include/ext4l.h b/include/ext4l.h index 882a27dad42..59990a3a6f4 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -125,6 +125,17 @@ int ext4l_mkdir(const char *dirname); */ int ext4l_ln(const char *filename, const char *target); +/** + * ext4l_rename() - Rename a file or directory + * + * @old_path: Current path of file or directory + * @new_path: New path for file or directory + * Return: 0 on success, -ENOENT if source not found, + * -ENOTDIR if parent is not a directory, -EROFS if read-only, + * negative on other errors + */ +int ext4l_rename(const char *old_path, const char *new_path); + /** * ext4l_get_uuid() - Get the filesystem UUID * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index c1d10dcc816..0843ba1d5ba 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -586,3 +586,64 @@ static int fs_test_ext4l_ln_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_ln_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_rename_norun() - Test ext4l_rename function + * + * Verifies that ext4l can rename files and directories on the filesystem. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_rename_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + const char *test_data = "rename test\n"; + size_t test_len = strlen(test_data); + static int test_counter; + char old_name[32], new_name[32], subdir_name[32], moved_name[64]; + loff_t actwrite, size; + + ut_assertnonnull(fs_image); + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY)); + + /* Use unique names to avoid issues with test re-runs */ + snprintf(old_name, sizeof(old_name), "/renameme%d.txt", test_counter); + snprintf(new_name, sizeof(new_name), "/renamed%d.txt", test_counter); + snprintf(subdir_name, sizeof(subdir_name), "/renamedir%d", test_counter); + snprintf(moved_name, sizeof(moved_name), "%s/moved.txt", subdir_name); + test_counter++; + + /* Create a file to rename */ + ut_assertok(ext4l_write(old_name, (void *)test_data, 0, + test_len, &actwrite)); + ut_asserteq(test_len, actwrite); + + /* Verify file exists */ + ut_asserteq(1, ext4l_exists(old_name)); + + /* Rename the file */ + ut_assertok(ext4l_rename(old_name, new_name)); + + /* Verify old name no longer exists, new name does */ + ut_asserteq(0, ext4l_exists(old_name)); + ut_asserteq(1, ext4l_exists(new_name)); + + /* Verify file size is preserved */ + ut_assertok(ext4l_size(new_name, &size)); + ut_asserteq(test_len, size); + + /* Verify renaming non-existent file returns -ENOENT */ + ut_asserteq(-ENOENT, ext4l_rename("/nonexistent", "/newname")); + + /* Test cross-directory rename */ + ut_assertok(ext4l_mkdir(subdir_name)); + ut_assertok(ext4l_rename(new_name, moved_name)); + ut_asserteq(0, ext4l_exists(new_name)); + ut_asserteq(1, ext4l_exists(moved_name)); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_rename_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }); diff --git a/test/py/tests/test_fs/test_ext4l.py b/test/py/tests/test_fs/test_ext4l.py index edea38f7faf..0930ebd01ea 100644 --- a/test/py/tests/test_fs/test_ext4l.py +++ b/test/py/tests/test_fs/test_ext4l.py @@ -128,3 +128,18 @@ class TestExt4l: """Test that ext4l can delete files.""" with ubman.log.section('Test ext4l unlink'): ubman.run_ut('fs', 'fs_test_ext4l_unlink', fs_image=ext4_image) + + def test_mkdir(self, ubman, ext4_image): + """Test that ext4l can create directories.""" + with ubman.log.section('Test ext4l mkdir'): + ubman.run_ut('fs', 'fs_test_ext4l_mkdir', fs_image=ext4_image) + + def test_ln(self, ubman, ext4_image): + """Test that ext4l can create symbolic links.""" + with ubman.log.section('Test ext4l ln'): + ubman.run_ut('fs', 'fs_test_ext4l_ln', fs_image=ext4_image) + + def test_rename(self, ubman, ext4_image): + """Test that ext4l can rename files and directories.""" + with ubman.log.section('Test ext4l rename'): + ubman.run_ut('fs', 'fs_test_ext4l_rename', fs_image=ext4_image) From patchwork Wed Dec 31 22:29:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1163 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=1767220337; bh=v4VFYKxzDPYbptv0hTbRFb8zDJy/0qm/NNz64GuWWFc=; 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=c4N6Uy/BwP+FMRxAn1mIQSADnDbtK5j1GC1h1r6O4ppS012xLHTmcNUOjwAr1o5W3 gcOcxn6HxKYicMsSeXBP/pAbWUM+p9ibsN+lEjHRgG4RqSCtqYy5W7Z8QZmWdR6NC/ L2UWd1l9vb28DtjY40BiupUD80oy4oSBE625hsFYWtJ/aGEFpKoRkhRKJU6+DylNCe fF4/07wVDm2xeOgHRb5RGHnMX2oXa713RPWUB8u9jSzLndjRWG8DSIfkMBMv08PqZC JLgfWas9OqD9lULbHs7lLtWDQN7bG4E5pOOI3opUm1+JQG1bAWv2Go3ZkuQojpHxsd lfypYUHzZnYyQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8ED9B68FD3 for ; Wed, 31 Dec 2025 15:32:17 -0700 (MST) 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 vJ2649I2H0Ql for ; Wed, 31 Dec 2025 15:32:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220337; bh=v4VFYKxzDPYbptv0hTbRFb8zDJy/0qm/NNz64GuWWFc=; 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=c4N6Uy/BwP+FMRxAn1mIQSADnDbtK5j1GC1h1r6O4ppS012xLHTmcNUOjwAr1o5W3 gcOcxn6HxKYicMsSeXBP/pAbWUM+p9ibsN+lEjHRgG4RqSCtqYy5W7Z8QZmWdR6NC/ L2UWd1l9vb28DtjY40BiupUD80oy4oSBE625hsFYWtJ/aGEFpKoRkhRKJU6+DylNCe fF4/07wVDm2xeOgHRb5RGHnMX2oXa713RPWUB8u9jSzLndjRWG8DSIfkMBMv08PqZC JLgfWas9OqD9lULbHs7lLtWDQN7bG4E5pOOI3opUm1+JQG1bAWv2Go3ZkuQojpHxsd lfypYUHzZnYyQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7E4D568F61 for ; Wed, 31 Dec 2025 15:32:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220335; bh=SryMyZRelmcgAZN6uLSmouoSeVIgqUsFoGp6OL5qeGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HAmQRAMGf9PiFTNCVZIcc6DU7oPFReqrGNXtq5qkMrBMTOK+2hrqELXJED/TpIwMg vIWP3m6RVGAqyU2plRR9SQrUj9R6YtaTQqJ7Xth9P5AcOBKfzob95RmJ+Ceuv7s3Yj 9ViE9pktmFsEuCa1OCJI4Thu4SQmUK7R2RIRc758sQa5nS4Xp8MEZdT7DZRunZ3pIu J/nh8J6JSyoZjNrMk75fJhSnz85qPFETOtze1YDECSbZXctjzWNzc6BxDFwdguVvky HDnyXa09SG2lcT1Oh3YarpB4lUDwxAoTxm2+Nbw4J9/lHioGaWKu3KIcfwUc1g7ogZ cbQHp6x+GDsCA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 62E7A68F61; Wed, 31 Dec 2025 15:32:15 -0700 (MST) 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 h5dBTuZoO1Nb; Wed, 31 Dec 2025 15:32:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220329; bh=q+Q5R5PV556GM1fAlKzxaZLKWnt8mLKbuAJnSieJyUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TuIVViX4RWFoAlbac3Bo8AvzokR57rNTR5E21ZD3qhgZBKk9rC8UUBX+4Io/fRxss lEtIbWagAvQ9gfNsce1p8nokWECW5Nve7gg9ZBLNy/u7l49nP1k7jb/Ho9HFjQsW7n QtUL0SFEJOsFqGQsdz7herOSDw86JhPsKAnng2J33TtZ75ippJHJaVzOmWWhsfxVoi /I34YyH5q9U4hk7IT1+fPek4mjxWIgS94MDedXqeBugtbbKRsu4lhWZjdS+x77sTtY 8uIC4/uC1mQxveJ+4QG1OzhoeARvyDQATqlvGleYhKMhINlgFvqdr5EWo7uQ3nYmp0 OTYcVvnxzLgpg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F2FC568F51; Wed, 31 Dec 2025 15:32:08 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:58 -0700 Message-ID: <20251231223008.3251711-26-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 7ZS7576IJWBPPJ2UQJXX2E3G4QWZEC2H X-Message-ID-Hash: 7ZS7576IJWBPPJ2UQJXX2E3G4QWZEC2H 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 25/26] test: fs_helper: Keep metadata_csum enabled for ext4l 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 The ext4l driver supports metadata_csum checksums, unlike the old ext4 driver. Only disable metadata_csum when CONFIG_FS_EXT4L is not enabled, allowing ext4l to use modern ext4 filesystem features. Co-developed-by: Claude Signed-off-by: Simon Glass --- test/py/tests/fs_helper.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py index 3c4c6e2df6f..ccde6683534 100644 --- a/test/py/tests/fs_helper.py +++ b/test/py/tests/fs_helper.py @@ -174,10 +174,15 @@ class FsHelper: stdout=DEVNULL if self.quiet else None) if self.fs_type.startswith('ext'): - sb_content = check_output(f'tune2fs -l {fs_img}', - shell=True).decode() - if 'metadata_csum' in sb_content: - check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) + # ext4l supports metadata_csum; the old ext4 driver does not. + # Only disable metadata_csum when using the old driver. + if self.config and self.config.buildconfig.get( + 'config_fs_ext4l', 'n') != 'y': + sb_content = check_output(f'tune2fs -l {fs_img}', + shell=True).decode() + if 'metadata_csum' in sb_content: + check_call(f'tune2fs -O ^metadata_csum {fs_img}', + shell=True) elif fs_lnxtype == 'exfat': check_call(f'fattools cp {self.srcdir}/* {fs_img}', shell=True) elif self.srcdir and os.listdir(self.srcdir): From patchwork Wed Dec 31 22:29:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1164 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=1767220342; bh=GL/Hw03bhO33x5mrM3TvjZhxMbvk8xP9jSjVoEQZcA0=; 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=JR5GWdUNFNODDx4343tpgjKs3GtcN06yQT5ivkx/jEVlvVwT/UffeIPha5o8yRGCv lunKQ32iH8YcdlHwwVApU/IiWjb+FZOnzzRbAx1wJs/RzRSpaoKhUXkZSH3siWLvzX RzJlSK90s/AN/Cm+aJZvitt2odVvyFnqrVrOEMKq3jmSiZJvdVwu9qiCzbLJhkjz8p g12udhDdtBJ3SI7h6NpN3SxBv/xw1/XQi02V8ltvptVsBjAfCEoWZAv0Y0tHGx/6XQ XmKnvj8WwsQk0NQIOAointiSbZ6bcuopLzKw6cAos37784kbphdMF/Q48z7020lnT4 fXiU4mojoNCFg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1F48068FCB for ; Wed, 31 Dec 2025 15:32:22 -0700 (MST) 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 JNKnTtIDBnaK for ; Wed, 31 Dec 2025 15:32:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220342; bh=GL/Hw03bhO33x5mrM3TvjZhxMbvk8xP9jSjVoEQZcA0=; 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=JR5GWdUNFNODDx4343tpgjKs3GtcN06yQT5ivkx/jEVlvVwT/UffeIPha5o8yRGCv lunKQ32iH8YcdlHwwVApU/IiWjb+FZOnzzRbAx1wJs/RzRSpaoKhUXkZSH3siWLvzX RzJlSK90s/AN/Cm+aJZvitt2odVvyFnqrVrOEMKq3jmSiZJvdVwu9qiCzbLJhkjz8p g12udhDdtBJ3SI7h6NpN3SxBv/xw1/XQi02V8ltvptVsBjAfCEoWZAv0Y0tHGx/6XQ XmKnvj8WwsQk0NQIOAointiSbZ6bcuopLzKw6cAos37784kbphdMF/Q48z7020lnT4 fXiU4mojoNCFg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0EB6768F61 for ; Wed, 31 Dec 2025 15:32:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220340; bh=5aLbh348+P8msJx5Y2wCTbAr+v3hpaRAPq3ZiObbDGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wftUU234ctQgjBm+SbaKz223eHCIO5Vris6BapOVw64lCub6rxNT1H7qgfkXObX5T rwO/ZKfP4JPYF2Dio6lq4KN/C91SsuuEle9/PyXAlaVfCE1T7MfFjxUt3qsMZebQe7 bs0cYnMIdln2rw9e1E1QOdtxRz3dSBEalmeDhpsl1S1n65Zcwl9XEr11Hn/AWSj/TE UymaOc+iZWjMJsb9+7W55G9vU/qYCqBK9tceTmupiMDuo9/THy1HI9R9wjMQH51DAn dyFR2H3JUdT2Xd5ri2bgF7hqz1Ybevf4Oqo/zLuNzaoswfYWnpxRdhwIL++xb4lGAT N5/2TknpnphWA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0505268F51; Wed, 31 Dec 2025 15:32:20 -0700 (MST) 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 lzWnboMcgSYt; Wed, 31 Dec 2025 15:32:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220334; bh=RiNxu+ABh/uuRNmvwM5ls5YcE2kINUW3L3how6Cx0is=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C/cdjU7fPjfJvwQWrkKtSsTX1vOSqb1mG+Qlt0fngYhc6EJnwnvbVfHbckxnKJvKh VJsvGm8gQsGPe+hgUYSZDx7ELinlV7kzYkbfz3VsstGyqcfXbMCtF8tuCc6AMRPcCG sekDY1IzEf0zhhUqzE+MkrYu/4uV5ChaQ8/AbT27ohYmoI8aWDLQbhoIlEb+MJAX+X 4FrbOvYuzxCn4rgXyuo268vCO9JrPj+plf2uu8wqsVJqQPFlj/8IIuKjxiUuTC/KS+ OY2ZozTs6KJyfHCN5+vanoPwHqqfoYOY3MJKCZz8JQblf7DXhdVGNsTAYrC0yHdNyc hb0fEBJid4jaQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id ADE8C68FCB; Wed, 31 Dec 2025 15:32:13 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:59 -0700 Message-ID: <20251231223008.3251711-27-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: R3GOZD34TXGWHACG3NOXFSCOHCPFCZBW X-Message-ID-Hash: R3GOZD34TXGWHACG3NOXFSCOHCPFCZBW 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 26/26] sandbox: Enable CONFIG_FS_EXT4L 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 Enable the new ext4l filesystem (Linux ext4 port) for sandbox testing. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- configs/sandbox_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index e9ac6894d1a..e55aef8e7f9 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -358,6 +358,8 @@ CONFIG_WDT_FTWDT010=y CONFIG_FS_CBFS=y CONFIG_FS_EXFAT=y CONFIG_FS_CRAMFS=y +CONFIG_FS_EXT4L=y +CONFIG_EXT4_WRITE=y CONFIG_ADDR_MAP=y CONFIG_PANIC_HANG=y CONFIG_CMD_DHRYSTONE=y