From: krw Date: Tue, 7 Feb 2023 14:30:48 +0000 (+0000) Subject: Extend template parsing to allow "[mount point] *" as the specification for X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bc9d58e06a936fa798d4fc47e4b9e146557261e6;p=openbsd Extend template parsing to allow "[mount point] *" as the specification for putting the maximum available free space into a partition. Extend command line parsing to allow 'T-' as the specification to read the template file from stdin. Prompted by, feedback, testing and ok kn@ --- diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8 index 76648947c37..83319e98445 100644 --- a/sbin/disklabel/disklabel.8 +++ b/sbin/disklabel/disklabel.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: disklabel.8,v 1.151 2023/01/09 00:56:36 jsg Exp $ +.\" $OpenBSD: disklabel.8,v 1.152 2023/02/07 14:30:48 krw Exp $ .\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ .\" .\" Copyright (c) 1987, 1988, 1991, 1993 @@ -33,7 +33,7 @@ .\" .\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 .\" -.Dd $Mdocdate: January 9 2023 $ +.Dd $Mdocdate: February 7 2023 $ .Dt DISKLABEL 8 .Os .Sh NAME @@ -167,6 +167,11 @@ instead of using the builtin one. See .Sx AUTOMATIC DISK ALLOCATION below for the format. +If +.Ar file +is a single dash +.Pq Sq - , +the template is read from the standard input. .It Fl t Format the label as a .Xr disktab 5 @@ -540,9 +545,11 @@ the option. The template consists of one line per partition, each giving partition type or mount point, min-max size range, and percentage of disk, space-separated. -Max can be unlimited by specifying '*'. +Max can be unlimited by specifying +.Sq * . If max size and percentage of disk are omitted, the partition is -created with the exact min size. +created with the exact min size or unlimited if min is +.Sq * . .Bd -literal -offset indent / 250M swap 80M-256M 10% diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 6cc4dd9af59..a3e263f306d 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.401 2023/02/02 14:33:38 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.402 2023/02/07 14:30:48 krw Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -2097,7 +2097,9 @@ parse_autotable(char *filename) uint idx = 0, pctsum = 0; struct space_allocation *sa; - if ((cfile = fopen(filename, "r")) == NULL) + if (strcmp(filename, "-") == 0) + cfile = stdin; + else if ((cfile = fopen(filename, "r")) == NULL) err(1, "%s", filename); if ((alloc_table = calloc(1, sizeof(struct alloc_table))) == NULL) err(1, NULL); @@ -2206,6 +2208,12 @@ parse_sizerange(char *buf, u_int64_t *min, u_int64_t *max) char *p, *unit1 = NULL, *unit2 = NULL; double val1 = 0, val2 = 0; + if (strcmp(buf, "*") == 0) { + *min = 0; + *max = UINT64_MAX; + goto done; + } + if ((p = strchr(buf, '-')) != NULL) { p[0] = '\0'; p++; @@ -2230,6 +2238,7 @@ parse_sizerange(char *buf, u_int64_t *min, u_int64_t *max) } else if (*max == 0) *max = *min; + done: free(buf); return (0); }