Commit 15953580 authored by David Woodhouse's avatar David Woodhouse

[JFFS2] Improve getdents vs. f_pos handling on NOR flash.

Commit a491486a 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: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent d10a39d1
...@@ -32,15 +32,18 @@ void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new ...@@ -32,15 +32,18 @@ void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new
if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) { if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) {
/* Duplicate. Free one */ /* Duplicate. Free one */
if (new->version < (*prev)->version) { if (new->version < (*prev)->version) {
dbg_dentlist("Eep! Marking new dirent node is obsolete, old is \"%s\", ino #%u\n", dbg_dentlist("Eep! Marking new dirent node obsolete, old is \"%s\", ino #%u\n",
(*prev)->name, (*prev)->ino); (*prev)->name, (*prev)->ino);
jffs2_mark_node_obsolete(c, new->raw); jffs2_mark_node_obsolete(c, new->raw);
jffs2_free_full_dirent(new); jffs2_free_full_dirent(new);
} else { } else {
dbg_dentlist("marking old dirent \"%s\", ino #%u bsolete\n", dbg_dentlist("marking old dirent \"%s\", ino #%u obsolete\n",
(*prev)->name, (*prev)->ino); (*prev)->name, (*prev)->ino);
new->next = (*prev)->next; new->next = (*prev)->next;
jffs2_mark_node_obsolete(c, ((*prev)->raw)); /* It may have been a 'placeholder' deletion dirent,
if jffs2_can_mark_obsolete() (see jffs2_do_unlink()) */
if ((*prev)->raw)
jffs2_mark_node_obsolete(c, ((*prev)->raw));
jffs2_free_full_dirent(*prev); jffs2_free_full_dirent(*prev);
*prev = new; *prev = new;
} }
......
...@@ -582,7 +582,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, ...@@ -582,7 +582,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
jffs2_add_fd_to_list(c, fd, &dir_f->dents); jffs2_add_fd_to_list(c, fd, &dir_f->dents);
up(&dir_f->sem); up(&dir_f->sem);
} else { } else {
struct jffs2_full_dirent **prev = &dir_f->dents; struct jffs2_full_dirent *fd = dir_f->dents;
uint32_t nhash = full_name_hash(name, namelen); uint32_t nhash = full_name_hash(name, namelen);
/* We don't actually want to reserve any space, but we do /* We don't actually want to reserve any space, but we do
...@@ -590,18 +590,20 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, ...@@ -590,18 +590,20 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
down(&c->alloc_sem); down(&c->alloc_sem);
down(&dir_f->sem); down(&dir_f->sem);
while ((*prev) && (*prev)->nhash <= nhash) { for (fd = dir_f->dents; fd; fd = fd->next) {
if ((*prev)->nhash == nhash && if (fd->nhash == nhash &&
!memcmp((*prev)->name, name, namelen) && !memcmp(fd->name, name, namelen) &&
!(*prev)->name[namelen]) { !fd->name[namelen]) {
struct jffs2_full_dirent *this = *prev;
D1(printk(KERN_DEBUG "Marking old dirent node (ino #%u) @%08x obsolete\n", D1(printk(KERN_DEBUG "Marking old dirent node (ino #%u) @%08x obsolete\n",
this->ino, ref_offset(this->raw))); fd->ino, ref_offset(fd->raw)));
jffs2_mark_node_obsolete(c, fd->raw);
*prev = this->next; /* We don't want to remove it from the list immediately,
jffs2_mark_node_obsolete(c, (this->raw)); because that screws up getdents()/seek() semantics even
jffs2_free_full_dirent(this); more than they're screwed already. Turn it into a
node-less deletion dirent instead -- a placeholder */
fd->raw = NULL;
fd->ino = 0;
break; break;
} }
prev = &((*prev)->next); prev = &((*prev)->next);
...@@ -630,7 +632,8 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, ...@@ -630,7 +632,8 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
D1(printk(KERN_DEBUG "Removing deletion dirent for \"%s\" from dir ino #%u\n", D1(printk(KERN_DEBUG "Removing deletion dirent for \"%s\" from dir ino #%u\n",
fd->name, dead_f->inocache->ino)); fd->name, dead_f->inocache->ino));
} }
jffs2_mark_node_obsolete(c, fd->raw); if (fd->raw)
jffs2_mark_node_obsolete(c, fd->raw);
jffs2_free_full_dirent(fd); jffs2_free_full_dirent(fd);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment