Received: from list by lists.gnu.org with archive (Exim 4.71) id 1eOomV-0006ll-8y for mharc-grub-devel@gnu.org; Tue, 12 Dec 2017 12:55:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOomS-0006lS-FL for grub-devel@gnu.org; Tue, 12 Dec 2017 12:55:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOomN-00025y-Is for grub-devel@gnu.org; Tue, 12 Dec 2017 12:55:48 -0500 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:41777) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOomN-00025F-BJ for grub-devel@gnu.org; Tue, 12 Dec 2017 12:55:43 -0500 Received: by mail-pg0-x241.google.com with SMTP id o2so13912078pgc.8 for ; Tue, 12 Dec 2017 09:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=nLdC1IS/Xi0/+VR5r4sHsF4MX9O4q1vCjhwPApKUcu8=; b=r55fbbB9iFlUk6sFwiSfz/3Kkatkl0LUKzZC1PK2/bkWHQj5nP+E7CEKFw9R3IyU6F UjdEbk+MET5jpm7q7YkRdX2iT+qfzTt+3jfqKsm3HbcS0VgXY/oPTESN1lX7l7zoEzCR g4bojQPnMWXRi/zf/mFf12xUyK+8fgV7AkvP9KXYIZi0XNhb92DK1GPO38eF6kCdVn5t C2ZEG/g5a6cS3L2x5In76/Lgzh4Bgcd/Qb06rx2yBub5eFROHHt3/HeGU1j4Ozx82LHK +1RIm5QgKYZz/R+nSVZbDTBodQ2QCfahS3uEVuDKVJO9C6+t29IvVOBbXb2Xukn73Ihm GtjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=nLdC1IS/Xi0/+VR5r4sHsF4MX9O4q1vCjhwPApKUcu8=; b=GTxfk0TM+1uGaDTOIUpzzP6Cjw5aZ94xx8XLj3je4cbtLOJaDcYjPN65bY1gs06AYT gOgkPrCJfPyxxtKQUUvjKGg7TFAW2SNLGXW3laeUz9wd8ta4BTiW18bOyFsqnBe5AiOZ sRhaoCclpLVy0izStN/l/HQeKm/te80xmn0Nhkb45y4AaJJ4YPgKeBxpGUFXUR8yfBxW cJSxaNOiKuGyLQ0pfcB4WY1iNcyswP5Qe6szypWXGWQb7kLgrNRp+Y07r9Z44LNPiNgr 2kZz8lG825NK2yn7eeWNhcE454JEH2TWarjQMNLNXUuyEnU98WAUOpPCldl5bOKVHeRd roUQ== X-Gm-Message-State: AKGB3mJN769/BF3Y2oFUG7JMEU9HIOQokPrmFkUVqGJdMSWhp5ZoAgkO 5x7diLEBUuA12NxvEkAuMjCxYeRu X-Google-Smtp-Source: ACJfBosNNrmXAmymsaUsm3cmSpN3Z+/U4imo4D505mRLf/jobSybW4O6KD/u9YgzVtB6bvzBuTnZlw== X-Received: by 10.159.253.149 with SMTP id q21mr2973221pls.195.1513101341938; Tue, 12 Dec 2017 09:55:41 -0800 (PST) Received: from carlo-MacBookPro.endlessm-sf.com ([109.231.236.7]) by smtp.gmail.com with ESMTPSA id 67sm26637586pgg.50.2017.12.12.09.55.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 09:55:41 -0800 (PST) Sender: Carlo Caione From: Carlo Caione To: grub-devel@gnu.org, linux@endlessm.com Cc: Carlo Caione Subject: [PATCH] grub-core/commands/probe.c: Add bootable parameter Date: Tue, 12 Dec 2017 17:55:36 +0000 Message-Id: <20171212175536.29775-1-carlo@caione.org> X-Mailer: git-send-email 2.14.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Dec 2017 17:55:49 -0000 From: Carlo Caione Sometimes we are interested in checking whether an msdos partition has the boot flag set. Introduce a new parameter to the probe command to check this. Signed-off-by: Carlo Caione --- grub-core/commands/probe.c | 18 ++++++++++++++++++ grub-core/partmap/msdos.c | 1 + include/grub/partition.h | 3 +++ 3 files changed, 22 insertions(+) diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index cf2793e1d..22d1c5660 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -31,6 +31,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -45,6 +46,7 @@ static const struct grub_arg_option options[] = {"fs", 'f', 0, N_("Determine filesystem type."), 0, 0}, {"fs-uuid", 'u', 0, N_("Determine filesystem UUID."), 0, 0}, {"label", 'l', 0, N_("Determine filesystem label."), 0, 0}, + {"bootable", 'b', 0, N_("Determine if bootable / active flag is set."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -154,6 +156,22 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) grub_device_close (dev); return GRUB_ERR_NONE; } + if (state[6].set) + { + const char *val = "none"; + if (dev->disk && + dev->disk->partition && + dev->disk->partition->msdostype != GRUB_PC_PARTITION_TYPE_GPT_DISK && + grub_strcmp (dev->disk->partition->partmap->name, "msdos") == 0) + if (dev->disk->partition->flag & 0x80) + val = "bootable"; + if (state[0].set) + grub_env_set (state[0].arg, val); + else + grub_printf ("%s", val); + grub_device_close (dev); + return GRUB_ERR_NONE; + } grub_device_close (dev); return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target"); } diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 6d4b455a1..6c13c6b8b 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -180,6 +180,7 @@ grub_partition_msdos_iterate (grub_disk_t disk, p.len = grub_le_to_cpu32 (e->length) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); p.msdostype = e->type; + p.flag = e->flag; grub_dprintf ("partition", "partition %d: flag 0x%x, type 0x%x, start 0x%llx, len 0x%llx\n", diff --git a/include/grub/partition.h b/include/grub/partition.h index 7adb7ec6e..d450415e0 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -87,6 +87,9 @@ struct grub_partition /* The type of partition whne it's on MSDOS. Used for embedding detection. */ grub_uint8_t msdostype; + + /* Partition flag */ + grub_uint8_t flag; }; grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk, -- 2.14.1