KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
fs_vmu.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/fs_vmu.h
4 (c)2000-2001 Jordan DeLong
5
6*/
7
8/** \file dc/fs_vmu.h
9 \brief VMU filesystem driver.
10 \ingroup vfs_vmu
11
12 The VMU filesystem driver mounts itself on /vmu of the VFS. Each memory card
13 has its own subdirectory off of that directory (i.e, /vmu/a1 for slot 1 of
14 the first controller). VMUs themselves have no subdirectories, so the driver
15 itself is fairly simple.
16
17 Files on a VMU must be multiples of 512 bytes in size, and should have a
18 header attached so that they show up in the BIOS menu.
19
20 This layer is built off of the vmufs layer, which does all the low-level
21 operations. It is generally easier to work with things at this level though,
22 so that you can use the normal libc file access functions.
23
24 \author Megan Potter
25
26 \see dc/vmu_pkg.h
27 \see dc/vmufs.h
28*/
29
30#ifndef __DC_FS_VMU_H
31#define __DC_FS_VMU_H
32
33#include <sys/cdefs.h>
34__BEGIN_DECLS
35
36#include <kos/fs.h>
37#include <dc/vmu_pkg.h>
38
39/** \defgroup vfs_vmu VMU
40 \brief VFS driver for accessing Visual Memory Unit storage
41 \ingroup vfs
42
43 @{
44*/
45
46/* \cond */
47/* Initialization */
48int fs_vmu_init(void);
49int fs_vmu_shutdown(void);
50
51#define IOCTL_VMU_SET_HDR 0x564d5530 /* "VMU0" */
52/* \endcond */
53
54/** \brief Set a header to an opened VMU file
55
56 This function can be used to set a specific header (which contains the
57 metadata, icons...) to an opened VMU file, replacing the one it previously
58 had (if any).
59
60 Note that the "pkg" pointer as well as the eyecatch/icon data pointers it
61 contain can be freed (if dynamically allocated) as soon as this function
62 return, as the filesystem code will keep an internal copy.
63
64 It is valid to pass NULL as the header pointer, in which case the header
65 for the file will be discarded.
66
67 \param fd A file descriptor corresponding to the VMU file
68 \param pkg The header to set to the VMU file
69 \retval 0 On success.
70 \retval -1 On error.
71*/
72static inline int fs_vmu_set_header(file_t fd, const vmu_pkg_t *pkg) {
73 return fs_ioctl(fd, IOCTL_VMU_SET_HDR, pkg);
74}
75
76/** \brief Set a default header for newly created VMU files
77
78 This function will set a default header, that will be used for new files
79 which were not assignated their own header.
80
81 Note that files which already have a header, either because they were opened
82 read-write or because they were given one, will use their own header instead
83 of the default one.
84
85 Note that the "pkg" pointer as well as the eyecatch/icon data pointers it
86 contain can be freed (if dynamically allocated) as soon as this function
87 return, as the filesystem code will keep an internal copy.
88
89 It is valid to pass NULL as the header pointer, in which case the default
90 header will be discarded.
91
92 \param pkg The header to set to the VMU file
93 \retval 0 On success.
94 \retval -1 On error.
95*/
96static inline int fs_vmu_set_default_header(const vmu_pkg_t *pkg) {
97 file_t fd;
98 int ret;
99
100 fd = fs_open("/vmu", O_RDONLY | O_DIR);
101 if(!fd)
102 return -1;
103
104 ret = fs_vmu_set_header(fd, pkg);
105 fs_close(fd);
106
107 return ret;
108}
109
110/** @} */
111
112__END_DECLS
113
114#endif /* __DC_FS_VMU_H */
115
Virtual filesystem support.
file_t fs_open(const char *fn, int mode)
Open a file on the VFS.
int fs_close(file_t hnd)
Close an opened file.
int fs_ioctl(file_t hnd, int cmd,...)
Execute a device-specific command on a file descriptor.
int file_t
File descriptor type.
Definition fs.h:94
#define O_DIR
Open as directory.
Definition fs.h:229
static int fs_vmu_set_header(file_t fd, const vmu_pkg_t *pkg)
Set a header to an opened VMU file.
Definition fs_vmu.h:72
static int fs_vmu_set_default_header(const vmu_pkg_t *pkg)
Set a default header for newly created VMU files.
Definition fs_vmu.h:96
VMU Package type.
Definition vmu_pkg.h:46
VMU Packaging functionality.