9
0
Fork 0

svn_rev_396

fix truncate (again). This still looks ugly
This commit is contained in:
Sascha Hauer 2007-07-05 18:01:50 +02:00 committed by Sascha Hauer
parent 84ae341049
commit 5b4110a39c
1 changed files with 12 additions and 4 deletions

View File

@ -112,8 +112,14 @@ static int chunks = 0;
struct ramfs_chunk *ramfs_get_chunk(void)
{
struct ramfs_chunk *data = malloc(sizeof(struct ramfs_chunk));
if (!data)
return NULL;
// printf("get chunk\n");
data->data = malloc(CHUNK_SIZE);
if (!data->data) {
free(data);
return NULL;
}
data->next = NULL;
chunks++;
// printf("chunks: %d\n", chunks);
@ -398,6 +404,8 @@ int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
if (newchunks > oldchunks) {
if (!data) {
node->data = ramfs_get_chunk();
if (!node->data)
return -ENOMEM;
data = node->data;
}
@ -409,7 +417,9 @@ int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
while (newchunks--) {
data->next = ramfs_get_chunk();
data = data->next;
if (!data->next)
return -ENOMEM;
data = data->next;
}
}
node->size = size;
@ -431,9 +441,7 @@ struct dir* ramfs_opendir(struct device_d *dev, const char *pathname)
if (node->mode != S_IFDIR)
return NULL;
dir = malloc(sizeof(struct dir));
if (!dir)
return NULL;
dir = xmalloc(sizeof(struct dir));
dir->priv = node->child;