2017-12-01 17:17:24 +08:00
|
|
|
#ifndef _CPIO_H_
|
|
|
|
#define _CPIO_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2019-01-19 23:59:37 -05:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2017-12-01 17:17:24 +08:00
|
|
|
|
2018-10-24 21:08:06 -04:00
|
|
|
struct cpio_newc_header {
|
|
|
|
char magic[6];
|
|
|
|
char ino[8];
|
|
|
|
char mode[8];
|
|
|
|
char uid[8];
|
|
|
|
char gid[8];
|
|
|
|
char nlink[8];
|
|
|
|
char mtime[8];
|
|
|
|
char filesize[8];
|
|
|
|
char devmajor[8];
|
|
|
|
char devminor[8];
|
|
|
|
char rdevmajor[8];
|
|
|
|
char rdevminor[8];
|
|
|
|
char namesize[8];
|
|
|
|
char check[8];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct cpio_entry {
|
2017-12-01 17:17:24 +08:00
|
|
|
// uint32_t ino;
|
2018-10-26 17:02:07 -04:00
|
|
|
uint32_t mode = 0;
|
|
|
|
uint32_t uid = 0;
|
|
|
|
uint32_t gid = 0;
|
2017-12-01 17:17:24 +08:00
|
|
|
// uint32_t nlink;
|
|
|
|
// uint32_t mtime;
|
2018-10-26 17:02:07 -04:00
|
|
|
uint32_t filesize = 0;
|
2017-12-01 17:17:24 +08:00
|
|
|
// uint32_t devmajor;
|
|
|
|
// uint32_t devminor;
|
|
|
|
// uint32_t rdevmajor;
|
|
|
|
// uint32_t rdevminor;
|
2017-12-04 03:14:04 +08:00
|
|
|
// uint32_t namesize;
|
2017-12-01 17:17:24 +08:00
|
|
|
// uint32_t check;
|
2018-11-07 02:10:38 -05:00
|
|
|
// char *filename = nullptr;
|
2019-01-19 23:59:37 -05:00
|
|
|
std::string filename;
|
2018-10-26 17:02:07 -04:00
|
|
|
void *data = nullptr;
|
2017-12-01 17:17:24 +08:00
|
|
|
|
2019-01-19 23:59:37 -05:00
|
|
|
cpio_entry() = default;
|
|
|
|
explicit cpio_entry(const char *name) : filename(name) {}
|
2018-10-24 21:08:06 -04:00
|
|
|
cpio_entry(int fd, cpio_newc_header &header);
|
|
|
|
~cpio_entry();
|
|
|
|
};
|
|
|
|
|
|
|
|
class cpio {
|
|
|
|
public:
|
2019-01-19 23:59:37 -05:00
|
|
|
explicit cpio(const char *filename);
|
2018-10-24 21:08:06 -04:00
|
|
|
~cpio();
|
|
|
|
void dump(const char *file);
|
|
|
|
int find(const char *name);
|
|
|
|
void insert(cpio_entry *e);
|
2018-11-07 02:10:38 -05:00
|
|
|
void rm(const char *name, bool r = false);
|
2018-10-24 21:08:06 -04:00
|
|
|
void makedir(mode_t mode, const char *name);
|
|
|
|
void ln(const char *target, const char *name);
|
|
|
|
void add(mode_t mode, const char *name, const char *file);
|
|
|
|
bool mv(const char *from, const char *to);
|
|
|
|
void extract();
|
|
|
|
bool extract(const char *name, const char *file);
|
|
|
|
void sort();
|
|
|
|
|
|
|
|
protected:
|
2019-01-19 23:59:37 -05:00
|
|
|
std::vector<cpio_entry *> arr;
|
2018-10-24 21:08:06 -04:00
|
|
|
};
|
2017-12-04 03:14:04 +08:00
|
|
|
|
2017-12-01 17:17:24 +08:00
|
|
|
#endif
|