173f9b8cfSDoug MacEachern/*
273f9b8cfSDoug MacEachern * Copyright (c) 2004-2005 Hyperic, Inc.
373f9b8cfSDoug MacEachern *
473f9b8cfSDoug MacEachern * Licensed under the Apache License, Version 2.0 (the "License");
573f9b8cfSDoug MacEachern * you may not use this file except in compliance with the License.
673f9b8cfSDoug MacEachern * You may obtain a copy of the License at
773f9b8cfSDoug MacEachern *
873f9b8cfSDoug MacEachern *     http://www.apache.org/licenses/LICENSE-2.0
973f9b8cfSDoug MacEachern *
1073f9b8cfSDoug MacEachern * Unless required by applicable law or agreed to in writing, software
1173f9b8cfSDoug MacEachern * distributed under the License is distributed on an "AS IS" BASIS,
1273f9b8cfSDoug MacEachern * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1373f9b8cfSDoug MacEachern * See the License for the specific language governing permissions and
1473f9b8cfSDoug MacEachern * limitations under the License.
1573f9b8cfSDoug MacEachern */
1673f9b8cfSDoug MacEachern
17dffe0da8SDoug MacEachern/* ====================================================================
18dffe0da8SDoug MacEachern * The Apache Software License, Version 1.1
19dffe0da8SDoug MacEachern *
20dffe0da8SDoug MacEachern * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
21dffe0da8SDoug MacEachern * reserved.
22dffe0da8SDoug MacEachern *
23dffe0da8SDoug MacEachern * Redistribution and use in source and binary forms, with or without
24dffe0da8SDoug MacEachern * modification, are permitted provided that the following conditions
25dffe0da8SDoug MacEachern * are met:
26dffe0da8SDoug MacEachern *
27dffe0da8SDoug MacEachern * 1. Redistributions of source code must retain the above copyright
28dffe0da8SDoug MacEachern *    notice, this list of conditions and the following disclaimer.
29dffe0da8SDoug MacEachern *
30dffe0da8SDoug MacEachern * 2. Redistributions in binary form must reproduce the above copyright
31dffe0da8SDoug MacEachern *    notice, this list of conditions and the following disclaimer in
32dffe0da8SDoug MacEachern *    the documentation and/or other materials provided with the
33dffe0da8SDoug MacEachern *    distribution.
34dffe0da8SDoug MacEachern *
35dffe0da8SDoug MacEachern * 3. The end-user documentation included with the redistribution,
36dffe0da8SDoug MacEachern *    if any, must include the following acknowledgment:
37dffe0da8SDoug MacEachern *       "This product includes software developed by the
38dffe0da8SDoug MacEachern *        Apache Software Foundation (http://www.apache.org/)."
39dffe0da8SDoug MacEachern *    Alternately, this acknowledgment may appear in the software itself,
40dffe0da8SDoug MacEachern *    if and wherever such third-party acknowledgments normally appear.
41dffe0da8SDoug MacEachern *
42dffe0da8SDoug MacEachern * 4. The names "Apache" and "Apache Software Foundation" must
43dffe0da8SDoug MacEachern *    not be used to endorse or promote products derived from this
44dffe0da8SDoug MacEachern *    software without prior written permission. For written
45dffe0da8SDoug MacEachern *    permission, please contact apache@apache.org.
46dffe0da8SDoug MacEachern *
47dffe0da8SDoug MacEachern * 5. Products derived from this software may not be called "Apache",
48dffe0da8SDoug MacEachern *    nor may "Apache" appear in their name, without prior written
49dffe0da8SDoug MacEachern *    permission of the Apache Software Foundation.
50dffe0da8SDoug MacEachern *
51dffe0da8SDoug MacEachern * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
52dffe0da8SDoug MacEachern * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53dffe0da8SDoug MacEachern * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
54dffe0da8SDoug MacEachern * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
55dffe0da8SDoug MacEachern * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56dffe0da8SDoug MacEachern * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57dffe0da8SDoug MacEachern * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
58dffe0da8SDoug MacEachern * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
59dffe0da8SDoug MacEachern * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
60dffe0da8SDoug MacEachern * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
61dffe0da8SDoug MacEachern * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62dffe0da8SDoug MacEachern * SUCH DAMAGE.
63dffe0da8SDoug MacEachern * ====================================================================
64dffe0da8SDoug MacEachern *
65dffe0da8SDoug MacEachern * This software consists of voluntary contributions made by many
66dffe0da8SDoug MacEachern * individuals on behalf of the Apache Software Foundation.  For more
67dffe0da8SDoug MacEachern * information on the Apache Software Foundation, please see
68dffe0da8SDoug MacEachern * <http://www.apache.org/>.
69dffe0da8SDoug MacEachern */
70dffe0da8SDoug MacEachern
71dffe0da8SDoug MacEachern#include "sigar.h"
72dffe0da8SDoug MacEachern
73dffe0da8SDoug MacEacherntypedef enum {
74dffe0da8SDoug MacEachern    SIGAR_FILETYPE_NOFILE = 0,     /**< no file type determined */
75dffe0da8SDoug MacEachern    SIGAR_FILETYPE_REG,            /**< a regular file */
76dffe0da8SDoug MacEachern    SIGAR_FILETYPE_DIR,            /**< a directory */
77dffe0da8SDoug MacEachern    SIGAR_FILETYPE_CHR,            /**< a character device */
78dffe0da8SDoug MacEachern    SIGAR_FILETYPE_BLK,            /**< a block device */
79dffe0da8SDoug MacEachern    SIGAR_FILETYPE_PIPE,           /**< a FIFO / pipe */
80dffe0da8SDoug MacEachern    SIGAR_FILETYPE_LNK,            /**< a symbolic link */
81dffe0da8SDoug MacEachern    SIGAR_FILETYPE_SOCK,           /**< a [unix domain] socket */
82dffe0da8SDoug MacEachern    SIGAR_FILETYPE_UNKFILE         /**< a file of some other unknown type */
8342d0b984STrond Norbye} sigar_file_type_e;
84dffe0da8SDoug MacEachern
85dffe0da8SDoug MacEachern#define SIGAR_UREAD       0x0400 /**< Read by user */
86dffe0da8SDoug MacEachern#define SIGAR_UWRITE      0x0200 /**< Write by user */
87dffe0da8SDoug MacEachern#define SIGAR_UEXECUTE    0x0100 /**< Execute by user */
88dffe0da8SDoug MacEachern
89dffe0da8SDoug MacEachern#define SIGAR_GREAD       0x0040 /**< Read by group */
90dffe0da8SDoug MacEachern#define SIGAR_GWRITE      0x0020 /**< Write by group */
91dffe0da8SDoug MacEachern#define SIGAR_GEXECUTE    0x0010 /**< Execute by group */
92dffe0da8SDoug MacEachern
93dffe0da8SDoug MacEachern#define SIGAR_WREAD       0x0004 /**< Read by others */
94dffe0da8SDoug MacEachern#define SIGAR_WWRITE      0x0002 /**< Write by others */
95dffe0da8SDoug MacEachern#define SIGAR_WEXECUTE    0x0001 /**< Execute by others */
96dffe0da8SDoug MacEachern
97dffe0da8SDoug MacEacherntypedef struct {
98dffe0da8SDoug MacEachern    /** The access permissions of the file.  Mimics Unix access rights. */
99dffe0da8SDoug MacEachern    sigar_uint64_t permissions;
100dffe0da8SDoug MacEachern    sigar_file_type_e type;
101dffe0da8SDoug MacEachern    /** The user id that owns the file */
102dffe0da8SDoug MacEachern    sigar_uid_t uid;
103dffe0da8SDoug MacEachern    /** The group id that owns the file */
104dffe0da8SDoug MacEachern    sigar_gid_t gid;
105dffe0da8SDoug MacEachern    /** The inode of the file. */
106dffe0da8SDoug MacEachern    sigar_uint64_t inode;
107dffe0da8SDoug MacEachern    /** The id of the device the file is on. */
108dffe0da8SDoug MacEachern    sigar_uint64_t device;
109dffe0da8SDoug MacEachern    /** The number of hard links to the file. */
110dffe0da8SDoug MacEachern    sigar_uint64_t nlink;
111dffe0da8SDoug MacEachern    /** The size of the file */
112dffe0da8SDoug MacEachern    sigar_uint64_t size;
113dffe0da8SDoug MacEachern    /** The time the file was last accessed */
114dffe0da8SDoug MacEachern    sigar_uint64_t atime;
115dffe0da8SDoug MacEachern    /** The time the file was last modified */
116dffe0da8SDoug MacEachern    sigar_uint64_t mtime;
117dffe0da8SDoug MacEachern    /** The time the file was last changed */
118dffe0da8SDoug MacEachern    sigar_uint64_t ctime;
119dffe0da8SDoug MacEachern} sigar_file_attrs_t;
120dffe0da8SDoug MacEachern
121dffe0da8SDoug MacEacherntypedef struct {
122dffe0da8SDoug MacEachern    sigar_uint64_t total;
123dffe0da8SDoug MacEachern    sigar_uint64_t files;
124dffe0da8SDoug MacEachern    sigar_uint64_t subdirs;
125dffe0da8SDoug MacEachern    sigar_uint64_t symlinks;
126dffe0da8SDoug MacEachern    sigar_uint64_t chrdevs;
127dffe0da8SDoug MacEachern    sigar_uint64_t blkdevs;
128dffe0da8SDoug MacEachern    sigar_uint64_t sockets;
129ab3abd51SDoug MacEachern    sigar_uint64_t disk_usage;
130dffe0da8SDoug MacEachern} sigar_dir_stat_t;
131dffe0da8SDoug MacEachern
132d50e4efeSDoug MacEacherntypedef sigar_dir_stat_t sigar_dir_usage_t;
133d50e4efeSDoug MacEachern
134dffe0da8SDoug MacEachernSIGAR_DECLARE(const char *)
135dffe0da8SDoug MacEachernsigar_file_attrs_type_string_get(sigar_file_type_e type);
136dffe0da8SDoug MacEachern
137dffe0da8SDoug MacEachernSIGAR_DECLARE(int) sigar_file_attrs_get(sigar_t *sigar,
138dffe0da8SDoug MacEachern                                        const char *file,
139dffe0da8SDoug MacEachern                                        sigar_file_attrs_t *fileattrs);
140dffe0da8SDoug MacEachern
141dffe0da8SDoug MacEachernSIGAR_DECLARE(int) sigar_link_attrs_get(sigar_t *sigar,
142dffe0da8SDoug MacEachern                                        const char *file,
143dffe0da8SDoug MacEachern                                        sigar_file_attrs_t *fileattrs);
144dffe0da8SDoug MacEachern
145dffe0da8SDoug MacEachernSIGAR_DECLARE(int)sigar_file_attrs_mode_get(sigar_uint64_t permissions);
146dffe0da8SDoug MacEachern
147dffe0da8SDoug MacEachernSIGAR_DECLARE(char *)
148dffe0da8SDoug MacEachernsigar_file_attrs_permissions_string_get(sigar_uint64_t permissions,
149dffe0da8SDoug MacEachern                                       char *str);
150dffe0da8SDoug MacEachern
151dffe0da8SDoug MacEachernSIGAR_DECLARE(int) sigar_dir_stat_get(sigar_t *sigar,
152dffe0da8SDoug MacEachern                                      const char *dir,
153dffe0da8SDoug MacEachern                                      sigar_dir_stat_t *dirstats);
154d50e4efeSDoug MacEachern
155d50e4efeSDoug MacEachernSIGAR_DECLARE(int) sigar_dir_usage_get(sigar_t *sigar,
156d50e4efeSDoug MacEachern                                       const char *dir,
157d50e4efeSDoug MacEachern                                       sigar_dir_usage_t *dirusage);
158