1 /* 2 * Copyright (c) 2011 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Antonio Huete <tuxillo@quantumachine.net> 6 * by Matthew Dillon <dillon@backplane.com> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 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 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * 3. Neither the name of The DragonFly Project nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific, prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 */ 36 #ifndef _LIBHAMMER_H_ 37 #define _LIBHAMMER_H_ 38 39 #include <sys/queue.h> 40 #include <sys/param.h> 41 42 #include <vfs/hammer/hammer_disk.h> 43 #include <vfs/hammer/hammer_ioctl.h> 44 45 #define TXTLEN 64 46 47 #define HAMMER_BUFLISTS 64 48 #define HAMMER_BUFLISTMASK (HAMMER_BUFLISTS - 1) 49 #define COLLECT_HSIZE 1024 50 #define COLLECT_HMASK (COLLECT_HSIZE - 1) 51 #define HAMMER_BUFINFO_READAHEAD 0x0001 52 /* 53 * WARNING: Do not make the SNAPSHOTS_BASE "/var/snapshots" because 54 * it will interfere with the older HAMMER VERS < 3 snapshots directory 55 * for the /var PFS. 56 */ 57 #define SNAPSHOTS_BASE "/var/hammer" /* HAMMER VERS >= 3 */ 58 #define WS " \t\r\n" 59 60 #define SERIALBUF_SIZE (512 * 1024) 61 #define RD_HSIZE 32768 62 #define RD_HMASK (RD_HSIZE - 1) 63 64 #define DICTF_MADEDIR 0x01 65 #define DICTF_MADEFILE 0x02 66 #define DICTF_PARENT 0x04 /* parent attached for real */ 67 #define DICTF_TRAVERSED 0x80 68 #define FLAG_TOOFARLEFT 0x0001 69 #define FLAG_TOOFARRIGHT 0x0002 70 #define FLAG_BADTYPE 0x0004 71 #define FLAG_BADCHILDPARENT 0x0008 72 #define FLAG_BADMIRRORTID 0x0010 73 74 /* 75 * Hammer information system structures 76 */ 77 struct libhammer_head { 78 int32_t error; 79 int32_t flags; 80 int32_t rsv[2]; 81 }; 82 83 typedef struct libhammer_pfsinfo { 84 struct libhammer_head head; /* Additional error and flags */ 85 86 uint32_t snapcount; /* Snapshot count */ 87 u_int32_t version; /* HAMMER version */ 88 char *mountedon; /* Mount path of the PFS */ 89 int ismaster; /* Is a PFS master */ 90 int pfs_id; /* PFS ID number */ 91 int mirror_flags; /* Misc flags */ 92 char snapshots[64]; /* softlink dir for pruning */ 93 uuid_t unique_uuid; /* unique uuid of this master/slave */ 94 TAILQ_ENTRY(libhammer_pfsinfo) entries; 95 } *libhammer_pfsinfo_t; 96 97 typedef struct libhammer_volinfo { 98 struct libhammer_head head; /* Additional error and flags */ 99 100 char vol_name[TXTLEN]; /* Volume name */ 101 uuid_t vol_fsid; /* Filesystem UUID */ 102 int version; /* HAMMER version */ 103 int nvolumes; /* Number of volumes */ 104 int64_t inodes; /* no. of inodes */ 105 int64_t bigblocks; /* Total big blocks */ 106 int64_t freebigblocks; /* Free big blocks */ 107 int64_t rsvbigblocks; /* Reserved big blocks */ 108 int32_t rsv[8]; 109 TAILQ_HEAD(pfslist, libhammer_pfsinfo) list_pseudo; 110 } *libhammer_volinfo_t; 111 112 /* 113 * INFO directive prototypes 114 */ 115 __BEGIN_DECLS 116 libhammer_volinfo_t libhammer_get_volinfo(const char *); 117 void libhammer_free_volinfo(libhammer_volinfo_t); 118 __END_DECLS 119 120 static __inline libhammer_pfsinfo_t 121 libhammer_get_next_pfs(libhammer_pfsinfo_t pfsinfo) 122 { 123 return TAILQ_NEXT(pfsinfo, entries); 124 } 125 126 static __inline libhammer_pfsinfo_t 127 libhammer_get_prev_pfs(libhammer_pfsinfo_t pfsinfo) 128 { 129 return TAILQ_PREV(pfsinfo, pfslist, entries); 130 } 131 132 static __inline libhammer_pfsinfo_t 133 libhammer_get_first_pfs(libhammer_volinfo_t volinfo) 134 { 135 return TAILQ_FIRST(&volinfo->list_pseudo); 136 } 137 138 static __inline libhammer_pfsinfo_t 139 libhammer_get_last_pfs(libhammer_volinfo_t volinfo) 140 { 141 return TAILQ_LAST(&volinfo->list_pseudo, pfslist); 142 } 143 144 /* 145 * MISC directive prototypes 146 */ 147 __BEGIN_DECLS 148 char *libhammer_find_pfs_mount(int, uuid_t, int); 149 void *_libhammer_malloc(size_t); 150 __END_DECLS 151 152 #endif 153