EXTLINUX: simplify the ext2_fs_init function
[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     void *fs_info;             /* The fs-specific information */
27     int blk_bits;              /* block_size = 1 << (blk_bits + SECTOR_SHIFT) */
28 };
29
30 extern struct fs_info *this_fs;
31
32 struct dirent;                  /* Directory entry structure */
33 struct file;
34 enum fs_flags {
35     FS_NODEV = 1,
36 };
37
38 struct fs_ops {
39     /* in fact, we use fs_ops structure to find the right fs */
40     const char *fs_name;
41     enum fs_flags fs_flags;
42     
43     int      (*fs_init)(struct fs_info *);
44     void     (*searchdir)(char *, struct file *);
45     uint32_t (*getfssec)(struct file *, char *, int, bool *);
46     void     (*close_file)(struct file *);
47     void     (*mangle_name)(char *, const char *);
48     char *   (*unmangle_name)(char *, const char *);
49     int      (*load_config)();
50
51     struct inode * (*iget_root)(void);
52     struct inode * (*iget_current)(void);
53     struct inode * (*iget)(char *, struct inode *);
54     char * (*follow_symlink)(struct inode *, const char *);
55
56     /* the _dir_ stuff */
57     void     (*opendir)(com32sys_t *);
58     struct dirent * (*readdir)(struct file *);
59 };
60
61 enum inode_mode {I_FILE, I_DIR, I_SYMLINK};
62
63 /* 
64  * The inode structure, including the detail file information 
65  */
66 struct inode {
67     int          mode;   /* FILE , DIR or SYMLINK */
68     uint32_t     size;
69     uint32_t     ino;    /* Inode number */
70     uint32_t     atime;  /* Access time */
71     uint32_t     mtime;  /* Modify time */
72     uint32_t     ctime;  /* Create time */
73     uint32_t     dtime;  /* Delete time */
74     int          blocks; /* How many blocks the file take */
75     uint32_t *   data;   /* The block address array where the file stored */
76     uint32_t     flags;
77     int          blkbits;
78     int          blksize;
79     uint32_t     file_acl;
80 };
81
82 extern struct inode *this_inode;
83
84 struct open_file_t;
85
86 struct file {
87     struct fs_info *fs;
88     union {
89         /* For the new universal-path_lookup */
90         struct {
91             struct inode *inode;        /* The file-specific information */
92             uint32_t offset;            /* for next read */
93         };
94
95         /* For the old searhdir method */
96         struct {
97             struct open_file_t *open_file;/* The fs-specific open file struct */
98             uint32_t file_len;
99         };
100     };
101 };
102
103
104 enum dev_type {CHS, EDD};
105
106 /*
107  * Generic functions that filesystem drivers may choose to use
108  */
109 void generic_mangle_name(char *, const char *);
110 #define generic_unmangle_name stpcpy
111
112 /*
113  * Struct device contains:
114  *     the pointer points to the disk structure,
115  *     the cache stuff.
116  */
117 struct device {
118     struct disk *disk;
119
120     /* the cache stuff */
121     char* cache_data;
122     void* cache_head;
123     uint16_t cache_block_size;
124     uint16_t cache_entries;
125     uint32_t cache_size;
126 };
127
128 /*
129  * Our definition of "not whitespace"
130  */
131 static inline bool not_whitespace(char c)
132 {
133   return (unsigned char)c > ' ';
134 }
135
136 static inline void free_inode(struct inode * inode)
137 {
138     if (inode) {
139         if (inode->data)
140             free(inode->data);
141         free(inode);
142     }
143 }
144
145 static inline void malloc_error(char *obj)
146 {
147         printf("Out of memory: can't allocate memory for %s\n", obj);
148 }
149
150 /* 
151  * functions
152  */
153 void mangle_name(com32sys_t *);
154 void searchdir(com32sys_t *);
155 void _close_file(struct file *);
156 inline uint16_t file_to_handle(struct file *);
157 inline struct file *handle_to_file(uint16_t);
158
159 #endif /* FS_H */