Selaa lähdekoodia

+ 64 bit file support for linux

git-svn-id: trunk@5116 -
micha 19 vuotta sitten
vanhempi
commit
9238003e4f
4 muutettua tiedostoa jossa 62 lisäystä ja 70 poistoa
  1. 15 11
      rtl/linux/ossysc.inc
  2. 35 51
      rtl/linux/ostypes.inc
  3. 8 4
      rtl/linux/ptypes.inc
  4. 4 4
      rtl/unix/sysfile.inc

+ 15 - 11
rtl/linux/ossysc.inc

@@ -32,7 +32,7 @@ End;
 function Fpopen(path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
 
 Begin
- Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags),TSysParam(mode));
+ Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags or O_LARGEFILE),TSysParam(mode));
 End;
 
 function Fpclose(fd : cint): cint; [public, alias : 'FPC_SYSC_CLOSE'];
@@ -41,13 +41,11 @@ begin
  Fpclose:=do_syscall(syscall_nr_close,fd);
 end;
 
-function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; [public, alias : 'FPC_SYSC_LSEEK'];
-{
-Must be adapted/overloaded for 64-bit support, but that is a different call under
-Linux?
-}
+function Fplseek(fd : cint; offset : off64_t; whence : cint): off64_t; [public, alias : 'FPC_SYSC_LSEEK'];
 begin
-  Fplseek:=do_syscall(syscall_nr_lseek,tsysparam(fd),tsysparam(offset),tsysparam(whence));
+  if do_syscall(syscall_nr__llseek,tsysparam(fd),tsysparam(offset shr 32),tsysparam(offset),
+      tsysparam(@result), tsysparam(whence)) = -1 then
+    result:=off64_t(-1);
 end;
 
 function Fpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_READ'];
@@ -86,12 +84,18 @@ begin
   Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
 end;
 
-function Fpstat(path: pchar; var buf : stat):cint; [public, alias : 'FPC_SYSC_STAT'];
+function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
 
 begin
  Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
 end;
 
+function Fpstat64(path: pchar; var buf: stat64):cint; [public, alias : 'FPC_SYSC_STAT64'];
+
+begin
+ Fpstat64:=do_syscall(syscall_nr_stat64,TSysParam(path),TSysParam(@buf));
+end;
+
 
 {*****************************************************************************
                --- Directory:Directory related calls ---
@@ -139,7 +143,7 @@ begin
   new(ptr);
   if ptr=nil then
    exit;
-  getmem(ptr^.dd_buf,sizeof(dirent));
+  new(ptr^.dd_buf);
   if ptr^.dd_buf=nil then
    exit;
   ptr^.dd_fd:=fd;
@@ -154,7 +158,7 @@ function Fpclosedir(dirp : pdir): cint; [public, alias : 'FPC_SYSC_CLOSEDIR'];
 
 begin
   Fpclosedir:=Fpclose(dirp^.dd_fd);
-  freemem(dirp^.dd_buf,sizeof(dirent));
+  dispose(dirp^.dd_buf);
   dispose(dirp);
 end;
 
@@ -165,7 +169,7 @@ begin
   repeat
     if dirp^.dd_nextoff >= dirp^.dd_size then
       begin
-        bytes := do_SysCall(SysCall_nr_getdents,TSysParam(dirp^.dd_fd),TSysParam(dirp^.dd_buf),TSysParam(dirp^.dd_max));
+        bytes := do_SysCall(SysCall_nr_getdents64,TSysParam(dirp^.dd_fd),TSysParam(dirp^.dd_buf),TSysParam(dirp^.dd_max));
         if bytes <= 0 then
           begin
             fpreaddir := nil;

+ 35 - 51
rtl/linux/ostypes.inc

@@ -48,17 +48,12 @@ CONST
 TYPE
    Blksize_t  = cuint;
    Blkcnt_t   = cuint;
-   Ino64_t    = cint64;
-   Off64_t    = cint64;
+   Blkcnt64_t = cuint64;
 
    TBlkSize   = BlkSize_t;
    PBlkSize   = ^BlkSize_t;
    TBlkCnt    = Blkcnt_t;
    PBlkCnt    = ^Blkcnt_t;
-   TIno64     = Ino64_t;
-   PIno64     = ^Ino64_t;
-   TOff64     = Off64_t;
-   POff64     = ^Off64_t;
 
    { system information services }
    UtsName   = Record
@@ -92,67 +87,62 @@ type
   TStat      = Stat;
   PStat      = ^Stat;
 
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64) or defined(CPUSPARC) or defined(CPUSPARC64)}
+  {$define CLEAN_STAT64}
+{$endif}
 
-{$ifdef notused} // 64-bit support needs some work still :-)
   { file characteristics services }
+  { this record is incorrect for alpha, frv, h8300, mips, parisc, v850, xtensa }
    stat64    = record
-        st_dev        : dev_t;             // inode's device
-        pad1          : cushort;
-        {$ifdef 64bitfs}                   // ??
-        __st_ino      : ino_t;
-        {$else}
-        st_ino        : ino_t;             // inode's number
-        {$endif}
+        st_dev        : dev_t;             // inode's device        
+{$ifdef CLEAN_STAT64}
+        st_ino        : ino64_t;
+{$else}        
+        pad1          : array[0..3] of byte;
+        __st_ino      : ino_t;             // inode's number
+{$endif}        
         st_mode       : mode_t;            // inode protection mode
         st_nlink      : nlink_t;           // number of hard links
         st_uid        : uid_t;             // user ID of the file's owner
         st_gid        : gid_t;             // group ID of the file's group
         st_rdev       : dev_t;             // device type
+{$ifdef CPUSPARC}
+        pad2          : array[0..7] of byte;
+{$else}
+{$ifdef CLEAN_STAT64}        
         pad2          : cushort;
-        {$ifdef 64bitfs}
-        st_size       : off64_t;            // file size, in bytes
-        {$else}
-        st_size       : off_t;             // file size, in bytes
-        {$endif}
-        st_blksize    : blksize_t;           // optimal blocksize for I/O
-        {$ifdef 64bitfs}
-        st_blocks     : blkcnt64_t;            // blocks allocated for file
-        {$else}
-        st_blocks     : blkcnt_t;            // blocks allocated for file
-        {$endif}
+{$else}
+        pad2          : array[0..3] of byte;
+{$endif}        
+{$endif}        
+        st_size       : off64_t;           // file size, in bytes
+        st_blksize    : blksize_t;         // optimal blocksize for I/O
+        st_blocks     : blkcnt64_t;        // blocks allocated for file
         st_atime      : time_t;            // time of last access
-        unused1       : culong;
+        st_atime_nsec : culong;
         st_mtime      : time_t;            // time of last data modification
-        unused2       : culong;
+        st_mtime_nsec : culong;
         st_ctime      : time_t;            // time of last file status change
-        unused3       : culong;
-        {$ifdef 64bitfs}
-        st_ino        : ino64_t
-        {$else}
-        unused4       : culong;
-        unused5       : culong;
-        {$endif}
+        st_ctime_nsec : culong;
+{$ifdef CLEAN_STAT64}
+        pad4          : cuint;
+        pad5          : cuint;
+{$else}
+        st_ino        : ino64_t;
+{$endif}        
    end;
-{$endif}
 
   { directory services }
 
-  Dirent     = packed record
-               {$ifndef 64bitfs}
-                d_fileno      : ino_t;                          // file number of entry
-                d_off         : off_t;
-                {$else}
+  Dirent   = packed record
                 d_fileno      : ino64_t;                        // file number of entry
                 d_off         : off64_t;
-               {$endif}
                 d_reclen      : cushort;                        // length of string in d_name
-               {$ifdef Uselibc} // Libc different from kernel record!
                 d_type        : cuchar;                         // file type, see below
-               {$endif}
                 d_name        : array[0..(255 + 1)-1] of char;  // name must be no longer than this
                end;
-  TDirent    = Dirent;
-  pDirent    = ^Dirent;
+  TDirent  = Dirent;
+  pDirent  = ^Dirent;
 
 {$ifdef oldreaddir}
            { Still old one. This is a userland struct}
@@ -169,7 +159,6 @@ type
                end;
 {$else}
         // new libc one. NOTE that off_t must be real, so 64-bit ifdef
-        // 64bitsfs
    Dir       = Record   // packing doesn't matter. This is a userland struct.
                 fd      : cint;
                 data    : pchar;
@@ -195,13 +184,8 @@ type
    FLock     = Record
                 l_type  : cshort;       { lock type: read/write, etc. }
                 l_whence: cshort;       { type of l_start }
-                {$ifdef 64bitfs}
                 l_start : off64_t;      { starting offset }
                 l_len   : off64_t;      { len = 0 means until end of file }
-                {$else}
-                l_start : off_t;        { starting offset }
-                l_len   : off_t;        { len = 0 means until end of file }
-                {$endif}
                 l_pid   : pid_t;        { lock owner }
                End;
 

+ 8 - 4
rtl/linux/ptypes.inc

@@ -53,6 +53,10 @@ Type
     TIno     = ino_t;
     pIno     = ^ino_t;
 
+    ino64_t  = cuint64;
+    TIno64   = ino64_t;
+    pIno64   = ^ino64_t;
+
     mode_t   = cuint32;         { used for file attributes     }
     TMode    = mode_t;
     pMode    = ^mode_t;
@@ -64,14 +68,14 @@ Type
 {$ifdef cpu64}
     off_t    = cint64;          { used for file sizes          }
 {$else}
-   {$ifdef 64BitFS}
-    off_t    = cint64;
-   {$else}
     off_t    = cint;
-   {$endif}
 {$endif}
+    off64_t  = cint64;
+
     TOff     = off_t;
     pOff     = ^off_t;
+    toff64   = off64_t;
+    poff64   = ^off64_t;
 
     pid_t    = cint32;          { used as process identifier   }
     TPid     = pid_t;

+ 4 - 4
rtl/unix/sysfile.inc

@@ -99,7 +99,7 @@ Begin
    InOutRes:=0;
 End;
 
-function Do_FilePos(Handle: thandle):longint;
+function Do_FilePos(Handle: thandle):Int64;
 Begin
   do_FilePos:=Fplseek(Handle, 0, SEEK_CUR);
   If Do_FilePos<0 Then
@@ -108,7 +108,7 @@ Begin
    InOutRes:=0;
 End;
 
-Procedure Do_Seek(Handle:thandle;Pos:Longint);
+Procedure Do_Seek(Handle:thandle;Pos:Int64);
 Begin
   If Fplseek(Handle, pos, SEEK_SET)<0 Then
    Errno2Inoutres
@@ -116,7 +116,7 @@ Begin
    InOutRes:=0;
 End;
 
-Function Do_SeekEnd(Handle:thandle): Longint;
+Function Do_SeekEnd(Handle:thandle):Int64;
 begin
   Do_SeekEnd:=Fplseek(Handle,0,SEEK_END);
   If Do_SeekEnd<0 Then
@@ -125,7 +125,7 @@ begin
    InOutRes:=0;
 end;
 
-Function Do_FileSize(Handle:thandle): Longint;
+Function Do_FileSize(Handle:thandle):Int64;
 var
   Info : Stat;
   Ret  : Longint;