C# write to ext2 linux partition from Windows
I'm quite new to C# and I need to write a file (grub) on an EXt2 linux partition from windows 7.
What is the good way to do such thing? Do I need to mount the partition with external 开发者_运维技巧program?
I think you need to mount it with an external program such as: http://www.fs-driver.org/
Mount the drive using a a driver like FS-driver and then write to it using standard C# file writing techniques.
You can use Ext2Fsd to mount the partition in windows, and then write to as you would any other partition.
EXT2FSD Home Page
If you use Total Commander under Windows, one of the available plugins is for accessing ext2/3/4. It's probably already been mentioned here but it makes accessing Linux from Windows almost transparent. I don't have it installed right now or I'd look at the name.
SharpExt4 may help you with Linux file system read and write.
A .Net library to provide full access (read/write) to Linux ext2/ext3/ext4 filesystem
Here is the GitHub link https://github.com/nickdu088/SharpExt4
//Open EXT4 SD Card
//Here is SD Card physical disk number. you can get from Windows disk manager
ExtDisk SharpExt4.ExtDisk.Open(int DiskNumber);
//In your case FAT32 is 1st one, ext4 is 2nd one
//Open EXT4 partition
var fs = ExtFileSystem.Open(disk.Parititions[1]);
//Create /home/pi/file.conf file for write
var file = fs.OpenFile("/home/pi/file.conf", FileMode.Create, FileAccess.Write);
var hello = "Hello World";
var buf = Encoding.ASCII.GetBytes(hello);
//Write to file
file.Write(buf, 0, buf.Length);
file.Close();
How to use SharpExt4 to access Raspberry Pi SD Card Linux partition
精彩评论