[fpc-pascal] Writing to a drive which may be spun down

James Richters james at productionautomation.net
Fri Nov 22 16:21:36 CET 2019


Ooops made a mistake in the until...  also maybe a short delay between retries would be helpful


const
            A_Day = 1;
          An_Hour = A_Day/24;
         A_Minute = An_Hour/60;
         A_Second = A_Minute/60;
StartTime:=now;
assignFile(txt,'/mnt/test.txt');
{$I-}
rewrite (txt);
repeat
application.processmessages;
writeln (txt,'I''m so tired ...');
io := ioResult;
// showMessage ('--> '+IntToStr(io));
If io=NoSuchFileErrorCode then
   Sleep(100);
until (io<>NoSuchFileErrorCode) or (StartTime+(30*A_Second)<Now); {$I+} 
closeFile(txt); If io<>0 Then
    DoSomethingAboutError;



James  

-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Winfried Bartnick
Sent: Friday, November 22, 2019 9:35 AM
To: fpc-pascal at lists.freepascal.org
Subject: Re: [fpc-pascal] Writing to a drive which may be spun down

James dragged the solution a little bit away from the "quick-and-dirty-corner".

This way it is usable also in critical situations.

SMART is a never ending story and you jump into the jungle:

* A lot of noname disk have no entry in the SMART DB

* Even a half year old Maxtor/Seagate was not found  in an updated DB

* On external disks SMART is often disabled by default

* I don't know a Pascal interface to smart

But what will you exspect when the price for 1 TB is now down to 40.- €???

It would be a good idea if reality had not so many obstacles.

Winni




Am 22.11.19 um 14:38 schrieb James Richters:
> I thought there was a way to figure out if the drive was spun down, perhaps with a S.M.A.R.T command?
>
> I like the idea of using the ioResult, but I would put in a way to exit the loop for ioReults of errors not caused by a spun down drive would report right away and a timeout in case some other condition causes the same error as being spun down, so it's not caught in an infinite loop for errors not caused by the spindown.  Something like this... (Untested):
>
> const
>             A_Day = 1;
>           An_Hour = A_Day/24;
>          A_Minute = An_Hour/60;
>          A_Second = A_Minute/60;
>
> StartTime:=now;
> assignFile(txt,'/mnt/test.txt');
> {$I-}
> rewrite (txt);
> repeat
> application.processmessages;
> writeln (txt,'I''m so tired ...');
> io := ioResult;
> // showMessage ('--> '+IntToStr(io));
> until (io=NoSuchFileErrorCode) or (StartTime+(30*A_Second)<Now); {$I+} 
> closeFile(txt); If io<>0 Then
>     DoSomethingAboutError;
>
> It seems strange that this would be an issue at all,  I would think the drive itself would cache any data written to it for long enough to get the drive spun up... seems very short sighted on hard drive design for this to be an issue at all, and even if the drive didn't do this,  it seems like the operating system should take care of it for you.
>
>
> James
>
> -----Original Message-----
> From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf 
> Of Brian
> Sent: Thursday, November 21, 2019 8:55 PM
> To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
> Subject: Re: [fpc-pascal] Writing to a drive which may be spun down
>
> On 11/21/19 2:38 PM, Winfried Bartnick wrote:
>
> <...>
>
>> writeln (txt,'I''m so tired ...');
>> closeFile(txt);
>> io := ioResult;
> Thanks Winni, that sounds the sort of idea I'm looking for...
>
> Brian.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org 
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org 
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


More information about the fpc-pascal mailing list