From patchwork Sat Mar 23 10:56:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 7665 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4V1x3N35jvz3wtq for ; Sat, 23 Mar 2024 10:57:04 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4V1x3C5BzNzFM0; Sat, 23 Mar 2024 10:56:55 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4V1x3960gbz32vY; Sat, 23 Mar 2024 10:56:53 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4V1x2z4Hdfz32bJ for ; Sat, 23 Mar 2024 10:56:43 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4V1x2z22wrzFKr; Sat, 23 Mar 2024 10:56:43 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1711191403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YIDZP/bX32eOFNtrgGZHJYklKDUYcKOVfg2YqBzG/K4=; b=O8CHmc9As8K6b0v7j+lrlPekinWfpSYJ19h81mmxQ2Eeowuk10FCXYlTbZ+JwUutAb0kB+ bWCvtZOqDFwgskCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1711191403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YIDZP/bX32eOFNtrgGZHJYklKDUYcKOVfg2YqBzG/K4=; b=sgWn1rOdPNE+trThP491zVnQPSu/VwUT92ttuHOSvVzSdHM/dQM32a18mSrjAg/yHzNQhq wW9iOm489LS+P+lkq3iUBoSiK2/DAI36zb6tH2SkM9OdLBnZJJO+nv+dOYpqUpbriRJ4kW EG+ChthPvsF/4NYtcYk4g58XQl8OKnLZobr4eroljGUNLdMkXVxyGbpCqOG/Y3Tn+0lLlg 7LVyIXJV7Bn+1iCZDSs3ODdzEAU+J5b1sWwOJjDoebKCb1MO6+XzQylcZXWHI889F1R9GL /r4hdtAEV5Zd4OVcJdoWuK2dSei0kd6vb3JtkerXUN8aQZpAdbEwUkn3OYLbRw== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCHv2 07/12] installer: Add recurisve mkdir function Date: Sat, 23 Mar 2024 11:56:24 +0100 Message-Id: <20240323105629.371511-7-stefan.schantl@ipfire.org> In-Reply-To: <20240323105629.371511-1-stefan.schantl@ipfire.org> References: <20240323105629.371511-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: VS5B5QWFM3A56ZHTTPWPLLHB7Z46BL4R X-Message-ID-Hash: VS5B5QWFM3A56ZHTTPWPLLHB7Z46BL4R X-MailFrom: stefan.schantl@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Stefan Schantl --- src/installer/hw.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/installer/hw.c b/src/installer/hw.c index 8396d83cf..3fa8b889e 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -1281,6 +1281,49 @@ int hw_restore_backup(const char* output, const char* backup_path, const char* d return 0; } +int hw_mkdir(const char *dir) { + char tmp[STRING_SIZE]; + char *p = NULL; + size_t len; + int r; + + snprintf(tmp, sizeof(tmp),"%s",dir); + len = strlen(tmp); + + if (tmp[len - 1] == '/') { + tmp[len - 1] = 0; + } + + for (p = tmp + 1; *p; p++) { + if (*p == '/') { + *p = 0; + + // Create target if it does not exist + if (access(tmp, X_OK) != 0) { + r = mkdir(tmp, S_IRWXU|S_IRWXG|S_IRWXO); + + if (r) { + return r; + } + } + + *p = '/'; + } + } + + // Create target if it does not exist + if (access(tmp, X_OK) != 0) { + r = mkdir(tmp, S_IRWXU|S_IRWXG|S_IRWXO); + + if (r) { + return r; + } + } + + return 0; +} + + int hw_create_btrfs_subvolume(const char* output, const char* subvolume) { char command [STRING_SIZE]; int r;