1 | /* |
---|
2 | * fatfs.c - FATFS file system API implementation. |
---|
3 | * |
---|
4 | * Author Mohamed Lamine Karaoui (2015) |
---|
5 | * Alain Greiner (2016) |
---|
6 | * |
---|
7 | * Copyright (c) UPMC Sorbonne Universites |
---|
8 | * |
---|
9 | * This file is part of ALMOS-MKH. |
---|
10 | * |
---|
11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation; version 2.0 of the License. |
---|
14 | * |
---|
15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | |
---|
26 | #include <hal_types.h> |
---|
27 | #include <hal_special.h> |
---|
28 | #include <printk.h> |
---|
29 | #include <kmem.h> |
---|
30 | #include <vfs.h> |
---|
31 | #include <fatfs.h> |
---|
32 | |
---|
33 | |
---|
34 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
35 | // FATFS specific functions : these static functions cannot be directly |
---|
36 | // called by the VFS |
---|
37 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
43 | // Generic API : the following functions are called by the VFS, |
---|
44 | // and must be defined by all supported file systems. |
---|
45 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
46 | |
---|
47 | //////////////////////////////////////////////////////////// |
---|
48 | error_t fatfs_inode_create( struct vfs_inode_s * vfs_inode ) |
---|
49 | { |
---|
50 | printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ ); |
---|
51 | hal_core_sleep(); |
---|
52 | |
---|
53 | kmem_req_t req; |
---|
54 | error_t error; |
---|
55 | fatfs_inode_t * fatfs_inode; |
---|
56 | uint32_t cluster; // allocated cluster index |
---|
57 | |
---|
58 | // allocate memory for fatfs inode |
---|
59 | req.type = KMEM_FATFS_INODE; |
---|
60 | req.size = sizeof(fatfs_inode_t); |
---|
61 | req.flags = AF_KERNEL | AF_ZERO; |
---|
62 | fatfs_inode = (fatfs_inode_t *)kmem_alloc( &req ); |
---|
63 | |
---|
64 | if( fatfs_inode == NULL ) return ENOMEM; |
---|
65 | |
---|
66 | // initialise ramfs_inode |
---|
67 | fatfs_inode->first_cluster = 0; // TODO ??? |
---|
68 | fatfs_inode->ctx = (fatfs_ctx_t *)vfs_inode->ctx->extend; |
---|
69 | |
---|
70 | // link vfs_inode to ramfs_inode |
---|
71 | inode->extend = ramfs_inode; |
---|
72 | ramfs->vfs_inode = vfs_inode; |
---|
73 | |
---|
74 | return 0; |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | ////////////////////////////////////////////////////// |
---|
79 | void fatfs_inode_destroy( struct vfs_inode_s * inode ) |
---|
80 | { |
---|
81 | printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ ); |
---|
82 | hal_core_sleep(); |
---|
83 | } |
---|
84 | |
---|
85 | //////////////////////////////////////////////// |
---|
86 | error_t fatfs_write_page( struct page_s * page ) |
---|
87 | { |
---|
88 | printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ ); |
---|
89 | hal_core_sleep(); |
---|
90 | |
---|
91 | // get pointer on mapper and page index from page descriptor |
---|
92 | mapper_t * mapper = page->mapper; |
---|
93 | uint32_t index = page->index; |
---|
94 | |
---|
95 | if( mapper == NULL) |
---|
96 | { |
---|
97 | printk("\n[PANIC] in %s : no mapper for this page\n", __FUNCTION__ ); |
---|
98 | hal_core_sleep(); |
---|
99 | } |
---|
100 | |
---|
101 | // get VFS inode pointer from mapper |
---|
102 | vfs_inode_t * vfs_inode = mapper->inode; |
---|
103 | |
---|
104 | // get FATFS inode pointer for VFS inode |
---|
105 | fatfs_inode_t * fatfs_inode = (fatfs_inode_t)vfs_inode->extend; |
---|
106 | |
---|
107 | // get FATFS context and first cluster from FATFS inode |
---|
108 | fatfs_ctx_t * fatfs_ctx = fatfs_inode->ctx; |
---|
109 | uint32_t first_cluster = fatfs_inode->first_cluster; |
---|
110 | |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | /////////////////////////////////////////////// |
---|
115 | error_t fatfs_read_page( struct page_s * page ) |
---|
116 | { |
---|
117 | printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ ); |
---|
118 | hal_core_sleep(); |
---|
119 | |
---|
120 | // get pointer on mapper and page index from page descriptor |
---|
121 | mapper_t * mapper = page->mapper; |
---|
122 | uint32_t index = page->index; |
---|
123 | |
---|
124 | if( mapper == NULL) |
---|
125 | { |
---|
126 | printk("\n[PANIC] in %s : no mapper for this page\n", __FUNCTION__ ); |
---|
127 | hal_core_sleep(); |
---|
128 | } |
---|
129 | |
---|
130 | // get VFS inode pointer from mapper |
---|
131 | vfs_inode_t * vfs_inode = mapper->inode; |
---|
132 | |
---|
133 | // get FATFS inode pointer for VFS inode |
---|
134 | fatfs_inode_t * fatfs_inode = (fatfs_inode_t)vfs_inode->extend; |
---|
135 | |
---|
136 | // get FATFS context and first cluster from FATFS inode |
---|
137 | fatfs_ctx_t * fatfs_ctx = fatfs_inode->ctx; |
---|
138 | uint32_t first_cluster = fatfs_inode->first_cluster; |
---|
139 | |
---|
140 | |
---|
141 | } |
---|
142 | |
---|