2 * Copyright 2013, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT license.
17 #include <AutoDeleter.h>
20 static struct option
const kLongOptions
[] = {
21 {"help", no_argument
, 0, 'h'},
26 extern const char *__progname
;
27 static const char *kProgramName
= __progname
;
31 usage(int returnValue
)
33 fprintf(stderr
, "Usage: %s <path-to-mounted-file-system>\n", kProgramName
);
39 main(int argc
, char** argv
)
42 while ((c
= getopt_long(argc
, argv
, "h", kLongOptions
, NULL
)) != -1) {
55 if (argc
- optind
< 1)
57 const char* path
= argv
[optind
++];
59 int fd
= open(path
, O_RDONLY
);
61 fprintf(stderr
, "%s: Could not access path: %s\n", kProgramName
,
66 FileDescriptorCloser
closer(fd
);
68 fs_trim_data trimData
;
69 trimData
.range_count
= 1;
70 trimData
.ranges
[0].offset
= 0;
71 trimData
.ranges
[0].size
= UINT64_MAX
;
72 trimData
.trimmed_size
= 0;
74 if (ioctl(fd
, B_TRIM_DEVICE
, &trimData
, sizeof(fs_trim_data
)) != 0) {
75 fprintf(stderr
, "%s: Trimming failed: %s\n", kProgramName
,
80 printf("Trimmed %" B_PRIu64
" bytes from device.\n", trimData
.trimmed_size
);