|
|
|
@ -25,6 +25,41 @@
|
|
|
|
|
|
|
|
|
|
#include "uart.h"
|
|
|
|
|
|
|
|
|
|
/* POSIX ustar header format */
|
|
|
|
|
typedef struct { /* byte offset */
|
|
|
|
|
char name[100]; /* 0 */
|
|
|
|
|
char mode[8]; /* 100 */
|
|
|
|
|
char uid[8]; /* 108 */
|
|
|
|
|
char gid[8]; /* 116 */
|
|
|
|
|
char size[12]; /* 124 */
|
|
|
|
|
char mtime[12]; /* 136 */
|
|
|
|
|
char chksum[8]; /* 148 */
|
|
|
|
|
char typeflag; /* 156 */
|
|
|
|
|
char linkname[100]; /* 157 */
|
|
|
|
|
char magic[6]; /* 257 */
|
|
|
|
|
char version[2]; /* 263 */
|
|
|
|
|
char uname[32]; /* 265 */
|
|
|
|
|
char gname[32]; /* 297 */
|
|
|
|
|
char devmajor[8]; /* 329 */
|
|
|
|
|
char devminor[8]; /* 337 */
|
|
|
|
|
char prefix[167]; /* 345 */
|
|
|
|
|
} __attribute__((packed)) tar_t;
|
|
|
|
|
|
|
|
|
|
/* cpio hpodc format */
|
|
|
|
|
typedef struct {
|
|
|
|
|
char magic[6]; /* Magic header '070707'. */
|
|
|
|
|
char dev[6]; /* device number. */
|
|
|
|
|
char ino[6]; /* "i-node" number. */
|
|
|
|
|
char mode[6]; /* Permisions. */
|
|
|
|
|
char uid[6]; /* User ID. */
|
|
|
|
|
char gid[6]; /* Group ID. */
|
|
|
|
|
char nlink[6]; /* Number of hard links. */
|
|
|
|
|
char rdev[6]; /* device major/minor number. */
|
|
|
|
|
char mtime[11]; /* Modification time. */
|
|
|
|
|
char namesize[6]; /* Length of filename in bytes. */
|
|
|
|
|
char filesize[11]; /* File size. */
|
|
|
|
|
} __attribute__((packed)) cpio_t;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper function to convert ASCII octal number into binary
|
|
|
|
|
* s string
|
|
|
|
@ -41,36 +76,61 @@ int oct2bin(char *s, int n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List the contents of a tar archive
|
|
|
|
|
* List the contents of an archive
|
|
|
|
|
*/
|
|
|
|
|
void initrd_list(char *buf)
|
|
|
|
|
{
|
|
|
|
|
char *types[]={"regular", "link ", "symlnk", "chrdev", "blkdev", "dircty", "fifo ", "??? "};
|
|
|
|
|
|
|
|
|
|
uart_puts("Type Offset Size Access rights\tFilename\n");
|
|
|
|
|
uart_puts("Type Offset Size Access rights\tFilename\n");
|
|
|
|
|
|
|
|
|
|
// iterate on archive's contents
|
|
|
|
|
while(!__builtin_memcmp(buf+257,"ustar",5)){
|
|
|
|
|
int fs=oct2bin(buf+0x7c,11);
|
|
|
|
|
while(!__builtin_memcmp(buf+257,"ustar",5)) {
|
|
|
|
|
// if it's an ustar archive
|
|
|
|
|
tar_t *header=(tar_t*)buf;
|
|
|
|
|
int fs=oct2bin(header->size,11);
|
|
|
|
|
// print out meta information
|
|
|
|
|
uart_puts(types[buf[0x9c]-'0']);
|
|
|
|
|
uart_puts(types[header->typeflag-'0']);
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_hex((unsigned int)((unsigned long)buf)+512);
|
|
|
|
|
uart_hex((unsigned int)((unsigned long)buf)+sizeof(tar_t));
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_hex(fs); // file size in hex
|
|
|
|
|
uart_hex(fs); // file size in hex
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_puts(buf+0x64); // access bits in octal
|
|
|
|
|
uart_puts(header->mode); // access bits in octal
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_puts(buf+0x109); // owner
|
|
|
|
|
uart_puts(header->uname); // owner
|
|
|
|
|
uart_send('.');
|
|
|
|
|
uart_puts(buf+0x129); // group
|
|
|
|
|
uart_puts(header->gname); // group
|
|
|
|
|
uart_send('\t');
|
|
|
|
|
uart_puts(buf); // filename
|
|
|
|
|
if(buf[0x9c]=='2') {
|
|
|
|
|
uart_puts(" -> "); // symlink target
|
|
|
|
|
uart_puts(buf+0x9d);
|
|
|
|
|
uart_puts(buf); // filename
|
|
|
|
|
if(header->typeflag=='2') {
|
|
|
|
|
uart_puts(" -> "); // symlink target
|
|
|
|
|
uart_puts(header->linkname);
|
|
|
|
|
}
|
|
|
|
|
uart_puts("\n");
|
|
|
|
|
// jump to the next file
|
|
|
|
|
buf+=(((fs+511)/512)+1)*512;
|
|
|
|
|
}
|
|
|
|
|
// if it's a cpio archive. Cpio also has a trailer entry
|
|
|
|
|
while(!__builtin_memcmp(buf,"070707",6) && __builtin_memcmp(buf+sizeof(cpio_t),"TRAILER!!",9)) {
|
|
|
|
|
cpio_t *header = (cpio_t*)buf;
|
|
|
|
|
int ns=oct2bin(header->namesize,6);
|
|
|
|
|
int fs=oct2bin(header->filesize,11);
|
|
|
|
|
// print out meta information
|
|
|
|
|
uart_hex(oct2bin(header->mode,6)); // mode (access rights + type)
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_hex((unsigned int)((unsigned long)buf)+sizeof(cpio_t)+ns);
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_hex(fs); // file size in hex
|
|
|
|
|
uart_send(' ');
|
|
|
|
|
uart_hex(oct2bin(header->uid,6)); // user id in hex
|
|
|
|
|
uart_send('.');
|
|
|
|
|
uart_hex(oct2bin(header->gid,6)); // group id in hex
|
|
|
|
|
uart_send('\t');
|
|
|
|
|
uart_puts(buf+sizeof(cpio_t)); // filename
|
|
|
|
|
uart_puts("\n");
|
|
|
|
|
// jump to the next file
|
|
|
|
|
buf+=(sizeof(cpio_t)+ns+fs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|