summaryrefslogtreecommitdiff
path: root/core/include/fs.h
blob: f0fe5347c3972536701c2123425bce1717739100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef FS_H
#define FS_H

#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <com32.h>
#include <stdio.h>
#include "core.h"
#include "disk.h"

/*
 * Maximum number of open files.  This is *currently* constrained by the
 * fact that PXE needs to be able to fit all its packet buffers into a
 * 64K segment; this should be fixed by moving the packet buffers to high
 * memory.
 */
#define MAX_OPEN_LG2	5
#define MAX_OPEN	(1 << MAX_OPEN_LG2)

#define FILENAME_MAX_LG2 8
#define FILENAME_MAX     (1 << FILENAME_MAX_LG2)

#define BLOCK_SIZE(fs)   (1 << fs->block_shift)
#define SECTOR_SIZE(fs)  (1 << fs->sector_shift)

struct fs_info {
    const struct fs_ops *fs_ops;
    struct device *fs_dev;
    void *fs_info;             /* The fs-specific information */
    int sector_shift;
    int block_shift;
};

extern struct fs_info *this_fs;

struct dirent;                  /* Directory entry structure */
struct file;
enum fs_flags {
    FS_NODEV   = 1 << 0,
    FS_USEMEM  = 1 << 1,         /* If we need a malloc routine, set it */

 /* 
  * Update the this_inode pointer at each part of path searching. This 
  * flag is just used for FAT and ISO fs for now.
  */
    FS_THISIND = 1 << 2,        
};

struct fs_ops {
    /* in fact, we use fs_ops structure to find the right fs */
    const char *fs_name;
    enum fs_flags fs_flags;
    
    int      (*fs_init)(struct fs_info *);
    void     (*searchdir)(char *, struct file *);
    uint32_t (*getfssec)(struct file *, char *, int, bool *);
    void     (*close_file)(struct file *);
    void     (*mangle_name)(char *, const char *);
    char *   (*unmangle_name)(char *, const char *);
    int      (*load_config)();

    struct inode * (*iget_root)(void);
    struct inode * (*iget_current)(void);
    struct inode * (*iget)(char *, struct inode *);
    char * (*follow_symlink)(struct inode *, const char *);

    /* the _dir_ stuff */
    struct dirent * (*readdir)(struct file *);
};

enum inode_mode {I_FILE, I_DIR, I_SYMLINK};

/* 
 * The inode structure, including the detail file information 
 */
struct inode {
    int          mode;   /* FILE , DIR or SYMLINK */
    uint32_t     size;
    uint32_t     ino;    /* Inode number */
    uint32_t     atime;  /* Access time */
    uint32_t     mtime;  /* Modify time */
    uint32_t     ctime;  /* Create time */
    uint32_t     dtime;  /* Delete time */
    int          blocks; /* How many blocks the file take */
    uint32_t *   data;   /* The block address array where the file stored */
    uint32_t     flags;
    uint32_t     file_acl;
};

extern struct inode *this_inode;

struct open_file_t;

struct file {
    struct fs_info *fs;
    union {
	/* For the new universal-path_lookup */
	struct {
	    struct inode *inode;        /* The file-specific information */
	    uint32_t offset;            /* for next read */
	};

	/* For the old searhdir method */
	struct {
	    struct open_file_t *open_file;/* The fs-specific open file struct */
	    uint32_t file_len;
	};
    };
};


enum dev_type {CHS, EDD};

/*
 * Generic functions that filesystem drivers may choose to use
 */
void generic_mangle_name(char *, const char *);
#define generic_unmangle_name stpcpy

/*
 * Struct device contains:
 *     the pointer points to the disk structure,
 *     the cache stuff.
 */
struct device {
    struct disk *disk;

    /* the cache stuff */
    char* cache_data;
    void* cache_head;
    uint16_t cache_block_size;
    uint16_t cache_entries;
    uint32_t cache_size;
};

/*
 * Our definition of "not whitespace"
 */
static inline bool not_whitespace(char c)
{
  return (unsigned char)c > ' ';
}

static inline void free_inode(struct inode * inode)
{
    if (inode) {
	if (inode->data)
	    free(inode->data);
	free(inode);
    }
}

static inline void malloc_error(char *obj)
{
        printf("Out of memory: can't allocate memory for %s\n", obj);
	kaboom();
}

/* 
 * functions
 */
void mangle_name(com32sys_t *);
void searchdir(com32sys_t *);
void _close_file(struct file *);
inline uint16_t file_to_handle(struct file *);
inline struct file *handle_to_file(uint16_t);

#endif /* FS_H */