~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to sys-utils/fstrim.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <fcntl.h>
33
33
#include <limits.h>
34
34
#include <getopt.h>
35
 
#include <err.h>
36
 
#include <error.h>
37
 
#include <errno.h>
38
35
 
39
36
#include <sys/ioctl.h>
40
37
#include <sys/stat.h>
42
39
 
43
40
#include "nls.h"
44
41
#include "strutils.h"
 
42
#include "c.h"
45
43
 
46
44
#ifndef FITRIM
47
45
struct fstrim_range {
54
52
 
55
53
static void __attribute__((__noreturn__)) usage(FILE *out)
56
54
{
57
 
        fprintf(out, _("Usage: %s [options] <mount point>\n\nOptions:\n"),
58
 
                        program_invocation_short_name);
 
55
        fputs(_("\nUsage:\n"), out);
 
56
        fprintf(out,
 
57
              _(" %s [options] <mount point>\n"), program_invocation_short_name);
59
58
 
60
 
        fprintf(out, _(
61
 
                " -h, --help          this help\n"
 
59
        fputs(_("\nOptions:\n"), out);
 
60
        fputs(_(" -h, --help          this help\n"
62
61
                " -o, --offset <num>  offset in bytes to discard from\n"
63
62
                " -l, --length <num>  length of bytes to discard from the offset\n"
64
63
                " -m, --minimum <num> minimum extent length to discard\n"
65
 
                " -v, --verbose       print number of discarded bytes\n"));
 
64
                " -v, --verbose       print number of discarded bytes\n"), out);
66
65
 
67
 
        fprintf(out, _("\nFor more information see fstrim(1).\n"));
 
66
        fputs(_("\nFor more information see fstrim(8).\n"), out);
68
67
 
69
68
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
70
69
}
76
75
        struct fstrim_range range;
77
76
        struct stat sb;
78
77
 
79
 
        struct option longopts[] = {
 
78
        static const struct option longopts[] = {
80
79
            { "help",      0, 0, 'h' },
81
80
            { "offset",    1, 0, 'o' },
82
81
            { "length",    1, 0, 'l' },
98
97
                        usage(stdout);
99
98
                        break;
100
99
                case 'l':
101
 
                        if (strtosize(optarg, &range.len))
 
100
                        if (strtosize(optarg, (uint64_t *) &range.len))
102
101
                                errx(EXIT_FAILURE,
103
102
                                     _("failed to parse length: %s"), optarg);
104
103
                        break;
105
104
                case 'o':
106
 
                        if (strtosize(optarg, &range.start))
 
105
                        if (strtosize(optarg, (uint64_t *) &range.start))
107
106
                                errx(EXIT_FAILURE,
108
107
                                     _("failed to parse offset: %s"), optarg);
109
108
                        break;
110
109
                case 'm':
111
 
                        if (strtosize(optarg, &range.minlen))
 
110
                        if (strtosize(optarg, (uint64_t *) &range.minlen))
112
111
                                errx(EXIT_FAILURE,
113
 
                                     _("failed to parse minimal extend length: %s"),
 
112
                                     _("failed to parse minimum extent length: %s"),
114
113
                                     optarg);
115
114
                        break;
116
115
                case 'v':
141
140
        if (fd < 0)
142
141
                err(EXIT_FAILURE, _("%s: open failed"), path);
143
142
 
144
 
        if (ioctl(fd, FITRIM, &range)) {
145
 
                int errsv = errno;
146
 
                close(fd);
147
 
                error(EXIT_FAILURE, errsv, _("%s: FITRIM ioctl failed"), path);
148
 
        }
 
143
        if (ioctl(fd, FITRIM, &range))
 
144
                err(EXIT_FAILURE, _("%s: FITRIM ioctl failed"), path);
 
145
 
149
146
        if (verbose)
150
 
                printf(_("%s: %" PRIu64 " bytes was trimmed\n"),
151
 
                                                path, range.len);
 
147
                /* TRANSLATORS: The standard value here is a very large number. */
 
148
                printf(_("%s: %" PRIu64 " bytes were trimmed\n"),
 
149
                                                path, (uint64_t) range.len);
152
150
        close(fd);
153
151
        return EXIT_SUCCESS;
154
152
}