0

I tried to do some write/read operations on filesystems that I have enumerated for. The problem is when I want to write to other volumes rather than my self (fs0), it will return WRITE PROTECTED Error.

 ... Enumerated and opened all available volumes successfuly

 efiStatus = root->Open(root, &token, L"xxx", EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
    
    if (efiStatus == EFI_SUCCESS)
    {
        char* myStr = "Sample Content";
        UINTN myStrSize = strlenEx(myStr);

        efiStatus = token->Write(token, &myStrSize, myStr);
        if (efiStatus != EFI_SUCCESS)
        {
            Print(L"[X] ! Error [%r]!\n", efiStatus);
        }
        Print(L"Found Some\n", efiStatus);
    }

I Also tried ShellCreateDirectory, ShellWriteFile. Do I really can access write hard disk (pci) from EFI Application?

EDIT:

drivers command output:

                T   D
D           Y C I
R           P F A
V  VERSION  E G G #D #C DRIVER NAME                         IMAGE NAME
== ======== = = = == == =================================== ==========
43 00000014 D - -  1  - AMI USB Driver                      Uhcd
45 00000014 B - -  1  4 USB bus                             Uhcd
46 00000002 D - -  3  - USB Hid driver                      Uhcd
47 00000001 D - -  1  - USB Mass Storage driver             Uhcd
85 00010000 ? - -  -  - AMI ExFat Driver                    EXFAT
86 00010000 D - -  5  - AMI NTFS Driver                     NTFS
89 00000001 D - -  2  - <null string>                       MouseDriver
8B 00000001 B - -  1  3 AMI AHCI BUS Driver                 Ahci
8F 00000001 ? - -  -  - AMI NVMe BUS Driver                 Nvme
123 00000010 D - -  1  - Serial ATA Controller Initializatio SataController
12E 00000010 B - -  1  1 AMI Console Splitter Text Out Drive ConSplitter
12F 00000010 B - -  1  1 AMI Console Splitter Text In Driver ConSplitter
130 00000010 B - -  1  1 AMI Console Splitter Pointer Driver ConSplitter
133 00000010 D - -  1  - AMI Graphic Console Driver          GraphicsConsole
134 0000000A D - - 15  - Generic Disk I/O Driver             DiskIoDxe
135 0000000B B - -  3 11 Partition Driver(MBR/GPT/El Torito) PartitionDxe
137 00000000 ? - -  -  - Integrated Touch Driver             IntegratedTouch
13A 00000010 B - -  1  5 AMI Generic LPC Super I/O Driver    GenericSio
13C 00A50110 B - -  1 15 AMI PCI Bus Driver                  PciBus
13E 00000010 ? - -  -  - AMI PS/2 Driver                     Ps2Main
13F 00000000 ? - -  -  - DNS Network Service Driver          DnsDxe
140 00000000 ? - -  -  - DNS Network Service Driver          DnsDxe
145 0000000A D - -  2  - FAT File System Driver              Fat
147 00010001 ? - -  -  - AMI ISO9660 File System Driver      FsIso9660
149 00000001 ? - -  -  - <null string>                       PcieSataController
14A 00000001 ? - -  -  - <null string>                       PcieSataController
14B 0000001B B - -  1  3 Intel(R) RST 16.0.2.3402 RAID Drive RaidDriver
159 09000432 B - -  1  1 Intel(R) GOP Driver [9.0.1074]      MemoryMapped(0x3,0x845F3018,0x846040D8)
Ali Sepehri-Amin
  • 493
  • 1
  • 6
  • 18
  • 1
    Are the corresponding BlockIo protocols marked as ReadOnly (check the BlockIo->Media->ReadOnly flag)? – MiSimon Jul 22 '20 at 11:12
  • @MiSimon I tried and its not Readonly, but still I cant write – Ali Sepehri-Amin Jul 25 '20 at 08:38
  • So, you can write to fs0, right? but you cannot write to others? – Alex D Jul 26 '20 at 05:14
  • @AliSepehri-Amin what other FS ids do you have on your platform? – Alex D Jul 26 '20 at 05:27
  • @Alex Yes I can write on fs0, but not the others. I tested on a PC that installed Windows on it, it has 4 volumes, fs1 is C:\\ Volume, fs2 D:\\, fs3 F:\\, fs4 E:\\. I want to write on fs1 which is Windows C volume. – Ali Sepehri-Amin Jul 26 '20 at 06:36
  • @Alex, Even with Shell command line I can't edit or remove the files on ther FS ids. it says either 'Write Protected' or 'Unable to create' when using mkdir – Ali Sepehri-Amin Jul 26 '20 at 06:38
  • @AliSepehri-Amin are you sure that those volumes has fs id? Can you update your question with a screenshot of your device table from uefi shell? My guess that you have only one FS0 and the rest are BLK01...02 etc... – Alex D Jul 26 '20 at 21:00
  • 1
    If you update your question please provide the output of the "drivers" efi shell command, the windows partitions maybe using NTFS and not FAT32. – MiSimon Jul 27 '20 at 06:24
  • @MiSimon I added the output – Ali Sepehri-Amin Jul 27 '20 at 06:50
  • There is an NTFS driver in the list (#86), this driver might not be able to write to the file systems. – MiSimon Jul 27 '20 at 06:58
  • @MiSimon Can UEFI:NTFS work on this ? – Ali Sepehri-Amin Jul 27 '20 at 07:51
  • If you have a driver that supports writing to NTFS then yes, take a look at the refind project (https://www.rodsbooks.com/refind/) they have efi drivers for many file systems. – MiSimon Jul 27 '20 at 08:12

1 Answers1

1

My educated guess is that you trying to access NTFS volume (since you talked about Windows partitions) and NTFS is not supported by UEFI (by default). At least, I haven't seen any firmware that does. UEFI supports FAT32 file systems only.

If you drop into UEFI shell on your platform you should see the "Mapping table" (see the sample picture below), if there is a device labeled "FS0". This indicates that the firmware detected the disk, discovered the partition, and was able to mount the file system. The rest of the volumes labeled as BLK, which means UEFI can give the access using BlockIO Protocol only. No FS Protocol support.

Here is an example of the mapping table

Alex D
  • 942
  • 1
  • 6
  • 17
  • Thanks. Yes, I tested on a FAT32 volume and it worked fine on creating a Folder. is there anyway to write on NTFS? as I mentioned above about UEFI:NTFS? – Ali Sepehri-Amin Jul 28 '20 at 06:30
  • 1
    @AliSepehri-Amin That’s I don't know. Newer seen UEFI firmware with NTFS support. – Alex D Jul 28 '20 at 06:36