Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / utils / lfs.c
index 8d8d0d8..8772c5a 100644 (file)
@@ -214,9 +214,9 @@ static int lfs_setstripe(int argc, char **argv)
                 stripe_count_arg = argv[4];
                 optind = 4;
         } else {
+                optind = 0;
                 while ((c = getopt_long(argc, argv, "c:di:s:",
-                                                long_opts, NULL)) >= 0) 
-                {
+                                                long_opts, NULL)) >= 0) {
                         switch (c) {
                         case 0:
                                 /* Long options. */
@@ -362,6 +362,7 @@ static int lfs_find(int argc, char **argv)
 
         time(&t);
 
+        optind = 0;
         while ((c = getopt_long_only(argc, argv, "-A:C:D:M:n:PpO:qrs:t:v",
                                      long_opts, NULL)) >= 0) {
                 xtime = NULL;
@@ -736,7 +737,8 @@ static int showdf(char *mntdir, struct obd_statfs *stat,
         long long avail, used, total;
         double ratio = 0;
         char *suffix = "KMGTPEZY";
-        char tbuf[10], ubuf[10], abuf[10], rbuf[10];
+        /* Note if we have >2^64 bytes/fs these buffers will need to be grown */
+        char tbuf[20], ubuf[20], abuf[20], rbuf[20];
 
         if (!uuid || !stat)
                 return -EINVAL;
@@ -891,7 +893,7 @@ static int lfs_df(int argc, char **argv)
         FILE *fp;
         char *path = NULL;
         struct mntent *mnt = NULL;
-        char mntdir[PATH_MAX] = {'\0'};
+        char *mntdir = NULL;
         int ishow = 0, cooked = 0;
         int c, rc = 0;
 
@@ -918,10 +920,19 @@ static int lfs_df(int argc, char **argv)
                         argv[0], MOUNTED, strerror(errno));
                 return rc;
         }
+
+        if ((mntdir = malloc(PATH_MAX)) == NULL) {
+                fprintf(stderr, "error: cannot allocate %d bytes\n",
+                        PATH_MAX);
+                return -ENOMEM;
+        }
+        memset(mntdir, 0, PATH_MAX);
+
         if (path) {
-                rc = path2mnt(path, fp, mntdir, sizeof(mntdir));
+                rc = path2mnt(path, fp, mntdir, PATH_MAX);
                 if (rc) {
                         endmntent(fp);
+                        free(mntdir);
                         return rc;
                 }
 
@@ -942,6 +953,7 @@ static int lfs_df(int argc, char **argv)
                 endmntent(fp);
         }
 
+        free(mntdir);
         return rc;
 }
 
@@ -1083,6 +1095,7 @@ static int lfs_quotachown(int argc, char **argv)
         int c,rc;
         int flag = 0;
 
+        optind = 0;
         while ((c = getopt(argc, argv, "i")) != -1) {
                 switch (c) {
                 case 'i':