diff --git a/build/jam/images/HaikuImage b/build/jam/images/HaikuImage index 3dd454f25c..74bfa6daba 100644 --- a/build/jam/images/HaikuImage +++ b/build/jam/images/HaikuImage @@ -13,7 +13,7 @@ SYSTEM_BIN = [ FFilterByBuildFeatures diskimage draggers driveinfo dstcheck du dumpcatalog echo eject env error expand expr 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 hd head hey hostname id ident ifconfig install installsound iroster isvolume diff --git a/src/bin/Jamfile b/src/bin/Jamfile index aeb8a7646f..e2fb698fc4 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -35,6 +35,7 @@ StdBinCommands error.c fortune.c finddir.c + fstrim.cpp hd.c idestatus.c listarea.c diff --git a/src/bin/fstrim.cpp b/src/bin/fstrim.cpp new file mode 100644 index 0000000000..d5dda26dfe --- /dev/null +++ b/src/bin/fstrim.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT license. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + + +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 \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; +}