1273929Sjmmv/* Copyright (c) 2008 The NetBSD Foundation, Inc.
2240116Smarcel * All rights reserved.
3240116Smarcel *
4240116Smarcel * Redistribution and use in source and binary forms, with or without
5240116Smarcel * modification, are permitted provided that the following conditions
6240116Smarcel * are met:
7240116Smarcel * 1. Redistributions of source code must retain the above copyright
8240116Smarcel *    notice, this list of conditions and the following disclaimer.
9240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright
10240116Smarcel *    notice, this list of conditions and the following disclaimer in the
11240116Smarcel *    documentation and/or other materials provided with the distribution.
12240116Smarcel *
13240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14240116Smarcel * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15240116Smarcel * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16240116Smarcel * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17240116Smarcel * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18240116Smarcel * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20240116Smarcel * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21240116Smarcel * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22240116Smarcel * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23240116Smarcel * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24273929Sjmmv * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25240116Smarcel
26273929Sjmmv#if !defined(ATF_C_DETAIL_FS_H)
27273929Sjmmv#define ATF_C_DETAIL_FS_H
28240116Smarcel
29240116Smarcel#include <sys/types.h>
30240116Smarcel#include <sys/stat.h>
31240116Smarcel
32240116Smarcel#include <stdarg.h>
33240116Smarcel#include <stdbool.h>
34240116Smarcel
35273929Sjmmv#include <atf-c/detail/dynstr.h>
36240116Smarcel#include <atf-c/error_fwd.h>
37240116Smarcel
38240116Smarcel/* ---------------------------------------------------------------------
39240116Smarcel * The "atf_fs_path" type.
40240116Smarcel * --------------------------------------------------------------------- */
41240116Smarcel
42240116Smarcelstruct atf_fs_path {
43240116Smarcel    atf_dynstr_t m_data;
44240116Smarcel};
45240116Smarceltypedef struct atf_fs_path atf_fs_path_t;
46240116Smarcel
47240116Smarcel/* Constructors/destructors. */
48240116Smarcelatf_error_t atf_fs_path_init_ap(atf_fs_path_t *, const char *, va_list);
49240116Smarcelatf_error_t atf_fs_path_init_fmt(atf_fs_path_t *, const char *, ...);
50240116Smarcelatf_error_t atf_fs_path_copy(atf_fs_path_t *, const atf_fs_path_t *);
51240116Smarcelvoid atf_fs_path_fini(atf_fs_path_t *);
52240116Smarcel
53240116Smarcel/* Getters. */
54240116Smarcelatf_error_t atf_fs_path_branch_path(const atf_fs_path_t *, atf_fs_path_t *);
55240116Smarcelconst char *atf_fs_path_cstring(const atf_fs_path_t *);
56240116Smarcelatf_error_t atf_fs_path_leaf_name(const atf_fs_path_t *, atf_dynstr_t *);
57240116Smarcelbool atf_fs_path_is_absolute(const atf_fs_path_t *);
58240116Smarcelbool atf_fs_path_is_root(const atf_fs_path_t *);
59240116Smarcel
60240116Smarcel/* Modifiers. */
61240116Smarcelatf_error_t atf_fs_path_append_ap(atf_fs_path_t *, const char *, va_list);
62240116Smarcelatf_error_t atf_fs_path_append_fmt(atf_fs_path_t *, const char *, ...);
63240116Smarcelatf_error_t atf_fs_path_append_path(atf_fs_path_t *, const atf_fs_path_t *);
64240116Smarcelatf_error_t atf_fs_path_to_absolute(const atf_fs_path_t *, atf_fs_path_t *);
65240116Smarcel
66240116Smarcel/* Operators. */
67240116Smarcelbool atf_equal_fs_path_fs_path(const atf_fs_path_t *,
68240116Smarcel                               const atf_fs_path_t *);
69240116Smarcel
70240116Smarcel/* ---------------------------------------------------------------------
71240116Smarcel * The "atf_fs_stat" type.
72240116Smarcel * --------------------------------------------------------------------- */
73240116Smarcel
74240116Smarcelstruct atf_fs_stat {
75240116Smarcel    int m_type;
76240116Smarcel    struct stat m_sb;
77240116Smarcel};
78240116Smarceltypedef struct atf_fs_stat atf_fs_stat_t;
79240116Smarcel
80240116Smarcel/* Constants. */
81240116Smarcelextern const int atf_fs_stat_blk_type;
82240116Smarcelextern const int atf_fs_stat_chr_type;
83240116Smarcelextern const int atf_fs_stat_dir_type;
84240116Smarcelextern const int atf_fs_stat_fifo_type;
85240116Smarcelextern const int atf_fs_stat_lnk_type;
86240116Smarcelextern const int atf_fs_stat_reg_type;
87240116Smarcelextern const int atf_fs_stat_sock_type;
88240116Smarcelextern const int atf_fs_stat_wht_type;
89240116Smarcel
90240116Smarcel/* Constructors/destructors. */
91240116Smarcelatf_error_t atf_fs_stat_init(atf_fs_stat_t *, const atf_fs_path_t *);
92240116Smarcelvoid atf_fs_stat_copy(atf_fs_stat_t *, const atf_fs_stat_t *);
93240116Smarcelvoid atf_fs_stat_fini(atf_fs_stat_t *);
94240116Smarcel
95240116Smarcel/* Getters. */
96240116Smarceldev_t atf_fs_stat_get_device(const atf_fs_stat_t *);
97240116Smarcelino_t atf_fs_stat_get_inode(const atf_fs_stat_t *);
98240116Smarcelmode_t atf_fs_stat_get_mode(const atf_fs_stat_t *);
99240116Smarceloff_t atf_fs_stat_get_size(const atf_fs_stat_t *);
100240116Smarcelint atf_fs_stat_get_type(const atf_fs_stat_t *);
101240116Smarcelbool atf_fs_stat_is_owner_readable(const atf_fs_stat_t *);
102240116Smarcelbool atf_fs_stat_is_owner_writable(const atf_fs_stat_t *);
103240116Smarcelbool atf_fs_stat_is_owner_executable(const atf_fs_stat_t *);
104240116Smarcelbool atf_fs_stat_is_group_readable(const atf_fs_stat_t *);
105240116Smarcelbool atf_fs_stat_is_group_writable(const atf_fs_stat_t *);
106240116Smarcelbool atf_fs_stat_is_group_executable(const atf_fs_stat_t *);
107240116Smarcelbool atf_fs_stat_is_other_readable(const atf_fs_stat_t *);
108240116Smarcelbool atf_fs_stat_is_other_writable(const atf_fs_stat_t *);
109240116Smarcelbool atf_fs_stat_is_other_executable(const atf_fs_stat_t *);
110240116Smarcel
111240116Smarcel/* ---------------------------------------------------------------------
112240116Smarcel * Free functions.
113240116Smarcel * --------------------------------------------------------------------- */
114240116Smarcel
115240116Smarcelextern const int atf_fs_access_f;
116240116Smarcelextern const int atf_fs_access_r;
117240116Smarcelextern const int atf_fs_access_w;
118240116Smarcelextern const int atf_fs_access_x;
119240116Smarcel
120240116Smarcelatf_error_t atf_fs_eaccess(const atf_fs_path_t *, int);
121240116Smarcelatf_error_t atf_fs_exists(const atf_fs_path_t *, bool *);
122240116Smarcelatf_error_t atf_fs_getcwd(atf_fs_path_t *);
123240116Smarcelatf_error_t atf_fs_mkdtemp(atf_fs_path_t *);
124240116Smarcelatf_error_t atf_fs_mkstemp(atf_fs_path_t *, int *);
125240116Smarcelatf_error_t atf_fs_rmdir(const atf_fs_path_t *);
126240116Smarcelatf_error_t atf_fs_unlink(const atf_fs_path_t *);
127240116Smarcel
128273929Sjmmv#endif /* !defined(ATF_C_DETAIL_FS_H) */
129