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

In my previous post, I introduced the SharpExt4 .Net library. In this post, I will show how to use SharpExt4 to access the Raspberry Pi SD card from Windows OS.

  • Take out the Raspberry Pi SD card and insert it into a USB card reader
  • Run “diskpart” from Windows command prompt and find out the SD card disk number and partition number. In my case, the disk number is 3 and the partition is 2.
  • Clone the SharpExt4 from GitHub, and open Visual Studio as Admin

Note: If you want to access physical drive, you must run application in admin permission

  • Open SharpExt4 and edit the Program.cs from the Sample project
static void Main(string[] args)
{
    //Open Raspberry Pi SD card, see diskpart disk number
    var disk = ExtDisk.Open(3);
    //Get the file system, see diskpart partition number
    var fs = ExtFileSystem.Open(disk.Parititions[1]);
    //List all directories in root folder
    foreach (var file in fs.GetDirectories("/", "*", SearchOption.TopDirectoryOnly))
    {
        Console.WriteLine(file);
    }
}

Run the Sample project and see the result to list all the folders in Raspberry Pi root folder.

4 thoughts on “How to use SharpExt4 to access Raspberry Pi SD Card Linux partition”

  1. Hi Nick’s Lounge,

    Thanks for this Nice article. I have a similar scenario in which I wanted to read a EXT4 file system through my C# code running in a windows (10/11) machine. I have a USB drive, which contains my EX4 file system, and I followed the steps which is mentioned in your blog. But I am getting a runtime error by saying “Could not read disk MBR.”

    The error I am getting in file: ExtDisk.cpp
    Line # 117 (if (r == EOK))
    Error : Unable to resolve identifier: ‘EOK” . Due to this, the code is throwing an exception “Could not read disk MBR.”

    It will be great if you are able to help me to resolve this issue.

      1. I got this error , System.IO.IOException: ‘Could not read disk MBR.’
        my disk is MBR.

        help please.

Comments are closed.