More driver cleanup
[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-2011 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 #include <assert.h>
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 int yaffsfs_CheckMemRegion(const void *addr, size_t size, int writeable)
41 {
42         if(!addr)
43                 return -1;
44         return 0;
45 }
46
47
48 #ifdef CONFIG_YAFFS_USE_PTHREADS
49 #include <pthread.h>
50 static pthread_mutex_t mutex1;
51
52
53 void yaffsfs_Lock(void)
54 {
55         pthread_mutex_lock( &mutex1 );
56 }
57
58 void yaffsfs_Unlock(void)
59 {
60         pthread_mutex_unlock( &mutex1 );
61 }
62
63 void yaffsfs_LockInit(void)
64 {
65         pthread_mutex_init( &mutex1, NULL);
66 }
67
68 #else
69
70 void yaffsfs_Lock(void)
71 {
72 }
73
74 void yaffsfs_Unlock(void)
75 {
76 }
77
78 void yaffsfs_LockInit(void)
79 {
80 }
81 #endif
82
83 u32 yaffsfs_CurrentTime(void)
84 {
85         return time(NULL);
86 }
87
88
89 static int yaffs_kill_alloc = 0;
90 static size_t total_malloced = 0;
91 static size_t malloc_limit = 0 & 6000000;
92
93 void *yaffsfs_malloc(size_t size)
94 {
95         void * this;
96         if(yaffs_kill_alloc)
97                 return NULL;
98         if(malloc_limit && malloc_limit <(total_malloced + size) )
99                 return NULL;
100
101         this = malloc(size);
102         if(this)
103                 total_malloced += size;
104         return this;
105 }
106
107 void yaffsfs_free(void *ptr)
108 {
109         free(ptr);
110 }
111
112 void yaffsfs_OSInitialisation(void)
113 {
114         yaffsfs_LockInit();
115 }
116
117
118 void yaffs_bug_fn(const char *file_name, int line_no)
119 {
120         printf("yaffs bug detected %s:%d\n",
121                 file_name, line_no);
122         assert(0);
123 }