1 /* 2 * Copyright (c) 2012-2017, Robin Hahling 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * * Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * * Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * * Neither the name of the author nor the names of its contributors may be 16 * used to endorse or promote products derived from this software without 17 * specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef H_LIST 33 #define H_LIST 34 /* 35 * list.h 36 * 37 * list structure 38 */ 39 40 #include <sys/types.h> 41 42 /* 43 * Structure to store information about mounted fs 44 */ 45 struct fsmntinfo { 46 /* infos to get from getmntent(3) */ 47 char *fsname; /* name of mounted file system */ 48 char *fsnameog; /* original name of file system */ 49 char *fstype; /* mount type */ 50 char *fstypeog; /* original mount type */ 51 char *mntdir; /* file system path prefix */ 52 char *mntdirog; /* original file system path prefix */ 53 char *mntopts; /* mount options (see mntent.h) */ 54 55 double perctused; /* fs usage in % */ 56 double total; /* fs total size */ 57 double avail; /* fs available size */ 58 double used; /* fs used size */ 59 60 /* infos to get from statvfs(3) */ 61 #if defined(__linux__) || defined(__GLIBC__) 62 int flags; /* XXX: does not exist on Linux */ 63 unsigned long bsize; /* file system block size */ 64 unsigned long frsize; /* fragment size */ 65 fsblkcnt_t blocks; /* size of fs in frsize unit */ 66 fsblkcnt_t bfree; /* # of free blocks */ 67 fsblkcnt_t bavail; /* # of available blocks */ 68 fsfilcnt_t files; /* # of inodes */ 69 fsfilcnt_t ffree; /* # of free inodes */ 70 fsfilcnt_t favail; /* # of available inodes */ 71 #endif /* __linux__ */ 72 #if defined(__NetBSD__) 73 unsigned long flags; /* mount exported flags */ 74 unsigned long bsize; /* file system block size */ 75 unsigned long frsize; /* fragment size */ 76 fsblkcnt_t blocks; /* size of fs in frsize unit */ 77 fsblkcnt_t bfree; /* # of free blocks */ 78 fsblkcnt_t bavail; /* # of available blocks */ 79 fsfilcnt_t files; /* # of inodes */ 80 fsfilcnt_t ffree; /* # of free inodes */ 81 fsfilcnt_t favail; /* # of available inodes */ 82 #endif /* __NetBSD__ */ 83 #if defined(__FreeBSD__) 84 uint64_t flags; /* mount exported flags */ 85 uint64_t bsize; /* file system block size */ 86 unsigned long frsize; /* XXX: does not exist on FreeBSD */ 87 uint64_t blocks; /* size of fs in frsize unit */ 88 uint64_t bfree; /* # of free blocks */ 89 int64_t bavail; /* # of available blocks */ 90 uint64_t files; /* # of inodes */ 91 int64_t ffree; /* # of free nodes to non super-user */ 92 unsigned long favail; /* XXX: does not exist on FreeBSD */ 93 #endif /* __FreeBSD__ */ 94 #if defined(__OpenBSD__) 95 u_int32_t flags; /* mount exported flags */ 96 u_int32_t bsize; /* file system block size */ 97 unsigned long frsize; /* XXX: does not exist on OpenBSD */ 98 u_int64_t blocks; /* size of fs in frsize unit */ 99 u_int64_t bfree; /* # of free blocks */ 100 int64_t bavail; /* # of available blocks */ 101 u_int64_t files; /* # of inodes */ 102 u_int64_t ffree; /* # of free inodes */ 103 int64_t favail; /* # of available inodes */ 104 #endif /* __OpenBSD__ */ 105 #if defined(__DragonFly__) 106 int flags; /* mount exported flags */ 107 long bsize; /* file system block size */ 108 unsigned long frsize; /* XXX: does not exist on DragonFly */ 109 long blocks; /* size of fs in frsize unit */ 110 long bfree; /* # of free blocks */ 111 long bavail; /* # of available blocks */ 112 long files; /* # of inodes */ 113 long ffree; /* # of free inodes */ 114 unsigned long favail; /* XXX: does not exist on DragonFly */ 115 #endif /* __DragonFly__ */ 116 #if defined(__APPLE__) 117 uint32_t flags; /* mount exported flags */ 118 uint32_t bsize; /* file system block size */ 119 unsigned long frsize; /* XXX: does not exist on OSX */ 120 uint64_t blocks; /* size of fs in frsize unit */ 121 uint64_t bfree; /* # of free blocks */ 122 uint64_t bavail; /* # of available blocks */ 123 uint64_t files; /* # of inodes */ 124 uint64_t ffree; /* # of free inodes */ 125 unsigned long favail; /* XXX: does not exist on OSX */ 126 #endif /* __APPLE__ */ 127 #if defined(__sun) 128 int flags; /* XXX: does not exist on Solaris */ 129 u_long bsize; /* file system block size */ 130 u_long frsize; /* fragment size */ 131 fsblkcnt_t blocks; /* size of fs in frsize unit */ 132 fsblkcnt_t bfree; /* # of free blocks */ 133 fsblkcnt_t bavail; /* # of available blocks */ 134 fsfilcnt_t files; /* # of inodes */ 135 fsfilcnt_t ffree; /* # of free inodes */ 136 fsfilcnt_t favail; /* # of available inodes */ 137 #endif /* __sun */ 138 139 int ignored; 140 /* pointer to the next element of the list */ 141 struct fsmntinfo *next; 142 }; 143 144 /* list structure to store fsmntinfo */ 145 struct list { 146 struct fsmntinfo *head; 147 struct fsmntinfo *tail; 148 }; 149 150 /* function declaration */ 151 void init_queue(struct list *lst); 152 int is_empty(struct list lst); 153 int enqueue(struct list *lst, struct fsmntinfo elt); 154 struct fsmntinfo fmi_init(void); 155 struct fsmntinfo *delete_struct_and_get_next(struct fsmntinfo *p); 156 157 #endif /* ndef LIST_H */ 158