Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / misc / e4defrag.c
index fd2b626..c6c6f13 100644 (file)
@@ -169,13 +169,13 @@ static int        block_size;
 static int     extents_before_defrag;
 static int     extents_after_defrag;
 static int     mode_flag;
-static uid_t   current_uid;
-static unsigned long long      defraged_file_count;
-static unsigned long long      frag_files_before_defrag;
-static unsigned long long      frag_files_after_defrag;
-static unsigned long long      regular_count;
-static unsigned long long      succeed_cnt;
-static unsigned long long      total_count;
+static unsigned int    current_uid;
+static unsigned int    defraged_file_count;
+static unsigned int    frag_files_before_defrag;
+static unsigned int    frag_files_after_defrag;
+static unsigned int    regular_count;
+static unsigned int    succeed_cnt;
+static unsigned int    total_count;
 static __u8 log_groups_per_flex;
 static __u32 blocks_per_group;
 static __u32 feature_incompat;
@@ -441,7 +441,8 @@ static int defrag_fadvise(int fd, struct move_extent defrag_data,
                        offset += pagesize;
                        continue;
                }
-               if (posix_fadvise(fd, offset, pagesize, fadvise_flag) < 0) {
+               if ((errno = posix_fadvise(fd, offset,
+                                          pagesize, fadvise_flag)) != 0) {
                        if ((mode_flag & DETAIL) && flag) {
                                perror("\tFailed to fadvise");
                                flag = 0;
@@ -1055,6 +1056,8 @@ static int file_statistic(const char *file, const struct stat64 *buf,
        struct fiemap_extent_list *logical_list_head = NULL;
 
        defraged_file_count++;
+       if (defraged_file_count > total_count)
+               total_count = defraged_file_count;
 
        if (mode_flag & DETAIL) {
                if (total_count == 1 && regular_count == 1)
@@ -1421,6 +1424,8 @@ static int file_defrag(const char *file, const struct stat64 *buf,
        struct fiemap_extent_group      *orig_group_tmp = NULL;
 
        defraged_file_count++;
+       if (defraged_file_count > total_count)
+               total_count = defraged_file_count;
 
        if (mode_flag & DETAIL) {
                printf("[%u/%u]", defraged_file_count, total_count);
@@ -1912,9 +1917,9 @@ int main(int argc, char *argv[])
                        }
                        /* File tree walk */
                        nftw64(dir_name, file_defrag, FTW_OPEN_FD, flags);
-                       printf("\n\tSuccess:\t\t\t[ %llu/%llu ]\n",
-                              succeed_cnt, total_count);
-                       printf("\tFailure:\t\t\t[ %llu/%llu ]\n",
+                       printf("\n\tSuccess:\t\t\t[ %u/%u ]\n", succeed_cnt,
+                               total_count);
+                       printf("\tFailure:\t\t\t[ %u/%u ]\n",
                                total_count - succeed_cnt, total_count);
                        if (mode_flag & DETAIL) {
                                printf("\tTotal extents:\t\t\t%4d->%d\n",
@@ -1923,10 +1928,12 @@ int main(int argc, char *argv[])
                                printf("\tFragmented percentage:\t\t"
                                        "%3llu%%->%llu%%\n",
                                        !regular_count ? 0 :
-                                       (frag_files_before_defrag * 100) /
+                                       ((unsigned long long)
+                                       frag_files_before_defrag * 100) /
                                        regular_count,
                                        !regular_count ? 0 :
-                                       (frag_files_after_defrag * 100) /
+                                       ((unsigned long long)
+                                       frag_files_after_defrag * 100) /
                                        regular_count);
                        }
                        break;