io/kfile.h
Go to the documentation of this file.00001
00104 #ifndef KERN_KFILE_H
00105 #define KERN_KFILE_H
00106
00107 #include <cfg/compiler.h>
00108 #include <cfg/debug.h>
00109 #include <cfg/macros.h>
00110
00111
00112 struct KFile;
00113
00114 typedef int32_t kfile_off_t;
00115
00121 typedef enum KSeekMode
00122 {
00123 KSM_SEEK_SET,
00124 KSM_SEEK_CUR,
00125 KSM_SEEK_END,
00126 } KSeekMode;
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 typedef size_t (*ReadFunc_t) (struct KFile *fd, void *buf, size_t size);
00140
00141
00142
00143
00144
00145 typedef size_t (*WriteFunc_t) (struct KFile *fd, const void *buf, size_t size);
00146
00147
00148
00149
00150
00151 typedef kfile_off_t (*SeekFunc_t) (struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00152
00153
00154
00155
00156
00157 typedef struct KFile * (*ReOpenFunc_t) (struct KFile *fd);
00158
00159
00160
00161
00162
00163 typedef int (*CloseFunc_t) (struct KFile *fd);
00164
00165
00166
00167
00168
00169 typedef int (*FlushFunc_t) (struct KFile *fd);
00170
00171
00172
00173
00174
00175 typedef int (*ErrorFunc_t) (struct KFile *fd);
00176
00177
00178
00179
00180 typedef void (*ClearErrFunc_t) (struct KFile *fd);
00181
00189 typedef struct KFile
00190 {
00191 ReadFunc_t read;
00192 WriteFunc_t write;
00193 ReOpenFunc_t reopen;
00194 CloseFunc_t close;
00195 SeekFunc_t seek;
00196 FlushFunc_t flush;
00197 ErrorFunc_t error;
00198 ClearErrFunc_t clearerr;
00199 DB(id_t _type);
00200
00201
00202 kfile_off_t seek_pos;
00203 kfile_off_t size;
00204 } KFile;
00205
00206
00207
00208
00209 kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00210
00211
00212
00213
00214 struct KFile * kfile_genericReopen(struct KFile *fd);
00215
00216 int kfile_genericClose(struct KFile *fd);
00217
00240 INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size)
00241 {
00242 ASSERT(fd->read);
00243 return fd->read(fd, buf, size);
00244 }
00245 int kfile_gets(struct KFile *fd, char *buf, int size);
00246 int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
00247
00256 kfile_off_t kfile_copy(KFile *src, KFile *dst, kfile_off_t size);
00257
00268 INLINE size_t kfile_write(struct KFile *fd, const void *buf, size_t size)
00269 {
00270 ASSERT(fd->write);
00271 return fd->write(fd, buf, size);
00272 }
00273
00274 int kfile_printf(struct KFile *fd, const char *format, ...);
00275 int kfile_print(struct KFile *fd, const char *s);
00276
00287 INLINE kfile_off_t kfile_seek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
00288 {
00289 ASSERT(fd->seek);
00290 return fd->seek(fd, offset, whence);
00291 }
00292
00297 INLINE KFile * kfile_reopen(struct KFile *fd)
00298 {
00299 ASSERT(fd->reopen);
00300 return fd->reopen(fd);
00301 }
00302
00307 INLINE int kfile_close(struct KFile *fd)
00308 {
00309 ASSERT(fd->close);
00310 return fd->close(fd);
00311 }
00312
00317 INLINE int kfile_flush(struct KFile *fd)
00318 {
00319 ASSERT(fd->flush);
00320 return fd->flush(fd);
00321 }
00322
00327 INLINE int kfile_error(struct KFile *fd)
00328 {
00329 ASSERT(fd->error);
00330 return fd->error(fd);
00331 }
00332
00336 INLINE void kfile_clearerr(struct KFile *fd)
00337 {
00338 ASSERT(fd->clearerr);
00339 fd->clearerr(fd);
00340 }
00341
00342 int kfile_putc(int c, struct KFile *fd);
00343 int kfile_getc(struct KFile *fd);
00344 void kfile_resync(KFile *fd, mtime_t delay);
00345 void kfile_init(struct KFile *fd);
00346
00347
00349
00350
00351
00352
00353 int kfile_testSetup(void);
00354 int kfile_testRun(void);
00355 int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
00356 int kfile_testTearDown(void);
00357
00358
00359 #endif