nickdu088 / sharpext4 Goto Github PK
View Code? Open in Web Editor NEWA .Net library to provide full access (read/write) to Linux ext2/ext3/ext4 filesystem
Home Page: https://www.nickdu.com/?p=890
A .Net library to provide full access (read/write) to Linux ext2/ext3/ext4 filesystem
Home Page: https://www.nickdu.com/?p=890
Hello!
I want install my Windows 11 for test into EXT4 base partition or into vDISK.vhdx, which save into EXT4 base partition.
I do this:
Now I have work OS Windows 11 on vDISK.vhdx into NTFS base partition. This work. I want use EXT4 base partition.
Can you help me?
Hey Nick, I was trying to access a 1TB Sandisk sdxc card formatted as EXT4 and I am getting the error :
An unhandled exception of type 'System.IO.IOException' occurred in SharpExt4.dll
Could not read disk MBR.
Basic Code:
var disk = ExtDisk.Open(1);
Debug.WriteLine(disk.ToString());
I can confirm I am passing in the correct Disk number (verified via Disk Manager. Here's some additional info that may help.
OS: Windows 11 Home (10.0.22000)
Visual Studio Community 2022
.NET 4.8
Could it be because I'm using EXT4 with casefolding?
Tried to reference this project to a dotnet core based project (a dotnet core console application), Then I am getting an issue as mentioned below. It will be great if you are able to help me to fix the same.
Could not load file or assembly 'SharpExt4, Version=1.0.8402.18282, Culture=neutral, PublicKeyToken=null'. Format of the executable (.exe) or library (.dll) is invalid.
Hello
I mount a Linux-based virtual machine (vhdx) with the arsenal mounter. I see this added in Disk management I want to access this disk with Sharpext4 and read and copy it I couldn't find how to do it. I used the code below but I get the Could not read disk MBR error.
private void Mountet_Click(object sender, RoutedEventArgs e)
{
//Open a Linux ext4 disk image
var disk = ExtDisk.Open(1);
//Get the Linux partition, and open
var fs = ExtFileSystem.Open(disk, disk.Partitions[0]);
//List all files in /etc folder
foreach (var file in fs.GetFiles("/etc", "*", SearchOption.AllDirectories))
{
Console.WriteLine(file);
}
} }
Hello,
I want to mount a ext4 partition GPT, is it possible ?
Regards.
Seems not to have received a single commit in over 2 years
Hello!
I compiled the sample code SharpExt4-main on .net 4.5, I run on my computer it works fine. When I copy file .exe and .dll to another computer, I get the above error: "Could not load file or assembly 'SharpExt4.dll' or one of its dependencies. The specified module could not be found".
Help me!
Hello!
My project has 2 winform, Form A used the command: fs.OpenFile(); it's ok, but from Form A call Form B, get error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt" in the command: fs.GetDirectories();
Help me!
Thanks!
Hi,
i am testing your lib with an external ext4 disk on a usb hard disk. Under Windows 10 I plugged in the usb disk. Then I used diskpart to determine the disk number (in my case 8). I changed the Sample code to:
//Open a Linux ext4 disk image
//var disk = ExtDisk.Open(@".\ext4.img");
var disk = ExtDisk.Open(8);
foreach(var part in disk.Partitions)
{
Console.WriteLine("part = " + part.ToString());
}
...
Sample.exe returns an exception:
C:\Users\mic\source\repos\SharpExt4\Sample\bin\Debug>Sample.exe
part = SharpExt4.Partition
part = SharpExt4.Partition
part = SharpExt4.Partition
part = SharpExt4.Partition
Unbehandelte Ausnahme: System.IO.IOException: Could not mount partition.
bei SharpExt4.ExtFileSystem.Open(Partition partition) in C:\Users\mic\Source\Repos\SharpExt4\SharpExt4\ExtFileSystem.cpp:Zeile 219.
bei Sample.Program.Main(String[] args) in C:\Users\mic\Source\Repos\SharpExt4\Sample\Program.cs:Zeile 48.
Interesting is, that the disk seems to contain four partitions, but the usb disk just has one partition on it.
So I assume, that the physical Disk number may not be the one which diskPart is showing me. I checked with wmic as well. The disk index fΓΌr the usb disk is 8.
Do you have an idea what goes wrong?
Best
Mic
Hi,
I get an unhandled exception during disposing the ExtFileStream.
The target framework of my application is .NET 7.
I do simple copy operations of large files (up to 2 GB) from my NTFS-Disk to a Micro-SD (Ext4).
Source
ExtDisk disk = ExtDisk.Open(diskNumber);
ExtFileSystem fileSystem = ExtFileSystem.Open(disk, disk.Partitions[0]);
byte[] buffer = File.ReadAllBytes(sourcePath);
using ExtFileStream stream = fileSystem.OpenFile(destinationPath, FileMode.Create, FileAccess.Write);
stream.Write(buffer, 0, buffer.Length);
stream.Close();
The operation is successful but after the call of Dispose via the using-operator or calling Dispose I get the following exception:
Is this the default behavior?
Any idea for a workaround?
~Best Regards
Hi,
I've been using this library and It's really helpful, thanks for it!
I just noticed there's a typo on the "Partitions" getter in the "ExtDisk" class.
Instead of saying Partitions
it says Parititions
.
Files:
SharpExt4/SharpExt4/ExtDisk.cpp
Line 155 in 36d52b6
Line 90 in 36d52b6
Recently, I use SharpEXT4 to read and write SD-Card OrangePI. But when executing the command SharpExt4.ExtDisk.Open(1); /* 1 is the drive shown in diskpart */
then ExtDisk.cpp
gives the error System.IO.IOException: 'Could not read disk MBR.'
.
What should I do in this case? Looking forward to receiving a solution or patch for this error soon!
I want to read the Android virtual machine file vmdk
Does this project support reading vmdk?
This library is great, but can you update the docs, it's very difficult to learn and use,
Thank u
Hello!
I compiled using visual studio 2013 with .NET 3.5 and got error LNK2001 and LNK2019 in lwext4.lib
(It can be simply modified to be compiled in Visual Studio 2013). How?
Thanks!
Could you add the read and write function of the extended partition to SharpExt4?
I would need to copy some files from one ext4 disk to another.
The problem is that when I try to open the second image if I haven't dispose of the first one first an exception is thrown.
var d1 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_1.img");
var fs1 = ExtFileSystem.Open(d1.Partitions[1]);
//d1.Dispose(); //with this line code working but i cant copy file
var d2 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_2.img");
var fs2 = ExtFileSystem.Open(d2.Partitions[1]);
hi
does this lib support ext4 filesystem en/decryption with fscrypt ?
Hi there,
Firstly thanks for open sourcing this library! Awesome stuff.
Re the below, if you have a preferred issue format I'm happy to re-submit this with whatever details you need - I've tried to include everything you might need to know.
I'm hitting a "Could not read disk MBR."
exception when attempting to write a file, interesting I can read the file I am writing to, just not write to it.
Here's a quick breakdown of what the code is doing:
ManagementObjectSearcher
to find the disks and parse the disk indexes)/etc/wpa_supplicant/wpa_supplicant.conf
and parse out ssid and psk strings, using: var disk = ExtDisk.Open(this.index); // Physical disk index found using ManagementObjectSearcher
var fs = ExtFileSystem.Open(disk.Parititions[1]);
var file = fs.OpenFile("/etc/wpa_supplicant/wpa_supplicant.conf", FileMode.Open, FileAccess.Read);
var filelen = file.Length;
var buf = new byte[filelen];
file.Read(buf, 0, (int)filelen);
file.Close();
fs.Dispose();
var content = Encoding.Default.GetString(buf);
// Do stuff with the content to pull out ssid and psk
Note: This step is working.
string template = $@"ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev";
template += "\nupdate_config=1";
template += "\ncountry=AU";
template += "\nnetwork={";
template += "\n ssid=" + ssid;
template += "\n psk=" + password;
template += "\n}";
var disk = ExtDisk.Open(this.index); // Physical disk index found using ManagementObjectSearcher - same as in the read step
var fs = ExtFileSystem.Open(disk.Parititions[1]);
var file = fs.OpenFile("/etc/wpa_supplicant/wpa_supplicant.conf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
var buf = Encoding.UTF8.GetBytes(template);
//Write to file
file.Write(buf, 0, buf.Length);
file.Close();
fs.Dispose();
Step three throws the error when attempting to Open
the disk.
Hello!
I use this library to read data in Usb Ext4 but get an error "Could not mount partition" at the line: var fs = ExtFileSystem.Open(disk, disk.Partitions[0]);
Please help me! Thanks!
Is there an easy way to currently open a partition from an image of the partition itself vs a full disk image? I don't see any easy way to do that with the sample provided/library code.
So far, I kinda 'hacked' in a partition to fake disk by just populating the partitions array and that worked to read/write from the partition image on disk basically tricking things into thinking it was a disk image, but the resulting image is damaged once a file is written and has to be repaired.
Just wondering if this use case has ever been considered or if there's a known easy way to approach it?
This is what I'd done so far to 'hack' my partition in as the 'disk':
SharpExt4::ExtDisk^ SharpExt4::ExtDisk::Open(String^ imagePath)
{
if (File::Exists(imagePath))
{
auto disk = gcnew ExtDisk(imagePath);
disk->bdevs = new ext4_mbr_bdevs();
disk->capacity = 786432000;
disk->geometry = gcnew SharpExt4::Geometry(0, 0, 0, 0);
disk->partitions = gcnew List<Partition^>();
Partition^ partition = gcnew Partition();
partition->Offset = 0;
partition->Size = 786432000;
disk->partitions->Add(partition);
return disk;
Which worked to list, create, and get contents of files; but again upon saving it seems to damage the partition image maybe because it's trying to update data in relation to a disk not sure, what it does is fixable via e2fsck but I'm wanting to avoid having to use that every time I modify the image.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.