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"
28 * yaffsfs_SetError() and yaffsfs_GetError()
29 * Do whatever to set the system error.
30 * yaffsfs_GetError() just fetches the last error.
33 static int yaffsfs_lastError;
35 void yaffsfs_SetError(int err)
37 //Do whatever to set error
38 yaffsfs_lastError = err;
42 int yaffsfs_GetLastError(void)
44 return yaffsfs_lastError;
48 * yaffsfs_CheckMemRegion()
49 * Check that access to an address is valid.
50 * This can check memory is in bounds and is writable etc.
52 * Returns 0 if ok, negative if not.
54 int yaffsfs_CheckMemRegion(const void *addr, size_t size, int write_request)
64 * A single mechanism to lock and unlock yaffs. Hook up to a mutex or whatever.
65 * Here are two examples, one using POSIX pthreads, the other doing nothing.
67 * If we use pthreads then we also start a background gc thread.
74 static pthread_mutex_t mutex1;
75 static pthread_t bc_gc_thread;
77 void yaffsfs_Lock(void)
79 pthread_mutex_lock( &mutex1 );
82 void yaffsfs_Unlock(void)
84 pthread_mutex_unlock( &mutex1 );
87 static void *bg_gc_func(void *dummy)
89 struct yaffs_dev *dev;
94 /* Sleep for a bit to allow start up */
99 /* Iterate through devices, do bg gc updating ungency */
103 while ((dev = yaffs_next_dev()) != NULL) {
104 result = yaffs_do_background_gc_reldev(dev, urgent);
109 urgent = next_urgent;
117 /* Don't ever return. */
121 void yaffsfs_LockInit(void)
123 /* Initialise lock */
124 pthread_mutex_init(&mutex1, NULL);
126 /* Sneak in starting a background gc thread too */
127 pthread_create(&bc_gc_thread, NULL, bg_gc_func, NULL);
132 void yaffsfs_Lock(void)
136 void yaffsfs_Unlock(void)
140 void yaffsfs_LockInit(void)
146 * yaffsfs_CurrentTime() retrns a 32-bit timestamp.
148 * Can return 0 if your system does not care about time.
151 u32 yaffsfs_CurrentTime(void)
161 * Functions to allocate and free memory.
164 #ifdef CONFIG_YAFFS_TEST_MALLOC
166 static int yaffs_kill_alloc = 0;
167 static size_t total_malloced = 0;
168 static size_t malloc_limit = 0 & 6000000;
170 void *yaffsfs_malloc(size_t size)
175 if(malloc_limit && malloc_limit <(total_malloced + size) )
180 total_malloced += size;
186 void *yaffsfs_malloc(size_t size)
193 void yaffsfs_free(void *ptr)
198 void yaffsfs_OSInitialisation(void)
205 * Function to report a bug.
208 void yaffs_bug_fn(const char *file_name, int line_no)
210 printf("yaffs bug detected %s:%d\n",