2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2018 Aleph One Ltd.
6 * Created by Charles Manning <charles@aleph1.co.uk>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 * Example OS glue functions for running on a Linux/POSIX system.
18 #include "yaffs_guts.h"
20 #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)
66 * A single mechanism to lock and unlock yaffs. Hook up to a mutex or whatever.
67 * Here are two examples, one using POSIX pthreads, the other doing nothing.
69 * If we use pthreads then we also start a background gc thread.
76 static pthread_mutex_t mutex1;
77 static pthread_t bc_gc_thread;
79 void yaffsfs_Lock(void)
81 pthread_mutex_lock( &mutex1 );
84 void yaffsfs_Unlock(void)
86 pthread_mutex_unlock( &mutex1 );
89 static void *bg_gc_func(void *dummy)
91 struct yaffs_dev *dev;
98 /* Sleep for a bit to allow start up */
103 /* Iterate through devices, do bg gc updating ungency */
107 while ((dev = yaffs_next_dev()) != NULL) {
108 result = yaffs_do_background_gc_reldev(dev, urgent);
113 urgent = next_urgent;
121 /* Don't ever return. */
125 void yaffsfs_LockInit(void)
127 /* Initialise lock */
128 pthread_mutex_init(&mutex1, NULL);
130 /* Sneak in starting a background gc thread too */
131 pthread_create(&bc_gc_thread, NULL, bg_gc_func, NULL);
136 void yaffsfs_Lock(void)
140 void yaffsfs_Unlock(void)
144 void yaffsfs_LockInit(void)
150 * yaffsfs_CurrentTime() retrns a 32-bit timestamp.
152 * Can return 0 if your system does not care about time.
155 u32 yaffsfs_CurrentTime(void)
165 * Functions to allocate and free memory.
168 #ifdef CONFIG_YAFFS_TEST_MALLOC
170 static int yaffs_kill_alloc = 0;
171 static size_t total_malloced = 0;
172 static size_t malloc_limit = 0 & 6000000;
174 void *yaffsfs_malloc(size_t size)
179 if(malloc_limit && malloc_limit <(total_malloced + size) )
184 total_malloced += size;
190 void *yaffsfs_malloc(size_t size)
197 void yaffsfs_free(void *ptr)
202 void yaffsfs_OSInitialisation(void)
209 * Function to report a bug.
212 void yaffs_bug_fn(const char *file_name, int line_no)
214 printf("yaffs bug detected %s:%d\n",