fs.h: fix prototype
[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 <stdio.h>
9 #include "core.h"
10 #include "disk.h"
11
12 /*
13  * Maximum number of open files.  This is *currently* constrained by the
14  * fact that PXE needs to be able to fit all its packet buffers into a
15  * 64K segment; this should be fixed by moving the packet buffers to high
16  * memory.
17  */
18 #define MAX_OPEN_LG2    5
19 #define MAX_OPEN        (1 << MAX_OPEN_LG2)
20
21 #define FILENAME_MAX_LG2 8
22 #define FILENAME_MAX     (1 << FILENAME_MAX_LG2)
23
24 #define BLOCK_SIZE(fs)   (1 << fs->block_shift)
25 #define SECTOR_SIZE(fs)  (1 << fs->sector_shift)
26
27 struct fs_info {
28     const struct fs_ops *fs_ops;
29     struct device *fs_dev;
30     void *fs_info;             /* The fs-specific information */
31     int sector_shift;
32     int block_shift;
33 };
34
35 extern struct fs_info *this_fs;
36
37 struct dirent;                  /* Directory entry structure */
38 struct file;
39 enum fs_flags {
40     FS_NODEV   = 1 << 0,
41     FS_USEMEM  = 1 << 1,         /* If we need a malloc routine, set it */
42
43  /* 
44   * Update the this_inode pointer at each part of path searching. This 
45   * flag is just used for FAT and ISO fs for now.
46   */
47     FS_THISIND = 1 << 2,        
48 };
49
50 struct fs_ops {
51     /* in fact, we use fs_ops structure to find the right fs */
52     const char *fs_name;
53     enum fs_flags fs_flags;
54     
55     int      (*fs_init)(struct fs_info *);
56     void     (*searchdir)(char *, struct file *);
57     uint32_t (*getfssec)(struct file *, char *, int, bool *);
58     void     (*close_file)(struct file *);
59     void     (*mangle_name)(char *, const char *);
60     char *   (*unmangle_name)(char *, const char *);
61     int      (*load_config)(void);
62
63     struct inode * (*iget_root)(void);
64     struct inode * (*iget_current)(void);
65     struct inode * (*iget)(char *, struct inode *);
66     char * (*follow_symlink)(struct inode *, const char *);
67
68     /* the _dir_ stuff */
69     struct dirent * (*readdir)(struct file *);
70 };
71
72 enum inode_mode {I_FILE, I_DIR, I_SYMLINK};
73
74 /* 
75  * The inode structure, including the detail file information 
76  */
77 struct inode {
78     int          mode;   /* FILE , DIR or SYMLINK */
79     uint32_t     size;
80     uint32_t     ino;    /* Inode number */
81     uint32_t     atime;  /* Access time */
82     uint32_t     mtime;  /* Modify time */
83     uint32_t     ctime;  /* Create time */
84     uint32_t     dtime;  /* Delete time */
85     int          blocks; /* How many blocks the file take */
86     uint32_t *   data;   /* The block address array where the file stored */
87     uint32_t     flags;
88     uint32_t     file_acl;
89 };
90
91 extern struct inode *this_inode;
92
93 struct open_file_t;
94
95 struct file {
96     struct fs_info *fs;
97     union {
98         /* For the new universal-path_lookup */
99         struct {
100             struct inode *inode;        /* The file-specific information */
101             uint32_t offset;            /* for next read */
102         };
103
104         /* For the old searhdir method */
105         struct {
106             struct open_file_t *open_file;/* The fs-specific open file struct */
107             uint32_t file_len;
108         };
109     };
110 };
111
112
113 enum dev_type {CHS, EDD};
114
115 /*
116  * Generic functions that filesystem drivers may choose to use
117  */
118 void generic_mangle_name(char *, const char *);
119 #define generic_unmangle_name stpcpy
120
121 /*
122  * Struct device contains:
123  *     the pointer points to the disk structure,
124  *     the cache stuff.
125  */
126 struct device {
127     struct disk *disk;
128
129     /* the cache stuff */
130     char* cache_data;
131     void* cache_head;
132     uint16_t cache_block_size;
133     uint16_t cache_entries;
134     uint32_t cache_size;
135 };
136
137 /*
138  * Our definition of "not whitespace"
139  */
140 static inline bool not_whitespace(char c)
141 {
142   return (unsigned char)c > ' ';
143 }
144
145 static inline void free_inode(struct inode * inode)
146 {
147     if (inode) {
148         if (inode->data)
149             free(inode->data);
150         free(inode);
151     }
152 }
153
154 static inline void malloc_error(char *obj)
155 {
156         printf("Out of memory: can't allocate memory for %s\n", obj);
157         kaboom();
158 }
159
160 /* 
161  * functions
162  */
163 void mangle_name(com32sys_t *);
164 void searchdir(com32sys_t *);
165 void _close_file(struct file *);
166 inline uint16_t file_to_handle(struct file *);
167 inline struct file *handle_to_file(uint16_t);
168
169 #endif /* FS_H */