【问题标题】:C# write and read files from an EXT4 SD CardC# 从 EXT4 SD 卡写入和读取文件
【发布时间】:2021-05-30 04:57:19
【问题描述】:

我有一个 Raspberry Pi SD 卡,它有 2 个分区,第一个是 Fat32,第二个是 EXT4 分区,现在我想用 C# 访问 EXT4 分区上的文件来写入、编辑、读取和创建文件。 我已经用 System.IO 尝试了一些东西来获取目录等(非常基本的东西)。 那么有谁知道是否有办法使用 C# 代码访问 EXT4 分区/磁盘?

我使用的是 Windows 10 操作系统。

它应该像这样工作:File.Create("path to the Disk(J:)/rootfs/home/pi/file.conf");

但是,我收到一个错误:System.IO.IOException: "There is no recognized file system on the data carrier

【问题讨论】:

标签: c# .net windows raspberry-pi ext4


【解决方案1】:

SharpExt4 可以帮助您进行 Linux 文件系统的读写。

提供对 Linux ext2/ext3/ext4 文件系统的完全访问(读/写)的 .Net 库

这里是 GitHub 链接 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多