Skip to content

Commit

Permalink
Fix merge bug, fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
teplofizik committed Sep 10, 2022
1 parent 2ac0bbc commit 7004eb2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 30 deletions.
3 changes: 1 addition & 2 deletions NyaFs/Filesystem/Ext2/Ext2FsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,5 @@ internal byte[] GetINodeContent(Types.ExtINode Node)
return GetINodeBlockContent(Node);
}
}

}
}
}
24 changes: 12 additions & 12 deletions NyaFs/Filesystem/Ext2/Ext2FsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void MarkBlockBusy(uint Block, bool MarkInBG = true)
{
BlockMap[MapIndex] |= (1u << MapBit);

if(MarkInBG)
if (MarkInBG)
MarkBlockAsUsedInBlockGroup(Block);
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ private void DuplicateSuperblocks()
/// <returns></returns>
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));
Expand All @@ -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;
}

Expand Down Expand Up @@ -266,7 +266,7 @@ private void AddNestedNode(string Path, Func<Types.ExtINode> 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++;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -635,4 +635,4 @@ public byte[] Content
}
}
}
}
}
2 changes: 1 addition & 1 deletion NyaFs/Filesystem/Ext2/Types/ExtBlockGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ public uint Checksum
set { WriteUInt16(0x1E, value); }
}
}
}
}
4 changes: 2 additions & 2 deletions NyaFs/Filesystem/Ext2/Types/ExtINode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Wrapper for INode struct
Expand Down Expand Up @@ -77,7 +77,7 @@ public uint Mode
/// 0xA000 S_IFLNK(Symbolic link)
/// 0xC000 S_IFSOCK(Socket)
/// </summary>
public ExtINodeType NodeType => (ExtINodeType)(Mode & 0xF000);
public ExtINodeType NodeType => (ExtINodeType)(Mode & 0xF000);

/// <summary>
/// Filesystem node type
Expand Down
33 changes: 26 additions & 7 deletions NyaFs/Filesystem/Ext2/Types/ExtSuperBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public DateTime MountTime
/// </summary>
public uint WTime
{
get { return ReadUInt32(0x30); }
set { WriteUInt32(0x30, value); }
get { return ReadUInt32(0x2C); }
set { WriteUInt32(0x2C, value); }
}

/// <summary>
Expand Down Expand Up @@ -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...

/// <summary>
/// First non-reserved inode.
Expand Down Expand Up @@ -467,5 +467,24 @@ public string VolumeName
set { WriteString(0x78, value, 0x10); }
}

/// <summary>
/// Directory where filesystem was last mounted.
/// char s_last_mounted[64] (0x88)
/// </summary>
public string LastMountedDir
{
get { return ReadString(0x88, 0x40); }
set { WriteString(0x88, value, 0x40); }
}

/// <summary>
/// For compression (Not used in e2fsprogs/Linux)
/// s_algorithm_usage_bitmap (0xC8)
/// </summary>
public uint AlgorithmUsageBitmap
{
get { return ReadUInt32(0xC8); }
set { WriteUInt32(0xC8, value); }
}
}
}
23 changes: 17 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <filename>
```

### Composite images
Load only one image from FIT image, where imagetype is "kernel", "ramfs" or "devtree":
```
load <filename.fit> <imagetype> fit
Expand All @@ -106,7 +106,7 @@ load <filename.ext2> ramfs ext2
```
Load fs from squashfs image:
```
load <filename.ext2> ramfs squashfs
load <filename.sqfs> ramfs squashfs
```

### Kernel image
Expand Down Expand Up @@ -150,12 +150,17 @@ Store fs as legacy image:
```
store <filename.legacy> ramfs legacy
```
Store fs as compressed cpio archive:
Store fs as compressed cpio/ext2 archive:
```
store <filename.cpio.ct> ramfs <compression>
store <filename.fs.ct> ramfs <compression>
```
(compression) is "gzip", "lz4", "lzma", "bzip2"

Store fs as ext2 image:
```
store <filename.ext2> ramfs ext2
```

Store fs as cpio file:
```
store <filename.cpio> ramfs cpio
Expand Down Expand Up @@ -190,6 +195,12 @@ export <path>
```

## Commands for modify image parameters:
Update filesystem type:
```
set ramfs filesystem <fs>
```
(fs) is one of 'ext2' or 'cpio'.

Update target OS for image:
```
set <imagetype> os <ostype>
Expand Down

0 comments on commit 7004eb2

Please sign in to comment.