kfile.h
Go to the documentation of this file.00001
00088 #ifndef KERN_KFILE_H
00089 #define KERN_KFILE_H
00090
00091 #include <cfg/compiler.h>
00092 #include <cfg/debug.h>
00093 #include <cfg/macros.h>
00094
00095
00096 struct KFile;
00097
00098 typedef int32_t kfile_off_t;
00099
00105 typedef enum KSeekMode
00106 {
00107 KSM_SEEK_SET,
00108 KSM_SEEK_CUR,
00109 KSM_SEEK_END,
00110 } KSeekMode;
00111
00124 typedef size_t (*ReadFunc_t) (struct KFile *fd, void *buf, size_t size);
00125
00130 typedef size_t (*WriteFunc_t) (struct KFile *fd, const void *buf, size_t size);
00131
00136 typedef kfile_off_t (*SeekFunc_t) (struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00137
00142 typedef struct KFile * (*ReOpenFunc_t) (struct KFile *fd);
00143
00148 typedef int (*CloseFunc_t) (struct KFile *fd);
00149
00154 typedef int (*FlushFunc_t) (struct KFile *fd);
00155
00160 typedef int (*ErrorFunc_t) (struct KFile *fd);
00161
00165 typedef void (*ClearErrFunc_t) (struct KFile *fd);
00166
00167
00173 typedef struct KFile
00174 {
00175 ReadFunc_t read;
00176 WriteFunc_t write;
00177 ReOpenFunc_t reopen;
00178 CloseFunc_t close;
00179 SeekFunc_t seek;
00180 FlushFunc_t flush;
00181 ErrorFunc_t error;
00182 ClearErrFunc_t clearerr;
00183 DB(id_t _type);
00184
00185
00186 uint32_t seek_pos;
00187 uint32_t size;
00188 } KFile;
00189
00193 kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence);
00194
00198 struct KFile * kfile_genericReopen(struct KFile *fd);
00199
00200 int kfile_putc(int c, struct KFile *fd);
00201 int kfile_getc(struct KFile *fd);
00202 int kfile_printf(struct KFile *fd, const char *format, ...);
00203 int kfile_print(struct KFile *fd, const char *s);
00204 int kfile_gets(struct KFile *fd, char *buf, int size);
00205 int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
00206
00212 INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size)
00213 {
00214 ASSERT(fd->read);
00215 return fd->read(fd, buf, size);
00216 }
00217
00218 INLINE size_t kfile_write(struct KFile *fd, const void *buf, size_t size)
00219 {
00220 ASSERT(fd->write);
00221 return fd->write(fd, buf, size);
00222 }
00223
00224 INLINE KFile * kfile_reopen(struct KFile *fd)
00225 {
00226 ASSERT(fd->reopen);
00227 return fd->reopen(fd);
00228 }
00229
00230 INLINE int kfile_close(struct KFile *fd)
00231 {
00232 ASSERT(fd->close);
00233 return fd->close(fd);
00234 }
00235
00236 INLINE kfile_off_t kfile_seek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
00237 {
00238 ASSERT(fd->seek);
00239 return fd->seek(fd, offset, whence);
00240 }
00241
00242 INLINE int kfile_flush(struct KFile *fd)
00243 {
00244 ASSERT(fd->flush);
00245 return fd->flush(fd);
00246 }
00247
00248 INLINE int kfile_error(struct KFile *fd)
00249 {
00250 ASSERT(fd->error);
00251 return fd->error(fd);
00252 }
00253
00254 INLINE void kfile_clearerr(struct KFile *fd)
00255 {
00256 ASSERT(fd->clearerr);
00257 fd->clearerr(fd);
00258 }
00259
00260
00264 bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
00265
00266 #endif