Page 1 of 1

SysFn70.5:GetFileAttributes

Posted: Tue Nov 08, 2016 12:47 am
by 0CodErr
А оно поддерживает AccessTime? Почему-то всегда 0. Пробовал узнать атрибуты файла '/sys/boardlog.txt'
Spoiler:
1.PNG
1.PNG (5.05 KiB)
Viewed 3365 times
Исходник
Spoiler:

Code: Select all

Unit Unit1;
(* -------------------------------------------------------- *)
Interface
(* -------------------------------------------------------- *)
Type

  Dword = Cardinal;

  TFileDate = Packed Record
    Day:   Byte;
    Month: Byte;
    Year:  Word;
  End;

  TFileTime = Packed Record
    Seconds: Byte;
    Minutes: Byte;
    Hours:   Byte;
    Zero:    Byte;
  End;

  TFileAttributes = Packed Record
    Attributes:   Dword;
    Flags:        Byte;
    reserved:     Array[0..2] Of Byte;
    CreationTime: TFileTime;
    CreationDate: TFileDate;
    AccessTime:   TFileTime;
    AccessDate:   TFileDate;
    ModifyTime:   TFileTime;
    ModifyDate:   TFileDate;
    SizeLo:       Dword;
    SizeHi:       Dword;
  End;

Var
  hConsole: Pointer;
  ConsoleInit:       Procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: Dword; Caption: PChar); StdCall;
  ConsoleExit:       Procedure(bCloseWindow: Cardinal); StdCall;
  printf:            Function(Const Format: PChar): Integer; CDecl VarArgs;
(* -------------------------------------------------------- *)
  Procedure Main; Forward;
  Procedure ThreadTerminate; Forward;
  Function  LoadLibrary(Path: PChar): Pointer; StdCall; Forward;
  Function  GetProcAddress(hLib: Pointer; ProcName: PChar): Pointer; StdCall; Forward;
  Function  GetFileAttributes(Path: PChar; Var Buffer: TFileAttributes): Integer; StdCall; Forward;
(* -------------------------------------------------------- *)
Implementation
(* -------------------------------------------------------- *)
Procedure Main();
Var
   FileAttributes: TFileAttributes;
Begin

   hConsole          := LoadLibrary('/sys/lib/console.obj');
   ConsoleInit       := GetProcAddress(hConsole, 'con_init');
   ConsoleExit       := GetProcAddress(hConsole, 'con_exit');
   printf            := GetProcAddress(hConsole, 'con_printf');

   ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Test');

   GetFileAttributes('/sys/boardlog.txt', FileAttributes);
   With FileAttributes Do Begin
     printf('Size         = %d'#10, SizeLo);
     With ModifyDate   Do printf('ModifyDate   = %02d.%02d.%02d'#10, Day, Month, Year);
     With ModifyTime   Do printf('ModifyTime   = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
     With AccessDate   Do printf('AccessDate   = %02d.%02d.%02d'#10, Day, Month, Year);
     With AccessTime   Do printf('AccessTime   = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
     With CreationDate Do printf('CreationDate = %02d.%02d.%02d'#10, Day, Month, Year);
     With CreationTime Do printf('CreationTime = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
   End;

   ConsoleExit(0);
   ThreadTerminate;
End;
(* -------------------------------------------------------- *)
Function  GetFileAttributes(Path: PChar; Var Buffer: TFileAttributes): Integer; StdCall;
Asm
        push   ebx
        push   Path
        dec    esp
        mov    byte[esp], 0
        push   Buffer
        push   0
        push   0
        push   0
        push   5
        mov    ebx, esp
        mov    eax, 70
        int    64
        add    esp, 25
        pop    ebx
End;
(* -------------------------------------------------------- *)
Procedure ThreadTerminate();
Asm
        mov    eax, $FFFFFFFF
        int    64
End;
(* -------------------------------------------------------- *)
Function GetProcAddress(hLib: Pointer; ProcName: PChar): Pointer;
Asm
        push   esi
        push   edi
        push   ebx
        mov    edx, hLib
        xor    eax, eax
        test   edx, edx
        jz     @end
        mov    edi, ProcName
        mov    ecx, $FFFFFFFF
        repne scasb
        mov    ebx, ecx
        not    ebx
@next:
        mov    esi, [edx]
        test   esi, esi
        jz     @end
        mov    ecx, ebx
        mov    edi, ProcName
        add    edx, 8
        repe cmpsb
        jne    @next
        mov    eax, [edx - 4]
@end:
        pop    ebx
        pop    edi
        pop    esi
End;
(* -------------------------------------------------------- *)
Function LoadLibrary(Path: PChar): Pointer;
Asm
        push   ebx
        mov    eax, 68
        mov    ebx, 19
        mov    ecx, Path
        int    64
        pop    ebx
End;
(* -------------------------------------------------------- *)
End.

Re: SysFn70.5:GetFileAttributes

Posted: Tue Nov 08, 2016 3:00 pm
by Pathoswithin
FAT не хранит AccessTime, только AccessDate.

Re: SysFn70.5:GetFileAttributes

Posted: Tue Nov 08, 2016 3:03 pm
by 0CodErr
Pathoswithin, а, то есть, в ext\ntfs оно должно работать нормально?

Re: SysFn70.5:GetFileAttributes

Posted: Tue Nov 08, 2016 3:06 pm
by Pathoswithin
Да.