#define HAVE_FID 1
+static __inline__ int
+platform_discard_blocks(int fd, off64_t start, off64_t end)
+{
+ return 0;
+}
+
#endif /* __XFS_DARWIN_H__ */
memcpy(dst, src, sizeof(uuid_t));
}
+static __inline__ int
+platform_discard_blocks(int fd, off64_t start, off64_t end)
+{
+ return 0;
+}
+
#endif /* __XFS_FREEBSD_H__ */
memcpy(dst, src, sizeof(uuid_t));
}
+static __inline__ int
+platform_discard_blocks(int fd, off64_t start, off64_t end)
+{
+ return 0;
+}
+
static __inline__ char * strsep(char **s, const char *ct)
{
char *sbegin = *s, *end;
uuid_copy(*dst, *src);
}
+#ifndef BLKDISCARD
+#define BLKDISCARD _IO(0x12,119)
+#endif
+
+static __inline__ int
+platform_discard_blocks(int fd, off64_t start, off64_t end)
+{
+ __uint64_t range[2] = { start, end };
+
+ if (ioctl(fd, BLKDISCARD, &range) < 0)
+ return errno;
+ return 0;
+}
+
#if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ <= 1))
# define constpp const char * const *
#else
.I label
] [
.B \-N
+] [
+.B \-K
]
.I device
.SH DESCRIPTION
.B \-N
Causes the file system parameters to be printed out without really
creating the file system.
+.TP
+.B \-K
+Do not attempt to discard blocks at mkfs time.
.SH SEE ALSO
.BR xfs (5),
.BR mkfs (8),
free(buf);
}
+static void
+discard_blocks(dev_t dev, __uint64_t nsectors)
+{
+ int fd;
+
+ /*
+ * We intentionally ignore errors from the discard ioctl. It is
+ * not necessary for the mkfs functionality but just an optimization.
+ */
+ fd = libxfs_device_to_fd(dev);
+ if (fd > 0)
+ platform_discard_blocks(fd, 0, nsectors << 9);
+}
+
int
main(
int argc,
int nvflag;
int nci;
int Nflag;
+ int discard = 1;
char *p;
char *protofile;
char *protostring;
xi.isdirect = LIBXFS_DIRECT;
xi.isreadonly = LIBXFS_EXCLUSIVELY;
- while ((c = getopt(argc, argv, "b:d:i:l:L:n:Np:qr:s:CfV")) != EOF) {
+ while ((c = getopt(argc, argv, "b:d:i:l:L:n:KNp:qr:s:CfV")) != EOF) {
switch (c) {
case 'C':
case 'f':
case 'N':
Nflag = 1;
break;
+ case 'K':
+ discard = 0;
+ break;
case 'p':
if (protofile)
respec('p', NULL, 0);
}
}
+ if (discard) {
+ discard_blocks(xi.ddev, xi.dsize);
+ if (xi.rtdev)
+ discard_blocks(xi.rtdev, xi.rtsize);
+ if (xi.logdev && xi.logdev != xi.ddev)
+ discard_blocks(xi.logdev, xi.logBBsize);
+ }
+
if (!liflag && !ldflag)
loginternal = xi.logdev == 0;
if (xi.logname)