source: trunk/kernel/fs/fatfs/fatfs.h @ 8

Last change on this file since 8 was 1, checked in by alain, 8 years ago

First import

File size: 6.4 KB
Line 
1/*
2 * fatfs.h - FATFS file system API definition.
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#ifndef _FATFS_H_
26#define _FATFS_H_
27
28#include <hal_types.h>
29#include <rwlock.h>
30
31/****  Forward declarations  ****/
32
33struct mapper_s;
34struct device_s;
35struct vfs_inode_s;
36struct page_s;
37
38/*****************************************************************************************
39 * This structure defines a FATFS context descriptor
40 ****************************************************************************************/
41
42typedef struct fatfs_ctx_s
43{
44    xptr_t            dev_xp;                /*! extended pointer on remote IOC device  */ 
45    rwlock_t          lock;                  /*! TODO protect what ???                  */
46    uint32_t          fat_begin_lba;
47    uint32_t          fat_sectors_count;
48    uint32_t          bytes_per_sector;
49    uint32_t          bytes_per_cluster;
50    uint32_t          cluster_begin_lba;
51    uint32_t          sectors_per_cluster;
52    uint32_t          rootdir_first_cluster;
53    uint32_t          last_allocated_sector;
54    uint32_t          last_allocated_index;  /*! TODO last allocated cluster ???        */
55    struct mapper_s * mapper;                /*! mapper for the FAT itself              */ 
56}
57fatfs_ctx_t;
58
59/*****************************************************************************************
60 * This structure defines the FAT specific inode extension (versus the VFS inode).
61 ****************************************************************************************/
62
63typedef struct fatfs_inode_s
64{
65    struct fatfs_ctx_s * ctx;                /*! local pointer on the FATFS context     */ 
66        uint32_t             first_cluster;      /*! first cluster on device                */ 
67}
68fatfs_inode_t;
69
70/*****************************************************************************************
71 * This structure defines a FAT specific extension to the generic vfs_dentry_t.
72 * TODO a-ton vraiment besoin de cette structure [AG]
73 ****************************************************************************************/
74
75struct fat_dentry_s
76{
77        uint32_t          entry_index;           /*! TODO ???                               */ 
78        uint32_t          first_cluster;         /*! TODO ???                               */
79}
80fat_dentry_t;
81
82
83
84
85
86/*****************************************************************************************
87 * This function allocates memory for a FATFS inode, initializes it,
88 * and link it to the VFS inode.
89 * TODO [AG] : faut-il rechercher le fichier correspondant sur le disque,
90 * ou faut-il allouer un nouveau cluster?
91 *****************************************************************************************
92 * @ inode   : local pointer on vfs_inode.
93 * @ return 0 if success / return ENOMEM if error.
94 ****************************************************************************************/
95error_t fatfs_inode_create( struct vfs_inode_s * inode );
96
97/*****************************************************************************************
98 * This function releases memory allocated for a FATFS inode.
99 *****************************************************************************************
100 * @ inode   : local pointer on vfs_inode.
101 ****************************************************************************************/
102void fatfs_inode_destroy( struct vfs_inode_s * inode );
103
104/*****************************************************************************************
105 * This function allocates memory for a FATFS context, initialises it,
106 * and link it to the local VFS context.
107 *****************************************************************************************
108 * @ inode   : local pointer on VFS context.
109 * @ return 0 if success / return ENOMEM if error.
110 ****************************************************************************************/
111error_t fatfs_context_create( struct vfs_ctx_s * ctx );
112
113/*****************************************************************************************
114 * This function releases memory allocated for a FATFS context.
115 *****************************************************************************************
116 * @ ctx   : local pointer on VFS context.
117 ****************************************************************************************/
118void fatfs_inode_destroy( struct vfs_ctx_s * ctx );
119
120/*****************************************************************************************
121 * This function moves a page from the mapper to the FATFS file system.
122 * It must be called by a thread running in cluster containing the mapper.
123 * The pointer on the mapper and the page index in file are supposed to be registered
124 * in the page descriptor.
125 *****************************************************************************************
126 * @ page    : local pointer on page descriptor.
127 * @ return 0 if success / return EIO if error.
128 ****************************************************************************************/
129error_t fatfs_write_page( struct page_s * page );
130
131/*****************************************************************************************
132 * This function moves a page from the FATFS file system on device to the mapper.
133 * It must be called by a thread running in cluster containing the mapper.
134 * The pointer on the mapper and the page index in file are supposed to be registered
135 * in the page descriptor.
136 *****************************************************************************************
137 * @ page    : local pointer on page descriptor.
138 * @ return 0 if success / return EIO if error.
139 ****************************************************************************************/
140error_t fatfs_read_page( struct page_s * page );
141
142
143#endif  /* _FATFS_H_ */
Note: See TracBrowser for help on using the repository browser.