KallistiOS  2.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
fs_ramdisk.h
Go to the documentation of this file.
1 /* KallistiOS 2.0.0
2 
3  kos/fs_ramdisk.h
4  (c)2002 Dan Potter
5 
6 */
7 
8 /** \file kos/fs_ramdisk.h
9  \brief RAM-based virtual file system.
10 
11  This file contains support for a ramdisk VFS. This VFS allows you to map
12  memory into files that will appear in /ram. Files in this VFS can grow as
13  large as memory allows, and there is full read/write support here. This is
14  useful, for (for instance) cacheing files read from the CD-ROM or for making
15  temporary files.
16 
17  You only have one ramdisk available, and its mounted on /ram.
18 
19  \author Dan Potter
20 */
21 
22 #ifndef __KOS_FS_RAMDISK_H
23 #define __KOS_FS_RAMDISK_H
24 
25 #include <sys/cdefs.h>
26 __BEGIN_DECLS
27 
28 #include <arch/types.h>
29 #include <kos/limits.h>
30 #include <kos/fs.h>
31 
32 /** \brief Attach a block of memory as a file in the ramdisk.
33 
34  This function takes a block of memory and associates it with a file on the
35  ramdisk. This memory should be allocated with malloc(), as an unlink() of
36  the file will call free on the block of memory. The ramdisk then effectively
37  takes control of the block, and is responsible for it at that point.
38 
39  \param fn The name to give the new file
40  \param obj The block of memory to associate
41  \param size The size of the block of memory
42  \retval 0 On success
43  \retval -1 On failure
44 */
45 int fs_ramdisk_attach(const char * fn, void * obj, size_t size);
46 
47 /** \brief Detach a file from the ramdisk.
48 
49  This function retrieves the block of memory associated with the file,
50  removing it from the ramdisk. You are responsible for freeing obj when you
51  are done with it.
52 
53  \param fn The name of the file to look for.
54  \param obj A pointer to return the address of the object in.
55  \param size A pointer to return the size of the object in.
56  \retval 0 On success
57  \retval -1 On failure
58 */
59 int fs_ramdisk_detach(const char * fn, void ** obj, size_t * size);
60 
61 /** \cond */
62 int fs_ramdisk_init();
63 int fs_ramdisk_shutdown();
64 /** \endcond */
65 
66 __END_DECLS
67 
68 #endif /* __KOS_FS_RAMDISK_H */
69