GithubHelp home page GithubHelp logo

hafidzizzudin / sharpext4 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nickdu088/sharpext4

0.0 1.0 0.0 334 KB

A .Net library to provide full access (read/write) to Linux ext2/ext3/ext4 filesystem

Home Page: https://www.nickdu.com/?p=890

C++ 7.98% C 92.02%

sharpext4's Introduction

SharpExt4

Donate

About

The main purpose of this SharpExt4 project is to provide full access to Linux ext2/3/4 filesystem from Windows .Net application.

For a day-to-day Windows user, it is not easy to read/write ext2/3/4 filesystem directly from Windows environment. Especially for a C# .Net programmer, it is hard to find a .Net library, which can provide full access to Linux ext2/3/4 filesystem.

These are the findings so far:

  1. DiscUtils, is a .NET library to read and write ISO files and Virtual Machine disk files (VHD, VDI, XVA, VMDK, etc). DiscUtils also provides limited access to ext2/3/4 filesystem.
  2. Ext2Fsd is another Windows file system driver for the Ext2, Ext3, and Ext4 file systems. It allows Windows to read Linux file systems natively, providing access to the file system via a drive letter that any program can access.
  3. DiskInternals Linux Reader is a freeware application from DiskInternals, developers of data recovery software.
  4. Ext2explore is an open-source application that works similarly to DiskInternals Linux Reader—but only for Ext4, Ext3, and Ext2 partitions.
  5. The lwext4 project is to provide ext2/3/4 filesystem for microcontrollers.

Overview

The lwext4 is a portable C project for microcontrollers and the library has some cool and unique features. Lwext4 is an excellent choice for SD/MMC card, USB flash drive or any other wear leveled memory types. In Windows, the author recommended to use MSYS-2

I port the lwext4 backbone over to MSVC compiler (Visual Studio 2019), and create the lwext4 as a static lib. SharpExt4 is a clr wrapper of lwext4 to provide modem .Net application access. The SharpExt4 borrows the DiscUtils class concept and creates a friendly interface for .Net

Compile

Visual Studio 2019 C/C++ (It can be simply modified to be compiled in Visual Studio 2013)

.Net Framework 4.5

.Net Core 3.1 .Net 5

How to use the Library

How to use SharpExt4 to access Raspberry Pi SD Card Linux partition.

Here's a few simple examples.

How to read a file from ext4 disk image

	...
	//Open a Linux ext4 disk image
	var disk = ExtDisk.Open(@".\ext4.img");
	//Get the Linux partition and open
	var fs = ExtFileSystem.Open(disk.Parititions[0]);
	//Open a file for read
	var file = fs.OpenFile("/etc/shells", FileMode.Open, FileAccess.Read);
	//Check the file length
	var filelen = file.Length;
	var buf = new byte[filelen];
	//Read the file content
	var count = file.Read(buf, 0, (int)filelen);
	file.Close();
	var content = Encoding.Default.GetString(buf);
	Console.WriteLine(content);
	...

How to list all files in a folder from ext4 disk image

	...
	//Open a Linux ext4 disk image
	var disk = ExtDisk.Open(@".\ext4.img");
	//Get the Linux partition, and open
	var fs = ExtFileSystem.Open(disk.Parititions[0]);
	//List all files in /etc folder
	foreach(var file in fs.GetFiles("/etc", "*", SearchOption.AllDirectories))
	{
		Console.WriteLine(file);
	}
	...

How to create a file in ext4 disk image

	...
	//Open a Linux ext4 disk image
	var disk = ExtDisk.Open(@".\org.img");
	//Get the file system
	var fs = ExtFileSystem.Open(disk.Parititions[0]);
	//Open a file for write
	var file = fs.OpenFile("/etc/test", FileMode.Create, FileAccess.Write);
	var hello = "Hello World";
	var buf = Encoding.ASCII.GetBytes(hello);
	//Write to file
	var count = file.Read(buf, 0, buf.Length);
	file.Close();
	...

How to change a file mode in ext4 disk

	...
	//Open a Linux ext4 disk assume your SD card/USB is physical disk 1
	var disk = ExtDisk.Open(1);
	//Get the file system
	var fs = ExtFileSystem.Open(disk.Parititions[0]);
	//Check file exists
	if(fs.FileExists("/etc/hosts"))
	{
		//0x1FF in HEX, 777 in OCT
		fs.SetMode("/etc/hosts", 0x1FF);
	}
	...

Credits

The core library of SharpExt4 was taken from lwext4:

sharpext4's People

Contributors

nickdu088 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.