1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 Red Hat, Inc.
12 static cmdinfo_t sync_range_cmd
;
19 " Trigger specific writeback commands on a range of the current file\n"
21 " With no options, the SYNC_FILE_RANGE_WRITE is implied.\n"
22 " -a -- wait for IO to finish after writing (SYNC_FILE_RANGE_WAIT_AFTER).\n"
23 " -b -- wait for IO to finish before writing (SYNC_FILE_RANGE_WAIT_BEFORE).\n"
24 " -w -- write dirty data in range (SYNC_FILE_RANGE_WRITE).\n"
33 off64_t offset
= 0, length
= 0;
35 size_t blocksize
, sectsize
;
37 while ((c
= getopt(argc
, argv
, "abw")) != EOF
) {
40 sync_mode
= SYNC_FILE_RANGE_WAIT_AFTER
;
43 sync_mode
= SYNC_FILE_RANGE_WAIT_BEFORE
;
46 sync_mode
= SYNC_FILE_RANGE_WRITE
;
49 return command_usage(&sync_range_cmd
);
53 /* default to just starting writeback on the range */
55 sync_mode
= SYNC_FILE_RANGE_WRITE
;
57 if (optind
!= argc
- 2)
58 return command_usage(&sync_range_cmd
);
59 init_cvtnum(&blocksize
, §size
);
60 offset
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
62 printf(_("non-numeric offset argument -- %s\n"),
67 length
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
69 printf(_("non-numeric length argument -- %s\n"),
74 if (sync_file_range(file
->fd
, offset
, length
, sync_mode
) < 0) {
75 perror("sync_file_range");
84 sync_range_cmd
.name
= "sync_range";
85 sync_range_cmd
.cfunc
= sync_range_f
;
86 sync_range_cmd
.argmin
= 2;
87 sync_range_cmd
.argmax
= -1;
88 sync_range_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
89 sync_range_cmd
.args
= _("[-abw] off len");
90 sync_range_cmd
.oneline
= _("Control writeback on a range of a file");
91 sync_range_cmd
.help
= sync_range_help
;
93 add_command(&sync_range_cmd
);