diff --git a/fs/ramfs.c b/fs/ramfs.c index 09dafe0..84ecfa0 100644 --- a/fs/ramfs.c +++ b/fs/ramfs.c @@ -379,24 +379,25 @@ } if (newchunks > oldchunks) { - if (!data) { + if (data) { + data = ramfs_find_chunk(node, oldchunks - 1); + } else { node->data = ramfs_get_chunk(); if (!node->data) return -ENOMEM; data = node->data; + oldchunks = 1; } - newchunks--; - while (data->next) { - newchunks--; + while (data->next) data = data->next; - } - while (newchunks--) { + while (newchunks > oldchunks) { data->next = ramfs_get_chunk(); if (!data->next) return -ENOMEM; data = data->next; + oldchunks++; } } node->size = size;