aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/fstat.h
blob: 64e79e1b559d7e915221c0d26effa943c75c7acf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

#include <util/generic/fwd.h>
#include <util/system/fhandle.h>

class TFile;
class TFsPath;

struct TFileStat {
    ui32 Mode = 0; /* protection */
    ui32 Uid = 0;  /* user ID of owner */
    ui32 Gid = 0;  /* group ID of owner */

    ui64 NLinks = 0;         /* number of hard links */
    ui64 Size = 0;           /* total size, in bytes */
    ui64 INode = 0;          /* inode number */
    ui64 AllocationSize = 0; /* number of bytes allocated on the disk */

    time_t ATime = 0; /* time of last access */
    time_t MTime = 0; /* time of last modification */
    time_t CTime = 0; /* time of last status change */

public:
    TFileStat();

    bool IsNull() const noexcept;

    bool IsFile() const noexcept;
    bool IsDir() const noexcept;
    bool IsSymlink() const noexcept;

    explicit TFileStat(const TFile& f);
    explicit TFileStat(FHANDLE f);
    TFileStat(const TFsPath& fileName, bool nofollow = false);
    TFileStat(const TString& fileName, bool nofollow = false);
    TFileStat(const char* fileName, bool nofollow = false);

    friend bool operator==(const TFileStat& l, const TFileStat& r) noexcept;
    friend bool operator!=(const TFileStat& l, const TFileStat& r) noexcept;

private:
    void MakeFromFileName(const char* fileName, bool nofollow);
};

i64 GetFileLength(FHANDLE fd);
i64 GetFileLength(const char* name);
i64 GetFileLength(const TString& name);