From patchwork Fri Apr 5 12:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 7708 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 4V9z9S6TfJz3wZV for ; Fri, 5 Apr 2024 13:00:12 +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 4V9z9F2tn7z5fk; Fri, 5 Apr 2024 13:00:01 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4V9z9C4mkMz32n6; Fri, 5 Apr 2024 12:59:59 +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 4V9z913xMpz30VV for ; Fri, 5 Apr 2024 12:59:49 +0000 (UTC) Received: from michael.haj.ipfire.org (michael.haj.ipfire.org [172.28.1.242]) (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 "michael.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4V9z9024xDz5SH; Fri, 5 Apr 2024 12:59:48 +0000 (UTC) Received: by michael.haj.ipfire.org (Postfix, from userid 0) id 4V9z8x3cKmzTj4c; Fri, 5 Apr 2024 12:59:45 +0000 (UTC) From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 06/13] installer: Make hw_mkdir static Date: Fri, 5 Apr 2024 12:59:35 +0000 Message-Id: <20240405125942.1803058-6-michael.tremer@ipfire.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240405125942.1803058-1-michael.tremer@ipfire.org> References: <20240405125942.1803058-1-michael.tremer@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: GCOZEIRIBX3433P2UVJWLPI2VSVBGDLQ X-Message-ID-Hash: GCOZEIRIBX3433P2UVJWLPI2VSVBGDLQ X-MailFrom: root@michael.haj.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 CC: Michael Tremer 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: Michael Tremer --- src/installer/hw.c | 86 +++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/installer/hw.c b/src/installer/hw.c index f4a84804d..f05608fd1 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -54,6 +54,48 @@ static int system_chroot(const char* output, const char* path, const char* cmd) return mysystem(output, chroot_cmd); } +static 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; +} + struct hw* hw_init() { struct hw* hw = calloc(1, sizeof(*hw)); assert(hw); @@ -959,7 +1001,7 @@ static int hw_mount_btrfs_subvolumes(const char* source) { return r; // Create the directory. - r = hw_mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO); + r = hw_mkdir(path); // Abort if the directory could not be created. if(r != 0 && errno != EEXIST) @@ -1416,45 +1458,3 @@ 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; -}