BlockWrite() version 2.6.4

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

BlockWrite() version 2.6.4

Brian
Can anyone familiar with FPC 2.6.4 comment on the specifics of how BlockWrite() functions under Linux. Specifically does BlockWrite() call the Linux kernel or call fWrite()?

Does BlockWrite() call fFlush or does it rely on the kernel when to flush and actually write to the disk?

In which file can the source code specific to BlockWrite() version 2.6.4 be found ?

Thanks
Brian
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BlockWrite() version 2.6.4

Michael Van Canneyt


On Sat, 5 Aug 2017, Brian wrote:

> Can anyone familiar with FPC 2.6.4 comment on the specifics of how
> BlockWrite() functions under Linux. Specifically does BlockWrite() call the
> Linux kernel or call fWrite()?

Normally, it calls the linux kernel.

>
> Does BlockWrite() call fFlush or does it rely on the kernel when to flush
> and actually write to the disk?

It relies on the kernel.

>
> In which file can the source code specific to BlockWrite() version 2.6.4 be
> found ?

Headers are in rtl/inc/systemh.inc
actual routines are in rtl/inc/file.inc

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BlockWrite() version 2.6.4

Karoly Balogh (Charlie/SGR)
Hi,

On Sat, 5 Aug 2017, Michael Van Canneyt wrote:

> > In which file can the source code specific to BlockWrite() version 2.6.4 be
> > found ?
>
> Headers are in rtl/inc/systemh.inc
> actual routines are in rtl/inc/file.inc

Just an addition, BlockWrite() actually calls the internal RTL function
Do_Write(), which is the write function implemented for all platforms in a
platform specific way in the RTL. On Un*x, it calls FpWrite, which calls
the kernel syscall directly.

Do_Write for all Unix (including Linux) is implemented in
rtl/unix/sysfile.inc

FpWrite is implemented for Linux in:
rtl/linux/ossysc.inc

But this later function is just a direct call to the syscall. That's the
entire code path then, more or less.

Charlie
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BlockWrite() version 2.6.4

Brian
Thanks Charlie.

I notice the Do_Write() uses  repeat .. until where fpWrite() does a direct call.

What was the reasoning for the repeat..until in Do_Write() ?

Thanks
Brian
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BlockWrite() version 2.6.4

Marco van de Voort
In our previous episode, Brian said:
> I notice the Do_Write() uses  repeat .. until where fpWrite() does a direct
> call.
>
> What was the reasoning for the repeat..until in Do_Write() ?

Syscalls that block for hardware can return EINTR (ESysIntr) on some
*nixes when a signal arrives while waiting for data.

Some *nixes restart the syscall after the signal was delivered, but afaik
Linux does not.  So the loop is just to restart the syscall if needed.

source:
Function Do_Write(Handle:thandle;Addr:Pointer;Len:Longint):longint;

var j : cint;
Begin
  repeat
    Do_Write:=Fpwrite(Handle,addr,len);
    j:=geterrno;
  until (do_write<>-1) or ((j<>ESysEINTR) and (j<>ESysEAgain));
  If Do_Write<0 Then
   Begin
    Errno2InOutRes;
    Do_Write:=0;
   End
  else
   InOutRes:=0;
End;

see also:
https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BlockWrite() version 2.6.4

Karoly Balogh (Charlie/SGR)
In reply to this post by Brian
Hi,

On Mon, 14 Aug 2017, Brian wrote:

> Thanks Charlie.
>
> I notice the Do_Write() uses  repeat .. until where fpWrite() does a direct
> call.
>
> What was the reasoning for the repeat..until in Do_Write() ?

Because FpWrite() is just the direct Unix OS call, so the RTL doesn't add
extra behavior there. While Do_Write() which integrates this OS call into
the FPC RTL has to do some error handling. In this case, if the system
reports EAGAIN or EINTR errors, the write call will be attempted again,
without returning an error to the program calling BlockWrite().

There are several reasons why an Unix write() might return EAGAIN or
EINTR. These are documented in the Unix manpage for write:

https://linux.die.net/man/2/write

The RTL just tries to handle these recoverable error cases in the
Do_Write() function, until the write() fails irrecoverably or it succeeds.
Hence the repeat...until.

Charlie

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BlockWrite() version 2.6.4

Brian
Ok. Many thanks guys.

Brian
Loading...