Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can it write to the specific partition? #2

Open
sskras opened this issue Jul 13, 2024 · 8 comments
Open

Can it write to the specific partition? #2

sskras opened this issue Jul 13, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@sskras
Copy link

sskras commented Jul 13, 2024

To me it looks like the tool cannot restore content of a specific partition:

image

If that's true, please take this a feature request :)

@raspopov raspopov added the enhancement New feature or request label Jul 13, 2024
@raspopov raspopov self-assigned this Jul 13, 2024
@raspopov
Copy link
Owner

Could you kindly clarify which scenario of interaction with the program requires the selection of a specific disc partition?

@sskras
Copy link
Author

sskras commented Jul 15, 2024

I wanted to test several FSDs (file systems drivers), like ext2fsd, rfsd. They come with no tool to create a specific file system. So I:

  • create them on Linux
  • image them to the file
  • transfer the images to my Windows machine
  • try writing them into the test partition I have made

I guess this fragment of the article I discovered might help if you go at implementing this feature:
The Perils of Writing Disk Images on Windows

@raspopov
Copy link
Owner

try writing them into the test partition I have made

But this would require editing the partition table, which is beyond the capabilities of this program... 🤔

@sskras
Copy link
Author

sskras commented Jul 21, 2024

Sure, I just described my workaround :)

And the linked text tells how to achieve that using the existing partition:

  • The sectors to be written to fall within a mounted volume, but you have explicitly locked or dismounted the volume by using FSCTL_LOCK_VOLUME or FSCTL_DISMOUNT_VOLUME.
  • The sectors to be written to fall within a volume that has no mounted file system other than RAW.

I guess locking the volume would be a quickest way. Dismounting the volume would be the safest one.

@sskras
Copy link
Author

sskras commented Jul 21, 2024

OK, I see your code already issues FSCTL_LOCK_VOLUME:

bool CDeviceVolume::Lock()
{
if ( Open() )
{
if ( ! m_bLocked )
{
Log( LOG_ACTION, IDS_VOLUME_LOCK, (LPCTSTR)Name );
DWORD returned;
if ( ! DeviceIoControl( m_h, FSCTL_LOCK_VOLUME, nullptr, 0, nullptr, 0, &returned, nullptr ) )
{
Log( LOG_WARNING, IDS_VOLUME_LOCK_ERROR, (LPCTSTR)GetErrorString( GetLastError() ) );
return false;
}
m_bLocked = true;
}
return true;
}
return false;
}

// Lock device volumes
for ( const auto& volume : device.Volumes )
{
volume->Lock();
}

@raspopov
Copy link
Owner

What I meant was that the partition table is physically in one place on the disk, and the partition data is a completely different place on the disk. It is not possible to write both as a simple image.

@sskras
Copy link
Author

sskras commented Jul 21, 2024

I agree, these are different things.

But my original message / feature request is about replacing data in an existing partition only (ie. to keep the partition table intact).

For this, only one volume would need locking / dismounting (and only in case it's not raw). Plus, starting offset on the media during the write operation would need to change from 0 to the partition's starting block, I suppose.

@raspopov
Copy link
Owner

Have a look at a new release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants