1--
2--  Copyright (c) 2014-15 John Marino <draco@marino.st>
3--
4--  Permission to use, copy, modify, and distribute this software for any
5--  purpose with or without fee is hereby granted, provided that the above
6--  copyright notice and this permission notice appear in all copies.
7--
8--  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9--  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10--  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11--  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12--  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13--  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14--  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15--
16
17
18with Interfaces.C.Strings;
19
20package DragonFly.FileStatus is
21
22
23   package ICS renames Interfaces.C.Strings;
24
25
26   --------------
27   ---  Types  --
28   --------------
29
30   subtype Tino    is uInt64;
31   subtype Tnlink  is uInt32;
32   subtype Tdev    is uInt32;
33   subtype Tmode   is uInt16;
34   subtype Tuid    is uInt32;
35   subtype Tgid    is uInt32;
36   subtype Toffset is uInt64;
37   subtype Ttime   is uInt64;  --  amd64 only, it's uInt32 on i386
38   subtype Tnsec   is uInt64;  --  amd64 only. However i386 is not supported
39
40   type timespec is record
41      tv_sec      : Ttime;
42      tv_nsec     : Tnsec;
43   end record;
44
45   type inode_data is record
46      st_ino      : Tino;
47      st_nlink    : Tnlink;
48      st_dev      : Tdev;
49      st_mode     : Tmode;
50      st_padding1 : uInt16;
51      st_uid      : Tuid;
52      st_gid      : Tgid;
53      st_rdev     : Tdev;
54      st_atim     : timespec;
55      st_mtim     : timespec;
56      st_ctim     : timespec;
57      st_size     : Toffset;
58      st_blocks   : Int64;
59      st_blksize  : uInt32;
60      st_flags    : uInt32;
61      st_gen      : uInt32;
62      st_lspare   : Int32;
63      st_qspare1  : Int32;
64      st_qspare2  : Int32;
65   end record;
66
67
68   ------------------
69   ---  Constants  --
70   ------------------
71
72   S_IFIFO  : constant Tmode :=  8#10000#;  --  named pipe (FIFO)
73   S_IFCHR  : constant Tmode :=  8#20000#;  --  special character
74   S_IFDIR  : constant Tmode :=  8#40000#;  --  directory
75   S_IFBLK  : constant Tmode :=  8#60000#;  --  special block
76   S_IFREG  : constant Tmode := 8#100000#;  --  regular
77   S_IFDB   : constant Tmode := 8#110000#;  --  record access file
78   S_IFLNK  : constant Tmode := 8#120000#;  --  symbolic link
79   S_IFSOCK : constant Tmode := 8#140000#;  --  socket
80   S_IFWHT  : constant Tmode := 8#160000#;  --  whiteout
81   S_IFMT   : constant Tmode := 8#170000#;  --  file mask type
82   S_ISVTX  : constant Tmode :=   8#1000#;  --  saved swapped text
83
84
85   -------------------------
86   ---  Import Functions  --
87   -------------------------
88
89   function fstat (fd : file_descriptor; sb : inode_data) return Int32;
90   pragma Import (C, fstat, "fstat");
91   --  polls information about an open file from a given file descriptor
92   --  return 0 on success, -1 on failure
93
94   procedure stat (
95                path   : in String;
96                sb     : in out inode_data;
97                result : out Int32);
98   --  polls information about a file from a given path (wrapper)
99   --  return 0 on success, -1 on failure
100
101   function symlink (source, newlink : String) return Boolean;
102   --  creates a symlink link "newlink" to the "source" path (wrapper)
103   --  returns True on success, False on failure
104
105private
106
107   function private_stat (path : ICS.chars_ptr; sb : inode_data) return Int32;
108   pragma Import (C, private_stat, "stat");
109   --  polls information about a file from a given path
110   --  return 0 on success, -1 on failure
111
112   function private_symlink (source, newlink : ICS.chars_ptr) return Int32;
113   pragma Import (C, private_symlink, "symlink");
114   --  creates a symlink link "newlink" to the "source" path
115   --  return 0 on success, -1 on failure
116
117end DragonFly.FileStatus;
118