resize2fs: Print a warning message if the ftruncate system call fails
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>
diff --git a/resize/main.c b/resize/main.c
index 3de333e..6977d84 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -455,12 +455,17 @@
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);