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)
67 * A single mechanism to lock and unlock yaffs. Hook up to a mutex or whatever.
68 * Here are two examples, one using POSIX pthreads, the other doing nothing.
70 * If we use pthreads then we also start a background gc thread.
77 static pthread_mutex_t mutex1;
78 static pthread_t bc_gc_thread;
80 void yaffsfs_Lock(void)
82 pthread_mutex_lock( &mutex1 );
85 void yaffsfs_Unlock(void)
87 pthread_mutex_unlock( &mutex1 );
90 static void *bg_gc_func(void *dummy)
92 struct yaffs_dev *dev;
99 /* Sleep for a bit to allow start up */
104 /* Iterate through devices, do bg gc updating ungency */
108 while ((dev = yaffs_next_dev()) != NULL) {
109 result = yaffs_do_background_gc_reldev(dev, urgent);
114 urgent = next_urgent;
122 /* Don't ever return. */
126 void yaffsfs_LockInit(void)
128 /* Initialise lock */
129 pthread_mutex_init(&mutex1, NULL);
131 /* Sneak in starting a background gc thread too */
132 pthread_create(&bc_gc_thread, NULL, bg_gc_func, NULL);
137 void yaffsfs_Lock(void)
141 void yaffsfs_Unlock(void)
145 void yaffsfs_LockInit(void)
151 * yaffsfs_CurrentTime() retrns a 32-bit timestamp.
153 * Can return 0 if your system does not care about time.
156 u32 yaffsfs_CurrentTime(void)
166 * Functions to allocate and free memory.
169 #ifdef CONFIG_YAFFS_TEST_MALLOC
171 static int yaffs_kill_alloc = 0;
172 static size_t total_malloced = 0;
173 static size_t malloc_limit = 0 & 6000000;
175 void *yaffsfs_malloc(size_t size)
180 if(malloc_limit && malloc_limit <(total_malloced + size) )
185 total_malloced += size;
191 void *yaffsfs_malloc(size_t size)
198 void yaffsfs_free(void *ptr)
203 void yaffsfs_OSInitialisation(void)
210 * Function to report a bug.
213 void yaffs_bug_fn(const char *file_name, int line_no)
215 printf("yaffs bug detected %s:%d\n",