mirror of git://git.suckless.org/ubase
Add blkdiscard(8)
This commit is contained in:
parent
4f5837147a
commit
604b66ae8b
1
Makefile
1
Makefile
|
@ -37,6 +37,7 @@ LIBUTILSRC = \
|
|||
LIB = $(LIBUTIL)
|
||||
|
||||
BIN = \
|
||||
blkdiscard \
|
||||
chvt \
|
||||
clear \
|
||||
ctrlaltdel \
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
.Dd July 2, 2018
|
||||
.Dt BLKDISCARD 8
|
||||
.Os ubase
|
||||
.Sh NAME
|
||||
.Nm blkdiscard
|
||||
.Nd discard sectors on a device
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ar device
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is used to discard all device sectors on solid-state devices.
|
|
@ -0,0 +1,48 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define OFFSET_IDX 0
|
||||
#define LENGTH_IDX 1
|
||||
|
||||
#define BLKDISCARD _IO(0x12, 119)
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
eprintf("usage: %s device\n", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
uint64_t range[2];
|
||||
int fd;
|
||||
|
||||
ARGBEGIN {
|
||||
default:
|
||||
usage();
|
||||
} ARGEND
|
||||
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
fd = open(argv[0], O_RDWR);
|
||||
if (fd < 0)
|
||||
eprintf("open: %s:", argv[0]);
|
||||
range[OFFSET_IDX] = 0;
|
||||
if (ioctl(fd, BLKGETSIZE64, &range[LENGTH_IDX]) < 0)
|
||||
eprintf("BLKGETSIZE64: %s:", argv[0]);
|
||||
if (ioctl(fd, BLKDISCARD, range) < 0)
|
||||
eprintf("BLKDISCARD: %s:", argv[0]);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue