From patchwork Mon May 27 10:18:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1939835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=TS1xDbuH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13f; helo=mail-lf1-x13f.google.com; envelope-from=swupdate+bncbd2zdgn6sekrbcf42gzamgqe3gwktaq@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lf1-x13f.google.com (mail-lf1-x13f.google.com [IPv6:2a00:1450:4864:20::13f]) (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 legolas.ozlabs.org (Postfix) with ESMTPS id 4Vns7R2001z20ds for ; Mon, 27 May 2024 20:18:58 +1000 (AEST) Received: by mail-lf1-x13f.google.com with SMTP id 2adb3069b0e04-52395bc1813sf3490116e87.2 for ; Mon, 27 May 2024 03:18:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716805130; cv=pass; d=google.com; s=arc-20160816; b=KPvvGGuV2gnDg9kx/EA5WBdvPRG4JXbhUHa9uBJaMVBH5V8aF7y4qMf7MC2jpoiNPS iaYQk2a4J1MR/RC5f/gU1HBUG2pMPnXSVg3CII/4iizwDUNvrsbciFt//pLM61oj1ykQ jdYwUwvWE3+LhqM393akIXMAlB0kp+ZysNSfNEi8vNHAWVNdp/gbpUdEKx8PQjuOtxRw 628SlgJiesWh48rouAc7/4WL1aKxIVaBGcMYBQ3faWfOy0x1PmY7hb77fVJtSSSR5UFd kKwKBPGG+TDlt8x0VMaIs7vD+QR+4tGcmjfgHdIsTHLB8PQzkywFNGAGcv6H555YMIE1 qQpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:ui-outboundreport:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=apVDN/hHQqJiz0wwcSO+GRGM6Jc68NMQeqqLjeU3HNM=; fh=8LORG5Aj7vQedjBXEa8bj5B7Y5pvUK2bnQAqoORYt0E=; b=w6M5OZXfLqmKAeXAaESPR8wjRHQPxLojNNHAf3bQiLrDaa2KO5j088LzRbg7YY/Osy 2CePvC940MMu4qbGC29EdvMtvMM6ckKLJmLDI+qPzuCRJvnjqREq91lH8u1hjK3cD5fz +J0cao7XFlQfpiXLxDEBJmOzG9vY3wJq70UVmdgudo2fo8nQl9JC0vSNOleLc+LeCWbc qWAbC4EUhuPc2opXyQ1/2Gp+AHE6bSYm0tpt7exV178qgcYdzypV61KXtPlTa6YhJNMc zoaWgzVnsd0H0iwac9u7GYkPyKCr6iyNXZ4qHFJYFVIEQ9ISKoZ8vMM1W/zAEeK8W7CY 8nXw==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=eHZjQHCU; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1716805130; x=1717409930; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:ui-outboundreport:mime-version:message-id:date :subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=apVDN/hHQqJiz0wwcSO+GRGM6Jc68NMQeqqLjeU3HNM=; b=TS1xDbuHJmWIk0l7yr5ITvdxHX4Ppd1j0fdnyPAOLbEO/JmmkPDb8xJ83FWjQ/EUeT ibGMbMLRLJcBTvgGiMjhysrTTzaEQBHRGr19GljJUB8yI8bQ11+DTrQzef4AeNlMUkKG 2qPeCp0rbemrt7BJOK7u55CwC3XZ11aDG0kZrrk8hFfGMzNGtz5RBIE7wT+Y/bKMkVTu SMZ3pdbQ2Y7S4WNl4p+M7J1WDdazj/cqsfxmS5wAlCr2LzInBjRCQzwko4n7cYtV90q/ E6VGwsWgJn8pHXrzuEtfm3Vj/gSQZiG2PKo4dlgI+FQzmqIaSkCpDk07oLsB3EhcaDdf rHsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716805130; x=1717409930; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender :ui-outboundreport:mime-version:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=apVDN/hHQqJiz0wwcSO+GRGM6Jc68NMQeqqLjeU3HNM=; b=krbZuWCAwu4AjwbT/1iZsj3GUsaFv49nJ9bWKNQNXn8db+kH2R/sWu8Ds84EGrkV49 T6tNEoxbzcNigyixLVgk2iv2gfITKYStN5JDXsvbhkrgno4amcLCqTlfwHvqnosM5tI+ YRqC3AgPF1VmeVED8khPwyuR+jW1R7MEQrophgeCQ9KOlsfXHh11jdUhYVOBTnO9dF7r 0GEcAL3UsC+4uNQ2h21MVXbJ4besL2bo1Bwhl5ciP5Od/REYKPEvGbpKLhJ5hWM7uVgC 4IlBxUN1ZhMR6yDtLRa8VngREAMJtdrR1+XIoGD74w6JTkBIocE29vz7tFBAaqUpOiBx N6nQ== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCX5NiFgdKTwnCpBpHsWG8Nd7SzG0j1BbgLj2tB/q7Ur9IEM8MUbUO8KwCDrP8yjiDB4HEeUHzZ5q5pfBPWvt+4CyX4Hon1ALlUcJYSHaQ== X-Gm-Message-State: AOJu0Ywcl2YwEDqijvySvBaQx5S25JxxkxULJGpA8mCVvAwZ9iO4N5Ba gylJV1P8XulB0/EIx0JdGzsVf6+sRgpPyVDgtzCgVEGIfG9mKfFI X-Google-Smtp-Source: AGHT+IGg+P6ZmOXAfLjph2F9vCU/uFAh3ibOomR6q5GdxOdWn+6ZpmGgW/4n06WEhpcPIxUhPPIiVA== X-Received: by 2002:a05:6512:33c2:b0:521:cee5:db36 with SMTP id 2adb3069b0e04-529661f2ef2mr6975339e87.48.1716805129539; Mon, 27 May 2024 03:18:49 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:ac2:550a:0:b0:51f:4a71:1afb with SMTP id 2adb3069b0e04-52931e923d3ls930422e87.0.-pod-prod-09-eu; Mon, 27 May 2024 03:18:46 -0700 (PDT) X-Received: by 2002:a05:6512:1152:b0:51b:9254:91e2 with SMTP id 2adb3069b0e04-529661f2cf1mr6485406e87.55.1716805126301; Mon, 27 May 2024 03:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716805126; cv=none; d=google.com; s=arc-20160816; b=j3PivSvhjVlcuNCkUKqu14gSBDeqaIyNfO//1HI1g0+d0mqn8WYuWAu5FwD2TzhliA M2r6wefCXK41U2udaYj2DQo3rxRgedcoYAVY3zRacHmtRE0S5wAcmRLPxwT1Py18YSD/ O9cxvTrBKFchf5ruUivr/mnxREqpSlt+/iaWWjoltDoHseAotR0dXVRgCa1h3c7yWgwJ mRaoD1XDAFJk2D+lXthSQIZxqvadzSxoHr7y0ZFYC+BWBVHT1wEPEr4qBNoyWoMmSrsk mFmfUxIjuwsbB0hgu6lsez/XMdq/YYAI8O7wIUNLq5TSDWMQr4llYkdRqaUVfdirWWMO 2Ydw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:message-id :date:subject:cc:to:from:dkim-signature; bh=rfcOhRoR8pFUklCumyc9kCyx9hVBRsSLRSErwzA5B4s=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=ja6UN03OPea0c+zF5H6qF5HVejo6/aMkTDRLkBEzySk0i+TpYEaGUdKFjwYMHn902v +bGwXsquGQ2CmlJFLR1WuSXa7V4jiNBjE1cSapwOtPVEZc9rcGnPA6KylxuWGw+L3Jkh GfRvGvWsIj/SFZ669gRStc0FC+dP2COepH/EP8ttExJ/FV6J32P+Aw9y9j1s3dGrcWub jqU5DjveY77cgJsZGFy7mCL206m2KooSCcFPVmrJ4npEOVbW6KezQI99reWi/nlOSMa4 rKsbDniCRHdKJv65Ecn2kPBmhbX4DwSMApy+NWA1NUZA+y2qYyNQ05DDLH0hbOJnLAqy XcdA==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=eHZjQHCU; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [212.227.126.133]) by gmr-mx.google.com with ESMTPS id 2adb3069b0e04-529a59decc4si98974e87.8.2024.05.27.03.18.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 03:18:46 -0700 (PDT) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) client-ip=212.227.126.133; X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue009 [213.165.67.97]) with ESMTPSA (Nemesis) id 1Mg6mM-1si5m71NHi-00ZvL0; Mon, 27 May 2024 12:18:45 +0200 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [libubootenv][ 1/3] Factorize function to set variables's flags Date: Mon, 27 May 2024 12:18:41 +0200 Message-Id: <20240527101843.380555-1-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:XtZIslpROZF8fEb+Ip8ylwLU3Lb6fBqYLxebRbpfRfbqYgRYI7y nS8hJOunDxHaaGvl6EH9lU+1agJz2gSYsUkvSjYQ03FAl6YKusMpj4X8pdmIxG7+w4oHIHj DhO5/PKht9YIEAtwwThsTjbJAE2zGH5ZEAwU1n+wp3RBC8IyOkagmINi3TPoibm1PRYXVsq TBIptPbiIyZp7I/9JGwuQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:ZgxUE844srM=;0UJBzu3mqPHPyeiywnmAqNmqWvl AXSMebWvjKWi5XEF6sBbMHEVTvr0PtZHIHmU9Brkbsyhr70xqHIFYQKumRO+LUeLbKdyzQ++z sOV6btq2jKkkvk8j/k40ggCZwQeshTWrtgrN8/Z12hFM+X/rLepDRkoSP5YrhM9tF7Ds7rlWe GNDN9M10Y2HQg5nqjlEFxye1yRt/qzDdCib/M39HHpzGUT9UbfZVSjxzFUrMQM8gOGFKl8Pr8 kap+oDizMzZj6Ia2i6juaxu5GtOMefgeBtxR04AALbEA6aU3/Q74oPdjDXuQW0X0bRAiigm9A OrpJvH9zFcwW5m6BH21WZK2pGp9hdaOm7Ha05+9ruFPg75iQLG1noswhpbnXfMabmdhEBLxg3 5Ea9NGQPToOcXIlk3WE/8rEpAwHlKlsMg1MF8XEBGwVi5MeZrui/r2tPuy4I3VHmRf5apDMRK NG2JYj4wFwKRjaiTKzcUx7WfXvUW49H6vN9j0snM4OeA7c8uVgyIRRWD6DeEmtY5Xi4+NqFKk YhBOJAOztMlMiZ9/gbZFY5V8SkIWn3PyHf98+bUfxNfP7KQDCpur82bx0e4tf3+pDHzFkOAPA WzIFZ4LboQGVByaQimmWcKgPbIGBhbqk4tHYETiz7rK6WTVOrk98LZalLGQtSII3PHE2a0l9v nR1WFeUFxJow14kqXNMufqga6HU2ZYIWVN4mu4+fVwSYHVif75naiHV+BPSTqokokap5ozwtz prH3/F7AyfCWRaL2ggve/lHFpcYXC8tDy8zXaRVf7kgeKojbIfiHEI= X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=eHZjQHCU; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Signed-off-by: Stefano Babic --- src/uboot_env.c | 82 ++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 39 deletions(-) -- 2.34.1 diff --git a/src/uboot_env.c b/src/uboot_env.c index 16480b4..f40511c 100644 --- a/src/uboot_env.c +++ b/src/uboot_env.c @@ -138,6 +138,48 @@ static char attr_tostring(type_attribute a) return 's'; } +static void set_var_access_type(struct var_entry *entry, const char *pvarflags) +{ + if (entry) { + for (int i = 0; i < strlen(pvarflags); i++) { + switch (pvarflags[i]) { + case 's': + entry->type = TYPE_ATTR_STRING; + break; + case 'd': + entry->type = TYPE_ATTR_DECIMAL; + break; + case 'x': + entry->type = TYPE_ATTR_HEX; + break; + case 'b': + entry->type = TYPE_ATTR_BOOL; + break; + case 'i': + entry->type = TYPE_ATTR_IP; + break; + case 'm': + entry->type = TYPE_ATTR_MAC; + break; + case 'a': + entry->access = ACCESS_ATTR_ANY; + break; + case 'r': + entry->access = ACCESS_ATTR_READ_ONLY; + break; + case 'o': + entry->access = ACCESS_ATTR_WRITE_ONCE; + break; + case 'c': + entry->access = ACCESS_ATTR_CHANGE_DEFAULT; + break; + default: /* ignore it */ + break; + } + } + } +} + static char access_tostring(access_attribute a) { switch(a) { @@ -811,45 +853,7 @@ static int libuboot_load(struct uboot_ctx *ctx) *pnext++ = '\0'; entry = __libuboot_get_env(&ctx->varlist, pvar); - if (entry) { - for (int i = 0; i < strlen(pval); i++) { - switch (pval[i]) { - case 's': - entry->type = TYPE_ATTR_STRING; - break; - case 'd': - entry->type = TYPE_ATTR_DECIMAL; - break; - case 'x': - entry->type = TYPE_ATTR_HEX; - break; - case 'b': - entry->type = TYPE_ATTR_BOOL; - break; - case 'i': - entry->type = TYPE_ATTR_IP; - break; - case 'm': - entry->type = TYPE_ATTR_MAC; - break; - case 'a': - entry->access = ACCESS_ATTR_ANY; - break; - case 'r': - entry->access = ACCESS_ATTR_READ_ONLY; - break; - case 'o': - entry->access = ACCESS_ATTR_WRITE_ONCE; - break; - case 'c': - entry->access = ACCESS_ATTR_CHANGE_DEFAULT; - break; - default: /* ignore it */ - break; - } - } - } - + set_var_access_type(entry, pval); pvar = pnext; } }