core: new diskio library
[profile/ivi/syslinux.git] / core / include / fs.h
1 #ifndef FS_H
2 #define FS_H
3
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include <com32.h>
7 #include "core.h"
8 #include "disk.h"
9
10 /* I don't know it's right or not */
11 #define USE_CACHE(device_num) (device_num >= 0x00 && device_num < 0xfe)
12
13
14 struct fs_info {
15     char *fs_name;
16     struct fs_ops *fs_ops;
17     struct device *fs_dev;
18 };
19
20 struct file {
21     void*    open_file; /* points to the fs-specific open_file_t */
22     struct   fs_info *fs;
23     uint32_t file_len;
24 };
25
26
27 struct fs_ops {
28     /* in fact, we use fs_ops structure to find the right fs */
29     char *fs_name;
30     
31     int      (*fs_init)(void);
32     void     (*searchdir)(char *, struct file *);
33     uint32_t (*getfssec)(struct fs_info *, char *, void * , int, int *);
34     void     (*mangle_name)(char *, char *);
35     void     (*unmangle_name)(void);
36     void     (*load_config)(com32sys_t *);
37 };
38
39 enum dev_type {CHS, EDD};
40
41 /*
42  * Struct device should have all the information about a specific disk
43  * structure, and contain either a pointer to the metadata cache or 
44  * actually contain the cache itself.
45  * 
46  * All the information in this case is stuff like BIOS device number, 
47  * type of access (CHS, EDD, ...), geometry, partition offset, and 
48  * sector size.
49  * 
50  * It would be usefull and much easier to implement the C version getlinsec
51  * later(I have not much time to implement it now, so I will leave it for 
52  * a while, maybe a long while).
53  */
54 struct device {
55     /* the device numger (in BIOS style ) */
56     uint8_t device_number;
57     
58     /* type of access (CHS or EDD ) */
59     uint8_t type;
60
61     /* the sector size, 512B for disk and floppy, 2048B for CD */
62     uint16_t sector_size;
63     uint8_t sector_shift;
64
65     /* CHS geometry */
66     uint8_t h, s;
67     uint8_t pad1;
68
69     /* the start address of this partition(in sectors) */
70     sector_t part_start;
71        
72     int (*rdwr_sectors)(struct device *, void *, sector_t, size_t, bool);
73
74     /* 
75      * I think we still need the cache_data filed here, 'cause hpa said 
76      * different device has diffrent cache buffer, and the following filed
77      * are quite for cache parts. 
78      */
79     char*    cache_data;
80     struct  cache_struct *cache_head;
81     uint16_t cache_block_size;
82     uint16_t cache_entries;
83     uint32_t cache_size;
84 };
85
86 #endif /* FS_H */