Whamcloud - gitweb
resize2fs: Print a warning message if the ftruncate system call fails
authorTheodore Ts'o <tytso@mit.edu>
Wed, 22 Apr 2009 19:10:36 +0000 (15:10 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 22 Apr 2009 19:10:36 +0000 (15:10 -0400)
Resize2fs will attempt to truncate an image file of a filesystem down
to size for the convenience of the system administrator.  If the
truncate operation fails, print a warning message.  This also avoids a
gcc warning message.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
resize/main.c

index 3de333e..6977d84 100644 (file)
@@ -455,12 +455,17 @@ int main (int argc, char ** argv)
        if ((st_buf.st_size > new_file_size) &&
            (fd > 0)) {
 #ifdef HAVE_FTRUNCATE64
-               ftruncate64(fd, new_file_size);
+               retval = ftruncate64(fd, new_file_size);
 #else
+               retval = 0;
                /* Only truncate if new_file_size doesn't overflow off_t */
                if (((off_t) new_file_size) == new_file_size)
-                       ftruncate(fd, (off_t) new_file_size);
+                       retval = ftruncate(fd, (off_t) new_file_size);
 #endif
+               if (retval)
+                       com_err(program_name, retval,
+                               _("while trying to truncate %s"),
+                               device_name);
        }
        if (fd > 0)
                close(fd);