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

Open multiple image #6

Closed
Giacomo-Gozzi opened this issue May 14, 2022 · 11 comments
Closed

Open multiple image #6

Giacomo-Gozzi opened this issue May 14, 2022 · 11 comments

Comments

@Giacomo-Gozzi
Copy link

Giacomo-Gozzi commented May 14, 2022

I would need to copy some files from one ext4 disk to another.
The problem is that when I try to open the second image if I haven't dispose of the first one first an exception is thrown.

var d1 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_1.img");
var fs1 = ExtFileSystem.Open(d1.Partitions[1]);
//d1.Dispose(); //with this line code working but i cant copy file
 
var d2 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_2.img");
var fs2 = ExtFileSystem.Open(d2.Partitions[1]);
@nickdu088
Copy link
Owner

What exception did you receive? I haven't tried two images at the same time. One temp solution is to save the files to your local drive and then transfer to the new image

@Giacomo-Gozzi
Copy link
Author

I tried saving them to the local disk but I would need to keep the file permissions, that way they are lost.

There are two kinds of exceptions(I assume there is a static pointer used by both):

1) Could not read disk MBR

var d1 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_1.img");
var fs1 = ExtFileSystem.Open(d1.Partitions[1]);
var d2 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_2.img");
var fs2 = ExtFileSystem.Open(d2.Partitions[1]);

The exception is generated at line 3

2) Could not register partition.

var d1 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_1.img");
var d2 = ExtDisk.Open(@"C:\Users\Giacomo\Downloads\raspbian_2.img");
var fs1 = ExtFileSystem.Open(d1.Partitions[1]);
var fs2 = ExtFileSystem.Open(d2.Partitions[1]);

The exception is generated at line 4

@nickdu088
Copy link
Owner

Probably yes.

When you transfer the file, keeping file permissions in a Dictionary<path, permission> in the memory, after the transfer, you can use
setmode to set the original permission.

@Giacomo-Gozzi
Copy link
Author

Yes of course but it would be much more convenient to move files directly between images.

Do you think it would be possible to fix the problem?

@nickdu088
Copy link
Owner

I need take a look.

@nickdu088
Copy link
Owner

Yes of course but it would be much more convenient to move files directly between images.

Do you think it would be possible to fix the problem?

This is the limitation of lew4. It only can take one disk image at a time, because the underline implementation is C. All variables are global variable and shared across the library.

@Giacomo-Gozzi
Copy link
Author

I tried to view the code, are you sure it is not a SharpExt4 problem?
I noticed that in the ExtDisk.cpp file on line 56

auto disk = gcnew ExtDisk(imagePath);

disk->bd always has the same pointer, they seem to me declared satatic in the io_raw.cpp file

@nickdu088
Copy link
Owner

nickdu088 commented May 22, 2022

I tried to view the code, are you sure it is not a SharpExt4 problem? I noticed that in the ExtDisk.cpp file on line 56

auto disk = gcnew ExtDisk(imagePath);

disk->bd always has the same pointer, they seem to me declared satatic in the io_raw.cpp file

I have done the quick fix. It seems working ok on my side. Let me know if you still have the issue.

@Giacomo-Gozzi
Copy link
Author

It now allows you to open two filesystems, the problem is that it always displays the last opened disk.

var disk1 = ExtDisk.Open(@".\disk1.img");
var disk2 = ExtDisk.Open(@".\disk2.img");

var fs1 = ExtFileSystem.Open(disk1.Partitions[1]);
ListAllFiles(fs1);
CreateFile(fs1);

var fs2 = ExtFileSystem.Open(disk2.Partitions[1]);
ListAllFiles(fs2);

ListAllFiles(fs1); View files in disk 2
CreateFile(fs1); Create the file in disk 2

In my project, the same pointer for ExtDisk.bd always remains.

@nickdu088
Copy link
Owner

It now allows you to open two filesystems, the problem is that it always displays the last opened disk.

var disk1 = ExtDisk.Open(@".\disk1.img");
var disk2 = ExtDisk.Open(@".\disk2.img");

var fs1 = ExtFileSystem.Open(disk1.Partitions[1]);
ListAllFiles(fs1);
CreateFile(fs1);

var fs2 = ExtFileSystem.Open(disk2.Partitions[1]);
ListAllFiles(fs2);

ListAllFiles(fs1); View files in disk 2 CreateFile(fs1); Create the file in disk 2

In my project, the same pointer for ExtDisk.bd always remains.

Hope this time, this issue get fixed. I did a quick test, and it's working.
The ExtFileSystem.Open API has been updated.

@Giacomo-Gozzi
Copy link
Author

Perfect everything seems to be working correctly, many thanks

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

No branches or pull requests

2 participants