Added fstrim command.

Later, there should be a service that runs this from time to time for all
devices that support it.

Conflicts:
	build/jam/HaikuImage
This commit is contained in:
Axel Dörfler
2013-11-07 19:02:53 +01:00
parent 29a8450843
commit a352b43896
3 changed files with 83 additions and 1 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ SYSTEM_BIN = [ FFilterByBuildFeatures
diskimage draggers driveinfo dstcheck du dumpcatalog diskimage draggers driveinfo dstcheck du dumpcatalog
echo eject env error expand expr echo eject env error expand expr
factor false fdinfo ffm filepanel find finddir findpaths FirstBootPrompt fmt factor false fdinfo ffm filepanel find finddir findpaths FirstBootPrompt fmt
fold fortune frcode ftp ftpd funzip fwcontrol@x86 fold fortune frcode fstrim ftp ftpd funzip fwcontrol@x86
gawk gdb@x86 getlimits groupadd groupdel groupmod groups gzip gzexe gawk gdb@x86 getlimits groupadd groupdel groupmod groups gzip gzexe
hd head hey hostname hd head hey hostname
id ident ifconfig <bin>install installsound iroster isvolume id ident ifconfig <bin>install installsound iroster isvolume
+1
View File
@@ -35,6 +35,7 @@ StdBinCommands
error.c error.c
fortune.c fortune.c
finddir.c finddir.c
fstrim.cpp
hd.c hd.c
idestatus.c idestatus.c
listarea.c listarea.c
+81
View File
@@ -0,0 +1,81 @@
/*
* Copyright 2013, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT license.
*/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Drivers.h>
#include <AutoDeleter.h>
static struct option const kLongOptions[] = {
{"help", no_argument, 0, 'h'},
{NULL}
};
extern const char *__progname;
static const char *kProgramName = __progname;
void
usage(int returnValue)
{
fprintf(stderr, "Usage: %s <path-to-mounted-file-system>\n", kProgramName);
exit(returnValue);
}
int
main(int argc, char** argv)
{
int c;
while ((c = getopt_long(argc, argv, "h", kLongOptions, NULL)) != -1) {
switch (c) {
case 0:
break;
case 'h':
usage(0);
break;
default:
usage(1);
break;
}
}
if (argc - optind < 1)
usage(1);
const char* path = argv[optind++];
int fd = open(path, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "%s: Could not access path: %s\n", kProgramName,
strerror(errno));
return EXIT_FAILURE;
}
FileDescriptorCloser closer(fd);
fs_trim_data trimData;
trimData.offset = 0;
trimData.size = OFF_MAX;
trimData.trimmed_size = 0;
if (ioctl(fd, B_TRIM_DEVICE, &trimData, sizeof(fs_trim_data)) != 0) {
fprintf(stderr, "%s: Trimming failed: %s\n", kProgramName,
strerror(errno));
return EXIT_FAILURE;
}
printf("Trimmed %lld bytes from device.\n", trimData.trimmed_size);
return EXIT_SUCCESS;
}