Skip to content

Commit 1595358

Browse files
committed
[JFFS2] Improve getdents vs. f_pos handling on NOR flash.
Commit a491486 started obliterating dirents directly on the medium, when jffs2_can_mark_obsolete(). Removing them immediately from the f->dents list, however, screws up handling of f_pos within a directory -- because the offset is equivalent to the number of entries through the list we are, and the existence of deletion dirents served to provide 'placeholders' for unlinked entries. Now, 'rm -r' doesn't even manage to unlink everything in the directory. Revert to keeping 'deletion' dirents in the list, at least in memory even though we no longer write anything to the medium. Spotted, debugged and mostly fixed by Joakim Tjernlund Signed-off-by: David Woodhouse <dwmw2@infradead.org>
1 parent d10a39d commit 1595358

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

‎fs/jffs2/nodelist.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new
3232
if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) {
3333
/* Duplicate. Free one */
3434
if (new->version < (*prev)->version) {
35-
dbg_dentlist("Eep! Marking new dirent node is obsolete, old is \"%s\", ino #%u\n",
35+
dbg_dentlist("Eep! Marking new dirent node obsolete, old is \"%s\", ino #%u\n",
3636
(*prev)->name, (*prev)->ino);
3737
jffs2_mark_node_obsolete(c, new->raw);
3838
jffs2_free_full_dirent(new);
3939
} else {
40-
dbg_dentlist("marking old dirent \"%s\", ino #%u bsolete\n",
40+
dbg_dentlist("marking old dirent \"%s\", ino #%u obsolete\n",
4141
(*prev)->name, (*prev)->ino);
4242
new->next = (*prev)->next;
43-
jffs2_mark_node_obsolete(c, ((*prev)->raw));
43+
/* It may have been a 'placeholder' deletion dirent,
44+
if jffs2_can_mark_obsolete() (see jffs2_do_unlink()) */
45+
if ((*prev)->raw)
46+
jffs2_mark_node_obsolete(c, ((*prev)->raw));
4447
jffs2_free_full_dirent(*prev);
4548
*prev = new;
4649
}

‎fs/jffs2/write.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -582,26 +582,28 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
582582
jffs2_add_fd_to_list(c, fd, &dir_f->dents);
583583
up(&dir_f->sem);
584584
} else {
585-
struct jffs2_full_dirent **prev = &dir_f->dents;
585+
struct jffs2_full_dirent *fd = dir_f->dents;
586586
uint32_t nhash = full_name_hash(name, namelen);
587587

588588
/* We don't actually want to reserve any space, but we do
589589
want to be holding the alloc_sem when we write to flash */
590590
down(&c->alloc_sem);
591591
down(&dir_f->sem);
592592

593-
while ((*prev) && (*prev)->nhash <= nhash) {
594-
if ((*prev)->nhash == nhash &&
595-
!memcmp((*prev)->name, name, namelen) &&
596-
!(*prev)->name[namelen]) {
597-
struct jffs2_full_dirent *this = *prev;
593+
for (fd = dir_f->dents; fd; fd = fd->next) {
594+
if (fd->nhash == nhash &&
595+
!memcmp(fd->name, name, namelen) &&
596+
!fd->name[namelen]) {
598597

599598
D1(printk(KERN_DEBUG "Marking old dirent node (ino #%u) @%08x obsolete\n",
600-
this->ino, ref_offset(this->raw)));
601-
602-
*prev = this->next;
603-
jffs2_mark_node_obsolete(c, (this->raw));
604-
jffs2_free_full_dirent(this);
599+
fd->ino, ref_offset(fd->raw)));
600+
jffs2_mark_node_obsolete(c, fd->raw);
601+
/* We don't want to remove it from the list immediately,
602+
because that screws up getdents()/seek() semantics even
603+
more than they're screwed already. Turn it into a
604+
node-less deletion dirent instead -- a placeholder */
605+
fd->raw = NULL;
606+
fd->ino = 0;
605607
break;
606608
}
607609
prev = &((*prev)->next);
@@ -630,7 +632,8 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
630632
D1(printk(KERN_DEBUG "Removing deletion dirent for \"%s\" from dir ino #%u\n",
631633
fd->name, dead_f->inocache->ino));
632634
}
633-
jffs2_mark_node_obsolete(c, fd->raw);
635+
if (fd->raw)
636+
jffs2_mark_node_obsolete(c, fd->raw);
634637
jffs2_free_full_dirent(fd);
635638
}
636639
}

0 commit comments

Comments
 (0)