1 /* 2 * Copyright (c)2004 The DragonFly Project. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * Neither the name of the DragonFly Project nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 * OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * diskutil.h 36 * $Id: diskutil.h,v 1.14 2005/02/07 06:41:42 cpressey Exp $ 37 */ 38 39 #include <stdio.h> 40 41 #ifndef __DISKUTIL_H_ 42 #define __DISKUTIL_H_ 43 44 #include "functions.h" 45 46 /*** TYPES ***/ 47 48 struct storage; 49 struct disk; 50 struct slice; 51 struct subpartition; 52 53 #define FS_UFS 0 54 #define FS_HAMMER 1 55 #define FS_HAMMER2 2 56 57 #ifdef NEEDS_DISKUTIL_STRUCTURE_DEFINITIONS 58 59 struct storage { 60 struct disk *disk_head; 61 struct disk *disk_tail; 62 struct disk *selected_disk; 63 struct slice *selected_slice; 64 long ram; /* amount of physical memory in MB */ 65 }; 66 67 struct disk { 68 struct disk *next; 69 struct disk *prev; 70 struct slice *slice_head; 71 struct slice *slice_tail; 72 char *desc; /* from whereever we get the best */ 73 int number; /* Position in kern.disks */ 74 char *device; /* `ad0', `da1', and such */ 75 char *serno; /* serial number */ 76 int cylinders; /* geometry information */ 77 int heads; 78 int sectors; /* (sectors per track) */ 79 long capacity; /* capacity in megabytes */ 80 int we_formatted; /* did we format it ourselves? */ 81 }; 82 83 struct slice { 84 struct disk *parent; 85 struct slice *next; 86 struct slice *prev; 87 struct subpartition *subpartition_head; 88 struct subpartition *subpartition_tail; 89 char *desc; /* description (w/sysid string) */ 90 int number; /* 1 - 4 (or more?) (from fdisk) */ 91 unsigned long start; /* start sector (from fdisk) */ 92 unsigned long size; /* size in sectors (from fdisk) */ 93 int type; /* sysid of slice (from fdisk) */ 94 int flags; /* flags (from fdisk) */ 95 unsigned long capacity; /* capacity in megabytes */ 96 }; 97 98 struct subpartition { 99 struct slice *parent; 100 struct subpartition *next; 101 struct subpartition *prev; 102 char letter; /* 'a' = root partition */ 103 char *mountpoint; /* includes leading slash */ 104 long capacity; /* in megabytes, -1 = "rest of disk" */ 105 int encrypted; 106 int softupdates; 107 long fsize; /* fragment size */ 108 long bsize; /* block size */ 109 int is_swap; 110 int tmpfsbacked; /* TMPFS Backed */ 111 int type; /* FS type (UFS, HAMMER) */ 112 int pfs; /* HAMMER pseudo file system */ 113 }; 114 115 #endif /* NEEDS_DISKUTIL_STRUCTURE_DEFINITIONS */ 116 117 /*** PROTOTYPES ***/ 118 119 struct storage *storage_new(void); 120 void storage_free(struct storage *); 121 void storage_set_memsize(struct storage *, unsigned long); 122 long storage_get_memsize(const struct storage *); 123 struct disk *storage_disk_first(const struct storage *); 124 void storage_set_selected_disk(struct storage *, struct disk *); 125 struct disk *storage_get_selected_disk(const struct storage *); 126 void storage_set_selected_slice(struct storage *, struct slice *); 127 struct slice *storage_get_selected_slice(const struct storage *); 128 int storage_get_tmpfs_status(const char *, struct storage *); 129 130 struct disk *disk_new(struct storage *, const char *); 131 struct disk *disk_find(const struct storage *, const char *); 132 struct disk *disk_next(const struct disk *); 133 void disks_free(struct storage *); 134 unsigned long disk_get_capacity(const struct disk *); 135 void disk_set_number(struct disk *, const int); 136 void disk_set_desc(struct disk *, const char *); 137 void disk_set_serno(struct disk *, const char *); 138 int disk_get_number(const struct disk *); 139 const char *disk_get_desc(const struct disk *); 140 const char *disk_get_device_name(const struct disk *); 141 const char *disk_get_serno(const struct disk *); 142 struct slice *disk_slice_first(const struct disk *); 143 void disk_set_formatted(struct disk *, int); 144 int disk_get_formatted(const struct disk *); 145 void disk_set_geometry(struct disk *, int, int, int); 146 void disk_get_geometry(const struct disk *, int *, int *, int *); 147 148 struct slice *slice_new(struct disk *, int, int, int, 149 unsigned long, unsigned long); 150 struct slice *slice_find(const struct disk *, int); 151 struct slice *slice_next(const struct slice *); 152 int slice_get_number(const struct slice *); 153 const char *slice_get_desc(const struct slice *); 154 const char *slice_get_device_name(const struct slice *); 155 unsigned long slice_get_capacity(const struct slice *); 156 unsigned long slice_get_start(const struct slice *); 157 unsigned long slice_get_size(const struct slice *); 158 int slice_get_type(const struct slice *); 159 int slice_get_flags(const struct slice *); 160 void slices_free(struct slice *); 161 struct subpartition *slice_subpartition_first(const struct slice *); 162 163 struct subpartition *subpartition_new_hammer(struct slice *, const char *, 164 long, int); 165 struct subpartition *subpartition_new_hammer2(struct slice *, const char *, 166 long, int); 167 struct subpartition *subpartition_new_ufs(struct slice *, const char *, 168 long, int, int, long, long, int); 169 int subpartition_count(const struct slice *); 170 struct subpartition *subpartition_find(const struct slice *, const char *, ...) 171 __printflike(2, 3); 172 struct subpartition *subpartition_of(const struct slice *, const char *, ...) 173 __printflike(2, 3); 174 struct subpartition *subpartition_find_capacity(const struct slice *, long); 175 void subpartitions_free(struct slice *); 176 struct subpartition *subpartition_next(const struct subpartition *); 177 int subpartition_get_pfs(const struct subpartition *); 178 const char *subpartition_get_mountpoint(const struct subpartition *); 179 const char *subpartition_get_device_name(const struct subpartition *); 180 const char *subpartition_get_mapper_name(const struct subpartition *, int); 181 char subpartition_get_letter(const struct subpartition *); 182 unsigned long subpartition_get_fsize(const struct subpartition *); 183 unsigned long subpartition_get_bsize(const struct subpartition *); 184 long subpartition_get_capacity(const struct subpartition *); 185 void subpartition_clr_encrypted(struct subpartition *); 186 int subpartition_is_encrypted(const struct subpartition *); 187 int subpartition_is_swap(const struct subpartition *); 188 int subpartition_is_softupdated(const struct subpartition *); 189 int subpartition_is_tmpfsbacked(const struct subpartition *); 190 191 long measure_activated_swap(const struct i_fn_args *); 192 long measure_activated_swap_from_slice(const struct i_fn_args *, 193 const struct disk *, const struct slice *); 194 long measure_activated_swap_from_disk(const struct i_fn_args *, 195 const struct disk *); 196 void *swapoff_all(const struct i_fn_args *); 197 void *remove_all_mappings(const struct i_fn_args *); 198 199 int survey_storage(struct i_fn_args *); 200 201 #endif /* !__DISKUTIL_H_ */ 202