diff options
author | Arnd Bergmann <arnd@arndb.de> | 2018-07-13 10:47:16 -0400 |
---|---|---|
committer | Boris Brezillon <boris.brezillon@bootlin.com> | 2018-07-18 10:43:58 -0400 |
commit | c4592b9c37889c2850b0edadcff063d5097f1cb9 (patch) | |
tree | 928bc9e3fb77afd7c99e739e5b1a144c6888afde | |
parent | 39675caa06e77547cf0692f854dce015e1b5c36b (diff) |
jffs2: use 64-bit intermediate timestamps
The VFS now uses timespec64 timestamps consistently, but jffs2 still
converts them to 32-bit numbers on the storage medium. As the helper
functions for the conversion (get_seconds() and timespec_to_timespec64())
are now deprecated, let's change them over to the more modern
replacements.
This keeps the traditional interpretation of those values, where
the on-disk 32-bit numbers are taken to be negative numbers, i.e.
dates before 1970, on 32-bit machines, but future numbers past 2038
on 64-bit machines.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
-rw-r--r-- | fs/jffs2/dir.c | 32 | ||||
-rw-r--r-- | fs/jffs2/file.c | 6 | ||||
-rw-r--r-- | fs/jffs2/fs.c | 12 | ||||
-rw-r--r-- | fs/jffs2/os-linux.h | 3 |
4 files changed, 27 insertions, 26 deletions
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c index b2944f9218f7..f20cff1194bb 100644 --- a/fs/jffs2/dir.c +++ b/fs/jffs2/dir.c | |||
@@ -201,7 +201,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, | |||
201 | if (ret) | 201 | if (ret) |
202 | goto fail; | 202 | goto fail; |
203 | 203 | ||
204 | dir_i->i_mtime = dir_i->i_ctime = timespec_to_timespec64(ITIME(je32_to_cpu(ri->ctime))); | 204 | dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(ri->ctime)); |
205 | 205 | ||
206 | jffs2_free_raw_inode(ri); | 206 | jffs2_free_raw_inode(ri); |
207 | 207 | ||
@@ -227,14 +227,14 @@ static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry) | |||
227 | struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); | 227 | struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); |
228 | struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(d_inode(dentry)); | 228 | struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(d_inode(dentry)); |
229 | int ret; | 229 | int ret; |
230 | uint32_t now = get_seconds(); | 230 | uint32_t now = JFFS2_NOW(); |
231 | 231 | ||
232 | ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, | 232 | ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, |
233 | dentry->d_name.len, dead_f, now); | 233 | dentry->d_name.len, dead_f, now); |
234 | if (dead_f->inocache) | 234 | if (dead_f->inocache) |
235 | set_nlink(d_inode(dentry), dead_f->inocache->pino_nlink); | 235 | set_nlink(d_inode(dentry), dead_f->inocache->pino_nlink); |
236 | if (!ret) | 236 | if (!ret) |
237 | dir_i->i_mtime = dir_i->i_ctime = timespec_to_timespec64(ITIME(now)); | 237 | dir_i->i_mtime = dir_i->i_ctime = ITIME(now); |
238 | return ret; | 238 | return ret; |
239 | } | 239 | } |
240 | /***********************************************************************/ | 240 | /***********************************************************************/ |
@@ -260,7 +260,7 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de | |||
260 | type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12; | 260 | type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12; |
261 | if (!type) type = DT_REG; | 261 | if (!type) type = DT_REG; |
262 | 262 | ||
263 | now = get_seconds(); | 263 | now = JFFS2_NOW(); |
264 | ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now); | 264 | ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now); |
265 | 265 | ||
266 | if (!ret) { | 266 | if (!ret) { |
@@ -268,7 +268,7 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de | |||
268 | set_nlink(d_inode(old_dentry), ++f->inocache->pino_nlink); | 268 | set_nlink(d_inode(old_dentry), ++f->inocache->pino_nlink); |
269 | mutex_unlock(&f->sem); | 269 | mutex_unlock(&f->sem); |
270 | d_instantiate(dentry, d_inode(old_dentry)); | 270 | d_instantiate(dentry, d_inode(old_dentry)); |
271 | dir_i->i_mtime = dir_i->i_ctime = timespec_to_timespec64(ITIME(now)); | 271 | dir_i->i_mtime = dir_i->i_ctime = ITIME(now); |
272 | ihold(d_inode(old_dentry)); | 272 | ihold(d_inode(old_dentry)); |
273 | } | 273 | } |
274 | return ret; | 274 | return ret; |
@@ -400,7 +400,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char | |||
400 | rd->pino = cpu_to_je32(dir_i->i_ino); | 400 | rd->pino = cpu_to_je32(dir_i->i_ino); |
401 | rd->version = cpu_to_je32(++dir_f->highest_version); | 401 | rd->version = cpu_to_je32(++dir_f->highest_version); |
402 | rd->ino = cpu_to_je32(inode->i_ino); | 402 | rd->ino = cpu_to_je32(inode->i_ino); |
403 | rd->mctime = cpu_to_je32(get_seconds()); | 403 | rd->mctime = cpu_to_je32(JFFS2_NOW()); |
404 | rd->nsize = namelen; | 404 | rd->nsize = namelen; |
405 | rd->type = DT_LNK; | 405 | rd->type = DT_LNK; |
406 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); | 406 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); |
@@ -418,7 +418,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char | |||
418 | goto fail; | 418 | goto fail; |
419 | } | 419 | } |
420 | 420 | ||
421 | dir_i->i_mtime = dir_i->i_ctime = timespec_to_timespec64(ITIME(je32_to_cpu(rd->mctime))); | 421 | dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime)); |
422 | 422 | ||
423 | jffs2_free_raw_dirent(rd); | 423 | jffs2_free_raw_dirent(rd); |
424 | 424 | ||
@@ -543,7 +543,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, umode_t mode | |||
543 | rd->pino = cpu_to_je32(dir_i->i_ino); | 543 | rd->pino = cpu_to_je32(dir_i->i_ino); |
544 | rd->version = cpu_to_je32(++dir_f->highest_version); | 544 | rd->version = cpu_to_je32(++dir_f->highest_version); |
545 | rd->ino = cpu_to_je32(inode->i_ino); | 545 | rd->ino = cpu_to_je32(inode->i_ino); |
546 | rd->mctime = cpu_to_je32(get_seconds()); | 546 | rd->mctime = cpu_to_je32(JFFS2_NOW()); |
547 | rd->nsize = namelen; | 547 | rd->nsize = namelen; |
548 | rd->type = DT_DIR; | 548 | rd->type = DT_DIR; |
549 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); | 549 | rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); |
@@ -561,7 +561,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, umode_t mode | |||
561 | goto fail; | 561 | goto fail; |
562 | } | 562 | } |
563 | 563 | ||
564 | dir_i->i_mtime = dir_i->i_ctime = timespec_to_timespec64(ITIME(je32_to_cpu(rd->mctime))); | 564 | dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime)); |
565 | inc_nlink(dir_i); | 565 | inc_nlink(dir_i); |
566 | 566 | ||
567 | jffs2_free_raw_dirent(rd); | 567 | jffs2_free_raw_dirent(rd); |
@@ -588,7 +588,7 @@ static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry) | |||
588 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(dentry)); | 588 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(dentry)); |
589 | struct jffs2_full_dirent *fd; | 589 | struct jffs2_full_dirent *fd; |
590 | int ret; | 590 | int ret; |
591 | uint32_t now = get_seconds(); | 591 | uint32_t now = JFFS2_NOW(); |
592 | 592 | ||
593 | for (fd = f->dents ; fd; fd = fd->next) { | 593 | for (fd = f->dents ; fd; fd = fd->next) { |
594 | if (fd->ino) | 594 | if (fd->ino) |
@@ -598,7 +598,7 @@ static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry) | |||
598 | ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, | 598 | ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, |
599 | dentry->d_name.len, f, now); | 599 | dentry->d_name.len, f, now); |
600 | if (!ret) { | 600 | if (!ret) { |
601 | dir_i->i_mtime = dir_i->i_ctime = timespec_to_timespec64(ITIME(now)); | 601 | dir_i->i_mtime = dir_i->i_ctime = ITIME(now); |
602 | clear_nlink(d_inode(dentry)); | 602 | clear_nlink(d_inode(dentry)); |
603 | drop_nlink(dir_i); | 603 | drop_nlink(dir_i); |
604 | } | 604 | } |
@@ -712,7 +712,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode | |||
712 | rd->pino = cpu_to_je32(dir_i->i_ino); | 712 | rd->pino = cpu_to_je32(dir_i->i_ino); |
713 | rd->version = cpu_to_je32(++dir_f->highest_version); | 713 | rd->version = cpu_to_je32(++dir_f->highest_version); |
714 | rd->ino = cpu_to_je32(inode->i_ino); | 714 | rd->ino = cpu_to_je32(inode->i_ino); |
715 | rd->mctime = cpu_to_je32(get_seconds()); | 715 | rd->mctime = cpu_to_je32(JFFS2_NOW()); |
716 | rd->nsize = namelen; | 716 | rd->nsize = namelen; |
717 | 717 | ||
718 | /* XXX: This is ugly. */ | 718 | /* XXX: This is ugly. */ |
@@ -733,7 +733,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode | |||
733 | goto fail; | 733 | goto fail; |
734 | } | 734 | } |
735 | 735 | ||
736 | dir_i->i_mtime = dir_i->i_ctime = timespec_to_timespec64(ITIME(je32_to_cpu(rd->mctime))); | 736 | dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime)); |
737 | 737 | ||
738 | jffs2_free_raw_dirent(rd); | 738 | jffs2_free_raw_dirent(rd); |
739 | 739 | ||
@@ -797,7 +797,7 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry, | |||
797 | type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12; | 797 | type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12; |
798 | if (!type) type = DT_REG; | 798 | if (!type) type = DT_REG; |
799 | 799 | ||
800 | now = get_seconds(); | 800 | now = JFFS2_NOW(); |
801 | ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i), | 801 | ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i), |
802 | d_inode(old_dentry)->i_ino, type, | 802 | d_inode(old_dentry)->i_ino, type, |
803 | new_dentry->d_name.name, new_dentry->d_name.len, now); | 803 | new_dentry->d_name.name, new_dentry->d_name.len, now); |
@@ -853,14 +853,14 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry, | |||
853 | * caller won't do it on its own since we are returning an error. | 853 | * caller won't do it on its own since we are returning an error. |
854 | */ | 854 | */ |
855 | d_invalidate(new_dentry); | 855 | d_invalidate(new_dentry); |
856 | new_dir_i->i_mtime = new_dir_i->i_ctime = timespec_to_timespec64(ITIME(now)); | 856 | new_dir_i->i_mtime = new_dir_i->i_ctime = ITIME(now); |
857 | return ret; | 857 | return ret; |
858 | } | 858 | } |
859 | 859 | ||
860 | if (d_is_dir(old_dentry)) | 860 | if (d_is_dir(old_dentry)) |
861 | drop_nlink(old_dir_i); | 861 | drop_nlink(old_dir_i); |
862 | 862 | ||
863 | new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = timespec_to_timespec64(ITIME(now)); | 863 | new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = ITIME(now); |
864 | 864 | ||
865 | return 0; | 865 | return 0; |
866 | } | 866 | } |
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index 481afd4c2e1a..7d8654a1472e 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c | |||
@@ -175,7 +175,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping, | |||
175 | ri.uid = cpu_to_je16(i_uid_read(inode)); | 175 | ri.uid = cpu_to_je16(i_uid_read(inode)); |
176 | ri.gid = cpu_to_je16(i_gid_read(inode)); | 176 | ri.gid = cpu_to_je16(i_gid_read(inode)); |
177 | ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs)); | 177 | ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs)); |
178 | ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds()); | 178 | ri.atime = ri.ctime = ri.mtime = cpu_to_je32(JFFS2_NOW()); |
179 | ri.offset = cpu_to_je32(inode->i_size); | 179 | ri.offset = cpu_to_je32(inode->i_size); |
180 | ri.dsize = cpu_to_je32(pageofs - inode->i_size); | 180 | ri.dsize = cpu_to_je32(pageofs - inode->i_size); |
181 | ri.csize = cpu_to_je32(0); | 181 | ri.csize = cpu_to_je32(0); |
@@ -283,7 +283,7 @@ static int jffs2_write_end(struct file *filp, struct address_space *mapping, | |||
283 | ri->uid = cpu_to_je16(i_uid_read(inode)); | 283 | ri->uid = cpu_to_je16(i_uid_read(inode)); |
284 | ri->gid = cpu_to_je16(i_gid_read(inode)); | 284 | ri->gid = cpu_to_je16(i_gid_read(inode)); |
285 | ri->isize = cpu_to_je32((uint32_t)inode->i_size); | 285 | ri->isize = cpu_to_je32((uint32_t)inode->i_size); |
286 | ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds()); | 286 | ri->atime = ri->ctime = ri->mtime = cpu_to_je32(JFFS2_NOW()); |
287 | 287 | ||
288 | /* In 2.4, it was already kmapped by generic_file_write(). Doesn't | 288 | /* In 2.4, it was already kmapped by generic_file_write(). Doesn't |
289 | hurt to do it again. The alternative is ifdefs, which are ugly. */ | 289 | hurt to do it again. The alternative is ifdefs, which are ugly. */ |
@@ -308,7 +308,7 @@ static int jffs2_write_end(struct file *filp, struct address_space *mapping, | |||
308 | inode->i_size = pos + writtenlen; | 308 | inode->i_size = pos + writtenlen; |
309 | inode->i_blocks = (inode->i_size + 511) >> 9; | 309 | inode->i_blocks = (inode->i_size + 511) >> 9; |
310 | 310 | ||
311 | inode->i_ctime = inode->i_mtime = timespec_to_timespec64(ITIME(je32_to_cpu(ri->ctime))); | 311 | inode->i_ctime = inode->i_mtime = ITIME(je32_to_cpu(ri->ctime)); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | 314 | ||
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 0ecfb8ea38cd..eab04eca95a3 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c | |||
@@ -146,9 +146,9 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr) | |||
146 | return PTR_ERR(new_metadata); | 146 | return PTR_ERR(new_metadata); |
147 | } | 147 | } |
148 | /* It worked. Update the inode */ | 148 | /* It worked. Update the inode */ |
149 | inode->i_atime = timespec_to_timespec64(ITIME(je32_to_cpu(ri->atime))); | 149 | inode->i_atime = ITIME(je32_to_cpu(ri->atime)); |
150 | inode->i_ctime = timespec_to_timespec64(ITIME(je32_to_cpu(ri->ctime))); | 150 | inode->i_ctime = ITIME(je32_to_cpu(ri->ctime)); |
151 | inode->i_mtime = timespec_to_timespec64(ITIME(je32_to_cpu(ri->mtime))); | 151 | inode->i_mtime = ITIME(je32_to_cpu(ri->mtime)); |
152 | inode->i_mode = jemode_to_cpu(ri->mode); | 152 | inode->i_mode = jemode_to_cpu(ri->mode); |
153 | i_uid_write(inode, je16_to_cpu(ri->uid)); | 153 | i_uid_write(inode, je16_to_cpu(ri->uid)); |
154 | i_gid_write(inode, je16_to_cpu(ri->gid)); | 154 | i_gid_write(inode, je16_to_cpu(ri->gid)); |
@@ -280,9 +280,9 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino) | |||
280 | i_uid_write(inode, je16_to_cpu(latest_node.uid)); | 280 | i_uid_write(inode, je16_to_cpu(latest_node.uid)); |
281 | i_gid_write(inode, je16_to_cpu(latest_node.gid)); | 281 | i_gid_write(inode, je16_to_cpu(latest_node.gid)); |
282 | inode->i_size = je32_to_cpu(latest_node.isize); | 282 | inode->i_size = je32_to_cpu(latest_node.isize); |
283 | inode->i_atime = timespec_to_timespec64(ITIME(je32_to_cpu(latest_node.atime))); | 283 | inode->i_atime = ITIME(je32_to_cpu(latest_node.atime)); |
284 | inode->i_mtime = timespec_to_timespec64(ITIME(je32_to_cpu(latest_node.mtime))); | 284 | inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime)); |
285 | inode->i_ctime = timespec_to_timespec64(ITIME(je32_to_cpu(latest_node.ctime))); | 285 | inode->i_ctime = ITIME(je32_to_cpu(latest_node.ctime)); |
286 | 286 | ||
287 | set_nlink(inode, f->inocache->pino_nlink); | 287 | set_nlink(inode, f->inocache->pino_nlink); |
288 | 288 | ||
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h index c2fbec19c616..acbe1f722f2d 100644 --- a/fs/jffs2/os-linux.h +++ b/fs/jffs2/os-linux.h | |||
@@ -31,7 +31,8 @@ struct kvec; | |||
31 | #define JFFS2_F_I_GID(f) (i_gid_read(OFNI_EDONI_2SFFJ(f))) | 31 | #define JFFS2_F_I_GID(f) (i_gid_read(OFNI_EDONI_2SFFJ(f))) |
32 | #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev) | 32 | #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev) |
33 | 33 | ||
34 | #define ITIME(sec) ((struct timespec){sec, 0}) | 34 | #define ITIME(sec) ((struct timespec64){(int32_t)sec, 0}) |
35 | #define JFFS2_NOW() (ktime_get_real_seconds()) | ||
35 | #define I_SEC(tv) ((tv).tv_sec) | 36 | #define I_SEC(tv) ((tv).tv_sec) |
36 | #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime.tv_sec) | 37 | #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime.tv_sec) |
37 | #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime.tv_sec) | 38 | #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime.tv_sec) |