[Lazarus] How can I write to arbitrary position on device

Carlos E. R. robin.listas at telefonica.net
Thu Apr 13 13:21:25 CEST 2017


On 2017-04-13 09:15, Mark Morgan Lloyd via Lazarus wrote:
> On 12/04/17 21:30, Carlos E. R. via Lazarus wrote:
>> Hi,
>> I'm new on this list, so if I should post this to a different place,
>> just tell me.
>> I want to find a function that I can use on Linux to write a memory
>> block to an arbitrary position on a device, say, /dev/sda or /dev/sda5 .
>> I can do that on an opened file with seek() and write(), but apparently
>> only on files. I need accessing the raw disk device. So currently I call
>> 'dd' instead.
>> I also had problems with blockread/write: it failed reading more than
>> one megabyte.
> 
> That's interesting, I need to look at some medium testing stuff over the
> next few days and was assuming I'd need to check the dd sources. Are you
> running as root to get direct access to the device?

Thanks for responding. :-)

I had and idea, tried it, and it worked. I simply assign:

   assign(Fout, '/dev/sdc');
   Reset (Fout);

The file can be a file of bytes, or in my case, a typed file (of an
array). Works perfectly, I can write chunks at 180 MiB/s.  :-)

For writing to some position, I assume I could use Seek(). I haven't tried.

Yes, of course, even for testing you need being root to run the code. So
the IDE runs as my user, the code in another terminal as root. Scary,
because I write directly to /dev/sdc (I'm filling the disk with random
data fast, prior to encrypting it. 7 hours for a 4TB disk).

Perhaps I could instead chmod or chown the device [...] Yes, it works,
better! It is undone on reboot, but that doesn't matter.

-- 
Cheers / Saludos,

		Carlos E. R.
		(from 42.2 x86_64 "Malachite" at Telcontar)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170413/9901abb2/attachment.sig>


More information about the Lazarus mailing list