From fb2ca1ef56af2a6ca9c45a8b3e4e99dec40cb429 Mon Sep 17 00:00:00 2001 From: Charles Manning Date: Mon, 13 May 2013 15:04:08 +1200 Subject: [PATCH] yaffsfs: Add commenting for OS glue interface Signed-off-by: Charles Manning --- direct/test-framework/yaffs_osglue.c | 54 ++++++++++++++++++++++++++-- direct/yaffs_osglue.h | 2 +- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/direct/test-framework/yaffs_osglue.c b/direct/test-framework/yaffs_osglue.c index 40e4052..9d83274 100644 --- a/direct/test-framework/yaffs_osglue.c +++ b/direct/test-framework/yaffs_osglue.c @@ -11,6 +11,9 @@ * published by the Free Software Foundation. */ +/* + * Example OS glue functions for running on a Linux/POSIX system. + */ #include "yaffscfg.h" #include "yaffs_guts.h" @@ -20,6 +23,11 @@ #include +/* + * yaffsfs_SetError() and yaffsfs_GetError() + * Do whatever to set the system error. + * yaffsfs_GetError() just fetches the last error. + */ static int yaffsfs_lastError; @@ -27,6 +35,7 @@ void yaffsfs_SetError(int err) { //Do whatever to set error yaffsfs_lastError = err; + errno = err; } int yaffsfs_GetLastError(void) @@ -34,13 +43,26 @@ int yaffsfs_GetLastError(void) return yaffsfs_lastError; } -int yaffsfs_CheckMemRegion(const void *addr, size_t size, int writeable) +/* + * yaffsfs_CheckMemRegion() + * Check that access to an address is valid. + * This can check memory is in bounds and is writable etc. + * + * Returns 0 if ok, negative if not. + */ +int yaffsfs_CheckMemRegion(const void *addr, size_t size, int write_request) { if(!addr) return -1; return 0; } +/* + * yaffsfs_Lock() + * yaffsfs_Unlock() + * A single mechanism to lock and unlock yaffs. Hook up to a mutex or whatever. + * Here are two examples, one using POSIX pthreads, the other doing nothing. + */ #ifdef CONFIG_YAFFS_USE_PTHREADS #include @@ -77,12 +99,27 @@ void yaffsfs_LockInit(void) } #endif +/* + * yaffsfs_CurrentTime() retrns a 32-bit timestamp. + * + * Can return 0 if your system does not care about time. + */ + u32 yaffsfs_CurrentTime(void) { return time(NULL); } +/* + * yaffsfs_malloc() + * yaffsfs_free() + * + * Functions to allocate and free memory. + */ + +#ifdef CONFIG_YAFFS_TEST_MALLOC + static int yaffs_kill_alloc = 0; static size_t total_malloced = 0; static size_t malloc_limit = 0 & 6000000; @@ -101,6 +138,15 @@ void *yaffsfs_malloc(size_t size) return this; } +#else + +void *yaffsfs_malloc(size_t size) +{ + return malloc(size); +} + +#endif + void yaffsfs_free(void *ptr) { free(ptr); @@ -111,7 +157,11 @@ void yaffsfs_OSInitialisation(void) yaffsfs_LockInit(); } - +/* + * yaffs_bug_fn() + * Function to report a bug. + */ + void yaffs_bug_fn(const char *file_name, int line_no) { printf("yaffs bug detected %s:%d\n", diff --git a/direct/yaffs_osglue.h b/direct/yaffs_osglue.h index 7fe0bf4..739dddb 100644 --- a/direct/yaffs_osglue.h +++ b/direct/yaffs_osglue.h @@ -35,7 +35,7 @@ void yaffsfs_SetError(int err); void *yaffsfs_malloc(size_t size); void yaffsfs_free(void *ptr); -int yaffsfs_CheckMemRegion(const void *addr, size_t size, int writeable); +int yaffsfs_CheckMemRegion(const void *addr, size_t size, int write_request); void yaffsfs_OSInitialisation(void); -- 2.30.2