-/* $OpenBSD: cmd.c,v 1.176 2023/04/10 19:44:43 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.177 2023/11/10 15:41:11 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
#include <sys/disklabel.h>
#include <err.h>
+#include <errno.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
int gsetpid(const int);
int setpid(const int, struct mbr *);
int parsepn(const char *);
+int parseflag(const char *, uint64_t *);
int ask_num(const char *, int, int, int);
int ask_pid(const int);
return pn;
}
+int
+parseflag(const char *flagstr, uint64_t *flagvalue)
+{
+ const char *errstr;
+ char *ep;
+ uint64_t val;
+
+ if (flagstr[0] == '0' && (flagstr[1] == 'x' || flagstr[1] == 'X')) {
+ errno = 0;
+ val = strtoull(flagstr, &ep, 16);
+ if (errno || ep == flagstr || *ep != '\0' ||
+ (gh.gh_sig != GPTSIGNATURE && val > 0xff)) {
+ printf("flag value is invalid: %s\n", flagstr);
+ return -1;
+ }
+ goto done;
+ }
+
+ if (gh.gh_sig == GPTSIGNATURE)
+ val = strtonum(flagstr, 0, INT64_MAX, &errstr);
+ else
+ val = strtonum(flagstr, 0, 0xff, &errstr);
+ if (errstr) {
+ printf("flag value is %s: %s\n", errstr, flagstr);
+ return -1;
+ }
+
+ done:
+ *flagvalue = val;
+ return 0;
+}
+
int
edit(const int pn, struct mbr *mbr)
{
Xflag(const char *args, struct mbr *mbr)
{
char lbuf[LINEBUFSZ];
- const char *errstr;
char *part, *flag;
- long long val = -1;
+ uint64_t val;
int i, pn;
if (strlcpy(lbuf, args, sizeof(lbuf)) >= sizeof(lbuf)) {
return CMD_CONT;
if (flag != NULL) {
- if (gh.gh_sig == GPTSIGNATURE)
- val = strtonum(flag, 0, INT64_MAX, &errstr);
- else
- val = strtonum(flag, 0, 0xff, &errstr);
- if (errstr) {
- printf("flag value is %s: %s.\n", errstr, flag);
+ if (parseflag(flag, &val) == -1)
return CMD_CONT;
- }
if (gh.gh_sig == GPTSIGNATURE)
gp[pn].gp_attrs = val;
else
-.\" $OpenBSD: fdisk.8,v 1.118 2023/05/07 13:03:03 krw Exp $
+.\" $OpenBSD: fdisk.8,v 1.119 2023/11/10 15:41:11 krw Exp $
.\"
.\"
.\" Copyright (c) 1997 Tobias Weingartner
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 7 2023 $
+.Dd $Mdocdate: November 10 2023 $
.Dt FDISK 8
.Os
.Sh NAME
.Sq *
causes the partition to be sized to use the remainder of the disk.
.It Cm flag Ar # Op Ar value
-Sets the partition entry's flag value.
+Set the partition's flag (MBR) or attribute (GPT) value.
+.Ar value
+can be a positive integer or a hex string.
+An MBR partition will accept values from 0 to 0xff.
+A GPT partition will accept values from 0 to 0xfffffffffffffff.
If
.Ar value
-is not provided the partition entry is flagged as being bootable
-and all other partition entries are flagged as not bootable.
-Partition entries flagged as bootable are printed with a
+is not provided the partition's bootable flag is set
+and all other partitions have their bootable flags reset.
+MBR partitions with the bootable flag set are printed with a
.Sq *
prefix.
-.Pp
-If
-.Ar value
-is provided the partition entry's flag value is set to
-.Ar value
-and no other partition entry is modified.
-A
-.Ar value
-of 0 is used to clear the bootable flag.
+GPT partitions with the bootable flag set display 'bootable' in
+their attributes list.
.It Cm update
Updates the MBR bootcode.
If a bootcode file is present (see