xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/uffs/src/emu/uffs_fileem.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2   This file is part of UFFS, the Ultra-low-cost Flash File System.
3 
4   Copyright (C) 2005-2009 Ricky Zheng <[email protected]>
5 
6   UFFS is free software; you can redistribute it and/or modify it under
7   the GNU Library General Public License as published by the Free Software
8   Foundation; either version 2 of the License, or (at your option) any
9   later version.
10 
11   UFFS is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   or GNU Library General Public License, as applicable, for more details.
15 
16   You should have received a copy of the GNU General Public License
17   and GNU Library General Public License along with UFFS; if not, write
18   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19   Boston, MA  02110-1301, USA.
20 
21   As a special exception, if other files instantiate templates or use
22   macros or inline functions from this file, or you compile this file
23   and link it with other works to produce a work based on this file,
24   this file does not by itself cause the resulting work to be covered
25   by the GNU General Public License. However the source code for this
26   file must still be made available in accordance with section (3) of
27   the GNU General Public License v2.
28 
29   This exception does not invalidate any other reasons why a work based
30   on this file might be covered by the GNU General Public License.
31 */
32 
33 /**
34  * \file uffs_fileem.c
35  * \brief emulate uffs file system
36  * \author Ricky Zheng, created 9th May, 2005
37  */
38 
39 
40 #include <sys/types.h>
41 #include <string.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include "uffs_config.h"
45 #include "uffs/uffs_device.h"
46 #include "uffs_fileem.h"
47 
48 #define PFX "femu: "
49 #define MSG(msg,...) uffs_PerrorRaw(UFFS_MSG_NORMAL, msg, ## __VA_ARGS__)
50 #define MSGLN(msg,...) uffs_Perror(UFFS_MSG_NORMAL, msg, ## __VA_ARGS__)
51 
52 
53 static struct uffs_StorageAttrSt g_femu_storage = {0};
54 
55 static struct uffs_FileEmuSt g_femu_private = {0};
56 
57 
femu_GetStorage()58 struct uffs_StorageAttrSt * femu_GetStorage()
59 {
60 	return &g_femu_storage;
61 }
62 
femu_GetPrivate()63 struct uffs_FileEmuSt *femu_GetPrivate()
64 {
65 	return &g_femu_private;
66 }
67 
femu_InitDevice(uffs_Device * dev)68 URET femu_InitDevice(uffs_Device *dev)
69 {
70 	uffs_FileEmu *emu = femu_GetPrivate();
71 
72 	// setup device storage attr and private data structure.
73 	// all femu partition share one storage attribute
74 
75 	dev->attr = femu_GetStorage();
76 	dev->attr->_private = (void *) emu;
77 
78 	// setup flash driver operations, according to the ecc option.
79 	switch(dev->attr->ecc_opt) {
80 		case UFFS_ECC_NONE:
81 		case UFFS_ECC_SOFT:
82 			dev->ops = &g_femu_ops_ecc_soft;
83 			break;
84 		case UFFS_ECC_HW:
85 			dev->ops = &g_femu_ops_ecc_hw;
86 			break;
87 		case UFFS_ECC_HW_AUTO:
88 			dev->ops = &g_femu_ops_ecc_hw_auto;
89 			break;
90 		default:
91 			break;
92 	}
93 
94 #ifdef UFFS_FEMU_ENABLE_INJECTION
95 	// setup wrap functions, for inject ECC errors, etc.
96 	// check wrap_inited so that multiple devices can share the same driver
97 	if (!emu->wrap_inited) {
98 		femu_setup_wrapper_functions(dev);
99 		emu->wrap_inited = U_TRUE;
100 	}
101 #endif
102 
103 	return U_SUCC;
104 }
105 
106 /* Nothing to do here */
femu_ReleaseDevice(uffs_Device * dev)107 URET femu_ReleaseDevice(uffs_Device *dev)
108 {
109 	return U_SUCC;
110 }
111 
112 
113 /////////////////////////////////////////////////////////////////////////////////
114