KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
fs_ext2.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 ext2/fs_ext2.h
4 Copyright (C) 2012, 2013 Lawrence Sebald
5*/
6
7/** \file ext2/fs_ext2.h
8 \brief VFS interface for an ext2 filesystem.
9 \ingroup vfs_ext2
10
11 This file defines the public interface to add support for the Second
12 Extended Filesystem (ext2) to KOS' VFS. ext2 is one of the many filesystems
13 that is natively supported by Linux, and was the main filesystem used by
14 most Linux installations pretty much until the creation of the ext3
15 filesystem.
16
17 The KOS ext2 driver was designed with two purposes. First of all, this fs
18 was added to provide a filesystem for use on SD cards used with the
19 Dreamcast SD adapter. ext2 was chosen for this purpose for a bunch of
20 reasons, but probably the biggest one was the non-patent-encumbered nature
21 of ext2 and the availability of programs/drivers to read ext2 on most major
22 OSes available for PCs today. The second purpose of this filesystem driver
23 is to provide an alternative for fs_romdisk when swapping out disk images at
24 runtime. Basically, if a disk image is useful to you, but caching it fully
25 in memory is not important, then you could rig up a relatively simple
26 interface with this filesystem driver.
27
28 Note that there is a lower-level interface sitting underneath of this layer.
29 This lower-level interface (simply called ext2fs) should not generally be
30 used by any normal applications. As of this point, it is completely non
31 thread-safe and the fs_ext2 layer takes extreme care to overcome those
32 issues with the lower-level interface. Over time, I may fix the thread-
33 safety issues in ext2fs, but that is not particularly high on my priority
34 list at the moment. There shouldn't really be a reason to work directly with
35 the ext2fs layer anyway, as this layer should give you everything you need
36 by interfacing with the VFS in the normal fashion.
37
38 There's one final note that I should make. Everything in fs_ext2 and ext2fs
39 is licensed under the same license as the rest of KOS. None of it was
40 derived from GPLed sources. Pretty much all of what's in ext2fs was written
41 based on the documentation at http://www.nongnu.org/ext2-doc/ .
42
43 \author Lawrence Sebald
44*/
45
46#ifndef __EXT2_FS_EXT2_H
47#define __EXT2_FS_EXT2_H
48
49#include <sys/cdefs.h>
50__BEGIN_DECLS
51
52#include <stdint.h>
53#include <kos/blockdev.h>
54
55/** \defgroup vfs_ext2 EXT2
56 \brief KOS VFS support for the Second Extended Filesystem
57 \ingroup vfs_drivers
58*/
59
60/** \brief Initialize fs_ext2.
61 \ingroup vfs_ext2
62
63 This function initializes fs_ext2, preparing various internal structures for
64 use.
65
66 \retval 0 On success. No error conditions currently defined.
67*/
68int fs_ext2_init(void);
69
70/** \brief Shut down fs_ext2.
71 \ingroup vfs_ext2
72
73 This function shuts down fs_ext2, basically undoing what fs_ext2_init() did.
74
75 \retval 0 On success. No error conditions currently defined.
76*/
78
79/** \defgroup ext2_mount_flags Mount Flags
80 \brief Mount flags for fs_ext2
81 \ingroup vfs_ext2
82
83 These values are the valid flags that can be passed for the flags parameter
84 to the fs_ext2_mount() function. Note that these can be combined, except for
85 the read-only flag.
86
87 Also, it is not possible to mount some filesystems as read-write. For
88 instance, if the filesystem was marked as not cleanly unmounted (from Linux
89 itself), the driver will fail to mount the device as read-write. Also, if
90 the block device does not support writing, then the filesystem will not be
91 mounted as read-write (for obvious reasons).
92
93 These should stay synchronized with the ones in ext2fs.h.
94
95 @{
96*/
97#define FS_EXT2_MOUNT_READONLY 0x00000000 /**< \brief Mount read-only */
98#define FS_EXT2_MOUNT_READWRITE 0x00000001 /**< \brief Mount read-write */
99/** @} */
100
101/** \brief Mount an ext2 filesystem in the VFS.
102 \ingroup vfs_ext2
103
104 This function mounts an ext2 filesystem to the specified mount point on the
105 VFS. This function will detect whether or not an ext2 filesystem exists on
106 the given block device and mount it only if there is actually an ext2
107 filesystem.
108
109 \param mp The path to mount the filesystem at.
110 \param dev The block device containing the filesystem.
111 \param flags Mount flags. Bitwise OR of values from ext2_mount_flags
112
113 \retval 0 On success.
114 \retval -1 On error.
115*/
116int fs_ext2_mount(const char *mp, kos_blockdev_t *dev, uint32_t flags);
117
118/** \brief Unmount an ext2 filesystem from the VFS.
119 \ingroup vfs_ext2
120
121 This function unmoutns an ext2 filesystem that was previously mounted by the
122 fs_ext2_mount() function.
123
124 \param mp The mount point of the filesystem to be unmounted.
125
126 \retval 0 On success.
127 \retval -1 On error.
128*/
129int fs_ext2_unmount(const char *mp);
130
131/** \brief Sync an ext2 filesystem, flushing all pending writes to the block
132 device.
133 \ingroup vfs_ext2
134
135 This function completes all pending writes on the filesystem, making sure
136 all data and metadata are in a consistent state on the block device. As both
137 inode and block writes are normally postponed until they are either evicted
138 from the cache or the filesystem is unmounted, doing this periodically may
139 be a good idea if there is a chance that the filesystem will not be
140 unmounted cleanly.
141
142 \note This function has no effect if the filesystem was mounted read-only.
143
144 \param mp The mount point of the filesystem to be synced.
145
146 \retval 0 On success.
147 \retval -1 On error.
148*/
149int fs_ext2_sync(const char *mp);
150
151__END_DECLS
152#endif /* !__EXT2_FS_EXT2_H */
Definitions for a simple block device interface.
int fs_ext2_init(void)
Initialize fs_ext2.
int fs_ext2_mount(const char *mp, kos_blockdev_t *dev, uint32_t flags)
Mount an ext2 filesystem in the VFS.
int fs_ext2_unmount(const char *mp)
Unmount an ext2 filesystem from the VFS.
int fs_ext2_sync(const char *mp)
Sync an ext2 filesystem, flushing all pending writes to the block device.
int fs_ext2_shutdown(void)
Shut down fs_ext2.
A simple block device.
Definition blockdev.h:54