Merge branch 'master' into fsc
[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 <string.h>
7 #include <com32.h>
8 #include "core.h"
9 #include "disk.h"
10
11 /*
12  * Maximum number of open files.  This is *currently* constrained by the
13  * fact that PXE needs to be able to fit all its packet buffers into a
14  * 64K segment; this should be fixed by moving the packet buffers to high
15  * memory.
16  */
17 #define MAX_OPEN_LG2    5
18 #define MAX_OPEN        (1 << MAX_OPEN_LG2)
19
20 #define FILENAME_MAX_LG2 8
21 #define FILENAME_MAX     (1 << FILENAME_MAX_LG2)
22
23 struct fs_info {
24     const struct fs_ops *fs_ops;
25     struct device *fs_dev;
26 };
27
28 struct open_file_t;             /* Filesystem private structure */
29 struct dirent;          /* Directory entry structure */
30
31 struct file {
32     struct open_file_t *open_file; /* Filesystem private data */
33     struct fs_info *fs;
34     uint32_t file_len;
35 };
36
37 enum fs_flags {
38     FS_NODEV = 1,
39 };
40
41 struct fs_ops {
42     /* in fact, we use fs_ops structure to find the right fs */
43     const char *fs_name;
44     enum fs_flags fs_flags;
45     
46     int      (*fs_init)(struct fs_info *);
47     void     (*searchdir)(char *, struct file *);
48     uint32_t (*getfssec)(struct file *, char *, int, bool *);
49     void     (*close_file)(struct file *);
50     void     (*mangle_name)(char *, const char *);
51     char *   (*unmangle_name)(char *, const char *);
52     int      (*load_config)();
53
54     /* the _dir_ stuff */
55     void     (*opendir)(com32sys_t *);
56     struct dirent * (*readdir)(struct file *);
57 };
58
59 enum dev_type {CHS, EDD};
60
61 /*
62  * Generic functions that filesystem drivers may choose to use
63  */
64 void generic_mangle_name(char *, const char *);
65 #define generic_unmangle_name stpcpy
66
67 /*
68  * Struct device contains:
69  *     the pointer points to the disk structure,
70  *     the cache stuff.
71  */
72 struct device {
73     struct disk *disk;
74
75     /* the cache stuff */
76     char* cache_data;
77     void* cache_head;
78     uint16_t cache_block_size;
79     uint16_t cache_entries;
80     uint32_t cache_size;
81 };
82
83 /*
84  * Our definition of "not whitespace"
85  */
86 static inline bool not_whitespace(char c)
87 {
88   return (unsigned char)c > ' ';
89 }
90
91 /* 
92  * functions
93  */
94 void mangle_name(com32sys_t *);
95 void searchdir(com32sys_t *);
96 void _close_file(struct file *);
97 inline uint16_t file_to_handle(struct file *);
98 inline struct file *handle_to_file(uint16_t);
99
100 #endif /* FS_H */