2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * Example OS glue functions for running on a Linux/POSIX system.
19 #include "yaffs_guts.h"
21 #include "yaffs_trace.h"
27 * yaffsfs_SetError() and yaffsfs_GetError()
28 * Do whatever to set the system error.
29 * yaffsfs_GetError() just fetches the last error.
32 static int yaffsfs_lastError;
34 void yaffsfs_SetError(int err)
36 //Do whatever to set error
37 yaffsfs_lastError = err;
41 int yaffsfs_GetLastError(void)
43 return yaffsfs_lastError;
47 * yaffsfs_CheckMemRegion()
48 * Check that access to an address is valid.
49 * This can check memory is in bounds and is writable etc.
51 * Returns 0 if ok, negative if not.
53 int yaffsfs_CheckMemRegion(const void *addr, size_t size, int write_request)
63 * A single mechanism to lock and unlock yaffs. Hook up to a mutex or whatever.
64 * Here are two examples, one using POSIX pthreads, the other doing nothing.
67 #ifdef CONFIG_YAFFS_USE_PTHREADS
69 static pthread_mutex_t mutex1;
72 void yaffsfs_Lock(void)
74 pthread_mutex_lock( &mutex1 );
77 void yaffsfs_Unlock(void)
79 pthread_mutex_unlock( &mutex1 );
82 void yaffsfs_LockInit(void)
84 pthread_mutex_init( &mutex1, NULL);
89 void yaffsfs_Lock(void)
93 void yaffsfs_Unlock(void)
97 void yaffsfs_LockInit(void)
103 * yaffsfs_CurrentTime() retrns a 32-bit timestamp.
105 * Can return 0 if your system does not care about time.
108 u32 yaffsfs_CurrentTime(void)
118 * Functions to allocate and free memory.
121 #ifdef CONFIG_YAFFS_TEST_MALLOC
123 static int yaffs_kill_alloc = 0;
124 static size_t total_malloced = 0;
125 static size_t malloc_limit = 0 & 6000000;
127 void *yaffsfs_malloc(size_t size)
132 if(malloc_limit && malloc_limit <(total_malloced + size) )
137 total_malloced += size;
143 void *yaffsfs_malloc(size_t size)
150 void yaffsfs_free(void *ptr)
155 void yaffsfs_OSInitialisation(void)
162 * Function to report a bug.
165 void yaffs_bug_fn(const char *file_name, int line_no)
167 printf("yaffs bug detected %s:%d\n",