Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F159228810
D31556.id93747.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D31556.id93747.diff
View Options
Index: usr.bin/Makefile
===================================================================
--- usr.bin/Makefile
+++ usr.bin/Makefile
@@ -43,6 +43,7 @@
find \
fmt \
fold \
+ fspacectl \
fstat \
fsync \
gcore \
Index: usr.bin/fspacectl/Makefile
===================================================================
--- /dev/null
+++ usr.bin/fspacectl/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+PROG= fspacectl
+LIBADD= util
+
+.include <bsd.prog.mk>
Index: usr.bin/fspacectl/Makefile.depend
===================================================================
--- /dev/null
+++ usr.bin/fspacectl/Makefile.depend
@@ -0,0 +1,17 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libutil
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
Index: usr.bin/fspacectl/fspacectl.1
===================================================================
--- /dev/null
+++ usr.bin/fspacectl/fspacectl.1
@@ -0,0 +1,107 @@
+.\"
+.\" Copyright (c) 2021 The FreeBSD Foundation
+.\"
+.\" This manual page was written by Ka Ho Ng <khng@FreeBSD.org>
+.\" under sponsorship from the FreeBSD Foundation.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd Aug 16, 2021
+.Dt FSPACECTL 1
+.Os
+.Sh NAME
+.Nm fspacectl
+.Nd perform space management in a file
+.Sh SYNOPSIS
+.Nm
+.Fl d
+.Bk -words
+.Oo
+.Fl o Xo
+.Sm off
+.Ar offset
+.Op Cm K | k | M | m | G | g | T | t
+.Sm on
+.Xc
+.Oc
+.Fl l Xo
+.Sm off
+.Ar length
+.Op Cm K | k | M | m | G | g | T | t
+.Sm on
+.Xc
+.Ek
+.Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility performs space management with the given offset and the length over a regular file given on the command-line.
+.Pp
+The following operations are supported and must be one of:
+.Bl -tag -width indent
+.It Fl d
+Zero a region in the specified file.
+If the underlying file system of the given file supports hole-punching,
+file system space deallocation may be performed in the operation region.
+.El
+.Pp
+The following options are available:
+.Bl -tag -width indent
+.It Fl o Ar offset
+The space management operation is performed at the given
+.Ar offset
+bytes in the file.
+If this option is not specified, the operation is performed at the beginning of the file.
+.It Fl l Ar length
+The length of the operation range in bytes. This option must always be specified.
+.El
+.Pp
+The
+.Ar offset
+and
+.Ar length
+arguments may be suffixed with one of
+.Cm K ,
+.Cm M ,
+.Cm G
+or
+.Cm T
+(either upper or lower case) to indicate a multiple of
+Kilobytes, Megabytes, Gigabytes or Terabytes
+respectively.
+.Sh SEE ALSO
+.Xr dd 1 ,
+.Xr truncate 1 ,
+.Xr fspacectl 2 ,
+.Xr fpathconf 2
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 14 .
+.Sh AUTHORS
+The
+.Nm
+utility was written by
+.An Ka Ho Ng Aq Mt khng@FreeBSD.org .
Index: usr.bin/fspacectl/fspacectl.c
===================================================================
--- /dev/null
+++ usr.bin/fspacectl/fspacectl.c
@@ -0,0 +1,116 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 The FreeBSD Foundation
+ *
+ * This software was developed by Ka Ho Ng <khng@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <libutil.h>
+
+static void usage(void);
+
+int
+main(int argc, char **argv)
+{
+ int fd;
+ bool do_dealloc;
+ int ch, error;
+ char *fname;
+ off_t offset, length;
+ uint64_t uol;
+ struct spacectl_range sr;
+
+ fd = -1;
+ do_dealloc = false;
+ error = 0;
+ offset = 0;
+ length = -1;
+ while ((ch = getopt(argc, argv, "do:l:")) != -1)
+ switch (ch) {
+ case 'd':
+ do_dealloc = true;
+ break;
+ case 'o':
+ if (expand_number(optarg, &uol) == -1 ||
+ (off_t)uol < 0)
+ errx(EXIT_FAILURE,
+ "invalid offset argument `%s'", optarg);
+
+ offset = uol;
+ break;
+ case 'l':
+ if (expand_number(optarg, &uol) == -1 ||
+ (off_t)uol < 0)
+ errx(EXIT_FAILURE,
+ "invalid length argument `%s'", optarg);
+
+ length = uol;
+ break;
+ default:
+ usage();
+ }
+
+ argv += optind;
+ argc -= optind;
+
+ if (do_dealloc == false || length == -1 || argc < 1)
+ usage();
+
+ fname = *argv;
+ if ((fd = open(fname, O_WRONLY)) == -1)
+ errx(EXIT_FAILURE, "%s", fname);
+
+ sr.r_len = length;
+ sr.r_offset = offset;
+ while ((error = fspacectl(fd, SPACECTL_DEALLOC, &sr, 0, &sr)) != -1 &&
+ sr.r_len != 0);
+ if (error == -1)
+ warn("%s", fname);
+ close(fd);
+
+ return error ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
+static void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: fspacectl -d [-o offset[K|k|M|m|G|g|T|t]] -l length[K|k|M|m|G|g|T|t] file\n");
+ exit(EXIT_FAILURE);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jun 12, 2:35 PM (10 h, 14 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33909720
Default Alt Text
D31556.id93747.diff (7 KB)
Attached To
Mode
D31556: truncate(1): Add hole-punching support
Attached
Detach File
Event Timeline
Log In to Comment