From: Charles Manning Date: Sun, 28 Nov 2010 21:56:27 +0000 (+1300) Subject: yaffs direct: Partition off os glue code X-Git-Tag: linux-mainline-patchset-4~39 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=efe3b1808c66ecfecf16498eee78aeedc9809705;hp=58bd37c91ae156c746b7b57be68987eacb0d5cb2 yaffs direct: Partition off os glue code This makes the porting process a bit cleaner. Signed-off-by: Charles Manning --- diff --git a/direct/basic-test/Makefile b/direct/basic-test/Makefile index 2c558f0..a4207aa 100644 --- a/direct/basic-test/Makefile +++ b/direct/basic-test/Makefile @@ -30,7 +30,8 @@ CFLAGS+= -Werror=strict-prototypes -Werror=missing-parameter-type CFLAGS+= -Werror=redundant-decls -Werror=nested-externs -Winline CFLAGS+= -Werror=undef -COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ +COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o \ + yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o yaffs_nand.o \ yaffs_checkptrw.o yaffs_qsort.o\ @@ -58,7 +59,7 @@ YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscomp yaffs_verify.c yaffs_verify.h YAFFSDIRECTSYMLINKS = yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\ - yaffsfs.h yaffs_malloc.h ydirectenv.h \ + yaffsfs.h yaffs_osglue.h ydirectenv.h \ yaffs_flashif.c yaffscfg.h yaffs_list.h \ yaffs_qsort.c yportenv.h yaffs_attribs.c \ yaffs_nandif.c yaffs_nandif.h yaffs_nandemul2k.h diff --git a/direct/basic-test/yaffs_osglue.c b/direct/basic-test/yaffs_osglue.c new file mode 100644 index 0000000..1496383 --- /dev/null +++ b/direct/basic-test/yaffs_osglue.c @@ -0,0 +1,110 @@ +/* + * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + + +#include "yaffscfg.h" +#include "yaffs_guts.h" +#include "yaffsfs.h" +#include "yaffs_fileem2k.h" +#include "yaffs_nandemul2k.h" +#include "yaffs_norif1.h" +#include "yaffs_trace.h" + + +#include + + +static int yaffsfs_lastError; + +void yaffsfs_SetError(int err) +{ + //Do whatever to set error + yaffsfs_lastError = err; +} + +int yaffsfs_GetLastError(void) +{ + return yaffsfs_lastError; +} + + +#ifdef CONFIG_YAFFS_USE_PTHREADS +#include +static pthread_mutex_t mutex1; + + +void yaffsfs_Lock(void) +{ + pthread_mutex_lock( &mutex1 ); +} + +void yaffsfs_Unlock(void) +{ + pthread_mutex_unlock( &mutex1 ); +} + +void yaffsfs_LockInit(void) +{ + pthread_mutex_init( &mutex, NULL); +} + +#else + +void yaffsfs_Lock(void) +{ +} + +void yaffsfs_Unlock(void) +{ +} + +void yaffsfs_LockInit(void) +{ +} +#endif + +u32 yaffsfs_CurrentTime(void) +{ + return 0; +} + + +static int yaffs_kill_alloc = 0; +static size_t total_malloced = 0; +static size_t malloc_limit = 0 & 6000000; + +void *yaffs_malloc(size_t size) +{ + void * this; + if(yaffs_kill_alloc) + return NULL; + if(malloc_limit && malloc_limit <(total_malloced + size) ) + return NULL; + + this = malloc(size); + if(this) + total_malloced += size; + return this; +} + +void yaffs_free(void *ptr) +{ + free(ptr); +} + +void yaffsfs_OSInitialisation(void) +{ + yaffsfs_LockInit(); +} + + diff --git a/direct/basic-test/yaffscfg2k.c b/direct/basic-test/yaffscfg2k.c index 6f7d212..f83aad1 100644 --- a/direct/basic-test/yaffscfg2k.c +++ b/direct/basic-test/yaffscfg2k.c @@ -25,6 +25,7 @@ #include "yaffs_nandemul2k.h" #include "yaffs_norif1.h" #include "yaffs_trace.h" +#include "yaffs_osglue.h" #include @@ -43,61 +44,6 @@ unsigned yaffs_trace_mask = 0; -static int yaffsfs_lastError; - -void yaffsfs_SetError(int err) -{ - //Do whatever to set error - yaffsfs_lastError = err; -} - - -int yaffsfs_GetLastError(void) -{ - return yaffsfs_lastError; -} - -void yaffsfs_Lock(void) -{ -} - -void yaffsfs_Unlock(void) -{ -} - -u32 yaffsfs_CurrentTime(void) -{ - return 0; -} - - -static int yaffs_kill_alloc = 0; -static size_t total_malloced = 0; -static size_t malloc_limit = 0 & 6000000; - -void *yaffs_malloc(size_t size) -{ - void * this; - if(yaffs_kill_alloc) - return NULL; - if(malloc_limit && malloc_limit <(total_malloced + size) ) - return NULL; - - this = malloc(size); - if(this) - total_malloced += size; - return this; -} - -void yaffs_free(void *ptr) -{ - free(ptr); -} - -void yaffsfs_LocalInitialisation(void) -{ - // Define locking semaphore. -} // Configuration @@ -114,7 +60,7 @@ int yaffs_start_up(void) { // Stuff to configure YAFFS // Stuff to initialise anything special (eg lock semaphore). - yaffsfs_LocalInitialisation(); + yaffsfs_OSInitialisation(); // Set up devices // /ram1 ram, yaffs1 diff --git a/direct/basic-test/yaffsnewcfg.c b/direct/basic-test/yaffsnewcfg.c index 60dcf02..5add1e6 100644 --- a/direct/basic-test/yaffsnewcfg.c +++ b/direct/basic-test/yaffsnewcfg.c @@ -37,61 +37,6 @@ unsigned yaffs_trace_mask = 0; -static int yaffsfs_lastError; - -void yaffsfs_SetError(int err) -{ - //Do whatever to set error - yaffsfs_lastError = err; -} - - -int yaffsfs_GetLastError(void) -{ - return yaffsfs_lastError; -} - -void yaffsfs_Lock(void) -{ -} - -void yaffsfs_Unlock(void) -{ -} - -u32 yaffsfs_CurrentTime(void) -{ - return 0; -} - - -static int yaffs_kill_alloc = 0; -static size_t total_malloced = 0; -static size_t malloc_limit = 0 & 6000000; - -void *yaffs_malloc(size_t size) -{ - void * this; - if(yaffs_kill_alloc) - return NULL; - if(malloc_limit && malloc_limit <(total_malloced + size) ) - return NULL; - - this = malloc(size); - if(this) - total_malloced += size; - return this; -} - -void yaffs_free(void *ptr) -{ - free(ptr); -} - -void yaffsfs_LocalInitialisation(void) -{ - // Define locking semaphore. -} // Configuration @@ -100,7 +45,7 @@ int yaffs_start_up(void) { // Stuff to configure YAFFS // Stuff to initialise anything special (eg lock semaphore). - yaffsfs_LocalInitialisation(); + yaffsfs_OSInitialisation(); yramsim_CreateRamSim("yaffs2",1,1000,0,0); yramsim_CreateRamSim("p0",0,0x400,1,0xff); yramsim_CreateRamSim("p1",0,0x400,1,0); diff --git a/direct/python/Makefile b/direct/python/Makefile index 38f8b11..ad5b47f 100644 --- a/direct/python/Makefile +++ b/direct/python/Makefile @@ -29,7 +29,8 @@ CFLAGS += -O0 -fPIC #CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -COMMONTESTOBJS = yaffscfg2k.o yramsim.o yaffs_fileem2k.o\ +COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o \ + yramsim.o yaffs_fileem2k.o\ yaffs_nandif.o yaffs_attribs.o \ yaffsfs.o yaffs_ecc.o yaffs_guts.o \ yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ @@ -60,7 +61,7 @@ YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscomp yaffs_verify.c yaffs_verify.h -YAFFSDIRECTSYMLINKS = yaffsfs.c yaffsfs.h yaffscfg.h yaffs_malloc.h ydirectenv.h \ +YAFFSDIRECTSYMLINKS = yaffsfs.c yaffsfs.h yaffscfg.h yaffs_osglue.h ydirectenv.h \ yaffs_flashif.c yaffs_flashif.h yaffs_flashif2.h yaffs_list.h \ yaffs_nandif.c yaffs_nandif.h yaffs_qsort.c yaffs_nandemul2k.h \ yportenv.h yaffs_attribs.c @@ -69,7 +70,7 @@ DIRECTEXTRASYMLINKS = yaffscfg2k.c yaffs_fileem2k.c yaffs_fileem2k.h\ yaffs_fileem.c yaffs_norif1.c yaffs_norif1.h \ yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \ yaffsnewcfg.c yramsim.c yramsim.h \ - ynorsim.h ynorsim.c + ynorsim.h ynorsim.c yaffs_osglue.c SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS) diff --git a/direct/tests/Makefile b/direct/tests/Makefile index 956e34f..bbeb8de 100644 --- a/direct/tests/Makefile +++ b/direct/tests/Makefile @@ -30,7 +30,8 @@ CFLAGS += -Wextra -Wpointer-arith #CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ +COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o \ + yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o yaffs_nand.o \ yaffs_checkptrw.o yaffs_qsort.o\ @@ -50,7 +51,7 @@ YAFFSTESTOBJS = $(COMMONTESTOBJS) yaffs_test.o ALLOBJS = $(sort $(YAFFSTESTOBJS)) YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \ - yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h yaffs_nandemul2k.h \ + yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h \ yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \ yaffs_tagsvalidity.c yaffs_tagsvalidity.h yaffs_checkptrw.h yaffs_checkptrw.c \ yaffs_nameval.c yaffs_nameval.h \ @@ -62,7 +63,7 @@ YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscomp yaffs_verify.c yaffs_verify.h YAFFSDIRECTSYMLINKS = yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\ - yaffsfs.h yaffs_malloc.h ydirectenv.h \ + yaffsfs.h yaffs_osglue.h ydirectenv.h \ yaffs_flashif.c yaffscfg.h yaffs_qsort.c \ yaffs_nandemul2k.h yaffs_list.h \ yaffs_attribs.c \ @@ -72,7 +73,7 @@ YAFFSDIRECTSYMLINKS = yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\ DIRECTEXTRASYMLINKS = yaffscfg2k.c yaffs_fileem2k.c yaffs_fileem2k.h\ yaffs_fileem.c yaffs_norif1.c yaffs_norif1.h \ yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \ - ynorsim.h ynorsim.c + ynorsim.h ynorsim.c yaffs_osglue.c SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS) #all: directtest2k boottest diff --git a/direct/timothy_tests/quick_tests/Makefile b/direct/timothy_tests/quick_tests/Makefile index 252c635..8aa843a 100644 --- a/direct/timothy_tests/quick_tests/Makefile +++ b/direct/timothy_tests/quick_tests/Makefile @@ -30,7 +30,8 @@ CFLAGS += -Wextra -Wpointer-arith #CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ +COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o \ + yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o yaffs_nand.o \ yaffs_checkptrw.o yaffs_qsort.o\ @@ -106,7 +107,7 @@ PYTHONOBJS = yaffs_error_converter.o ALLOBJS = $(sort $(YAFFSTESTOBJS)) $(PYTHONOBJS) YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \ - yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h yaffs_nandemul2k.h \ + yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h \ yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \ yaffs_tagsvalidity.c yaffs_tagsvalidity.h yaffs_checkptrw.h yaffs_checkptrw.c \ yaffs_nameval.c yaffs_nameval.h \ @@ -118,17 +119,17 @@ YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscomp yaffs_verify.c yaffs_verify.h YAFFSDIRECTSYMLINKS = yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\ - yaffsfs.h yaffs_malloc.h ydirectenv.h \ + yaffsfs.h ydirectenv.h \ yaffs_flashif.c yaffscfg.h yaffs_qsort.c \ yaffs_nandemul2k.h yaffs_list.h \ - yaffs_attribs.c \ + yaffs_attribs.c yaffs_osglue.h \ yaffs_nandif.c yaffs_nandif.h yportenv.h DIRECTEXTRASYMLINKS = yaffscfg2k.c yaffs_fileem2k.c yaffs_fileem2k.h\ yaffs_fileem.c yaffs_norif1.c yaffs_norif1.h \ yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \ - ynorsim.h ynorsim.c + ynorsim.h ynorsim.c yaffs_osglue.c SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS) $(PYTONOSYMLINKS) #all: directtest2k boottest diff --git a/direct/yaffs_malloc.h b/direct/yaffs_osglue.h similarity index 64% rename from direct/yaffs_malloc.h rename to direct/yaffs_osglue.h index d0c2347..ab05fd4 100644 --- a/direct/yaffs_malloc.h +++ b/direct/yaffs_osglue.h @@ -12,14 +12,31 @@ * * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. */ - -#ifndef __YAFFS_MALLOC_H__ -#define __YAFFS_MALLOC_H__ -#include - +/* + * Header file for using yaffs in an application via + * a direct interface. + */ + + +#ifndef __YAFFS_OSGLUE_H__ +#define __YAFFS_OSGLUE_H__ + + +#include "yportenv.h" + +void yaffsfs_Lock(void); +void yaffsfs_Unlock(void); + +u32 yaffsfs_CurrentTime(void); + +void yaffsfs_SetError(int err); + void *yaffs_malloc(size_t size); void yaffs_free(void *ptr); + +void yaffsfs_OSInitialisation(void); + #endif diff --git a/direct/yaffscfg.h b/direct/yaffscfg.h index 42fd78c..9157b82 100644 --- a/direct/yaffscfg.h +++ b/direct/yaffscfg.h @@ -34,12 +34,5 @@ typedef struct yaffsfs_DeviceConfigurationStruct { } yaffsfs_DeviceConfiguration; -void yaffsfs_Lock(void); -void yaffsfs_Unlock(void); - -u32 yaffsfs_CurrentTime(void); - -void yaffsfs_SetError(int err); - #endif diff --git a/direct/ydirectenv.h b/direct/ydirectenv.h index ee6e8f5..be80e68 100644 --- a/direct/ydirectenv.h +++ b/direct/ydirectenv.h @@ -25,7 +25,7 @@ #include "stdlib.h" #include "stdio.h" #include "string.h" -#include "yaffs_malloc.h" +#include "yaffs_osglue.h" #include "assert.h" #define YBUG() assert(0)