Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p53Xl-0003kH-Nq for mharc-grub-devel@gnu.org; Tue, 13 Dec 2022 06:33:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p53XB-0003dA-VM for grub-devel@gnu.org; Tue, 13 Dec 2022 06:33:22 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p53X7-0000py-Sk for grub-devel@gnu.org; Tue, 13 Dec 2022 06:33:16 -0500 Received: by mail-pj1-x102a.google.com with SMTP id fa4-20020a17090af0c400b002198d1328a0so1402927pjb.0 for ; Tue, 13 Dec 2022 03:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=UhiSlvj6tQFKGR/lzt5fDfyM8L/uznkWsCqZFzAdENA=; b=RfzBkReV6fCX37H/vcbJp5Hv6hl++9lvVNMOXmjLgP1PAeB/4dJZZz1d/3B5/bA1LW F3LvhOgh5s1sSGDNJX+4K+EhTKMyMLrea2mged2gTvv8CPy8HFxKwjflWBKJLN6/2XpK fbWGybfUasLd5D4cxyW7oRY178E6Pye7utKQ9ImYKUrEzpgEOgzAIzHWlR2LlMO3AyCv 4ECZE2XZnB4aONpQeFjf3XLzjNPRYIMI3AKFlNzyyBAY+AbTRs18QGNlen0uc5emm07A f02EItxyb641VEv4E1CUg3X9Rb2aey1YTXUbs3jaqshjMfzX9nVCam1x94srp/0hwyyY JD+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UhiSlvj6tQFKGR/lzt5fDfyM8L/uznkWsCqZFzAdENA=; b=lSbGP9+NJ4bU/0TbVZ8LgNUZSvwuzoIlwy4ZMyzmv3cXyMTh2mVTevbU0frfTofEf/ yRt4iky7Jj6kNXevaeOVL8ZbC+Mm2+js5xLOKKrqUzAQyUUOW3Bx1/jfc9NVxNzefMOe cQBWL2+wsrMbRtaompVDc/sszgUuvXrLs57icNQrtW5+FA3fWQ4vnzAWJC0kobsmc8dU 1/39LdpZjxMzOuMRt7U6pfdVhvZk82oOjmT4aCCN0/Rcgzqd9GLCs6qxRxNcVCEXR5U7 uXCY5R5dMAuXu/orsfS4K/sQ7CAbs7Rj0NYrlXe93gcfG1eU3Kblhqgab8alOHxnjbXE KUKw== X-Gm-Message-State: ANoB5pmy5dtv11FVWyuXKDhSIIJf4anVTlWv9gb2ANbXwLye4kr3G5PN 8J+ROgI0G0u25NVEVY6MyDH03uck4Zg= X-Google-Smtp-Source: AA0mqf79LL1QdvptK7Ppl3YPW3+zQJiKLTS6+sNShjoY12xgqCRgJvmisH2oI79Z1H+CpGbWbzZ9fQ== X-Received: by 2002:a17:902:a60c:b0:189:f990:24af with SMTP id u12-20020a170902a60c00b00189f99024afmr20274923plq.20.1670931192225; Tue, 13 Dec 2022 03:33:12 -0800 (PST) Received: from [0.0.0.0] (ec2-13-113-80-70.ap-northeast-1.compute.amazonaws.com. [13.113.80.70]) by smtp.gmail.com with ESMTPSA id b4-20020a170902d50400b0017f73caf588sm8240554plg.218.2022.12.13.03.33.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Dec 2022 03:33:11 -0800 (PST) Message-ID: <28ceda39-f7d0-7920-5eaa-e33990d1b5f4@gmail.com> Date: Tue, 13 Dec 2022 19:33:09 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH 1/1] feat: add --set argument to videoinfo to write current resolution to grub env var Content-Language: en-US To: Markus Scholz , grub-devel@gnu.org References: <00a001d9097d$7dd0d3e0$79727ba0$@novelsense.com> <20221206154848.13604-1-scholz@novelsense.com> <20221206154848.13604-2-scholz@novelsense.com> From: Zhang Boyang In-Reply-To: <20221206154848.13604-2-scholz@novelsense.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=zhangboyang.id@gmail.com; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Dec 2022 11:33:34 -0000 Hi, On 2022/12/6 23:48, Markus Scholz wrote: > --- > grub-core/commands/videoinfo.c | 92 +++++++++++++++++++++++----------- > 1 file changed, 63 insertions(+), 29 deletions(-) > Commit message shouldn't be empty. You need to write something about your changes. You also need to add your Signed-off-by tags. > diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c > index 5eb969748..75e3b4e9f 100644 > --- a/grub-core/commands/videoinfo.c > +++ b/grub-core/commands/videoinfo.c > @@ -30,6 +30,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); > struct hook_ctx > { > unsigned height, width, depth; > + unsigned char set_variable; `bool` can be used instead of `unsigned char` here. > struct grub_video_mode_info *current_mode; > }; > > @@ -38,6 +39,9 @@ hook (const struct grub_video_mode_info *info, void *hook_arg) > { > struct hook_ctx *ctx = hook_arg; > > + if (ctx->set_variable) /* if variable should be set don't print all modes */ > + return 0; > + > if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height)) > return 0; > > @@ -132,31 +136,40 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), > grub_video_adapter_t adapter; > grub_video_driver_id_t id; > struct hook_ctx ctx; > - > - ctx.height = ctx.width = ctx.depth = 0; > + > + ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0; > + > if (argc) > { > + if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") - 1) == 0 ) grub_strcmp() is more appropriate here? > + ctx.set_variable = 1; > + else > + { > const char *ptr; > ptr = args[0]; > ctx.width = grub_strtoul (ptr, &ptr, 0); > if (grub_errno) > - return grub_errno; > + return grub_errno; There are white space issues in your patch. Please use GNU coding style. > if (*ptr != 'x') > - return grub_error (GRUB_ERR_BAD_ARGUMENT, > - N_("invalid video mode specification `%s'"), > - args[0]); > + return grub_error (GRUB_ERR_BAD_ARGUMENT, > + N_("invalid video mode specification `%s'"), > + args[0]); > ptr++; > ctx.height = grub_strtoul (ptr, &ptr, 0); > if (grub_errno) > - return grub_errno; > + return grub_errno; > if (*ptr == 'x') > - { > - ptr++; > - ctx.depth = grub_strtoul (ptr, &ptr, 0); > - if (grub_errno) > - return grub_errno; > - } > + { > + ptr++; > + ctx.depth = grub_strtoul (ptr, &ptr, 0); > + if (grub_errno) > + return grub_errno; > + } > + } > + > } > + > + > > #ifdef GRUB_MACHINE_PCBIOS > if (grub_strcmp (cmd->name, "vbeinfo") == 0) > @@ -164,20 +177,23 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), > #endif > > id = grub_video_get_driver_id (); > - > - grub_puts_ (N_("List of supported video modes:")); > - grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved")); > - > + if (!ctx.set_variable) > + { > +grub_puts_ (N_("List of supported video modes:")); > +grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved")); > + } > + > FOR_VIDEO_ADAPTERS (adapter) > { > struct grub_video_mode_info info; > struct grub_video_edid_info edid_info; > - > - grub_printf_ (N_("Adapter `%s':\n"), adapter->name); > + if (!ctx.set_variable) > + grub_printf_ (N_("Adapter `%s':\n"), adapter->name); > > if (!adapter->iterate) > { > - grub_puts_ (N_(" No info available")); > + if (!ctx.set_variable) > + grub_puts_ (N_(" No info available")); > continue; > } > > @@ -186,7 +202,18 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), > if (adapter->id == id) > { > if (grub_video_get_info (&info) == GRUB_ERR_NONE) > - ctx.current_mode = &info; > + { > + ctx.current_mode = &info; > + if (ctx.set_variable) > + { > + /* set grub env var to current mode */ > + char screen_wxh[20]; 20 is not sufficient (theoretically) because 32 bit unsigned integer can be as large as 4294967296 (10 digits). You might find grub_xasprintf() useful. > + unsigned int width = info.width; > + unsigned int height = info.height; > + grub_snprintf (screen_wxh, 20, "%ux%u", width, height); > + grub_env_set (args[1], screen_wxh); > + } > + } > else > /* Don't worry about errors. */ > grub_errno = GRUB_ERR_NONE; > @@ -236,19 +263,26 @@ GRUB_MOD_INIT(videoinfo) > /* TRANSLATORS: "x" has to be entered in, > like an identifier, so please don't > use better Unicode codepoints. */ > - N_("[WxH[xD]]"), > - N_("List available video modes. If " > - "resolution is given show only modes" > - " matching it.")); > + N_("[--set var | [WxH]xD]"), > + N_("Retrieve available video modes. " > + "--set is given, assign the currently" > + "active resolution to var. If --set " > + "is not provided the available video " > + "modes are listed. If resolution is " > + "given, show only matching modes.")); > + The docs in docs/grub.texi also needs updates. > #ifdef GRUB_MACHINE_PCBIOS > cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo, > /* TRANSLATORS: "x" has to be entered in, > like an identifier, so please don't > use better Unicode codepoints. */ > - N_("[WxH[xD]]"), > - N_("List available video modes. If " > - "resolution is given show only modes" > - " matching it.")); > + N_("[--set var | [WxH]xD]"), > + N_("Retrieve available video modes. " > + "--set is given, assign the currently" > + "active resolution to var. If --set " > + "is not provided the available video " > + "modes are listed. If resolution is " > + "given, show only matching modes.")); > #endif > } > Best Regards, Zhang Boyang