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

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Thu May 4 12:02:01 CEST 2017


On 13/04/17 07:30, 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?

In case this is useful to anybody at any point: I was filling a device 
with a pattern and then reading it back, and found that the read time 
depended crucially on the amount of RAM available (relative to the size 
of device I was testing). This turned out to be because I was relying on 
Reset() with FileMode = 2 to open the file R/W, but this was causing the 
Linux kernel to buffer as much as possible in RAM. Switching to using 
Rewrite(), then closing and reopening with Reset() only if needed, 
resulted in predictable performance.

So I think that the lesson is that Reset() should only be used for R/W 
files when the write and read operations are expected to be 
comparatively close to each other in time and position.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]


More information about the Lazarus mailing list