/[eiffelstudio]/FreeELKS/trunk/library/kernel/unix_file_info.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/unix_file_info.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91626 - (show annotations)
Tue Oct 21 13:06:39 2008 UTC (11 years, 3 months ago) by kwaxer
File size: 6796 byte(s)
Changed `file_name' to be detachable as it is not set by the creation procedure and added preconditions to the features where it is used.
1 indexing
2 description: "Internal file information"
3 library: "Free implementation of ELKS library"
4 copyright: "Copyright (c) 1986-2006, Eiffel Software and others"
5 license: "Eiffel Forum License v2 (see forum.txt)"
6 date: "$Date$"
7 revision: "$Revision$"
8
9 class UNIX_FILE_INFO inherit
10
11 TO_SPECIAL [CHARACTER]
12 rename
13 area as buffered_file_info,
14 make_area as make_buffered_file_info
15 end
16
17 create
18
19 make
20
21 feature -- Initialization
22
23 make is
24 -- Creation procedure
25 do
26 make_buffered_file_info (stat_size)
27 end
28
29 feature -- Access
30
31 protection: INTEGER is
32 -- Protection mode of file (12 lower bits)
33 do
34 Result := file_info ($buffered_file_info, 0)
35 end
36
37 type: INTEGER is
38 -- File type (4 bits, 12 lowest bits zeroed)
39 do
40 Result := file_info ($buffered_file_info, 11)
41 end
42
43 inode: INTEGER is
44 -- Inode number
45 do
46 Result := file_info ($buffered_file_info, 1)
47 end
48
49 size: INTEGER is
50 -- File size, in bytes
51 do
52 Result := file_info ($buffered_file_info, 6)
53 end
54
55 user_id: INTEGER is
56 -- UID of the file owner
57 do
58 Result := file_info ($buffered_file_info, 4)
59 end
60
61 group_id: INTEGER is
62 -- GID of the file
63 do
64 Result := file_info ($buffered_file_info, 5)
65 end
66
67 date: INTEGER is
68 -- Last modification date
69 do
70 Result := file_info ($buffered_file_info, 7)
71 end
72
73 access_date: INTEGER is
74 -- Date of last access
75 do
76 Result := file_info ($buffered_file_info, 8)
77 end
78
79 change_date: INTEGER is
80 -- Date of last status change
81 do
82 Result := file_info ($buffered_file_info, 9)
83 end
84
85 device: INTEGER is
86 -- Device number on which inode resides
87 do
88 Result := file_info ($buffered_file_info, 2)
89 end
90
91 device_type: INTEGER is
92 -- Device type on which inode resides
93 do
94 Result := file_info ($buffered_file_info, 3)
95 end
96
97 links: INTEGER is
98 -- Number of links
99 do
100 Result := file_info ($buffered_file_info, 10)
101 end
102
103 owner_name: STRING is
104 -- Name of the file owner, if available from /etc/passwd.
105 -- Otherwise, the UID
106 do
107 Result := file_owner (user_id)
108 end
109
110 group_name: STRING is
111 -- Name of the file group, if available from /etc/group.
112 -- Otherwise, the GID
113 do
114 Result := file_group (group_id)
115 end
116
117 file_name: ?STRING
118 -- File name to which information applies
119
120 feature -- Status report
121
122 is_plain: BOOLEAN is
123 -- Is file a plain file?
124 do
125 Result := file_info ($buffered_file_info, 13) /= 0
126 end
127
128 is_device: BOOLEAN is
129 -- Is file a device?
130 do
131 Result := file_info ($buffered_file_info, 14) /= 0
132 end
133
134 is_directory: BOOLEAN is
135 -- Is file a directory?
136 do
137 Result := file_info ($buffered_file_info, 12) /= 0
138 end
139
140 is_symlink: BOOLEAN is
141 -- Is file a symbolic link?
142 do
143 Result := file_info ($buffered_file_info, 18) /= 0
144 end
145
146 is_fifo: BOOLEAN is
147 -- Is file a named pipe?
148 do
149 Result := file_info ($buffered_file_info, 17) /= 0
150 end
151
152 is_socket: BOOLEAN is
153 -- Is file a named socket?
154 do
155 Result := file_info ($buffered_file_info, 19) /= 0
156 end
157
158 is_block: BOOLEAN is
159 -- Is file a device block special file?
160 do
161 Result := file_info ($buffered_file_info, 16) /= 0
162 end
163
164 is_character: BOOLEAN is
165 -- Is file a character block special file?
166 do
167 Result := file_info ($buffered_file_info, 15) /= 0
168 end
169
170 is_readable: BOOLEAN is
171 -- Is file readable by effective UID?
172 do
173 Result := file_eaccess ($buffered_file_info, 0)
174 end
175
176 is_writable: BOOLEAN is
177 -- Is file writable by effective UID?
178 do
179 Result := file_eaccess ($buffered_file_info, 1)
180 end
181
182 is_executable: BOOLEAN is
183 -- Is file executable by effective UID?
184 do
185 Result := file_eaccess ($buffered_file_info, 2)
186 end
187
188 is_setuid: BOOLEAN is
189 -- Is file setuid?
190 do
191 Result := file_eaccess ($buffered_file_info, 3)
192 end
193
194 is_setgid: BOOLEAN is
195 -- Is file setgid?
196 do
197 Result := file_eaccess ($buffered_file_info, 4)
198 end
199
200 is_sticky: BOOLEAN is
201 -- Is file sticky?
202 do
203 Result := file_eaccess ($buffered_file_info, 5)
204 end
205
206 is_owner: BOOLEAN is
207 -- Is file owned by effective UID?
208 do
209 Result := file_eaccess ($buffered_file_info, 6)
210 end
211
212 is_access_owner: BOOLEAN is
213 -- Is file owned by real UID?
214 do
215 Result := file_eaccess ($buffered_file_info, 7)
216 end
217
218 is_access_readable: BOOLEAN is
219 -- Is file readable by real UID?
220 require
221 file_name_attached: file_name /= Void
222 local
223 ext_name: ANY
224 f: ?STRING
225 do
226 f := file_name
227 if f /= Void then
228 ext_name := f.to_c
229 Result := file_access ($ext_name, 3)
230 end
231 end
232
233 is_access_writable: BOOLEAN is
234 -- Is file writable by real UID?
235 require
236 file_name_attached: file_name /= Void
237 local
238 ext_name: ANY
239 f: ?STRING
240 do
241 f := file_name
242 if f /= Void then
243 ext_name := f.to_c
244 Result := file_access ($ext_name, 2)
245 end
246 end
247
248 is_access_executable: BOOLEAN is
249 -- Is file executable by real UID?
250 require
251 file_name_attached: file_name /= Void
252 local
253 ext_name: ANY
254 f: ?STRING
255 do
256 f := file_name
257 if f /= Void then
258 ext_name := f.to_c
259 Result := file_access ($ext_name, 1)
260 end
261 end
262
263 feature -- Element change
264
265 update (f_name: STRING) is
266 -- Update information buffer: fill it in with information
267 -- from the inode of `f_name'.
268 local
269 ext_name: ANY
270 do
271 ext_name := f_name.to_c
272 file_stat ($ext_name, $buffered_file_info)
273 -- Do not duplicate the file name. That way, if the file is
274 -- renamed, the name here will change accordingly and access()
275 -- based calls will continue to work properly.
276 file_name := f_name
277 end
278
279 feature {NONE} -- Implementation
280
281 stat_size: INTEGER is
282 -- Get size of 'struct stat' (in bytes)
283 external
284 "C use %"eif_file.h%""
285 end
286
287 file_stat (name, stat_buf: POINTER) is
288 -- Get information from file `name' into `stat_buf'
289 external
290 "C signature (char *, struct stat *) use %"eif_file.h%""
291 end
292
293 file_access (f_name: POINTER; which: INTEGER): BOOLEAN is
294 -- Perform access test `which' on `f_name' using real ID.
295 external
296 "C signature (char *, EIF_INTEGER): EIF_BOOLEAN use %"eif_file.h%""
297 end
298
299 file_eaccess (stat_buf: POINTER; which: INTEGER): BOOLEAN is
300 -- Perform access tests using effective ID.
301 external
302 "C signature (struct stat *, int): EIF_BOOLEAN use %"eif_file.h%""
303 end
304
305 file_info (stat_buf: POINTER; which: INTEGER): INTEGER is
306 -- Extract information `which' from information buffer
307 external
308 "C signature (struct stat *, int): EIF_INTEGER use %"eif_file.h%""
309 end
310
311 file_owner (uid: INTEGER): STRING is
312 -- Convert UID to login name if possible
313 external
314 "C signature (int): EIF_REFERENCE use %"eif_file.h%""
315 end
316
317 file_group (gid: INTEGER): STRING is
318 -- Convert GID to group name if possible
319 external
320 "C signature (int): EIF_REFERENCE use %"eif_file.h%""
321 end
322
323 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23