Whamcloud - gitweb
LU-13314 utils: fix lfs find time calculation margin
[fs/lustre-release.git] / lustre / utils / llverdev.c
index 1ebf72d..18f7eb5 100644 (file)
 #include <sys/time.h>
 #include <gnu/stubs.h>
 
-#ifdef HAVE_EXT2FS_EXT2FS_H
-#  include <ext2fs/ext2fs.h>
-#endif
-
 #define ONE_MB (1024 * 1024)
 #define ONE_GB (1024 * 1024 * 1024)
 #define HALF_MB (ONE_MB / 2)
@@ -110,22 +106,20 @@ static unsigned full = 1; /* flag to full check */
 static int error_count;                /* number of IO errors hit during run */
 static int isatty_flag;
 
-static struct option const longopts[] =
-{
-       { "chunksize", required_argument, 0, 'c' },
-       { "force", no_argument, 0, 'f' },
-       { "help", no_argument, 0, 'h' },
-       { "offset", required_argument, 0, 'o' },
-       { "partial", required_argument, 0, 'p' },
-       { "quiet", required_argument, 0, 'q' },
-       { "read", no_argument, 0, 'r' },
-       { "timestamp", required_argument, 0, 't' },
-       { "verbose", no_argument, 0, 'v' },
-       { "write", no_argument, 0, 'w' },
-       { "long", no_argument, 0, 'l' },
-       { "full", no_argument, 0, 'l' },
-       { 0, 0, 0, 0}
-};
+static struct option const long_opts[] = {
+       { .val = 'c',   .name = "chunksize",    .has_arg = required_argument },
+       { .val = 'f',   .name = "force",        .has_arg = no_argument },
+       { .val = 'h',   .name = "help",         .has_arg = no_argument },
+       { .val = 'l',   .name = "long",         .has_arg = no_argument },
+       { .val = 'l',   .name = "full",         .has_arg = no_argument },
+       { .val = 'o',   .name = "offset",       .has_arg = required_argument },
+       { .val = 'p',   .name = "partial",      .has_arg = required_argument },
+       { .val = 'q',   .name = "quiet",        .has_arg = required_argument },
+       { .val = 'r',   .name = "read",         .has_arg = no_argument },
+       { .val = 't',   .name = "timestamp",    .has_arg = required_argument },
+       { .val = 'v',   .name = "verbose",      .has_arg = no_argument },
+       { .val = 'w',   .name = "write",        .has_arg = no_argument },
+       { .name = NULL } };
 
 /*
  * Usage: displays help information, whenever user supply --help option in
@@ -159,23 +153,8 @@ void usage(int status)
  */
 static int open_dev(const char *devname, int mode)
 {
-       int     fd;
-#ifdef HAVE_EXT2FS_EXT2FS_H
-       int     mount_flags;
-       char    mountpt[80] = "";
-
-       if (ext2fs_check_mount_point(devname, &mount_flags, mountpt,
-                                    sizeof(mountpt))) {
-               fprintf(stderr, "%s: ext2fs_check_mount_point failed:%s",
-                       progname, strerror(errno));
-               exit(1);
-       }
-       if (mount_flags & EXT2_MF_MOUNTED){
-               fprintf(stderr, "%s: %s is already mounted\n", progname,
-                       devname);
-               exit(1);
-       }
-#endif
+       int fd;
+
        fd = open(devname, mode | O_EXCL | O_LARGEFILE);
        if (fd < 0) {
                fprintf(stderr, "%s: Open failed: %s",progname,strerror(errno));
@@ -184,25 +163,13 @@ static int open_dev(const char *devname, int mode)
        return fd;
 }
 
-#ifdef HAVE_BLKID_BLKID_H
-#include <blkid/blkid.h>
-#endif
 /*
  * sizeof_dev: Returns size of device in bytes
  */
-static loff_t sizeof_dev(int fd)
+static size_t sizeof_dev(int fd)
 {
-       loff_t numbytes;
+       size_t numbytes;
 
-#ifdef HAVE_BLKID_BLKID_H
-       numbytes = blkid_get_dev_size(fd);
-       if (numbytes <= 0) {
-               fprintf(stderr, "%s: blkid_get_dev_size(%s) failed",
-                       progname, devname);
-               return 1;
-       }
-       goto out;
-#else
 # if defined BLKGETSIZE64      /* in sys/mount.h */
        if (ioctl(fd, BLKGETSIZE64, &numbytes) >= 0)
                goto out;
@@ -228,7 +195,6 @@ static loff_t sizeof_dev(int fd)
        fprintf(stderr, "%s: unable to determine size of %s\n",
                progname, devname);
        return 0;
-#endif
 
 out:
        if (verbose)
@@ -520,14 +486,14 @@ int main(int argc, char **argv)
 
        progname = strrchr(argv[0], '/') == NULL ?
                argv[0] : strrchr(argv[0], '/') + 1;
-       while ((c = getopt_long(argc, argv, "c:fhlo:pqrt:vw", longopts,
+       while ((c = getopt_long(argc, argv, "c:fhlo:pqrt:vw", long_opts,
                                NULL)) != -1) {
                switch (c) {
                case 'c':
                        chunksize = (strtoul(optarg, NULL, 0) * ONE_MB);
                        if (!chunksize) {
-                               fprintf(stderr, "%s: chunk size value should be"
-                                       "nonzero and multiple of 1MB\n",
+                               fprintf(stderr,
+                                       "%s: chunk size value should be nonzero and multiple of 1MB\n",
                                        progname);
                                return -1;
                        }
@@ -585,10 +551,10 @@ int main(int argc, char **argv)
        if (!force && writeoption) {
                printf("%s: permanently overwrite all data on %s (yes/no)? ",
                       progname, devname);
-                if (scanf("%3s", yesno) == EOF && ferror(stdin)) {
-                        perror("reading from stdin");
-                        return -1;
-                }
+               if (scanf("%3s", yesno) == EOF && ferror(stdin)) {
+                       perror("reading from stdin");
+                       return -1;
+               }
                if (!(strcasecmp("yes", yesno) || strcasecmp("y", yesno))) {
                        printf("Not continuing due to '%s' response", yesno);
                        return 0;