2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * File system access functions.
26 #ifndef FS_FS_H_INCLUDED
27 #define FS_FS_H_INCLUDED
30 #include "mm/memory.h"
33 * File system driver can only create one file system.
35 #define FS_DRIVER_SINGLE 1
37 * File system driver can not be mounted manually.
39 #define FS_DRIVER_NOMOUNT 2
41 * File system does not need any data source (e.g. /dev).
43 #define FS_DRIVER_NODATA 4
49 * File system information.
51 typedef struct FsFileSystem
54 * Path at which the file system was mounted.
58 * Device file which works as the data source for this file system.
60 struct FsFileHandle
*device
;
62 * Driver which made this file system.
64 struct FsFileSystemDriver
*driver
;
67 * Callback for unmounting the file system.
69 int (*unmount
)(struct FsFileSystem
*fs
);
71 * Callback for file system requests.
73 int (*query_request
)(struct FsFileSystem
*fs
, struct FsRequest
*request
);
79 typedef struct FsFileSystemDriver
82 * File system driver flags.
87 * Mounts a file system using this driver.
89 FsFileSystem
*(*mount
)(struct FsFileSystemDriver
*driver
, const char *path
,
90 const char *device
, uint32_t flags
);
94 * File information as created by a file system.
99 * Number of file handles referring to this file. The file is not closed
100 * unless this goes down to 0.
104 * File system which created this file.
110 * File handle information
112 typedef struct FsFileHandle
115 * The file which this file handle refers to.
119 * Current reading/writing position.
123 * File flags as specified at fsOpen().
129 * Initializes the file system.
134 * Registers a file system driver with the given name.
136 int fsRegisterDriver(FsFileSystemDriver
*driver
, const char *name
);
138 * Removes a file system driver.
140 int fsUnregisterDriver(FsFileSystemDriver
*driver
);
142 * Returns the file system driver with the given name.
144 FsFileSystemDriver
*fsGetDriver(const char *name
);
146 * Mounts a file system onto a directory.
147 * \param driver Driver to be used.
148 * \param path Path for the file system.
149 * \param device Device to be used as the data source for the file system.
150 * \param flags Mounting flags like readonly access.
152 int fsMount(FsFileSystemDriver
*driver
, const char *path
, const char *device
,
155 * Unmounts the file system at the given path.
157 int fsUnmount(const char *path
);
159 #define FS_OPEN_CREATE 1
160 #define FS_OPEN_READ 2
161 #define FS_OPEN_WRITE 4
164 #define FS_MKNOD_FILE 1
165 #define FS_MKNOD_DIR 2
168 * Opens a file for use from within the kernel and creates a file handle.
169 * \param filename Absolute file name.
170 * \param mode Flags for the open request.
172 FsFileHandle
*fsOpen(const char *filename
, uint32_t mode
);
174 * Overrides the process variable for the open request.
176 FsFileHandle
*fsProcessOpen(struct KeProcess
*process
, const char *filename
, uint32_t mode
);
178 * Closes a file handle.
180 int fsClose(FsFileHandle
*file
);
182 * Creates a file system node.
184 int fsMknod(const char *filename
, uint32_t mode
);
187 * Writes data to an opened file.
189 int fsWrite(FsFileHandle
*file
, void *buffer
, int size
);
191 * Reads data from an opened file.
193 int fsRead(FsFileHandle
*file
, void *buffer
, int size
, int blocking
);
195 * Changes the current position within a file. The position can be different
196 * within multiple file handles even if they point to one file internally.
197 * \param file File handle to be used.
198 * \param offset New offset, relative to whence.
199 * \param whence Origin for the seek request, can be 0 (from the start of the
200 * file), 1 (from the current position) or 2 (from the end of the file).
201 * \return Current absolute file offset.
203 uint64_t fsSeek(FsFileHandle
*file
, int64_t offset
, int whence
);
205 * Issues a file ioctl request.
207 int fsIOCTL(FsFileHandle
*file
, int request
, ...);
209 * Returns the buffer size for the ioctl parameter or 0 if only one number is
210 * passed to it directly as an argument.
212 int fsGetIOCTLSize(FsFileHandle
*file
, int request
);