From: Evgeniy Ivanov Date: Fri, 15 Jul 2011 14:21:05 +0000 (+0000) Subject: Fix time modification on truncate() X-Git-Tag: v3.2.0~456 X-Git-Url: http://zhaoyanbai.com/repos/icons/jhe061.png?a=commitdiff_plain;h=255ae85b1ea2a42d0df32f3326e03f8201efc46b;p=minix.git Fix time modification on truncate() POSIX truncate specification says "Upon successful completion, if the *file size is changed*, this function shall mark for update the st_ctime and st_mtime fields of the file." This patch prevents changing of the date fields when the size stays the same. --- diff --git a/servers/ext2/link.c b/servers/ext2/link.c index 2cf634b1b..4da39513d 100644 --- a/servers/ext2/link.c +++ b/servers/ext2/link.c @@ -563,6 +563,8 @@ off_t newsize; /* inode must become this size */ return(EINVAL); if (newsize > rip->i_sp->s_max_size) /* don't let inode grow too big */ return(EFBIG); + if (rip->i_size == newsize) + return(OK); /* Free the actual space if truncating. */ if (newsize < rip->i_size) { diff --git a/servers/mfs/link.c b/servers/mfs/link.c index f43e2e945..580988e2c 100644 --- a/servers/mfs/link.c +++ b/servers/mfs/link.c @@ -525,17 +525,19 @@ off_t newsize; /* inode must become this size */ file_type = rip->i_mode & I_TYPE; /* check to see if file is special */ if (file_type == I_CHAR_SPECIAL || file_type == I_BLOCK_SPECIAL) return(EINVAL); - if(newsize > rip->i_sp->s_max_size) /* don't let inode grow too big */ + if (rip->i_size == newsize) + return(OK); + if (newsize > rip->i_sp->s_max_size) /* don't let inode grow too big */ return(EFBIG); /* Free the actual space if truncating. */ - if(newsize < rip->i_size) { + if (newsize < rip->i_size) { if ((r = freesp_inode(rip, newsize, rip->i_size)) != OK) return(r); } /* Clear the rest of the last zone if expanding. */ - if(newsize > rip->i_size) clear_zone(rip, rip->i_size, 0); + if (newsize > rip->i_size) clear_zone(rip, rip->i_size, 0); /* Next correct the inode size. */ rip->i_size = newsize; diff --git a/test/test16.c b/test/test16.c index ac5a1e40d..033bdcff0 100644 --- a/test/test16.c +++ b/test/test16.c @@ -204,6 +204,15 @@ void test16a() if (unlink("T16.i1") != 0) e(84); if (unlink("T16.j") != 0) e(85); if (unlink("T16.k") != 0) e(86); + + /* Test the times for truncate. */ + if (system("echo 1 > T16.l") != 0) e(87); + stat("T16.l", &s); + get_times("T16.l", &a, &c, &m); + sleep(1); + truncate("T16.l", s.st_size); + get_times("T16.l", &ta, &tc, &tm); + if (a != ta || c != tc || m != tm) e(88); } void get_times(name, a, c, m)