From b5737016254ef30ea60ef74a2c311224b6036881 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 27 Sep 2023 00:37:23 +0300 Subject: [PATCH] Sync: Add some argument parsing to sync(1) You can specify --block to make the program wait until sync is complete. --- userspace/sync/main.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/userspace/sync/main.cpp b/userspace/sync/main.cpp index 964b808f..2aa438bd 100644 --- a/userspace/sync/main.cpp +++ b/userspace/sync/main.cpp @@ -1,6 +1,29 @@ +#include +#include #include -int main() +void usage(int ret, char* cmd) { - sync(); + FILE* fout = (ret == 0) ? stdout : stderr; + fprintf(fout, "usage: %s [OPTION]...\n", cmd); + fprintf(fout, "Tells the kernel to start a disk sync as soon as possible\n"); + fprintf(fout, " -b, --block return only after sync is complete\n"); + fprintf(fout, " -h, --help show this message and exit\n"); + exit(ret); +} + +int main(int argc, char** argv) +{ + bool block = false; + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--block") == 0) + block = true; + else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) + usage(0, argv[0]); + else + usage(1, argv[0]); + } + syncsync(block); + return 0; }