Index: geom_part.c =================================================================== --- geom_part.c (revision 246183) +++ geom_part.c (working copy) @@ -90,6 +90,7 @@ static void gpart_print_error(const char *); static void gpart_backup(struct gctl_req *, unsigned int); static void gpart_restore(struct gctl_req *, unsigned int); +static void gpart_trim(struct gctl_req *, unsigned int); struct g_command PUBSYM(class_commands)[] = { { "add", 0, gpart_issue, { @@ -159,6 +160,9 @@ G_OPT_SENTINEL }, "[-l | -r] [-p] [geom ...]" }, + { "trim", 0, gpart_trim, G_NULL_OPTS, + "provider" + }, { "undo", 0, gpart_issue, G_NULL_OPTS, "geom" }, @@ -1279,3 +1283,22 @@ gctl_free(req); exit(status); } + +static void +gpart_trim(struct gctl_req *req, unsigned int fl __unused) +{ + const char *s; + int fd; + + if (gctl_get_int(req, "nargs") != 1) + errx(EXIT_FAILURE, "Invalid number of arguments."); + s = gctl_get_ascii(req, "arg0"); + if (s == NULL) + abort(); + fd = g_open(s, 1); + if (fd == -1) + err(EXIT_FAILURE, "Cannot open %s", s); + if (g_delete(fd, 0, g_mediasize(fd)) == -1) + err(EXIT_FAILURE, "g_delete call failed"); + g_close(fd); +} Index: gpart.8 =================================================================== --- gpart.8 (revision 246183) +++ gpart.8 (working copy) @@ -144,6 +144,10 @@ .Op Fl l | r .Op Fl p .Op Ar geom ... +.\" ==== TRIM ==== +.Nm +.Cm trim +.Ar provider .\" ==== UNDO ==== .Nm .Cm undo @@ -471,6 +475,15 @@ .It Fl r Show raw partition type instead of symbolic name. .El +.\" ==== TRIM ==== +.It Cm trim +Sends a BIO_DELETE request for the contents of the provider +.Ar provider . +Depending on the underlying storage device, this may may fill its blocks +with a constant value (0x00 or 0xFF), or may do nothing. Running this +command on a partition on an SSD device before deleting it may improve +performance, since the SSD can immediately reuse the blocks for subsequent +write requests. .\" ==== UNDO ==== .It Cm undo Revert any pending changes for geom