Lines Matching refs:trail

65 struct trail {  struct
93 struct trail * argument
96 struct trail *trail; in trail_new() local
98 trail = calloc(1, sizeof(*trail)); in trail_new()
100 if (strlcpy(trail->tr_dirname, dirname, sizeof(trail->tr_dirname)) >= in trail_new()
101 sizeof(trail->tr_dirname)) { in trail_new()
102 free(trail); in trail_new()
107 trail->tr_dirfp = opendir(dirname); in trail_new()
108 if (trail->tr_dirfp == NULL) { in trail_new()
114 free(trail); in trail_new()
122 free(trail); in trail_new()
125 trail->tr_dirfp = opendir(dirname); in trail_new()
126 if (trail->tr_dirfp == NULL) { in trail_new()
130 free(trail); in trail_new()
134 trail->tr_filefd = -1; in trail_new()
135 trail->tr_magic = TRAIL_MAGIC; in trail_new()
136 return (trail); in trail_new()
140 trail_free(struct trail *trail) in trail_free() argument
143 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_free()
145 if (trail->tr_filefd != -1) in trail_free()
146 trail_close(trail); in trail_free()
147 closedir(trail->tr_dirfp); in trail_free()
148 bzero(trail, sizeof(*trail)); in trail_free()
149 trail->tr_magic = 0; in trail_free()
150 trail->tr_filefd = -1; in trail_free()
151 free(trail); in trail_free()
178 trail_find(struct trail *trail) in trail_find() argument
182 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_find()
183 PJDLOG_ASSERT(trail_is_not_terminated(trail->tr_filename)); in trail_find()
185 rewinddir(trail->tr_dirfp); in trail_find()
186 while ((dp = readdir(trail->tr_dirfp)) != NULL) { in trail_find()
187 if (strncmp(dp->d_name, trail->tr_filename, HALF_LEN + 1) == 0) in trail_find()
192 PJDLOG_VERIFY(strlcpy(trail->tr_filename, dp->d_name, in trail_find()
193 sizeof(trail->tr_filename)) < sizeof(trail->tr_filename)); in trail_find()
204 trail_start(struct trail *trail, const char *filename, off_t offset) in trail_start() argument
209 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_start()
211 PJDLOG_VERIFY(strlcpy(trail->tr_filename, filename, in trail_start()
212 sizeof(trail->tr_filename)) < sizeof(trail->tr_filename)); in trail_start()
213 trail->tr_filefd = -1; in trail_start()
215 if (trail->tr_filename[0] == '\0') { in trail_start()
217 trail_next(trail); in trail_start()
221 dfd = dirfd(trail->tr_dirfp); in trail_start()
224 fd = openat(dfd, trail->tr_filename, O_RDONLY); in trail_start()
227 trail_is_not_terminated(trail->tr_filename) && in trail_start()
228 trail_find(trail)) { in trail_start()
232 trail->tr_dirname, trail->tr_filename); in trail_start()
237 trail->tr_dirname, trail->tr_filename); in trail_start()
241 trail->tr_dirname, trail->tr_filename); in trail_start()
243 trail_next(trail); in trail_start()
249 trail->tr_dirname, trail->tr_filename); in trail_start()
251 trail_next(trail); in trail_start()
256 trail->tr_dirname, trail->tr_filename); in trail_start()
258 trail_next(trail); in trail_start()
282 trail_is_not_terminated(trail->tr_filename)) || in trail_start()
284 !trail_is_not_terminated(trail->tr_filename))) { in trail_start()
289 (intmax_t)offset, trail->tr_dirname, in trail_start()
290 trail->tr_filename); in trail_start()
292 trail_next(trail); in trail_start()
295 if (!trail_is_crash_recovery(trail->tr_filename)) { in trail_start()
298 trail->tr_dirname, trail->tr_filename, in trail_start()
301 trail->tr_filefd = fd; in trail_start()
307 trail->tr_dirname, trail->tr_filename); in trail_start()
310 trail->tr_dirname, trail->tr_filename); in trail_start()
313 if (unlinkat(dfd, trail->tr_filename, 0) == -1) { in trail_start()
315 trail->tr_dirname, trail->tr_filename); in trail_start()
317 trail_next(trail); in trail_start()
324 trail_next(struct trail *trail) in trail_next() argument
330 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_next()
331 PJDLOG_ASSERT(trail->tr_filefd == -1); in trail_next()
336 rewinddir(trail->tr_dirfp); in trail_next()
337 while ((dp = readdir(trail->tr_dirfp)) != NULL) { in trail_next()
341 dp->d_type = trail_type(trail->tr_dirfp, dp->d_name); in trail_next()
346 trail->tr_dirname, dp->d_name); in trail_next()
353 if (trail->tr_filename[0] != '\0' && in trail_next()
354 strcmp(dp->d_name, trail->tr_filename) <= 0) { in trail_next()
366 PJDLOG_ASSERT(trail->tr_filefd == -1); in trail_next()
370 dfd = dirfd(trail->tr_dirfp); in trail_next()
372 trail->tr_filefd = openat(dfd, curfile, O_RDONLY); in trail_next()
373 if (trail->tr_filefd == -1) { in trail_next()
382 trail->tr_dirname, curfile); in trail_next()
391 PJDLOG_VERIFY(strlcpy(trail->tr_filename, curfile, in trail_next()
392 sizeof(trail->tr_filename)) < in trail_next()
393 sizeof(trail->tr_filename)); in trail_next()
396 trail->tr_dirname, curfile); in trail_next()
400 PJDLOG_VERIFY(strlcpy(trail->tr_filename, curfile, in trail_next()
401 sizeof(trail->tr_filename)) < sizeof(trail->tr_filename)); in trail_next()
402 pjdlog_debug(1, "Found next trail file: \"%s/%s\".", trail->tr_dirname, in trail_next()
403 trail->tr_filename); in trail_next()
410 trail_close(struct trail *trail) in trail_close() argument
413 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_close()
414 PJDLOG_ASSERT(trail->tr_filefd >= 0); in trail_close()
415 PJDLOG_ASSERT(trail->tr_filename[0] != '\0'); in trail_close()
417 PJDLOG_VERIFY(close(trail->tr_filefd) == 0); in trail_close()
418 trail->tr_filefd = -1; in trail_close()
426 trail_reset(struct trail *trail) in trail_reset() argument
429 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_reset()
430 PJDLOG_ASSERT(trail->tr_filefd == -1); in trail_reset()
432 trail->tr_filename[0] = '\0'; in trail_reset()
439 trail_unlink(struct trail *trail, const char *filename) in trail_unlink() argument
443 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_unlink()
447 dfd = dirfd(trail->tr_dirfp); in trail_unlink()
452 trail->tr_dirname, filename); in trail_unlink()
455 trail->tr_dirname, filename); in trail_unlink()
465 trail_switch(struct trail *trail) in trail_switch() argument
470 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_switch()
471 PJDLOG_ASSERT(trail->tr_filefd >= 0); in trail_switch()
473 if (!trail_is_not_terminated(trail->tr_filename)) in trail_switch()
475 fd = dirfd(trail->tr_dirfp); in trail_switch()
477 if (faccessat(fd, trail->tr_filename, F_OK, 0) == 0) in trail_switch()
481 trail->tr_dirname, trail->tr_filename); in trail_switch()
483 strlcpy(filename, trail->tr_filename, sizeof(filename)); in trail_switch()
484 if (!trail_find(trail)) { in trail_switch()
486 trail->tr_dirname, trail->tr_filename); in trail_switch()
490 trail->tr_dirname, filename, trail->tr_dirname, in trail_switch()
491 trail->tr_filename); in trail_switch()
496 trail_filename(const struct trail *trail) in trail_filename() argument
499 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_filename()
501 return (trail->tr_filename); in trail_filename()
505 trail_filefd(const struct trail *trail) in trail_filefd() argument
508 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_filefd()
510 return (trail->tr_filefd); in trail_filefd()
514 trail_dirfd(const struct trail *trail) in trail_dirfd() argument
517 PJDLOG_ASSERT(trail->tr_magic == TRAIL_MAGIC); in trail_dirfd()
519 return (dirfd(trail->tr_dirfp)); in trail_dirfd()