Import of openhackware-0.4.1
[openhackware.git] / src / libfs / libfs.h
blob1c05bcbb3f3a52724c9fbf43578545d0ae806f0b
1 /*
2 * <libfs.h>
4 * Open Hack'Ware BIOS: file system library definitions
5 *
6 * Copyright (c) 2004-2005 Jocelyn Mayer
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License V2
10 * as published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #if !defined(__OHW_LIBFS_H__)
23 #define __OHW_LIBFS_H__
25 //#define DEBUG_FS 1
26 #define FS_SPECIAL "<special>"
28 static inline int is_special_file (const unsigned char *name)
30 int splen = strlen(FS_SPECIAL);
32 return name[0] == '\0' && memcmp(name + 1, FS_SPECIAL, splen) == 0 &&
33 name[splen + 1] == '\0';
36 #if defined (DEBUG_FS)
37 #define FS_DPRINTF(fmt, args...) \
38 do { dprintf("%s: " fmt, __func__ , ##args); } while (0)
39 #else
40 #define FS_DPRINTF(fmt, args...) \
41 do { } while (0)
42 #endif
43 #define FS_ERROR(fmt, args...) \
44 do { printf("ERROR in %s: " fmt, __func__ , ##args); } while (0)
46 typedef struct fs_ops_t {
47 inode_t *(*get_inode)(inode_t *parent, const unsigned char *name);
48 void (*put_inode)(inode_t *inode);
49 uint32_t (*map_bloc)(inode_t *inode, uint32_t bloc);
50 inode_t *(*get_special_inode)(fs_t *fs, int type);
51 } fs_ops_t;
53 #define MAXNAME_LEN 1024
55 struct fs_t {
56 int type;
57 part_t *part;
58 inode_t *root;
59 fs_ops_t *fs_ops;
60 uint32_t size;
61 unsigned char *name;
62 inode_t *bootfile;
63 inode_t *bootdir;
64 void *private;
67 struct dir_t {
68 inode_t *inode;
69 dirent_t *cur;
70 int pos;
73 /* All internals use inodes */
74 struct inode_t {
75 fs_t *fs;
76 /* parent inode */
77 inode_t *parent;
78 /* Next inode at the same level */
79 inode_t *next;
80 /* First child inode */
81 inode_t *child;
82 /* Private data */
83 int refcount;
84 uint32_t flags;
85 unsigned char *name;
86 int nb_blocs;
87 pos_t *blocs;
88 pos_t size;
89 void *private;
90 uint32_t vbloc;
91 uint32_t vpos;
94 /* Low-level helpers */
95 enum {
96 FILE_UNKNOWN = -1,
97 FILE_ROOT = 0,
98 FILE_BOOT,
99 FILE_BOOTDIR,
102 void fs_cache_add_inode (inode_t *parent, inode_t *inode);
104 int fs_raw_probe (part_t *part, uint32_t *size,
105 fs_ops_t **fs_ops, unsigned char **name,
106 void **private);
107 int fs_ext2_probe (part_t *part, uint32_t *size,
108 fs_ops_t **fs_ops, unsigned char **name,
109 void **private);
110 int fs_isofs_probe (part_t *part, uint32_t *size,
111 fs_ops_t **fs_ops, unsigned char **name,
112 void **private);
113 int fs_hfs_probe (part_t *part, uint32_t *size,
114 fs_ops_t **fs_ops, unsigned char **name,
115 void **private);
116 int fs_raw_set_bootfile (part_t *part,
117 uint32_t start_bloc, uint32_t start_offset,
118 uint32_t size_bloc, uint32_t size_offset);
120 enum {
121 FS_TYPE_UNKNOWN = -1,
122 FS_TYPE_RAW = 0,
123 FS_TYPE_EXT2,
124 FS_TYPE_ISOFS,
125 FS_TYPE_HFS,
126 FS_TYPE_HFSP,
129 #endif /* !defined(__OHW_LIBFS_H__) */