1 /*
2  * Permission is hereby granted, free of charge, to any person obtaining a copy
3  * of this software and associated documentation files (the "Software"), to
4  * deal in the Software without restriction, including without limitation the
5  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6  * sell copies of the Software, and to permit persons to whom the Software is
7  * furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in
10  * all copies or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18  * DEALINGS IN THE SOFTWARE.
19  *
20  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
21  * Use is subject to license terms.
22  */
23 
24 #ifndef _FSIMAGE_GRUB_H
25 #define	_FSIMAGE_GRUB_H
26 
27 #ifdef __cplusplus
28 extern C {
29 #endif
30 
31 #include <sys/types.h>
32 #include <string.h>
33 #include <stdlib.h>
34 #include <ctype.h>
35 
36 #include "xenfsimage.h"
37 #include "xenfsimage_plugin.h"
38 
39 typedef struct fsig_plugin_ops {
40 	int fpo_version;
41 	int (*fpo_mount)(fsi_file_t *, const char *);
42 	int (*fpo_dir)(fsi_file_t *, char *);
43 	int (*fpo_read)(fsi_file_t *, char *, int);
44 } fsig_plugin_ops_t;
45 
46 #define	STAGE1_5
47 #define FSYS_BUFLEN 0x40000
48 #define	SECTOR_BITS 9
49 #define	SECTOR_SIZE 0x200
50 
51 #define	FSYS_BUF (fsig_file_buf(ffi))
52 #define	filepos (*fsig_filepos(ffi))
53 #define	filemax (*fsig_filemax(ffi))
54 #define	devread fsig_devread
55 #define substring fsig_substring
56 #define	errnum (*fsig_errnum(ffi))
57 #define	disk_read_func (*fsig_disk_read_junk())
58 #define	disk_read_hook (*fsig_disk_read_junk())
59 #define	print_possibilities 0
60 #define	noisy_printf(fmt...)
61 
62 #define	grub_memset memset
63 #define	grub_memmove memmove
64 #define grub_log2 fsig_log2
65 
66 extern char **fsig_disk_read_junk(void);
67 unsigned long fsig_log2(unsigned long);
68 
69 #define	ERR_FSYS_CORRUPT 1
70 #define	ERR_OUTSIDE_PART 1
71 #define	ERR_SYMLINK_LOOP 1
72 #define	ERR_FILELENGTH 1
73 #define	ERR_BAD_FILETYPE 1
74 #define	ERR_FILE_NOT_FOUND 1
75 #define	ERR_BAD_ARGUMENT 1
76 #define	ERR_FILESYSTEM_NOT_FOUND 1
77 #define	ERR_NO_BOOTPATH 1
78 #define	ERR_DEV_VALUES 1
79 #define	ERR_WONT_FIT 1
80 #define	ERR_READ 1
81 #define	ERR_NEWER_VERSION 1
82 
83 fsi_plugin_ops_t *fsig_init(fsi_plugin_t *, fsig_plugin_ops_t *);
84 
85 int fsig_devread(fsi_file_t *, unsigned int, unsigned int, unsigned int, char *);
86 int fsig_substring(const char *, const char *);
87 
88 void *fsig_fs_buf(fsi_t *);
89 
90 fsi_file_t *fsig_file_alloc(fsi_t *);
91 void *fsig_file_buf(fsi_file_t *);
92 uint64_t *fsig_filepos(fsi_file_t *);
93 uint64_t *fsig_filemax(fsi_file_t *);
94 int *fsig_int1(fsi_file_t *);
95 int *fsig_int2(fsi_file_t *);
96 int *fsig_errnum(fsi_file_t *);
97 
98 #ifdef __cplusplus
99 };
100 #endif
101 
102 #endif /* _FSIMAGE_GRUB_H */
103