-
Notifications
You must be signed in to change notification settings - Fork 69
/
fs.h
144 lines (117 loc) · 4.49 KB
/
fs.h
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
/*
* Copyright (c) 2012 Dave Vasilevsky <dave@vasilevsky.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQFS_FS_H
#define SQFS_FS_H
#include "common.h"
#include "squashfs_fs.h"
#include "cache.h"
#include "decompress.h"
#include "table.h"
struct sqfs {
sqfs_fd_t fd;
size_t offset;
int uid;
int gid;
struct squashfs_super_block sb;
const char *notify_pipe;
sqfs_table id_table;
sqfs_table frag_table;
sqfs_table export_table;
sqfs_cache md_cache;
sqfs_cache data_cache;
sqfs_cache frag_cache;
sqfs_cache blockidx;
sqfs_decompressor decompressor;
struct squashfs_xattr_id_table xattr_info;
sqfs_table xattr_table;
};
typedef uint32_t sqfs_xattr_idx;
struct sqfs_inode {
struct squashfs_base_inode base;
int nlink;
sqfs_xattr_idx xattr;
sqfs_md_cursor next;
union {
struct {
int major, minor;
} dev;
size_t symlink_size;
struct {
uint64_t start_block;
uint64_t file_size;
uint32_t frag_idx;
uint32_t frag_off;
} reg;
struct {
uint32_t start_block;
uint16_t offset;
uint32_t dir_size;
uint16_t idx_count;
uint32_t parent_inode;
} dir;
} xtra;
};
void sqfs_version_supported(int *min_major, int *min_minor, int *max_major,
int *max_minor);
/* Number of groups of size 'group' required to hold size 'total' */
size_t sqfs_divceil(uint64_t total, size_t group);
sqfs_err sqfs_init(sqfs *fs, sqfs_fd_t fd, size_t offset);
sqfs_err sqfs_init_with_subdir(sqfs *fs, sqfs_fd_t fd, size_t offset, const char *subdir);
void sqfs_destroy(sqfs *fs);
/* Ok to call these even on incompletely constructed filesystems */
void sqfs_version(sqfs *fs, int *major, int *minor);
sqfs_compression_type sqfs_compression(sqfs *fs);
void sqfs_md_header(uint16_t hdr, bool *compressed, uint16_t *size);
void sqfs_data_header(uint32_t hdr, bool *compressed, uint32_t *size);
typedef struct {
sqfs_block *block;
size_t data_size;
} sqfs_block_cache_entry;
sqfs_err sqfs_block_cache_init(sqfs_cache *cache, size_t count);
sqfs_err sqfs_block_read(sqfs *fs, sqfs_off_t pos, bool compressed, uint32_t size,
size_t outsize, sqfs_block **block);
void sqfs_block_dispose(sqfs_block *block);
sqfs_err sqfs_md_block_read(sqfs *fs, sqfs_off_t pos, size_t *data_size,
sqfs_block **block);
sqfs_err sqfs_data_block_read(sqfs *fs, sqfs_off_t pos, uint32_t hdr,
sqfs_block **block);
/* Don't dispose after getting block, it's in the cache */
sqfs_err sqfs_md_cache(sqfs *fs, sqfs_off_t *pos, sqfs_block **block);
sqfs_err sqfs_data_cache(sqfs *fs, sqfs_cache *cache, sqfs_off_t pos,
uint32_t hdr, sqfs_block **block);
void sqfs_md_cursor_inode(sqfs_md_cursor *cur, sqfs_inode_id id, sqfs_off_t base);
sqfs_err sqfs_md_read(sqfs *fs, sqfs_md_cursor *cur, void *buf, size_t size);
sqfs_err sqfs_inode_get(sqfs *fs, sqfs_inode *inode, sqfs_inode_id id);
sqfs_mode_t sqfs_mode(int inode_type);
sqfs_err sqfs_id_get(sqfs *fs, uint16_t idx, sqfs_id_t *id);
/* Puts up to *size characters of the link name into buf. Always null-
* terminates the buffer. Pass null as buf to have the size returned. */
sqfs_err sqfs_readlink(sqfs *fs, sqfs_inode *inode, char *buf, size_t *size);
/* Find inode_id by inode_num */
int sqfs_export_ok(sqfs *fs);
sqfs_err sqfs_export_inode(sqfs *fs, sqfs_inode_num n, sqfs_inode_id *i);
/* Find the root inode */
sqfs_inode_id sqfs_inode_root(sqfs *fs);
#endif