1/* $NetBSD: fs.h,v 1.1.1.1 2011/09/11 17:20:31 christos Exp $ */ 2 3/* 4 * Automated Testing Framework (atf) 5 * 6 * Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#if !defined(ATF_C_FS_H) 33#define ATF_C_FS_H 34 35#include <sys/types.h> 36#include <sys/stat.h> 37 38#include <stdarg.h> 39#include <stdbool.h> 40 41#include <atf-c/error_fwd.h> 42 43#include "dynstr.h" 44 45/* --------------------------------------------------------------------- 46 * The "atf_fs_path" type. 47 * --------------------------------------------------------------------- */ 48 49struct atf_fs_path { 50 atf_dynstr_t m_data; 51}; 52typedef struct atf_fs_path atf_fs_path_t; 53 54/* Constructors/destructors. */ 55atf_error_t atf_fs_path_init_ap(atf_fs_path_t *, const char *, va_list); 56atf_error_t atf_fs_path_init_fmt(atf_fs_path_t *, const char *, ...); 57atf_error_t atf_fs_path_copy(atf_fs_path_t *, const atf_fs_path_t *); 58void atf_fs_path_fini(atf_fs_path_t *); 59 60/* Getters. */ 61atf_error_t atf_fs_path_branch_path(const atf_fs_path_t *, atf_fs_path_t *); 62const char *atf_fs_path_cstring(const atf_fs_path_t *); 63atf_error_t atf_fs_path_leaf_name(const atf_fs_path_t *, atf_dynstr_t *); 64bool atf_fs_path_is_absolute(const atf_fs_path_t *); 65bool atf_fs_path_is_root(const atf_fs_path_t *); 66 67/* Modifiers. */ 68atf_error_t atf_fs_path_append_ap(atf_fs_path_t *, const char *, va_list); 69atf_error_t atf_fs_path_append_fmt(atf_fs_path_t *, const char *, ...); 70atf_error_t atf_fs_path_append_path(atf_fs_path_t *, const atf_fs_path_t *); 71atf_error_t atf_fs_path_to_absolute(const atf_fs_path_t *, atf_fs_path_t *); 72 73/* Operators. */ 74bool atf_equal_fs_path_fs_path(const atf_fs_path_t *, 75 const atf_fs_path_t *); 76 77/* --------------------------------------------------------------------- 78 * The "atf_fs_stat" type. 79 * --------------------------------------------------------------------- */ 80 81struct atf_fs_stat { 82 int m_type; 83 struct stat m_sb; 84}; 85typedef struct atf_fs_stat atf_fs_stat_t; 86 87/* Constants. */ 88extern const int atf_fs_stat_blk_type; 89extern const int atf_fs_stat_chr_type; 90extern const int atf_fs_stat_dir_type; 91extern const int atf_fs_stat_fifo_type; 92extern const int atf_fs_stat_lnk_type; 93extern const int atf_fs_stat_reg_type; 94extern const int atf_fs_stat_sock_type; 95extern const int atf_fs_stat_wht_type; 96 97/* Constructors/destructors. */ 98atf_error_t atf_fs_stat_init(atf_fs_stat_t *, const atf_fs_path_t *); 99void atf_fs_stat_copy(atf_fs_stat_t *, const atf_fs_stat_t *); 100void atf_fs_stat_fini(atf_fs_stat_t *); 101 102/* Getters. */ 103dev_t atf_fs_stat_get_device(const atf_fs_stat_t *); 104ino_t atf_fs_stat_get_inode(const atf_fs_stat_t *); 105mode_t atf_fs_stat_get_mode(const atf_fs_stat_t *); 106off_t atf_fs_stat_get_size(const atf_fs_stat_t *); 107int atf_fs_stat_get_type(const atf_fs_stat_t *); 108bool atf_fs_stat_is_owner_readable(const atf_fs_stat_t *); 109bool atf_fs_stat_is_owner_writable(const atf_fs_stat_t *); 110bool atf_fs_stat_is_owner_executable(const atf_fs_stat_t *); 111bool atf_fs_stat_is_group_readable(const atf_fs_stat_t *); 112bool atf_fs_stat_is_group_writable(const atf_fs_stat_t *); 113bool atf_fs_stat_is_group_executable(const atf_fs_stat_t *); 114bool atf_fs_stat_is_other_readable(const atf_fs_stat_t *); 115bool atf_fs_stat_is_other_writable(const atf_fs_stat_t *); 116bool atf_fs_stat_is_other_executable(const atf_fs_stat_t *); 117 118/* --------------------------------------------------------------------- 119 * Free functions. 120 * --------------------------------------------------------------------- */ 121 122extern const int atf_fs_access_f; 123extern const int atf_fs_access_r; 124extern const int atf_fs_access_w; 125extern const int atf_fs_access_x; 126 127atf_error_t atf_fs_eaccess(const atf_fs_path_t *, int); 128atf_error_t atf_fs_exists(const atf_fs_path_t *, bool *); 129atf_error_t atf_fs_getcwd(atf_fs_path_t *); 130atf_error_t atf_fs_mkdtemp(atf_fs_path_t *); 131atf_error_t atf_fs_mkstemp(atf_fs_path_t *, int *); 132atf_error_t atf_fs_rmdir(const atf_fs_path_t *); 133atf_error_t atf_fs_unlink(const atf_fs_path_t *); 134 135#endif /* !defined(ATF_C_FS_H) */ 136