yaffs direct: Partition off os glue code
[yaffs2.git] / direct / basic-test / yaffs_osglue.c
1 /*
2  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
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.
12  */
13
14
15 #include "yaffscfg.h"
16 #include "yaffs_guts.h"
17 #include "yaffsfs.h"
18 #include "yaffs_fileem2k.h"
19 #include "yaffs_nandemul2k.h"
20 #include "yaffs_norif1.h"
21 #include "yaffs_trace.h"
22
23
24 #include <errno.h>
25
26
27 static int yaffsfs_lastError;
28
29 void yaffsfs_SetError(int err)
30 {
31         //Do whatever to set error
32         yaffsfs_lastError = err;
33 }
34
35 int yaffsfs_GetLastError(void)
36 {
37         return yaffsfs_lastError;
38 }
39
40
41 #ifdef CONFIG_YAFFS_USE_PTHREADS
42 #include <pthreads.h>
43 static pthread_mutex_t mutex1;
44
45
46 void yaffsfs_Lock(void)
47 {
48         pthread_mutex_lock( &mutex1 );
49 }
50
51 void yaffsfs_Unlock(void)
52 {
53         pthread_mutex_unlock( &mutex1 );
54 }
55
56 void yaffsfs_LockInit(void)
57 {
58         pthread_mutex_init( &mutex, NULL);
59 }
60
61 #else
62
63 void yaffsfs_Lock(void)
64 {
65 }
66
67 void yaffsfs_Unlock(void)
68 {
69 }
70
71 void yaffsfs_LockInit(void)
72 {
73 }
74 #endif
75
76 u32 yaffsfs_CurrentTime(void)
77 {
78         return 0;
79 }
80
81
82 static int yaffs_kill_alloc = 0;
83 static size_t total_malloced = 0;
84 static size_t malloc_limit = 0 & 6000000;
85
86 void *yaffs_malloc(size_t size)
87 {
88         void * this;
89         if(yaffs_kill_alloc)
90                 return NULL;
91         if(malloc_limit && malloc_limit <(total_malloced + size) )
92                 return NULL;
93
94         this = malloc(size);
95         if(this)
96                 total_malloced += size;
97         return this;
98 }
99
100 void yaffs_free(void *ptr)
101 {
102         free(ptr);
103 }
104
105 void yaffsfs_OSInitialisation(void)
106 {
107         yaffsfs_LockInit();
108 }
109
110