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