kfile.h
Go to the documentation of this file.00001
00101 #ifndef KERN_KFILE_H
00102 #define KERN_KFILE_H
00103
00104 #include <cfg/compiler.h>
00105 #include <cfg/debug.h>
00106 #include <cfg/macros.h>
00107
00108
00109 struct KFile;
00110
00111 typedef int32_t kfile_off_t;
00112
00118 typedef enum KSeekMode
00119 {
00120 KSM_SEEK_SET,
00121 KSM_SEEK_CUR,
00122 KSM_SEEK_END,
00123 } KSeekMode;
00124
00137 typedef size_t (*ReadFunc_t) (struct KFile *fd, void *buf, size_t size);
00138
00143 typedef size_t (*WriteFunc_t) (struct KFile *fd, const void *buf, size_t size);
00144
00149 typedef kfile_off_t (*SeekFunc_t) (struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00150
00155 typedef struct KFile * (*ReOpenFunc_t) (struct KFile *fd);
00156
00161 typedef int (*CloseFunc_t) (struct KFile *fd);
00162
00167 typedef int (*FlushFunc_t) (struct KFile *fd);
00168
00173 typedef int (*ErrorFunc_t) (struct KFile *fd);
00174
00178 typedef void (*ClearErrFunc_t) (struct KFile *fd);
00179
00180
00188 typedef struct KFile
00189 {
00190 ReadFunc_t read;
00191 WriteFunc_t write;
00192 ReOpenFunc_t reopen;
00193 CloseFunc_t close;
00194 SeekFunc_t seek;
00195 FlushFunc_t flush;
00196 ErrorFunc_t error;
00197 ClearErrFunc_t clearerr;
00198 DB(id_t _type);
00199
00200
00201 kfile_off_t seek_pos;
00202 kfile_off_t size;
00203 } KFile;
00204
00208 kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00209
00213 struct KFile * kfile_genericReopen(struct KFile *fd);
00214
00215 int kfile_genericClose(struct KFile *fd);
00216
00217 int kfile_putc(int c, struct KFile *fd);
00218 int kfile_getc(struct KFile *fd);
00219 int kfile_printf(struct KFile *fd, const char *format, ...);
00220 int kfile_print(struct KFile *fd, const char *s);
00221 int kfile_gets(struct KFile *fd, char *buf, int size);
00222 int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
00223 void kfile_resync(KFile *fd, mtime_t delay);
00224 void kfile_init(struct KFile *fd);
00225
00231 INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size)
00232 {
00233 ASSERT(fd->read);
00234 return fd->read(fd, buf, size);
00235 }
00236
00237 INLINE size_t kfile_write(struct KFile *fd, const void *buf, size_t size)
00238 {
00239 ASSERT(fd->write);
00240 return fd->write(fd, buf, size);
00241 }
00242
00243 INLINE KFile * kfile_reopen(struct KFile *fd)
00244 {
00245 ASSERT(fd->reopen);
00246 return fd->reopen(fd);
00247 }
00248
00249 INLINE int kfile_close(struct KFile *fd)
00250 {
00251 ASSERT(fd->close);
00252 return fd->close(fd);
00253 }
00254
00255 INLINE kfile_off_t kfile_seek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
00256 {
00257 ASSERT(fd->seek);
00258 return fd->seek(fd, offset, whence);
00259 }
00260
00261 INLINE int kfile_flush(struct KFile *fd)
00262 {
00263 ASSERT(fd->flush);
00264 return fd->flush(fd);
00265 }
00266
00267 INLINE int kfile_error(struct KFile *fd)
00268 {
00269 ASSERT(fd->error);
00270 return fd->error(fd);
00271 }
00272
00273 INLINE void kfile_clearerr(struct KFile *fd)
00274 {
00275 ASSERT(fd->clearerr);
00276 fd->clearerr(fd);
00277 }
00278
00279
00283 int kfile_testSetup(void);
00284 int kfile_testRun(void);
00285 int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
00286 int kfile_testTearDown(void);
00287
00288
00289 #endif