From: asterix Date: Thu, 29 Nov 2007 15:22:59 +0000 (+0000) Subject: Add a generic implentation o seek function. Add test prototype. X-Git-Tag: 1.0.0~228 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=9440bf5d1e06bbbecd17da05a2be5705e3503a47;p=bertos.git Add a generic implentation o seek function. Add test prototype. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1014 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/kern/kfile.c b/kern/kfile.c index b9934e79..38f43802 100644 --- a/kern/kfile.c +++ b/kern/kfile.c @@ -42,6 +42,50 @@ #include +#inclede + + +/** + * Move \a fd file seek position of \a offset bytes + * from current position. + * This is a generic implementation of seek function, you should redefine + * it in your local module. + */ +int32_t kfile_seek(struct _KFile *fd, kfile_off_t offset, KSeekMode whence) +{ + uint32_t seek_pos; + + switch(whence) + { + + case KSM_SEEK_SET: + seek_pos = 0; + break; + case KSM_SEEK_END: + seek_pos = fd->size - 1; + break; + case KSM_SEEK_CUR: + seek_pos = fd->seek_pos; + break; + default: + ASSERT(0); + return -1; + break; + + } + + /* Bound check */ + if (seek_pos + offset > fd->size) + { + ASSERT(0); + return -1; + } + + fd->seek_pos = seek_pos + offset; + kprintf("Flash seek to [%lu]\n", fd->seek_pos); + + return fd->seek_pos; +} #if CONFIG_TEST diff --git a/kern/kfile.h b/kern/kfile.h index e9d4a5c8..d59f7fb9 100644 --- a/kern/kfile.h +++ b/kern/kfile.h @@ -83,4 +83,15 @@ typedef struct _KFile uint32_t size; } KFile; + +/* + * Generic implementation of seek function. + */ +int32_t kfile_seek(struct _KFile *fd, kfile_off_t offset, KSeekMode whence); + +/* + * Kfile test function + */ +bool kfile_test(uint8_t *buf, size_t _size , uint8_t *save_buf, size_t * save_buf_size); + #endif /* MWARE_KFILE_H */