Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/gpt - automatically sync the wedge information unless -...
details: https://anonhg.NetBSD.org/src/rev/0946e7dfaef8
branches: trunk
changeset: 341943:0946e7dfaef8
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 30 19:59:34 2015 +0000
description:
- automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
diffstat:
sbin/gpt/Makefile | 4 +-
sbin/gpt/add.c | 9 +-
sbin/gpt/gpt.8 | 59 +++++++-------
sbin/gpt/gpt.c | 190 +++--------------------------------------------
sbin/gpt/gpt.h | 2 +-
sbin/gpt/main.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
sbin/gpt/resize.c | 8 +-
7 files changed, 268 insertions(+), 217 deletions(-)
diffs (truncated from 636 to 300 lines):
diff -r 8024a711a040 -r 0946e7dfaef8 sbin/gpt/Makefile
--- a/sbin/gpt/Makefile Mon Nov 30 16:33:00 2015 +0000
+++ b/sbin/gpt/Makefile Mon Nov 30 19:59:34 2015 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.15 2015/11/29 15:32:46 christos Exp $
+# $NetBSD: Makefile,v 1.16 2015/11/30 19:59:34 christos Exp $
# $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $
PROG= gpt
SRCS= add.c biosboot.c create.c destroy.c gpt.c header.c label.c map.c \
- migrate.c recover.c remove.c resize.c resizedisk.c \
+ main.c migrate.c recover.c remove.c resize.c resizedisk.c \
set.c show.c type.c unset.c gpt_uuid.c
MAN= gpt.8
diff -r 8024a711a040 -r 0946e7dfaef8 sbin/gpt/add.c
--- a/sbin/gpt/add.c Mon Nov 30 16:33:00 2015 +0000
+++ b/sbin/gpt/add.c Mon Nov 30 19:59:34 2015 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: add.c,v 1.28 2015/11/29 00:14:46 christos Exp $");
+__RCSID("$NetBSD: add.c,v 1.29 2015/11/30 19:59:34 christos Exp $");
#endif
#include <sys/types.h>
@@ -180,10 +180,9 @@
gpt_write(fd, lbt);
gpt_write(fd, tpg);
- printf("Partition %d added, use:\n", i + 1);
- printf("\tdkctl %s addwedge <wedgename> %" PRIu64 " %" PRIu64
- " <type>\n", device_arg, map->map_start, map->map_size);
- printf("to create a wedge for it\n");
+ printf("Partition %d added on %s: ", i + 1, device_arg);
+ printf("%s %" PRIu64 " %" PRIu64 "\n", type, map->map_start,
+ map->map_size);
}
int
diff -r 8024a711a040 -r 0946e7dfaef8 sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8 Mon Nov 30 16:33:00 2015 +0000
+++ b/sbin/gpt/gpt.8 Mon Nov 30 19:59:34 2015 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.37 2015/11/03 02:19:24 jnemeth Exp $
+.\" $NetBSD: gpt.8,v 1.38 2015/11/30 19:59:34 christos Exp $
.\"
.\" Copyright (c) 2002 Marcel Moolenaar
.\" All rights reserved.
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
.\"
-.Dd November 2, 2015
+.Dd November 30, 2015
.Dt GPT 8
.Os
.Sh NAME
@@ -34,7 +34,10 @@
.Nd GUID partition table maintenance utility
.Sh SYNOPSIS
.Nm
-.Op Ar general_options
+.Op Fl mnprqv
+.Op Fl m Ar mediasize
+.Op Fl p Ar partitions
+.Op Fl s Ar sectorsize
.Ar command
.Op Ar command_options
.Ar device ...
@@ -66,44 +69,44 @@
change the behaviour that is applicable to all commands.
Not all commands use all default settings, so some general options may not
have an effect on all commands.
-.Pp
-The
-.Fl m Ar mediasize
-option overrides the default media size for the device (obtained
+.Bl -tag -width XXXX
+.It Fl m Ar mediasize
+Override the default media size for the device (obtained
from the kernel if possible) or defaulting to the file size for
plain files.
-.Pp
-The
-.Fl p Ar partitions
-option allows the user to change the number of partitions the GPT can
+.It Fl n
+Don't update the wedge information that
+.Nm
+changed.
+You need to use the
+.Xr dkctl 8
+command manually update the device's wedge configuration if you do that.
+.It Fl p Ar partitions
+Change the default number of partitions the GPT can
accommodate.
This is used whenever a new GPT is created.
By default, the
.Nm
utility will create space for 128 partitions (or 32 sectors of 512 bytes).
-.Pp
-The
-.Fl r
-option causes the
+.It Fl r
+Open the device for reading only.
.Nm
-utility to open the device for reading only.
Currently this option is primarily useful for the
.Ic show
-command, but the intent
-is to use it to implement dry-run behaviour.
-.Pp
-The
-.Fl s Ar sectorsize
-option overrides the default sector size for the device (obtained
+command, but the intent is to use it to implement dry-run behaviour.
+.It Fl q
+Don't print error messages.
+This is not implemented completely yet.
+.It Fl s Ar sectorsize
+Override the default sector size for the device (obtained
from the kernel if possible) or
.Dv 512
for plain files.
-.Pp
-The
-.Fl v
-option controls the verbosity level.
+.It Fl v
+Controls the verbosity level.
The level increases with every occurrence of this option.
There is no formalized definition of the different levels yet.
+.El
.Ss Commands
.Bl -tag -width indent
.\" ==== add ====
@@ -585,9 +588,6 @@
3907029135 32 Sec GPT table
3907029167 1 Sec GPT header
nas# gpt add -s 10486224 -t swap -i 1 wd3
-Partition added, use:
- dkctl rwd3d addwedge dk<N> 34 10486224 <type>
-to create a wedge for it
nas# gpt label -i 1 -l swap_1 wd3
parition 1 on rwd3d labeled swap_1
nas# gpt show wd3
@@ -612,6 +612,7 @@
.Ed
.Sh SEE ALSO
.Xr boot 8 ,
+.Xr dkctl 8 ,
.Xr fdisk 8 ,
.Xr installboot 8 ,
.Xr mount 8 ,
diff -r 8024a711a040 -r 0946e7dfaef8 sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c Mon Nov 30 16:33:00 2015 +0000
+++ b/sbin/gpt/gpt.c Mon Nov 30 19:59:34 2015 +0000
@@ -35,7 +35,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: gpt.c,v 1.45 2015/11/29 14:03:35 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.46 2015/11/30 19:59:34 christos Exp $");
#endif
#include <sys/param.h>
@@ -68,7 +68,9 @@
u_int parts;
u_int secsz;
-int readonly, verbose, quiet;
+int readonly, verbose, quiet, nosync;
+
+static int modified;
static uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
@@ -269,10 +271,11 @@
count = map->map_size * secsz;
ofs = map->map_start * secsz;
- if (lseek(fd, ofs, SEEK_SET) == ofs &&
- write(fd, map->map_data, count) == (ssize_t)count)
- return (0);
- return (-1);
+ if (lseek(fd, ofs, SEEK_SET) != ofs ||
+ write(fd, map->map_data, count) != (ssize_t)count)
+ return -1;
+ modified = 1;
+ return 0;
}
static int
@@ -569,6 +572,12 @@
void
gpt_close(int fd)
{
+ int bits;
+
+ if (modified && !nosync)
+ if (ioctl(fd, DIOCMWEDGES, &bits) == -1)
+ warn("Can't update wedge information");
+
/* XXX post processing? */
close(fd);
}
@@ -583,172 +592,3 @@
va_end(ap);
printf("\n");
}
-
-static struct {
- int (*fptr)(int, char *[]);
- const char *name;
-} cmdsw[] = {
- { cmd_add, "add" },
-#ifndef HAVE_NBTOOL_CONFIG_H
- { cmd_backup, "backup" },
-#endif
- { cmd_biosboot, "biosboot" },
- { cmd_create, "create" },
- { cmd_destroy, "destroy" },
- { cmd_header, "header" },
- { NULL, "help" },
- { cmd_label, "label" },
- { cmd_migrate, "migrate" },
- { cmd_recover, "recover" },
- { cmd_remove, "remove" },
- { NULL, "rename" },
- { cmd_resize, "resize" },
- { cmd_resizedisk, "resizedisk" },
-#ifndef HAVE_NBTOOL_CONFIG_H
- { cmd_restore, "restore" },
-#endif
- { cmd_set, "set" },
- { cmd_show, "show" },
- { cmd_type, "type" },
- { cmd_unset, "unset" },
- { NULL, "verify" },
- { NULL, NULL }
-};
-
-__dead static void
-usage(void)
-{
- extern const char addmsg1[], addmsg2[], biosbootmsg[];
- extern const char createmsg[], destroymsg[], headermsg[], labelmsg1[];
- extern const char labelmsg2[], labelmsg3[], migratemsg[], recovermsg[];
- extern const char removemsg1[], removemsg2[], resizemsg[];
- extern const char resizediskmsg[], setmsg[], showmsg[], typemsg1[];
- extern const char typemsg2[], typemsg3[], unsetmsg[];
-#ifndef HAVE_NBTOOL_CONFIG_H
- extern const char backupmsg[], restoremsg[];
-#endif
- const char *p = getprogname();
- const char *f =
- "[-rv] [-m <mediasize>] [-p <partitionnum>] [-s <sectorsize>]";
-
- fprintf(stderr,
- "Usage: %s %s <command> [<args>]\n", p, f);
- fprintf(stderr,
- "Commands:\n"
-#ifndef HAVE_NBTOOL_CONFIG_H
- " %s\n"
- " %s\n"
-#endif
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n"
- " %s\n",
- addmsg1, addmsg2,
-#ifndef HAVE_NBTOOL_CONFIG_H
- backupmsg,
-#endif
- biosbootmsg, createmsg, destroymsg,
- headermsg, labelmsg1, labelmsg2, labelmsg3,
- migratemsg, recovermsg,
- removemsg1, removemsg2,
- resizemsg, resizediskmsg,
-#ifndef HAVE_NBTOOL_CONFIG_H
Home |
Main Index |
Thread Index |
Old Index