Support use statx syscall in fpstat and fpfstat

This commit is contained in:
Jinyang He 2023-06-20 17:48:02 +08:00 committed by Michael Van Canneyt
parent 6b4ee224bf
commit bcf7701887
4 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,36 @@
{
This file is part of the Free Pascal run time library.
Copyright (c) 1999-2000 by Jonas Maebe, (c) 2005 Thomas Schatzl,
members of the Free Pascal development team.
Contains the transformation from struct stat to struct statx.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
procedure cp_new_stat(nbuf: pstatx; buf: pstat);
begin
buf^.st_dev:=makedev(nbuf^.stx_dev_major,nbuf^.stx_dev_minor);
buf^.st_rdev:=makedev(nbuf^.stx_rdev_major,nbuf^.stx_rdev_minor);
buf^.st_ino:=nbuf^.stx_ino;
buf^.st_mode:=nbuf^.stx_mode;
buf^.st_nlink:=nbuf^.stx_nlink;
buf^.st_uid:=nbuf^.stx_uid;
buf^.st_gid:=nbuf^.stx_gid;
buf^.st_size:=nbuf^.stx_size;
buf^.st_blksize:=nbuf^.stx_blksize;
buf^.st_blocks:=nbuf^.stx_blocks;
buf^.st_atime:=nbuf^.stx_atime.tv_sec;
buf^.st_atime_nsec:=nbuf^.stx_atime.tv_nsec;
buf^.st_mtime:=nbuf^.stx_mtime.tv_sec;
buf^.st_mtime_nsec:=nbuf^.stx_mtime.tv_nsec;
buf^.st_ctime:=nbuf^.stx_ctime.tv_sec;
buf^.st_ctime_nsec:=nbuf^.stx_ctime.tv_nsec;
end;

View File

@ -125,5 +125,6 @@
{$ifdef cpuloongarch64}
{$define generic_linux_syscalls}
{$define use_statx_syscall}
{$undef usestime}
{$endif cpuloongarch64}

View File

@ -110,6 +110,28 @@ begin
{$endif}
end;
{$if defined(use_statx_syscall)}
function makedev(major,minor: cuint32): cuint32;
begin
makedev:=(minor and $ff) or (major shl 8) or ((minor and $fffffff00) shl 12);
end;
{$i cp_new_stat.inc}
function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
var
nbuf:tstatx;
begin
Fpstat:=do_syscall(syscall_nr_statx,AT_FDCWD,TSysParam(path),AT_NO_AUTOMOUNT,STATX_BASIC_STATS,TSysParam(@nbuf));
if Fpstat=0 then
cp_new_stat(@nbuf,@buf);
end;
{$else defined(use_statx_syscall)}
function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
begin
@ -124,6 +146,7 @@ begin
Fpstat:=do_syscall(syscall_nr_stat64,TSysParam(path),TSysParam(@buf));
{$endif}
end;
{$endif defined(use_statx_syscall)}
{*****************************************************************************
--- Directory:Directory related calls ---
@ -403,6 +426,20 @@ end;
{$undef FPC_ALIGN_DUMMY}
{$if defined(use_statx_syscall)}
function Fpfstat(fd : cint; var sb : stat): cint; [public, alias : 'FPC_SYSC_FSTAT'];
var
nbuf:tstatx;
nonestr:char=#0;
begin
Fpfstat:=do_syscall(syscall_nr_statx,fd,TSysParam(@nonestr),AT_EMPTY_PATH,STATX_BASIC_STATS,TSysParam(@nbuf));
if Fpfstat=0 then
cp_new_stat(@nbuf,@sb);
end;
{$else defined(use_statx_syscall)}
function Fpfstat(fd : cint; var sb : stat): cint; [public, alias : 'FPC_SYSC_FSTAT'];
begin
@ -416,6 +453,7 @@ begin
FpFStat:=do_SysCall(syscall_nr_fstat64,TSysParam(fd),TSysParam(@sb));
{$endif}
end;
{$endif defined(use_statx_syscall)}
{$ifndef FPC_SYSTEM_HAS_FPFORK}

View File

@ -90,6 +90,10 @@ const
{$endif}
_STAT_VER = _STAT_VER_LINUX;
{$if defined(use_statx_syscall)}
STATX_BASIC_STATS=$000007ff;
{$endif}
type
{$i stat.inc}
@ -97,6 +101,39 @@ type
TStat = Stat;
PStat = ^Stat;
{ Referred to rtl/linux/linux.pp }
statx_timestamp = record
tv_sec : cint64;
tv_nsec : cuint32;
__reserved : cint32;
end;
pstatx_timestamp = ^statx_timestamp;
tstatx = record
stx_mask : cuint32;
stx_blksize : cuint32;
stx_attributes : cuint64;
stx_nlink : cuint32;
stx_uid : cuint32;
stx_gid : cuint32;
stx_mode : word;
__spare0 : array[0..0] of word;
stx_ino : cuint64;
stx_size : cuint64;
stx_blocks : cuint64;
stx_attributes_mask : cuint64;
stx_atime : statx_timestamp;
stx_btime : statx_timestamp;
stx_ctime : statx_timestamp;
stx_mtime : statx_timestamp;
stx_rdev_major : cuint32;
stx_rdev_minor : cuint32;
stx_dev_major : cuint32;
stx_dev_minor : cuint32;
__spare2 : array[0..13] of cuint64;
end;
pstatx = ^tstatx;
{ directory services }
{ the Dirent type for getdents64 is no longer declared as ending with
an array 0..255, but as ending with a variable-sized array. While the