22#define CPIO_MODE_FILE_TYPE 0170000
23#define CPIO_MODE_SOCKET 0140000
24#define CPIO_MODE_SYMLINK 0120000
25#define CPIO_MODE_FILE 0100000
26#define CPIO_MODE_BLOCKDEV 0060000
27#define CPIO_MODE_DIR 0040000
28#define CPIO_MODE_CHARDEV 0020000
29#define CPIO_MODE_FIFO 0010000
30#define CPIO_MODE_SUID 0004000
31#define CPIO_MODE_SGID 0002000
32#define CPIO_MODE_STICKY 0001000
97 default:
mos_warn(
"invalid cpio file mode");
break;
107 mos_panic(
"what the heck are you doing?");
117 mos_warn(
"invalid cpio header magic, possibly corrupt archive");
125 char filename[filename_len + 1];
127 filename[filename_len] =
'\0';
129 bool found =
strncmp(filename, target, filename_len) == 0;
134 *name_offset = offset;
135 *name_length = filename_len;
141 offset += filename_len;
142 offset = ((offset + 3) & ~0x03);
147 *data_offset = offset;
148 *data_length = data_len;
152 offset = ((offset + 3) & ~0x03);
171 size_t header_offset = 0;
172 size_t name_offset = 0, name_length = 0;
173 size_t data_offset = 0, data_length = 0;
174 const bool found =
cpio_read_metadata(path, &header, &header_offset, &name_offset, &name_length, &data_offset, &data_length);
179 cpio_inode->
header = header;
194 inode->
size = data_length;
215 mos_warn(
"cpio: mount options are not supported");
217 if (dev_name &&
strcmp(dev_name,
"none") != 0)
218 pr_warn(
"cpio: mount: dev_name is not supported");
243 const char *path = pathbuf + 1;
256 if (d_parent ==
NULL)
270 size_t prefix_len =
strlen(path_prefix);
272 if (
strcmp(path_prefix,
".") == 0)
273 path_prefix[0] =
'\0', prefix_len = 0;
285 mos_panic(
"invalid cpio header magic, possibly corrupt archive");
289 char filename[filename_len + 1];
291 filename[filename_len] =
'\0';
293 const bool found =
strncmp(path_prefix, filename, prefix_len) == 0
294 && (prefix_len == 0 || filename[prefix_len] ==
'/')
295 &&
strchr(filename + prefix_len + 1,
'/') ==
NULL;
297 const bool is_TRAILER =
strcmp(filename,
"TRAILER!!!") == 0;
298 const bool is_root_dot =
strcmp(filename,
".") == 0;
300 if (found && !is_TRAILER && !is_root_dot)
302 pr_dinfo2(cpio,
"prefix '%s' filename '%s'", path_prefix, filename);
308 const char *
name = filename + prefix_len + (prefix_len == 0 ? 0 : 1);
309 const size_t name_len = filename_len - prefix_len - (prefix_len == 0 ? 0 : 1);
311 add_record(state, ino,
name, name_len, type);
317 offset += filename_len;
#define MOS_UNREACHABLE()
#define mos_warn(fmt,...)
#define MOS_PATH_MAX_LENGTH
#define CPIO_MODE_CHARDEV
static phyframe_t * cpio_fill_cache(inode_cache_t *cache, off_t pgoff)
static file_type_t cpio_modebits_to_filetype(u32 modebits)
static cpio_inode_t * cpio_inode_trycreate(const char *path, superblock_t *sb)
#define CPIO_MODE_FILE_TYPE
static const inode_ops_t cpio_file_inode_ops
static filesystem_t fs_cpiofs
static size_t cpio_i_readlink(dentry_t *dentry, char *buffer, size_t buflen)
static const file_ops_t cpio_noop_file_ops
#define CPIO_MODE_SYMLINK
static bool cpio_sb_drop_inode(inode_t *inode)
static void cpio_i_iterate_dir(dentry_t *dentry, vfs_listdir_state_t *state, dentry_iterator_op add_record)
static const inode_ops_t cpio_dir_inode_ops
should_inline cpio_inode_t * CPIO_INODE(inode_t *inode)
static const superblock_ops_t cpio_sb_ops
static bool cpio_read_metadata(const char *target, cpio_newc_header_t *header, size_t *header_offset, size_t *name_offset, size_t *name_length, size_t *data_offset, size_t *data_length)
static size_t initrd_read(void *buf, size_t size, size_t offset)
static const inode_cache_ops_t cpio_icache_ops
static const file_ops_t cpio_file_ops
static bool cpio_i_lookup(inode_t *parent_dir, dentry_t *dentry)
#define CPIO_MODE_BLOCKDEV
static slab_t * cpio_inode_cache
static dentry_t * cpio_mount(filesystem_t *fs, const char *dev_name, const char *mount_options)
void dentry_attach(dentry_t *d, inode_t *inode)
Attach an inode to a dentry.
ssize_t dentry_path(dentry_t *dentry, dentry_t *root, char *buf, size_t size)
Get the path of a dentry.
should_inline dentry_t * dentry_parent(const dentry_t *dentry)
MOSAPI char * strchr(const char *s, int c)
MOSAPI s32 strncmp(const char *str1, const char *str2, size_t n)
MOSAPI s32 strcmp(const char *str1, const char *str2)
MOSAPI s64 strntoll(const char *str, char **endptr, int base, size_t n)
__BEGIN_DECLS phyframe_t * mm_get_free_page(void)
#define phyframe_va(frame)
#define pmm_ref_one(thing)
void inode_init(inode_t *inode, superblock_t *sb, u64 ino, file_type_t type)
#define MOS_STATIC_ASSERT
#define ALIGN_UP(addr, size)
#define container_of(ptr, type, member)
#define mos_panic(fmt,...)
static void * memcpy(void *s1, const void *s2, size_t n)
static size_t strlen(const char *s)
#define pr_dinfo2(feat, fmt,...)
#define SLAB_AUTOINIT(name, var, type)
cpio_newc_header_t header
superblock_t * superblock
const inode_cache_ops_t * ops
superblock_t * superblock
const file_ops_t * file_ops
const superblock_ops_t * ops
slab_t * superblock_cache
void dentry_iterator_op(vfs_listdir_state_t *state, u64 ino, const char *name, size_t name_len, file_type_t type)
#define FILESYSTEM_DEFINE(var, fsname, mountfn, unmountfn)
#define FILESYSTEM_AUTOREGISTER(fs)
dentry_t * dentry_get_from_parent(superblock_t *sb, dentry_t *parent, const char *name)
Create a new dentry with the given name and parent.
ssize_t vfs_generic_read(const file_t *file, void *buf, size_t size, off_t offset)