summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-09-26 10:04:23 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-09-27 12:23:59 +0200
commit5154902196cb4d2da17a7236e720db0b8d4ac565 (patch)
treeb0aec9e02819b2739869e6fd5d25e1b7b66e8f0a /fs
parenta4514478e6a20edf70537af15fbffbfb1bc5982b (diff)
downloadbarebox-5154902196cb4d2da17a7236e720db0b8d4ac565.tar.gz
barebox-5154902196cb4d2da17a7236e720db0b8d4ac565.tar.xz
fs: ramfs: make chunk counting in truncate() better readable
In ramfs_truncate() "newchunks" denotes the number of chunks we want to have after the call. We decrease that number while iterating over the existing chunks and decrease it further with every newly allocated chunk until "newchunks" is zero. This is a bit hard to read. Instead we drop the decreasing while iterating over existing chunks and increase "oldchunks" while allocating until it reaches "newchunks". This is mainly done to make the next patch easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/ramfs.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/fs/ramfs.c b/fs/ramfs.c
index 09dafe02ae..65dcefcc06 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -384,19 +384,18 @@ static int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
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;