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
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.
36 #include "ramdisk_cdi.h"
38 int ramdisk_fs_res_load(struct cdi_fs_stream
* stream
)
40 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
42 if (res
->res
.loaded
) {
50 int ramdisk_fs_res_unload(struct cdi_fs_stream
* stream
)
52 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
54 if (!res
->res
.loaded
) {
62 int64_t ramdisk_fs_res_meta_read(struct cdi_fs_stream
* stream
, cdi_fs_meta_t meta
)
64 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
67 case CDI_FS_META_SIZE
:
70 case CDI_FS_META_USEDBLOCKS
:
73 case CDI_FS_META_BLOCKSZ
:
76 case CDI_FS_META_BESTBLOCKSZ
:
79 case CDI_FS_META_CREATETIME
:
80 return res
->creation_time
;
82 case CDI_FS_META_ACCESSTIME
:
83 return res
->access_time
;
85 case CDI_FS_META_CHANGETIME
:
86 return res
->modification_time
;
92 int ramdisk_fs_res_meta_write(struct cdi_fs_stream
* stream
, cdi_fs_meta_t meta
,
95 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
98 case CDI_FS_META_ACCESSTIME
:
99 res
->access_time
= value
;
102 case CDI_FS_META_CHANGETIME
:
103 res
->modification_time
= value
;
107 case CDI_FS_META_SIZE
:
108 case CDI_FS_META_USEDBLOCKS
:
109 case CDI_FS_META_BESTBLOCKSZ
:
110 case CDI_FS_META_BLOCKSZ
:
111 case CDI_FS_META_CREATETIME
:
118 int ramdisk_fs_res_assign_class(struct cdi_fs_stream
* stream
,
119 cdi_fs_res_class_t
class)
121 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
123 // In ramdisk koennen die Ressource nur zu maximal einer Klasse gleichzeitig
125 if (res
->res
.file
|| res
->res
.dir
|| res
->res
.link
|| res
->res
.special
)
127 stream
->error
= CDI_FS_ERROR_ONS
;
132 case CDI_FS_CLASS_FILE
:
133 res
->res
.file
= &ramdisk_fs_file
;
136 case CDI_FS_CLASS_DIR
:
137 res
->res
.dir
= &ramdisk_fs_dir
;
140 case CDI_FS_CLASS_LINK
:
141 res
->res
.link
= &ramdisk_fs_link
;
144 case CDI_FS_CLASS_SPECIAL
:
145 res
->res
.special
= &ramdisk_fs_special
;
153 int ramdisk_fs_res_remove_class(struct cdi_fs_stream
* stream
,
154 cdi_fs_res_class_t
class)
156 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
159 case CDI_FS_CLASS_FILE
:
161 res
->res
.file
= NULL
;
164 case CDI_FS_CLASS_DIR
:
168 case CDI_FS_CLASS_LINK
:
169 res
->res
.link
= NULL
;
172 case CDI_FS_CLASS_SPECIAL
:
173 res
->res
.special
= NULL
;
180 int ramdisk_fs_res_rename(struct cdi_fs_stream
* stream
, const char* name
)
182 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
184 res
->res
.name
= strdup(name
);
188 int ramdisk_fs_res_remove(struct cdi_fs_stream
* stream
)
190 struct ramdisk_fs_res
* res
= (struct ramdisk_fs_res
*) stream
->res
;
192 if (res
->res
.file
!=NULL
|| res
->res
.dir
!=NULL
|| res
->res
.link
!=NULL
|| res
->res
.special
!=NULL
) {
193 stream
->error
= CDI_FS_ERROR_ONS
;
197 // Link aus der Liste der Vater-Resource entfernen
199 struct ramdisk_fs_res
* child
;
200 for (i
=0;(child
= cdi_list_get(res
->res
.parent
->children
,i
));i
++) {
202 cdi_list_remove(res
->res
.parent
->children
,i
);
207 return ramdisk_fs_res_destroy(res
);
210 int ramdisk_fs_res_destroy(struct ramdisk_fs_res
* res
)
212 if (cdi_list_size(res
->res
.children
)>0) return 0;
216 free(res
->res
.link_path
);
217 cdi_list_destroy(res
->res
.children
);