nilfs_sb_write() function does not see the return value of write()
system call, thus it may incur silent failure problem.

This fixes the issue and kills the following warning.

sb.c: In function ��nilfs_sb_write��:
sb.c:206: warning: ignoring return value of ��write��, declared with attribute 
warn_unused_result

Signed-off-by: Ryusuke Konishi <[email protected]>
---
 lib/sb.c                     |   15 +++++++++++----
 sbin/nilfs-tune/nilfs-tune.c |   10 +++++++---
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/lib/sb.c b/lib/sb.c
index 293cd6f..d93504c 100644
--- a/lib/sb.c
+++ b/lib/sb.c
@@ -171,7 +171,8 @@ int nilfs_sb_write(int devfd, struct nilfs_super_block 
*sbp, int mask)
 {
        __u64 offsets[2];
        struct nilfs_super_block *sbps[2];
-       int i;
+       ssize_t count;
+       int i, ret;
        __u32 crc;
 
        assert(devfd >= 0);
@@ -182,6 +183,7 @@ int nilfs_sb_write(int devfd, struct nilfs_super_block 
*sbp, int mask)
        if (__nilfs_sb_read(devfd, sbps, offsets))
                return -1;
 
+       ret = 0;
        for (i = 0; i < 2; i++) {
                if (!sbps[i])
                        continue;
@@ -202,12 +204,17 @@ int nilfs_sb_write(int devfd, struct nilfs_super_block 
*sbp, int mask)
 
                crc = nilfs_sb_check_sum(sbps[i]);
                sbps[i]->s_sum = cpu_to_le32(crc);
-               if (lseek(devfd, offsets[i], SEEK_SET) > 0)
-                       write(devfd, sbps[i], NILFS_MAX_SB_SIZE);
+               if (lseek(devfd, offsets[i], SEEK_SET) > 0) {
+                       count = write(devfd, sbps[i], NILFS_MAX_SB_SIZE);
+                       if (count < NILFS_MAX_SB_SIZE) {
+                               ret = -1;
+                               break;
+                       }
+               }
        }
 
        free(sbps[0]);
        free(sbps[1]);
 
-       return 0;
+       return ret;
 }
diff --git a/sbin/nilfs-tune/nilfs-tune.c b/sbin/nilfs-tune/nilfs-tune.c
index f9e46a1..f5d5d83 100644
--- a/sbin/nilfs-tune/nilfs-tune.c
+++ b/sbin/nilfs-tune/nilfs-tune.c
@@ -434,9 +434,13 @@ int modify_nilfs(char *device, struct nilfs_tune_options 
*opts)
        if (opts->mask & NILFS_SB_BLOCK_MAX)
                sbp->s_c_block_max = cpu_to_le32(opts->c_block_max);
 
-       if (opts->mask)
-               nilfs_sb_write(devfd, sbp, opts->mask);
-
+       if (opts->mask) {
+               if (nilfs_sb_write(devfd, sbp, opts->mask) < 0) {
+                       fprintf(stderr, "%s: cannot write super blocks\n",
+                               device);
+                       ret = EXIT_FAILURE;
+               }
+       }
        if (opts->display)
                show_nilfs_sb(sbp);
 
-- 
1.6.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to