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