1 /*
2 Copyright (C) 2012-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5
6 /*
7 WARNING: This file was generated by the dkct program (see
8 http://dktools.sourceforge.net/ for details).
9 Changes you make here will be lost if dkct is run again!
10 You should modify the original source and run dkct on it.
11 Original source: dk3ufi.ctr
12 */
13
14 /** @file dk3ufi.c The dk3ufi module.
15 */
16
17
18 #include <libdk3c/dk3all.h>
19 #include <libdk3c/dk3ufi.h>
20 #include <libdk3c/dk3unused.h>
21
22
23
24
25
26
27
28 int
dk3ufi_get_app(dk3_ufi_t * pd,dkChar const * fn,dk3_app_t * app)29 dk3ufi_get_app(dk3_ufi_t *pd, dkChar const *fn, dk3_app_t *app)
30 {
31 #if DK3_ON_WINDOWS
32 BY_HANDLE_FILE_INFORMATION bhfi;
33 #endif
34 dk3_stat_t stb;
35 #if DK3_ON_WINDOWS
36 HANDLE hFile;
37 int i;
38 #endif
39 int back = 0;
40
41 if((pd) && (fn)) {
42 if(dk3sf_stat_app(&stb, fn, app)) {
43 switch(stb.ft & (~(DK3_FT_SYMLINK))) {
44 case DK3_FT_REGULAR: {
45 #if DK3_ON_WINDOWS
46 for(i = 0; ((i < 2) && (0 == back)); i++) {
47 #if DK3_CHAR_SIZE > 2
48 hFile = INVALID_HANDLE_VALUE;
49 #else
50 #if DK3_CHAR_SIZE > 1
51
52 hFile = CreateFileW(
53 fn,
54 ((0 == i) ? (FILE_READ_ATTRIBUTES) : 0),
55 (FILE_SHARE_READ),
56 NULL,
57 OPEN_EXISTING,
58 FILE_ATTRIBUTE_NORMAL,
59 NULL
60 );
61 #else
62
63 hFile = CreateFileA(
64 fn,
65 ((0 == i) ? (FILE_READ_ATTRIBUTES) : 0),
66 (FILE_SHARE_READ),
67 NULL,
68 OPEN_EXISTING,
69 FILE_ATTRIBUTE_NORMAL,
70 NULL
71 );
72 #endif
73 #endif
74 if(INVALID_HANDLE_VALUE != hFile) {
75 if(GetFileInformationByHandle(hFile, &bhfi)) {
76 back = 1;
77 i = 2;
78 pd->volser = bhfi.dwVolumeSerialNumber;
79 pd->indhigh = bhfi.nFileIndexHigh;
80 pd->indlow = bhfi.nFileIndexLow;
81 } else {
82 /* ERROR: Failed to obtain file information! */
83 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
84 }
85 CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE;
86 } else {
87 /* ERROR: Failed to obtain file information! */
88 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
89 }
90 }
91 #else
92 pd->device = stb.device;
93 pd->inode = stb.inode;
94 back = 1;
95 #endif
96 } break;
97 case DK3_FT_DIRECTORY: {
98 #if DK3_ON_WINDOWS
99 for(i = 0; ((i < 2) && (0 == back)); i++) {
100 #if DK3_CHAR_SIZE > 2
101 hFile = INVALID_HANDLE_VALUE;
102 #else
103 #if DK3_CHAR_SIZE > 1
104
105 hFile = CreateFileW(
106 fn,
107 ((0 == i) ? (FILE_READ_ATTRIBUTES) : 0),
108 (FILE_SHARE_READ),
109 NULL,
110 OPEN_EXISTING,
111 (FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS),
112 NULL
113 );
114 #else
115
116 hFile = CreateFileA(
117 fn,
118 ((0 == i) ? (FILE_READ_ATTRIBUTES) : 0),
119 (FILE_SHARE_READ),
120 NULL,
121 OPEN_EXISTING,
122 (FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS),
123 NULL
124 );
125 #endif
126 #endif
127 if(INVALID_HANDLE_VALUE != hFile) {
128 if(GetFileInformationByHandle(hFile, &bhfi)) {
129 back = 1;
130 i = 2;
131 pd->volser = bhfi.dwVolumeSerialNumber;
132 pd->indhigh = bhfi.nFileIndexHigh;
133 pd->indlow = bhfi.nFileIndexLow;
134 } else {
135 /* ERROR: Failed to obtain file information! */
136 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
137 }
138 CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE;
139 } else {
140 /* ERROR: Failed to obtain file information */
141 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
142 }
143 }
144 #else
145 pd->device = stb.device;
146 pd->inode = stb.inode;
147 back = 1;
148 #endif
149 } break;
150 default: {
151 } break;
152 }
153 } else {
154 }
155 } else {
156 }
157 return back;
158 }
159
160
161
162 int
dk3ufi_c8_get_app(dk3_ufi_t * pd,char const * fn,dk3_app_t * app)163 dk3ufi_c8_get_app(dk3_ufi_t *pd, char const *fn, dk3_app_t *app)
164 {
165 #if DK3_ON_WINDOWS
166 BY_HANDLE_FILE_INFORMATION bhfi;
167 #endif
168 dk3_stat_t stb;
169 #if DK3_ON_WINDOWS
170 HANDLE hFile;
171 int i;
172 #endif
173 int back = 0;
174
175 if((pd) && (fn)) {
176 if(dk3sf_c8_stat_app(&stb, fn, app)) {
177 switch(stb.ft & (~(DK3_FT_SYMLINK))) {
178 case DK3_FT_REGULAR: {
179 #if DK3_ON_WINDOWS
180 for(i = 0; ((i < 2) && (0 == back)); i++) {
181
182 hFile = CreateFileA(
183 fn,
184 ((0 == i) ? (FILE_READ_ATTRIBUTES) : 0),
185 (FILE_SHARE_READ),
186 NULL,
187 OPEN_EXISTING,
188 FILE_ATTRIBUTE_NORMAL,
189 NULL
190 );
191 if(INVALID_HANDLE_VALUE != hFile) {
192 if(GetFileInformationByHandle(hFile, &bhfi)) {
193 back = 1;
194 i = 2;
195 pd->volser = bhfi.dwVolumeSerialNumber;
196 pd->indhigh = bhfi.nFileIndexHigh;
197 pd->indlow = bhfi.nFileIndexLow;
198 } else {
199 /* ERROR: Failed to obtain file information! */
200 #if DK3_CHAR_SIZE == 1
201 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
202 #else
203 dk3app_log_i1(app, DK3_LL_ERROR, 368);
204 #endif
205 }
206 CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE;
207 } else {
208 /* ERROR: Failed to obtain file information! */
209 #if DK3_CHAR_SIZE == 1
210 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
211 #else
212 dk3app_log_i1(app, DK3_LL_ERROR, 368);
213 #endif
214 }
215 }
216 #else
217 pd->device = stb.device;
218 pd->inode = stb.inode;
219 back = 1;
220 #endif
221 } break;
222 case DK3_FT_DIRECTORY: {
223 #if DK3_ON_WINDOWS
224 for(i = 0; ((i < 2) && (0 == back)); i++) {
225
226 hFile = CreateFileA(
227 fn,
228 ((0 == i) ? (FILE_READ_ATTRIBUTES) : 0),
229 (FILE_SHARE_READ),
230 NULL,
231 OPEN_EXISTING,
232 (FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS),
233 NULL
234 );
235 if(INVALID_HANDLE_VALUE != hFile) {
236 if(GetFileInformationByHandle(hFile, &bhfi)) {
237 back = 1;
238 i = 2;
239 pd->volser = bhfi.dwVolumeSerialNumber;
240 pd->indhigh = bhfi.nFileIndexHigh;
241 pd->indlow = bhfi.nFileIndexLow;
242 } else {
243 /* ERROR: Failed to obtain file information! */
244 #if DK3_CHAR_SIZE == 1
245 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
246 #else
247 dk3app_log_i1(app, DK3_LL_ERROR, 368);
248 #endif
249 }
250 CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE;
251 } else {
252 /* ERROR: Failed to obtain file information! */
253 #if DK3_CHAR_SIZE == 1
254 dk3app_log_i3(app, DK3_LL_ERROR, 366, 367, fn);
255 #else
256 dk3app_log_i1(app, DK3_LL_ERROR, 368);
257 #endif
258 }
259 }
260 #else
261 pd->device = stb.device;
262 pd->inode = stb.inode;
263 back = 1;
264 #endif
265 } break;
266 default: {
267 } break;
268 }
269 } else {
270 }
271 } else {
272 }
273
274 return back;
275 }
276
277
278
279 int
dk3ufi_get(dk3_ufi_t * pd,dkChar const * fn)280 dk3ufi_get(dk3_ufi_t *pd, dkChar const *fn)
281 {
282 int back;
283 back = dk3ufi_get_app(pd, fn, NULL);
284 return back;
285 }
286
287
288
289 int
dk3ufi_c8_get(dk3_ufi_t * pd,char const * fn)290 dk3ufi_c8_get(dk3_ufi_t *pd, char const *fn)
291 {
292 int back;
293 back = dk3ufi_c8_get_app(pd, fn, NULL);
294 return back;
295 }
296
297
298
299 int
dk3ufi_compare(void const * l,void const * r,int DK3_ARG_UNUSED (cr))300 dk3ufi_compare(void const *l, void const *r, int DK3_ARG_UNUSED(cr) )
301 {
302 int back = 0;
303 dk3_ufi_t const *pl;
304 dk3_ufi_t const *pr;
305
306 DK3_UNUSED_ARG(cr)
307 if(l) {
308 if(r) {
309 pl = (dk3_ufi_t const *)l; pr = (dk3_ufi_t const *)r;
310 #if DK3_ON_WINDOWS
311 if(pl->volser < pr->volser) {
312 back = -1;
313 } else {
314 if(pl->volser > pr->volser) {
315 back = 1;
316 }
317 }
318 if(0 == back) {
319 if(pl->indhigh < pr->indhigh) {
320 back = -1;
321 } else {
322 if(pl->indhigh > pr->indhigh) {
323 back = 1;
324 }
325 }
326 }
327 if(0 == back) {
328 if(pl->indlow < pr->indlow) {
329 back = -1;
330 } else {
331 if(pl->indlow > pr->indlow) {
332 back = 1;
333 }
334 }
335 }
336 #else
337 if(pl->device < pr->device) {
338 back = -1;
339 } else {
340 if(pl->device > pr->device) {
341 back = 1;
342 }
343 }
344 if(0 == back) {
345 if(pl->inode < pr->inode) {
346 back = -1;
347 } else {
348 if(pl->inode > pr->inode) {
349 back = 1;
350 }
351 }
352 }
353 #endif
354 } else back = 1;
355 } else {
356 if(r) back = -1;
357 }
358 return back;
359 }
360
361
362