Added ramdisk driver.
[planlOS.git] / system / modules / ramdisk / dir.c
blob0a104a8f8a1dda026cdcdc8d07b446ae96f4c9e1
1 /*
2 * Copyright (c) 2008 The LOST Project. All rights reserved.
4 * This code is derived from software contributed to the LOST Project
5 * by Alexander Siol and Janosch Graef.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the LOST Project
18 * and its contributors.
19 * 4. Neither the name of the LOST Project nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <string.h>
37 #include "cdi/lists.h"
39 #include "ramdisk_cdi.h"
42 cdi_list_t ramdisk_fs_dir_list(struct cdi_fs_stream* stream)
44 return stream->res->children;
47 int ramdisk_fs_dir_create_child(struct cdi_fs_stream* stream, const char* name,
48 struct cdi_fs_res* parent)
50 struct ramdisk_fs_res* res = malloc(sizeof(*res));
51 struct ramdisk_fs_res* parent_res = (struct ramdisk_fs_res*) parent;
53 memset(res, 0, sizeof(*res));
55 res->res.loaded = 1;
56 res->res.name = strdup(name);
57 res->res.res = &ramdisk_fs_res;
58 res->res.children = cdi_list_create();
59 res->res.link_path = NULL;
60 res->creation_time = 0;
62 cdi_list_push(parent_res->res.children, res);
63 res->res.parent = parent;
65 stream->res = (struct cdi_fs_res*) res;
66 return 1;