diff options
-rw-r--r-- | fs/ramfs.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/ramfs.c b/fs/ramfs.c index 09dafe02ae..84ecfa0ddb 100644 --- a/fs/ramfs.c +++ b/fs/ramfs.c @@ -379,24 +379,25 @@ static int ramfs_truncate(struct device_d *dev, FILE *f, ulong size) } 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; |