-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcpio.h
85 lines (74 loc) · 2.08 KB
/
cpio.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
/*
* Copyright (c) 2020 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
* OS-Lab-2020 (i.e., ChCore) is licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
*/
#pragma once
#include <common/types.h>
/* Spec from https://man.openbsd.org/FreeBSD-12.0/cpio.5 */
struct cpio_newc_header {
char c_magic[6];
char c_ino[8];
char c_mode[8];
char c_uid[8];
char c_gid[8];
char c_nlink[8];
char c_mtime[8];
char c_filesize[8];
char c_devmajor[8];
char c_devminor[8];
char c_rdevmajor[8];
char c_rdevminor[8];
char c_namesize[8];
char c_check[8];
};
struct cpio_header {
char c_magic[6];
u64 c_ino;
u64 c_mode;
u64 c_uid;
u64 c_gid;
u64 c_nlink;
u64 c_mtime;
u64 c_filesize;
u64 c_devmajor;
u64 c_devminor;
u64 c_rdevmajor;
u64 c_rdevminor;
u64 c_namesize;
u64 c_check;
};
#define cpio_fatal(fmt, ...) do { \
fprintf(stderr, "CPIO tool fatal error: " fmt, ##__VA_ARGS__); \
exit(-1); \
} while (0)
#define cpio_fatal_e(fmt, ...) do { \
fprintf(stderr, "CPIO tool fatal error (%s): " fmt, \
strerror(errno), ##__VA_ARGS__); \
exit(-1); \
} while (0)
#define ALIGN4_UP(x) ((((u64)x) & (~3llu)) + ((!!(((u64)x) & 3)) << 2))
struct cpio_file {
struct cpio_header header;
const char *name;
const char *data;
struct cpio_file *next;
};
struct {
struct cpio_file head;
struct cpio_file *tail;
} g_files;
void cpio_init_g_files(void);
int cpio_extract_file(const void *addr, const char *dirat);
void cpio_extract(const void *addr, const char *dirat);
void *cpio_extract_single(const void *addr, const char *target,
void *(*cpio_single_file_filler) (const void *start,
size_t size,
void *data),
void *data);