OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:43 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 45 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 11:57 am 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Hi, I'm using WSL2 as my programming environment and was wondering if this would cause issues when trying to partition the disk to read and write to it. So I have a few questions in regard to partitioning the disk.

First, should I partition the disk on my windows machine, or on the virtual disk? When looking at the partition table, is it a separate one for WSL or is it the same one as windows? (I tried to find what partition WSL was on, but I must not understand how it works because I could not find one).

Mainly, what's the process to making sure my OS is able to find a partition on the hard disk if it is running from WSL?

I'm sorry if I did not phrase that very well.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 12:20 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Which disk are you trying to partition?


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 12:32 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
STOP, STOP, STOP!!!

Don’t mess with partitions if you are not absolutely sure what you are doing. (And it is obvious that you aren’t.)

Don’t touch your physical hard disk; create a virtual hard disk and use that. In Linux you would access this via a loop back device - a little Googling will provide a wealth of detail about this.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 12:50 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
iansjack wrote:
STOP, STOP, STOP!!!

Don’t mess with partitions if you are not absolutely sure what you are doing. (And it is obvious that you aren’t.)

Don’t touch your physical hard disk; create a virtual hard disk and use that. In Linux you would access this via a loop back device - a little Googling will provide a wealth of detail about this.


Thanks, I'll do that instead.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 5:53 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
I created a virtual hard disk using this command:
Code:
qemu-img create -f raw disk.img 2000M


And am running the OS with this:
Code:
qemu-system-i386 -hda disk.img -cdrom Binaries/caffieneOS.iso -m 16M -boot order=dc


But when writing to the disk using my ata driver (the code is below) and restarting the OS, the virtual hard disk does not save my changes. Is there a reason that this is happening?

The ataPioWrite() function to write to hard disk:
Code:
void ataPioWrite(unsigned int LBA, unsigned short sectorcount, unsigned char *target) {
    outportb(ATA_PRIMARY_DRIVE_HEAD, 0x40); // Select master
    outportb(ATA_PRIMARY_SECCOUNT, (sectorcount >> 8) & 0xFF);  // Sector Count hi
    outportb(ATA_PRIMARY_LBA_LO, (LBA << 24) & 0xFF); // LBA4
    outportb(ATA_PRIMARY_LBA_MID, (LBA << 32) & 0xFF);  //LBA5
    outportb(ATA_PRIMARY_LBA_HI, (LBA << 40) & 0xFF);  // LBA6

    outportb(ATA_PRIMARY_SECCOUNT, sectorcount & 0xFF); // Sector Count low
    outportb(ATA_PRIMARY_LBA_LO, LBA & 0xFF); // LBA1
    outportb(ATA_PRIMARY_LBA_MID, (LBA << 8) & 0xFF);  //LBA2
    outportb(ATA_PRIMARY_LBA_HI, (LBA << 16) & 0xFF);  // LBA3
    outportb(ATA_PRIMARY_COMM_REGSTAT, 0x34);  // WRITE SECTORS EXT command

    for (unsigned char i = 0; i < sectorcount; i++) {
        pollATA();  // Wait for it to be able to transfer data

        // Transfer the data
        for (int j = 0; j < 256; j++) { outportl(ATA_PRIMARY_DATA, target[i]); }
        target += 256;
    }

    // Flush the cache.
    outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7);
    // Poll for BSY.
    while (inportb(ATA_PRIMARY_COMM_REGSTAT) & STAT_BSY) {}
}


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 6:12 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Do you see any compiler warnings? If not, turn on compiler warnings, then fix the mistakes in your code that cause the warnings to appear.

Do you see any QEMU warnings?

Which direction does "<<" shift the bits?

What size is the data port? What size does outportl write? What size is target[i]?


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 6:56 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Do you see any compiler warnings? If not, turn on compiler warnings, then fix the mistakes in your code that cause the warnings to appear.

I've fixed all of the compiler warnings, so no luck with that

Octocontrabass wrote:
Do you see any QEMU warnings?

Yes, the warning is:
Code:
WARNING: Image format was not specified for 'disk.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.


Octocontrabass wrote:
Which direction does "<<" shift the bits?

I was shifting them the wrong way, thanks for catching that.

Octocontrabass wrote:
What size is the data port? What size does outportl write? What size is target[i]?

And here is the code for outportl:
Code:
void outportl(unsigned int port, unsigned int value) {
      __asm__ __volatile__("outl %%eax,%%dx"::"d" (port), "a" (value));
};


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 7:01 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Caffeine wrote:
And here is the code for outportl:

So outportl writes 32 bits. What size is the data port? What size is target[i]?


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 7:23 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Caffeine wrote:
And here is the code for outportl:

So outportl writes 32 bits. What size is the data port? What size is target[i]?


ATA_PRIMARY_DATA is defined as 0x1F0, and target[i] (in this case) is 0x1.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 7:43 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Caffeine wrote:
ATA_PRIMARY_DATA is defined as 0x1F0,

Yes, but how big is that port? What size of reads and writes does it accept?

Caffeine wrote:
and target[i] (in this case) is 0x1.

Yes, but how big is it? What would sizeof(target[i]) be?


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 8:10 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Caffeine wrote:
ATA_PRIMARY_DATA is defined as 0x1F0,

Yes, but how big is that port? What size of reads and writes does it accept?

Caffeine wrote:
and target[i] (in this case) is 0x1.

Yes, but how big is it? What would sizeof(target[i]) be?


target[i] would be uint8_t, and the port accepts sizes of uint16_t.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 10:35 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
So outportl writes a 32-bit value, but the data port only accepts 16-bit writes.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Wed Apr 06, 2022 10:47 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
So outportl writes a 32-bit value, but the data port only accepts 16-bit writes.

I fixed, this, but the problem still isn't solved. The disk still does not get saved when I restart the OS. But thanks for catching the error!


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 10:36 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
How are you checking whether the disk gets saved? Which LBA are you writing to?

Why aren't you waiting until the drive is ready before sending the next command?


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 11:14 am 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
How are you checking whether the disk gets saved? Which LBA are you writing to?

I'm writing to LBA 0x0 and I'm checking that the disk gets saved by restarting the OS and reading LBA 0x0 again. Is there a better way to check if the disk saved or not?

Octocontrabass wrote:
Why aren't you waiting until the drive is ready before sending the next command?

I added this, (I assume you mean to poll again) and it's still not saving when I restart the disk.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 45 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: belliash, Bing [Bot] and 71 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group