1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/mos_global.h>
6#include <mos/types.h>
7
8#define CPIO_MODE_FILE_TYPE 0170000 // This masks the file type bits.
9#define CPIO_MODE_SOCKET 0140000 // File type value for sockets.
10#define CPIO_MODE_SYMLINK 0120000 // File type value for symbolic links. For symbolic links, the link body is stored as file data.
11#define CPIO_MODE_FILE 0100000 // File type value for regular files.
12#define CPIO_MODE_BLOCKDEV 0060000 // File type value for block special devices.
13#define CPIO_MODE_DIR 0040000 // File type value for directories.
14#define CPIO_MODE_CHARDEV 0020000 // File type value for character special devices.
15#define CPIO_MODE_FIFO 0010000 // File type value for named pipes or FIFOs.
16#define CPIO_MODE_SUID 0004000 // SUID bit.
17#define CPIO_MODE_SGID 0002000 // SGID bit.
18#define CPIO_MODE_STICKY 0001000 // Sticky bit.
19
20typedef struct
21{
22 char magic[6];
23 char ino[8];
24 char mode[8];
25 char uid[8];
26 char gid[8];
27 char nlink[8];
28 char mtime[8];
29
30 char filesize[8];
31 char devmajor[8];
32 char devminor[8];
33 char rdevmajor[8];
34 char rdevminor[8];
35
36 char namesize[8];
37 char check[8];
38} cpio_header_t;
39
40MOS_STATIC_ASSERT(sizeof(cpio_header_t) == 110, "cpio_newc_header has wrong size");
41
42typedef struct
43{
44 size_t header_offset;
45 size_t name_offset;
46 size_t name_length;
47 size_t data_offset;
48 size_t data_length;
49} cpio_metadata_t;
50
51bool cpio_read_metadata(const char *target, cpio_header_t *header, cpio_metadata_t *metadata);
52
53size_t read_initrd(void *buf, size_t size, size_t offset);
54