tralph3 / ddi

A safer dd
GNU General Public License v3.0
81 stars 3 forks source link

Any way not to write to a non-existant /dev/ file? #3

Open jglauche opened 3 years ago

jglauche commented 3 years ago

I am in progress of writing a lot of images to an usb drive. They appear as /dev/sdb on my system.

I just ran ddi of=/dev/sdb [...] while my usb drive was disconnected and it happily wrote a file there (standard file on my file system). Is there a way to make this error out instead?

tralph3 commented 3 years ago

I could... but what would be the point? The program checks if the output file is a device block, if it is, it throws the warning, if its not, it just writes it out to not bother you. I guess I could add a flag to make it always throw the warning, but there would be no info to show, since it's not a block device.

Could you give me a use case for this? Thanks.

jglauche commented 3 years ago

My use case is that I have a bash script that configured and flashes an image with wireguard configuration and then flashes it to a usb adapter. I probably should hack something that queries /dev/disk/by-id , though on my laptop it's always being added as /dev/sdb .

I'd be happy with a flag that can be configured to only write if that file exists (do we need the opposite ?)

tralph3 commented 3 years ago

To only write if the file exists? What if it doesn't exist? It just exits? I think this is outside the scope of the project. You can very easily achieve that with an if statement on a bash script.

jglauche commented 3 years ago

unsure. Maybe warn and confirm or fail?

And yeah, I can do this in my script, just my expectation for a "safer" dd was that it doesn't do stupid shit when I don't pay attention to that (and yeah, I didn't)

tralph3 commented 3 years ago

I don't think I fully understand what you're proposing here. You want the program to only write to a block device?

jglauche commented 3 years ago

okay let me try to pseudocode:

if of starts with "/dev/" then 
  check if target exists
  if target exists
    continue with dd 
  else 
    error and exit
  endif
endif
tralph3 commented 3 years ago

Ok... I understand what you want, but I still don't understand why it's even a problem. If you want to write to the USB, you need to plug it in of course, and if you run it when it's unplugged, then it does no harm to write the file, just delete it. The goal of this program is to prevent writing over a device file unintentionally, I don't see a reason to prevent you from writing to an empty, or non-existent file.

jglauche commented 3 years ago

my use case was:

my script runs [hardware connection error makes the disk not appear in /dev] calls ddi to write stuff script thinks ddi exited correctly

dangers:

I understand your point that operational dangers can and should be mitigated by checking stuff on my end. However running out of disk or memory space can lead to frustration and troubleshooting efforts that waste time.

tralph3 commented 3 years ago

Ok, thank you for clarifying the possible issues it can cause. I'll consider adding it.