From 7004eb2d77da0d3d3280e10f82d88bfc1624bea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D0=BD=D1=8C=D0=BA=D0=B8=D0=BD=20=D0=90=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Sat, 10 Sep 2022 22:32:10 +0300 Subject: [PATCH] Fix merge bug, fix readme --- NyaFs/Filesystem/Ext2/Ext2FsBase.cs | 3 +- NyaFs/Filesystem/Ext2/Ext2FsBuilder.cs | 24 +++++++------- NyaFs/Filesystem/Ext2/Types/ExtBlockGroup.cs | 2 +- NyaFs/Filesystem/Ext2/Types/ExtINode.cs | 4 +-- NyaFs/Filesystem/Ext2/Types/ExtSuperBlock.cs | 33 +++++++++++++++----- readme.md | 23 ++++++++++---- 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/NyaFs/Filesystem/Ext2/Ext2FsBase.cs b/NyaFs/Filesystem/Ext2/Ext2FsBase.cs index 92fa77f..7c08905 100644 --- a/NyaFs/Filesystem/Ext2/Ext2FsBase.cs +++ b/NyaFs/Filesystem/Ext2/Ext2FsBase.cs @@ -163,6 +163,5 @@ internal byte[] GetINodeContent(Types.ExtINode Node) return GetINodeBlockContent(Node); } } - } -} +} \ No newline at end of file diff --git a/NyaFs/Filesystem/Ext2/Ext2FsBuilder.cs b/NyaFs/Filesystem/Ext2/Ext2FsBuilder.cs index 5280272..721e89a 100644 --- a/NyaFs/Filesystem/Ext2/Ext2FsBuilder.cs +++ b/NyaFs/Filesystem/Ext2/Ext2FsBuilder.cs @@ -55,7 +55,7 @@ private void MarkBlockBusy(uint Block, bool MarkInBG = true) { BlockMap[MapIndex] |= (1u << MapBit); - if(MarkInBG) + if (MarkInBG) MarkBlockAsUsedInBlockGroup(Block); } } @@ -190,7 +190,7 @@ private void DuplicateSuperblocks() /// public byte[] GetFilesystemImage() { - foreach(var D in Dirs) + foreach (var D in Dirs) { SetNodeBlockContent(D.Node, D.Content); D.Node.LinksCount = Convert.ToUInt32(D.Entries.Count(E => GetINode(E.INode).FsNodeType == Universal.Types.FilesystemItemType.Directory)); @@ -205,9 +205,9 @@ private BuilderDirectory GetParentDirectory(string Path) { var Parent = Universal.Helper.FsHelper.GetParentDirPath(Path); - foreach(var D in Dirs) + foreach (var D in Dirs) { - if(D.Path == Parent) + if (D.Path == Parent) return D; } @@ -266,7 +266,7 @@ private void AddNestedNode(string Path, Func NodeGetter) Parent.Entries.Add(new Types.ExtDirectoryEntry(Convert.ToUInt32(N.Index), Types.ExtINodeType.NONE, Universal.Helper.FsHelper.GetName(Path))); var BG = GetBlockGroupByNodeId(N.Index); - if(N.NodeType == Types.ExtINodeType.DIR) + if (N.NodeType == Types.ExtINodeType.DIR) { BG.UsedDirsCountLo++; @@ -340,14 +340,14 @@ public void Directory(string Path, uint User, uint Group, uint Mode) Dirs.Add(D); var BG = GetBlockGroupByNodeId(N.Index); - BG.UsedDirsCountLo++; + BG.UsedDirsCountLo++; D.Entries.Add(new Types.ExtDirectoryEntry(Convert.ToUInt32(N.Index), Types.ExtINodeType.NONE, ".")); D.Entries.Add(new Types.ExtDirectoryEntry(Convert.ToUInt32(N.Index), Types.ExtINodeType.NONE, "..")); INodeIndex += 12; // skip reserved items } - else + else throw new ArgumentException("Cannot create new root node"); } else @@ -422,7 +422,7 @@ public void SymLink(string Path, string Target, uint User, uint Group, uint Mode { var N = CreateNewINode(Types.ExtINodeType.LINK, User, Group, Mode); - if(Target.Length <= 60) + if (Target.Length <= 60) N.SetText(Target); else SetNodeBlockContent(N, UTF8Encoding.UTF8.GetBytes(Target)); @@ -472,11 +472,11 @@ uint GetNewBlock() void AddBlockToNode(Types.ExtINode Node, uint Block) { var Index = Node.BlocksCount; - if(Index < 12) + if (Index < 12) { Node.UpdateBlockByIndex(Index, Block); } - else if(Index < 12 + (Superblock.BlockSize / 4)) + else if (Index < 12 + (Superblock.BlockSize / 4)) { uint Offset = Index - 12; // One-level indirect table @@ -609,7 +609,7 @@ public byte[] Content for (int i = 0; i < Entries.Count; i++) { var E = Entries[i]; - if(Temp.Count + E.getLength() > TempBlock.Length) + if (Temp.Count + E.getLength() > TempBlock.Length) { TempBlock.WriteArray(0, Temp.ToArray(), Temp.Count); var Last = new Types.ExtDirectoryEntry(TempBlock, PrevSize); @@ -635,4 +635,4 @@ public byte[] Content } } } -} +} \ No newline at end of file diff --git a/NyaFs/Filesystem/Ext2/Types/ExtBlockGroup.cs b/NyaFs/Filesystem/Ext2/Types/ExtBlockGroup.cs index a1f4725..3337d6d 100644 --- a/NyaFs/Filesystem/Ext2/Types/ExtBlockGroup.cs +++ b/NyaFs/Filesystem/Ext2/Types/ExtBlockGroup.cs @@ -141,4 +141,4 @@ public uint Checksum set { WriteUInt16(0x1E, value); } } } -} +} \ No newline at end of file diff --git a/NyaFs/Filesystem/Ext2/Types/ExtINode.cs b/NyaFs/Filesystem/Ext2/Types/ExtINode.cs index 77a5236..5f67f4f 100644 --- a/NyaFs/Filesystem/Ext2/Types/ExtINode.cs +++ b/NyaFs/Filesystem/Ext2/Types/ExtINode.cs @@ -7,8 +7,8 @@ namespace NyaFs.Filesystem.Ext2.Types { internal class ExtINode : ArrayWrapper { - public readonly uint Index; public uint BlocksCount = 0; + public readonly uint Index; /// /// Wrapper for INode struct @@ -77,7 +77,7 @@ public uint Mode /// 0xA000 S_IFLNK(Symbolic link) /// 0xC000 S_IFSOCK(Socket) /// - public ExtINodeType NodeType => (ExtINodeType)(Mode & 0xF000); + public ExtINodeType NodeType => (ExtINodeType)(Mode & 0xF000); /// /// Filesystem node type diff --git a/NyaFs/Filesystem/Ext2/Types/ExtSuperBlock.cs b/NyaFs/Filesystem/Ext2/Types/ExtSuperBlock.cs index 2e9cfd5..cea08d3 100644 --- a/NyaFs/Filesystem/Ext2/Types/ExtSuperBlock.cs +++ b/NyaFs/Filesystem/Ext2/Types/ExtSuperBlock.cs @@ -162,8 +162,8 @@ public DateTime MountTime /// public uint WTime { - get { return ReadUInt32(0x30); } - set { WriteUInt32(0x30, value); } + get { return ReadUInt32(0x2C); } + set { WriteUInt32(0x2C, value); } } /// @@ -324,11 +324,11 @@ public uint DefaultReservedGid set { WriteUInt16(0x52, value); } } - // ext2: 0x68 74 CC 73 3B - // ext2: 0x6c 6C 44 44 AE - // ext2: 0x70 AE 20 23 9F - // ext2: 0x74 0F 21 C0 CB - + // These fields are for EXT4_DYNAMIC_REV superblocks only. + // Note: the difference between the compatible feature set and the incompatible feature set is that if there is a bit set in the incompatible + // feature set that the kernel doesn't know about, it should refuse to mount the filesystem. + // e2fsck's requirements are more strict; if it doesn't know about a feature in either the compatible or incompatible feature set, + // it must abort and not try to meddle with things it doesn't understand... /// /// First non-reserved inode. @@ -467,5 +467,24 @@ public string VolumeName set { WriteString(0x78, value, 0x10); } } + /// + /// Directory where filesystem was last mounted. + /// char s_last_mounted[64] (0x88) + /// + public string LastMountedDir + { + get { return ReadString(0x88, 0x40); } + set { WriteString(0x88, value, 0x40); } + } + + /// + /// For compression (Not used in e2fsprogs/Linux) + /// s_algorithm_usage_bitmap (0xC8) + /// + public uint AlgorithmUsageBitmap + { + get { return ReadUInt32(0xC8); } + set { WriteUInt32(0xC8, value); } + } } } diff --git a/readme.md b/readme.md index 5eab3f1..00eaa76 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ There is possible to add or update files in ramfs image. ## Supported filesystems Supported at now: 1. CPIO ASCII (RW) -2. EXT2 (R) +2. EXT2 (RW) 3. SquashFs (R) ## Supported compression types @@ -74,12 +74,12 @@ reset ``` ## Commands for image loading -### Composite images -Load kernel, fs or/and devtree from image (with autodetection of image type): +Default load command (type and image format autodetect): ``` load ``` +### Composite images Load only one image from FIT image, where imagetype is "kernel", "ramfs" or "devtree": ``` load fit @@ -106,7 +106,7 @@ load ramfs ext2 ``` Load fs from squashfs image: ``` -load ramfs squashfs +load ramfs squashfs ``` ### Kernel image @@ -150,12 +150,17 @@ Store fs as legacy image: ``` store ramfs legacy ``` -Store fs as compressed cpio archive: +Store fs as compressed cpio/ext2 archive: ``` -store ramfs +store ramfs ``` (compression) is "gzip", "lz4", "lzma", "bzip2" +Store fs as ext2 image: +``` +store ramfs ext2 +``` + Store fs as cpio file: ``` store ramfs cpio @@ -190,6 +195,12 @@ export ``` ## Commands for modify image parameters: +Update filesystem type: +``` +set ramfs filesystem +``` +(fs) is one of 'ext2' or 'cpio'. + Update target OS for image: ``` set os