Skip to content

Commit 3a69e0c

Browse files
dedekindThomas Gleixner
authored andcommitted
[JFFS2] Fix JFFS2 [mc]time handling
From: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Artem B. Bityutskiy <dedekind@infradead.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 01d445f commit 3a69e0c

5 files changed

Lines changed: 37 additions & 17 deletions

File tree

‎fs/jffs2/dir.c‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* For licensing information, see the file 'LICENCE' in this directory.
99
*
10-
* $Id: dir.c,v 1.87 2005/07/17 11:13:46 dedekind Exp $
10+
* $Id: dir.c,v 1.88 2005/08/17 13:46:22 dedekind Exp $
1111
*
1212
*/
1313

@@ -232,11 +232,14 @@ static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
232232
struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
233233
struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode);
234234
int ret;
235+
uint32_t now = get_seconds();
235236

236237
ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
237-
dentry->d_name.len, dead_f);
238+
dentry->d_name.len, dead_f, now);
238239
if (dead_f->inocache)
239240
dentry->d_inode->i_nlink = dead_f->inocache->nlink;
241+
if (!ret)
242+
dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
240243
return ret;
241244
}
242245
/***********************************************************************/
@@ -249,6 +252,7 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
249252
struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
250253
int ret;
251254
uint8_t type;
255+
uint32_t now;
252256

253257
/* Don't let people make hard links to bad inodes. */
254258
if (!f->inocache)
@@ -261,13 +265,15 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
261265
type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
262266
if (!type) type = DT_REG;
263267

264-
ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len);
268+
now = get_seconds();
269+
ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now);
265270

266271
if (!ret) {
267272
down(&f->sem);
268273
old_dentry->d_inode->i_nlink = ++f->inocache->nlink;
269274
up(&f->sem);
270275
d_instantiate(dentry, old_dentry->d_inode);
276+
dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
271277
atomic_inc(&old_dentry->d_inode->i_count);
272278
}
273279
return ret;
@@ -716,6 +722,7 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
716722
struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
717723
struct jffs2_inode_info *victim_f = NULL;
718724
uint8_t type;
725+
uint32_t now;
719726

720727
/* The VFS will check for us and prevent trying to rename a
721728
* file over a directory and vice versa, but if it's a directory,
@@ -749,9 +756,10 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
749756
type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
750757
if (!type) type = DT_REG;
751758

759+
now = get_seconds();
752760
ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
753761
old_dentry->d_inode->i_ino, type,
754-
new_dentry->d_name.name, new_dentry->d_name.len);
762+
new_dentry->d_name.name, new_dentry->d_name.len, now);
755763

756764
if (ret)
757765
return ret;
@@ -775,7 +783,7 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
775783

776784
/* Unlink the original */
777785
ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
778-
old_dentry->d_name.name, old_dentry->d_name.len, NULL);
786+
old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
779787

780788
/* We don't touch inode->i_nlink */
781789

@@ -792,12 +800,15 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
792800
/* Might as well let the VFS know */
793801
d_instantiate(new_dentry, old_dentry->d_inode);
794802
atomic_inc(&old_dentry->d_inode->i_count);
803+
new_dir_i->i_mtime = new_dir_i->i_ctime = ITIME(now);
795804
return ret;
796805
}
797806

798807
if (S_ISDIR(old_dentry->d_inode->i_mode))
799808
old_dir_i->i_nlink--;
800809

810+
new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = ITIME(now);
811+
801812
return 0;
802813
}
803814

‎fs/jffs2/gc.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* For licensing information, see the file 'LICENCE' in this directory.
99
*
10-
* $Id: gc.c,v 1.152 2005/07/24 15:14:14 dedekind Exp $
10+
* $Id: gc.c,v 1.153 2005/08/17 13:46:22 dedekind Exp $
1111
*
1212
*/
1313

@@ -771,7 +771,12 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
771771
rd.pino = cpu_to_je32(f->inocache->ino);
772772
rd.version = cpu_to_je32(++f->highest_version);
773773
rd.ino = cpu_to_je32(fd->ino);
774-
rd.mctime = cpu_to_je32(max(JFFS2_F_I_MTIME(f), JFFS2_F_I_CTIME(f)));
774+
/* If the times on this inode were set by explicit utime() they can be different,
775+
so refrain from splatting them. */
776+
if (JFFS2_F_I_MTIME(f) == JFFS2_F_I_CTIME(f))
777+
rd.mctime = cpu_to_je32(JFFS2_F_I_MTIME(f));
778+
else
779+
rd.mctime = cpu_to_je32(0);
775780
rd.type = fd->type;
776781
rd.node_crc = cpu_to_je32(crc32(0, &rd, sizeof(rd)-8));
777782
rd.name_crc = cpu_to_je32(crc32(0, fd->name, rd.nsize));
@@ -883,6 +888,9 @@ static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct
883888
kfree(rd);
884889
}
885890

891+
/* FIXME: If we're deleting a dirent which contains the current mtime and ctime,
892+
we should update the metadata node with those times accordingly */
893+
886894
/* No need for it any more. Just mark it obsolete and remove it from the list */
887895
while (*fdp) {
888896
if ((*fdp) == fd) {

‎fs/jffs2/nodelist.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* For licensing information, see the file 'LICENCE' in this directory.
99
*
10-
* $Id: nodelist.h,v 1.137 2005/08/01 12:05:19 dedekind Exp $
10+
* $Id: nodelist.h,v 1.138 2005/08/17 13:46:23 dedekind Exp $
1111
*
1212
*/
1313

@@ -336,8 +336,8 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
336336
struct jffs2_raw_inode *ri, unsigned char *buf,
337337
uint32_t offset, uint32_t writelen, uint32_t *retlen);
338338
int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const char *name, int namelen);
339-
int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name, int namelen, struct jffs2_inode_info *dead_f);
340-
int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen);
339+
int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name, int namelen, struct jffs2_inode_info *dead_f, uint32_t time);
340+
int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen, uint32_t time);
341341

342342

343343
/* readinode.c */

‎fs/jffs2/readinode.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* For licensing information, see the file 'LICENCE' in this directory.
99
*
10-
* $Id: readinode.c,v 1.139 2005/08/04 11:41:31 dedekind Exp $
10+
* $Id: readinode.c,v 1.140 2005/08/17 13:46:23 dedekind Exp $
1111
*
1212
*/
1313

@@ -139,7 +139,7 @@ static inline int read_direntry(struct jffs2_sb_info *c, struct jffs2_raw_node_r
139139
fd->type = rd->type;
140140

141141
/* Pick out the mctime of the latest dirent */
142-
if(fd->version > *mctime_ver) {
142+
if(fd->version > *mctime_ver && je32_to_cpu(rd->mctime)) {
143143
*mctime_ver = fd->version;
144144
*latest_mctime = je32_to_cpu(rd->mctime);
145145
}

‎fs/jffs2/write.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* For licensing information, see the file 'LICENCE' in this directory.
99
*
10-
* $Id: write.c,v 1.94 2005/07/20 15:50:51 dedekind Exp $
10+
* $Id: write.c,v 1.95 2005/08/17 13:46:23 dedekind Exp $
1111
*
1212
*/
1313

@@ -533,7 +533,8 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
533533

534534

535535
int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
536-
const char *name, int namelen, struct jffs2_inode_info *dead_f)
536+
const char *name, int namelen, struct jffs2_inode_info *dead_f,
537+
uint32_t time)
537538
{
538539
struct jffs2_raw_dirent *rd;
539540
struct jffs2_full_dirent *fd;
@@ -565,7 +566,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
565566
rd->pino = cpu_to_je32(dir_f->inocache->ino);
566567
rd->version = cpu_to_je32(++dir_f->highest_version);
567568
rd->ino = cpu_to_je32(0);
568-
rd->mctime = cpu_to_je32(get_seconds());
569+
rd->mctime = cpu_to_je32(time);
569570
rd->nsize = namelen;
570571
rd->type = DT_UNKNOWN;
571572
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
@@ -646,7 +647,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
646647
}
647648

648649

649-
int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen)
650+
int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen, uint32_t time)
650651
{
651652
struct jffs2_raw_dirent *rd;
652653
struct jffs2_full_dirent *fd;
@@ -674,7 +675,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
674675
rd->pino = cpu_to_je32(dir_f->inocache->ino);
675676
rd->version = cpu_to_je32(++dir_f->highest_version);
676677
rd->ino = cpu_to_je32(ino);
677-
rd->mctime = cpu_to_je32(get_seconds());
678+
rd->mctime = cpu_to_je32(time);
678679
rd->nsize = namelen;
679680

680681
rd->type = type;

0 commit comments

Comments
 (0)