From 1ac24e3c06498436734bb4d65452e617eff6be46 Mon Sep 17 00:00:00 2001 From: bzt Date: Thu, 25 Mar 2021 08:30:25 +0100 Subject: [PATCH] More file system stuff --- aarch64-rpi/fs.h | 12 ++++++------ dist/bootboot.bin | Bin 13312 -> 13312 bytes dist/bootboot.efi | Bin 103614 -> 103614 bytes dist/bootboot.img | Bin 35488 -> 35488 bytes dist/bootboot.rom | Bin 103936 -> 103936 bytes mkbootimg/OLVASSEL.md | 2 +- mkbootimg/README.md | 2 +- mkbootimg/data.c | 6 +++--- mkbootimg/data.h | 6 +++--- mkbootimg/ech.c | 1 + mkbootimg/ext2.c | 1 + mkbootimg/fat.c | 5 +++-- mkbootimg/fsZ.c | 1 - mkbootimg/fsZ.h | 23 +++++++++++------------ mkbootimg/lean.c | 15 ++++++++------- mkbootimg/minix.c | 1 + x86_64-bios/fs.inc | 8 +++----- x86_64-cb/fs.h | 12 ++++++------ x86_64-efi/fs.h | 10 +++++----- 19 files changed, 53 insertions(+), 52 deletions(-) diff --git a/aarch64-rpi/fs.h b/aarch64-rpi/fs.h index f0e200b..d804177 100644 --- a/aarch64-rpi/fs.h +++ b/aarch64-rpi/fs.h @@ -38,14 +38,14 @@ file_t fsz_initrd(unsigned char *initrd_p, char *kernel) return ret; } unsigned char passphrase[256],chk[32],iv[32]; - unsigned int i,j,k,l,ss=1<<(*((uint16_t*)(initrd_p+520))+11); + unsigned int i,j,k,l,ss=1<<(initrd_p[518]+11); unsigned char *ent, *in=(initrd_p+*((uint64_t*)(initrd_p+560))*ss); SHA256_CTX ctx; DBG(" * FS/Z "); DBG(kernel); DBG("\n"); //decrypt initrd - if(*((uint32_t*)(initrd_p+708))!=0 && ((initrd_p[518]>>2)&7)!=0) { + if(*((uint32_t*)(initrd_p+708))!=0 && initrd_p[519]!=0) { puts("BOOTBOOT-PANIC: Unsupported cipher\n"); return ret; } @@ -94,8 +94,8 @@ again: if(*e=='/'){e++;} if(!memcmp(in,"FSIN",4)){ //is it inlined? - if(!memcmp(initrd_p[518]&1? in + 2048 : in + 1024,"FSDR",4)){ - ent=(initrd_p[518]&1? in + 2048 : in + 1024); + if(!memcmp(initrd_p[520]&1? in + 2048 : in + 1024,"FSDR",4)){ + ent=(initrd_p[520]&1? in + 2048 : in + 1024); } else if(!memcmp(initrd_p+*((uint64_t*)(in+448))*ss,"FSDR",4)){ // go, get the sector pointed ent=(initrd_p+*((uint64_t*)(in+448))*ss); @@ -130,12 +130,12 @@ again: switch(in[488]) { case 0xFF: // inline data - ret.ptr=(uint8_t*)(initrd_p+i*ss+(initrd_p[518]&1? 2048 : 1024)); + ret.ptr=(uint8_t*)(initrd_p+i*ss+(initrd_p[520]&1? 2048 : 1024)); break; case 0x80: case 0x7F: // sector directory or list inlined - ret.ptr=(uint8_t*)(initrd_p + *((uint64_t*)(initrd_p[518]&1? in + 2048 : in + 1024))*ss); + ret.ptr=(uint8_t*)(initrd_p + *((uint64_t*)(initrd_p[520]&1? in + 2048 : in + 1024))*ss); break; case 0: // direct data diff --git a/dist/bootboot.bin b/dist/bootboot.bin index 204bdf0759841bf843ddf326e429a7c7879ee0df..acdcd4eeb30f2d022b0f8ee51ce873b67c7b0d29 100644 GIT binary patch delta 780 zcmX|8Ur19?96rajHg}y%)E+kNZrXIy(uSKgw`ulZLcN(+2)e#4pUPkZ3Bk!t;d()W z1NNX167>)Y#iS78I#aHQ^pY^5D2*OE^WKM4Fa*JVXG8D9;rzaT=R5bL22ul--Z#$N z2HJXOIV{EH1Us7X?{vU1!i}`o4cAxrI{eT42+13P^-&cSA=K5=eAh9?!%k9HVMUH7 zKQTfR;}#gKnM56(GLDZ0)oP_NLljgYOhbkkR~On4qKyXaHgbPJ-$x(jWo2P{-Vm33 zQO%6#4?XHia)R0trr01sS5stHSA9`9{?NZG+mG5IqNx-X8+ha5{djnaRY=$bb-j(g z(nWntP(5Kft&8+S`njtdS8wjHG7$K9N2F6b{cC2_0j1Bd#@6)bs;3wa67fRNYXjlS zL_M7KSITrQav-7yIlzVh6Z$0WwqhS7ZocwP8SG6VCN+f^sY|DTVrRgLyeDbmqLoDm zEFvG9m9*9ZcH<;g&a&VKh2Ux%lU+Q*+UyXy$@ARF2%+Q=-+)WV4Bz0$QV2ZfW1SRx ziH~^riWcXn#-3)D!RBN5yUVnAdAk^E`gDO&?2KB0LitZKM@W^s6-P*q+Z$|w_YGvO z2i7MhKY}+EivWNUXD24#vvJw7xh>nTGSL@h{B1!&=G;!OuemQ>V|GcaF@>0I|8>8Z z{3`D&UAB`PlhVb>S@7mF{{6z5a?1%MY4o(06Y$9U^YW*;=u)zhU5SukPX_OiSdBBd z*Mv|MCoQxW3SG%Wi;`yQ&KF<|0^$I!t-De&HsgdHHfg2i9>!bgToT4k1I2% clX$#U+{o$tf^>Vo;e~W<-MlHi;SbsV12hd7Y5)KL delta 813 zcmYk4ZAep57{|}q?YiNZYnZ(_b<^giV!DxUlW7ZM1Vs|DNkP{yu_Pi0c8NZOldFU4 z1xpT?ANCeuPvaHQ^vmq_#na7dQ6i(Yp=Pt!`m8 z>Kk|?YyWqQ&|o4DM2Z?*MpG*0ro-t>CZd{5v?VP>)QF#Y(?V2z-ii=)r)fue?FTe< z(JR@Q%};GHIwg3?qDpE^JNWg9)b^V zdf__W0x^9a7}h(RG;R=C@?vIQEsyl<8e9W?d=?!|Hw--GO|sUP}FB+ c+w7s(%M9dPQ*j4!(rZ00caR(nrIY1NuHIt|(rZ0version_major=FSZ_VERSION_MAJOR; sb->version_minor=FSZ_VERSION_MINOR; sb->logsec=fsz_secsize==2048?0:(fsz_secsize==4096?1:2); - sb->physec=fsz_secsize/512; sb->maxmounts=255; sb->currmounts=0; sb->createdate=sb->lastmountdate=sb->lastumountdate=t * 1000000; diff --git a/mkbootimg/fsZ.h b/mkbootimg/fsZ.h index 88f53e2..3c072ef 100644 --- a/mkbootimg/fsZ.h +++ b/mkbootimg/fsZ.h @@ -54,10 +54,9 @@ typedef struct { uint8_t magic[4]; /* 512 */ uint8_t version_major; /* 516 */ uint8_t version_minor; /* 517 */ - uint8_t flags; /* 518 flags */ + uint8_t logsec; /* 518 logical sector size, 0=2048,1=4096(default),2=8192... */ uint8_t enctype; /* 519 encryption alogirthm */ - uint16_t logsec; /* 520 logical sector size, 0=2048,1=4096(default),2=8192... */ - uint16_t physec; /* 522 how many physical sector gives up a logical one, defaults to 8 */ + uint32_t flags; /* 520 flags */ uint16_t maxmounts; /* 524 number of maximum mounts allowed to next fsck */ uint16_t currmounts; /* 526 current mount counter */ uint64_t numsec; /* 528 total number of logical sectors */ @@ -95,16 +94,17 @@ typedef struct { #define FSZ_MAGIC "FS/Z" #define FSZ_RAIDMAGIC "FSRD" -/* feature flags */ -#define FSZ_SB_FLAG_BIGINODE (1<<0) /* indicates inode size is 2048 (ACL size 96 instead of 32) */ -#define FSZ_SB_JOURNAL_DATA (1<<1) /* also put file content records in journal file, not just metadata */ -#define FSZ_SB_SOFTRAID (1<<2) /* single disk when not set */ -#define FSZ_SB_ACCESSDATE (1<<3) /* store last access timestamp in i-nodes */ -/* bits 4 - 7 are reserved for future use */ #define FSZ_SB_EALG_SHACBC 0 /* encrypted with SHA-XOR-CBC */ #define FSZ_SB_EALG_AESCBC 1 /* encrypted with AES-256-CBC */ /* values 2 - 255 are reserved for future use */ +/* feature flags */ +#define FSZ_SB_BIGINODE (1<<0) /* indicates inode size is 2048 (ACL size 96 instead of 32) */ +#define FSZ_SB_JOURNAL_DATA (1<<1) /* also put file content records in journal file, not just metadata */ +#define FSZ_SB_SOFTRAID (1<<2) /* single disk when not set */ +#define FSZ_SB_ACCESSDATE (1<<3) /* store last access timestamp in i-nodes */ +/* bits 4 - 31 are reserved for future use */ + /********************************************************* * I-node sector * *********************************************************/ @@ -202,9 +202,7 @@ typedef struct { #define FSZ_IN_MAGIC "FSIN" -/* (*) according to IANA, there's only two groups of mime types which does not fit into this (both vendor specific): - * application/vnd.collabio.xodicuments.* and application/vnd.openxmlformats-officedocument.* - * those two must be shortend. All the other, more than 1700 mime types are unique on 4+36 bytes. */ +/* (*) according to IANA, all, more than 1700 mime types are unique on 4+60 bytes. */ /* regular files, 4th character never ':' */ #define FSZ_FILETYPE_REG_TEXT "text" /* main part of mime type */ @@ -220,6 +218,7 @@ typedef struct { #define FSZ_FILETYPE_SYMLINK "lnk:" /* symbolic link, inlined data is a path */ #define FSZ_FILETYPE_PIPE "pip:" /* named pipe (FIFO) */ #define FSZ_FILETYPE_DEV "dev:" /* device */ +#define FSZ_FILETYPE_SOCK "sck:" /* socket */ /* mime types for filesystem specific files */ /* for FSZ_FILETYPE_DIR */ diff --git a/mkbootimg/lean.c b/mkbootimg/lean.c index 71127ff..b6562a2 100644 --- a/mkbootimg/lean.c +++ b/mkbootimg/lean.c @@ -26,12 +26,13 @@ * This file is part of the BOOTBOOT Protocol package. * @brief LeanFS file system driver * See http://freedos-32.sourceforge.net/lean/specification.php + * See http://www.fysnet.net/leanfs/specification.php * */ #include "main.h" #define LEAN_SUPER_MAGIC 0x4E41454C -#define LEAN_SUPER_VERSION 0x0006 +#define LEAN_SUPER_VERSION 0x0007 /* could be 0x0006 as well, backwards compatible */ #define LEAN_INODE_MAGIC 0x45444F4E #define LEAN_INODE_EXTENT_CNT 6 #define LEAN_FT_MT 0 @@ -63,15 +64,16 @@ typedef struct { uint64_t bitmap_start; uint64_t root_inode; uint64_t bad_inode; - uint8_t reserved2[360]; + uint64_t journal_inode; + uint8_t log_block_size; + uint8_t reserved2[344]; } __attribute__((packed)) lean_super_t; typedef struct { uint32_t checksum; uint32_t magic; uint8_t extent_count; - uint8_t inode_size; - uint16_t reserved; + uint8_t reserved[3]; uint32_t indirect_count; uint32_t links_count; uint32_t uid; @@ -153,9 +155,6 @@ int len_alloc_inode(uint16_t mode, uint8_t type, uint64_t size, time_t t) int n = len_alloc_blk(), i; inode = (lean_inode_t*)(fs_base + n * 512); inode->magic = LEAN_INODE_MAGIC; -#if LEAN_SUPER_VERSION == 0x0007 - inode->inode_size = sizeof(lean_inode_t) / 4; -#endif inode->attributes = (mode & 0xFFF) | LEAN_ATTR_IFTYPE(type) | LEAN_ATTR_INLINEXTATTR | (type == LEAN_FT_DIR ? LEAN_ATTR_PREALLOC : 0); inode->atime = inode->ctime = inode->mtime = inode->btime = (uint64_t)t * 1000000; @@ -230,6 +229,7 @@ uint8_t *len_add_dirent(uint8_t *dir, uint64_t toinode, uint64_t ino, uint8_t ty return dir; } +/*** mkbootimg interface ***/ void len_open(gpt_t *gpt_entry) { int i, j, numband; @@ -250,6 +250,7 @@ void len_open(gpt_t *gpt_entry) len_sb->state = 1; memcpy(&len_sb->uuid, &gpt_entry->guid, sizeof(guid_t)); memcpy(&len_sb->volume_label, "NO NAME", 7); + len_sb->log_block_size = 9; len_sb->sector_count = len_numblk; len_sb->free_sector_count = len_numblk - 34 - numband * LEAN_BITMAPSIZE; /* loader, superblock, backup, bitmaps */ len_sb->primary_super = 32; diff --git a/mkbootimg/minix.c b/mkbootimg/minix.c index 9aa77a5..a4035b5 100644 --- a/mkbootimg/minix.c +++ b/mkbootimg/minix.c @@ -253,6 +253,7 @@ void mnx_enter_dir(ino_t parent, char const *name, ino_t child) exit(1); } +/*** mkbootimg interface ***/ void mnx_open(gpt_t *gpt_entry) { zone_t z; diff --git a/x86_64-bios/fs.inc b/x86_64-bios/fs.inc index 337f1f7..9710d2d 100644 --- a/x86_64-bios/fs.inc +++ b/x86_64-bios/fs.inc @@ -57,9 +57,7 @@ fsz_initrd: ; encrypted initrd? cmp dword [esi+708], 0 ; FSZ_SuperBlock.enchash jz .noenc - mov al, byte [esi+518] ; FSZ_SuperBlock.flags - shr al, 2 - and al, 7 + mov al, byte [esi+519] ; FSZ_SuperBlock.enctype or al, al jz @f prot_realmode @@ -199,8 +197,8 @@ fsz_initrd: ; get root dir inode .noenc: mov dword [_i], 1024 - mov al, byte [esi+518] ; FSZ_SuperBlock.flags - bt ax, 0 ; FSZ_FLAG_BIGINODE? + mov al, byte [esi+520] ; FSZ_SuperBlock.flags + bt ax, 0 ; FSZ_SB_BIGINODE? jnc @f mov dword [_i], 2048 @@: mov eax, dword [esi+560] ; FSZ_SuperBlock.rootdirfid diff --git a/x86_64-cb/fs.h b/x86_64-cb/fs.h index 1dffec0..d800e84 100644 --- a/x86_64-cb/fs.h +++ b/x86_64-cb/fs.h @@ -38,12 +38,12 @@ file_t fsz_initrd(unsigned char *initrd_p, char *kernel) return ret; } unsigned char passphrase[256],chk[32],iv[32]; - unsigned int i,j,k,l,ss=1<<(*((uint16_t*)(initrd_p+520))+11); + unsigned int i,j,k,l,ss=1<<(initrd_p[518]+11); unsigned char *ent, *in=(initrd_p+*((uint64_t*)(initrd_p+560))*ss); SHA256_CTX ctx; DBG(" * FS/Z %s\n",kernel); //decrypt initrd - if(*((uint32_t*)(initrd_p+708))!=0 && ((initrd_p[518]>>2)&7)!=0) { + if(*((uint32_t*)(initrd_p+708))!=0 && initrd_p[519]!=0) { printf("BOOTBOOT-PANIC: Unsupported cipher\n"); return ret; } @@ -92,8 +92,8 @@ again: if(*e=='/'){e++;} if(!memcmp(in,"FSIN",4)){ //is it inlined? - if(!memcmp(initrd_p[518]&1? in + 2048 : in + 1024,"FSDR",4)){ - ent=(initrd_p[518]&1? in + 2048 : in + 1024); + if(!memcmp(initrd_p[520]&1? in + 2048 : in + 1024,"FSDR",4)){ + ent=(initrd_p[520]&1? in + 2048 : in + 1024); } else if(!memcmp(initrd_p+*((uint64_t*)(in+448))*ss,"FSDR",4)){ // go, get the sector pointed ent=(initrd_p+*((uint64_t*)(in+448))*ss); @@ -128,12 +128,12 @@ again: switch(in[488]) { case 0xFF: // inline data - ret.ptr=(uint8_t*)(initrd_p+i*ss+(initrd_p[518]&1? 2048 : 1024)); + ret.ptr=(uint8_t*)(initrd_p+i*ss+(initrd_p[520]&1? 2048 : 1024)); break; case 0x80: case 0x7F: // sector directory or list inlined - ret.ptr=(uint8_t*)(initrd_p + *((uint64_t*)(initrd_p[518]&1? in + 2048 : in + 1024))*ss); + ret.ptr=(uint8_t*)(initrd_p + *((uint64_t*)(initrd_p[520]&1? in + 2048 : in + 1024))*ss); break; case 0: // direct data diff --git a/x86_64-efi/fs.h b/x86_64-efi/fs.h index 3305965..8ee2642 100644 --- a/x86_64-efi/fs.h +++ b/x86_64-efi/fs.h @@ -38,7 +38,7 @@ file_t fsz_initrd(unsigned char *initrd_p, char *kernel) return ret; } unsigned char passphrase[256],chk[32],iv[32]; - unsigned int i,j,k,l,ss=1<<(*((uint16_t*)(initrd_p+520))+11); + unsigned int i,j,k,l,ss=1<<(initrd_p[519]+11); unsigned char *ent, *in=(initrd_p+*((uint64_t*)(initrd_p+560))*ss); SHA256_CTX ctx; DBG(L" * FS/Z %s\n",a2u(kernel)); @@ -95,8 +95,8 @@ again: if(*e=='/'){e++;} if(!CompareMem(in,"FSIN",4)){ //is it inlined? - if(!CompareMem(initrd_p[518]&1? in + 2048 : in + 1024,"FSDR",4)){ - ent=(initrd_p[518]&1? in + 2048 : in + 1024); + if(!CompareMem(initrd_p[520]&1? in + 2048 : in + 1024,"FSDR",4)){ + ent=(initrd_p[520]&1? in + 2048 : in + 1024); } else if(!CompareMem(initrd_p+*((uint64_t*)(in+448))*ss,"FSDR",4)){ // go, get the sector pointed ent=(initrd_p+*((uint64_t*)(in+448))*ss); @@ -131,12 +131,12 @@ again: switch(in[488]) { case 0xFF: // inline data - ret.ptr=(uint8_t*)(initrd_p+i*ss+(initrd_p[518]&1? 2048 : 1024)); + ret.ptr=(uint8_t*)(initrd_p+i*ss+(initrd_p[520]&1? 2048 : 1024)); break; case 0x80: case 0x7F: // sector directory or list inlined - ret.ptr=(uint8_t*)(initrd_p + *((uint64_t*)(initrd_p[518]&1? in + 2048 : in + 1024))*ss); + ret.ptr=(uint8_t*)(initrd_p + *((uint64_t*)(initrd_p[520]&1? in + 2048 : in + 1024))*ss); break; case 0: // direct data