| 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_HAMMER 0 |
| 54 | #define FS_UFS 1 |
| 55 | |
| 56 | #ifdef NEEDS_DISKUTIL_STRUCTURE_DEFINITIONS |
| 57 | |
| 58 | struct storage { |
| 59 | struct disk *disk_head; |
| 60 | struct disk *disk_tail; |
| 61 | struct disk *selected_disk; |
| 62 | struct slice *selected_slice; |
| 63 | unsigned long ram; /* amount of physical memory in MB */ |
| 64 | }; |
| 65 | |
| 66 | struct disk { |
| 67 | struct disk *next; |
| 68 | struct disk *prev; |
| 69 | struct slice *slice_head; |
| 70 | struct slice *slice_tail; |
| 71 | char *desc; /* from whereever we get the best */ |
| 72 | char *device; /* `ad0', `da1', and such */ |
| 73 | int cylinders; /* geometry information */ |
| 74 | int heads; |
| 75 | int sectors; /* (sectors per track) */ |
| 76 | long capacity; /* capacity in megabytes */ |
| 77 | int we_formatted; /* did we format it ourselves? */ |
| 78 | }; |
| 79 | |
| 80 | struct slice { |
| 81 | struct disk *parent; |
| 82 | struct slice *next; |
| 83 | struct slice *prev; |
| 84 | struct subpartition *subpartition_head; |
| 85 | struct subpartition *subpartition_tail; |
| 86 | char *desc; /* description (w/sysid string) */ |
| 87 | int number; /* 1 - 4 (or more?) (from fdisk) */ |
| 88 | unsigned long start; /* start sector (from fdisk) */ |
| 89 | unsigned long size; /* size in sectors (from fdisk) */ |
| 90 | int type; /* sysid of slice (from fdisk) */ |
| 91 | int flags; /* flags (from fdisk) */ |
| 92 | unsigned long capacity; /* capacity in megabytes */ |
| 93 | }; |
| 94 | |
| 95 | struct subpartition { |
| 96 | struct slice *parent; |
| 97 | struct subpartition *next; |
| 98 | struct subpartition *prev; |
| 99 | char letter; /* 'a' = root partition */ |
| 100 | char *mountpoint; /* includes leading slash */ |
| 101 | long capacity; /* in megabytes, -1 = "rest of disk" */ |
| 102 | int softupdates; |
| 103 | long fsize; /* fragment size */ |
| 104 | long bsize; /* block size */ |
| 105 | int is_swap; |
| 106 | int mfsbacked; /* Memory File System Backed */ |
| 107 | int type; /* FS type (UFS, HAMMER) */ |
| 108 | int pfs; /* HAMMER pseudo file system */ |
| 109 | }; |
| 110 | |
| 111 | #endif /* NEEDS_DISKUTIL_STRUCTURE_DEFINITIONS */ |
| 112 | |
| 113 | /*** PROTOTYPES ***/ |
| 114 | |
| 115 | struct storage *storage_new(void); |
| 116 | void storage_free(struct storage *); |
| 117 | void storage_set_memsize(struct storage *, unsigned long); |
| 118 | unsigned long storage_get_memsize(const struct storage *); |
| 119 | struct disk *storage_disk_first(const struct storage *); |
| 120 | void storage_set_selected_disk(struct storage *, struct disk *); |
| 121 | struct disk *storage_get_selected_disk(const struct storage *); |
| 122 | void storage_set_selected_slice(struct storage *, struct slice *); |
| 123 | struct slice *storage_get_selected_slice(const struct storage *); |
| 124 | int storage_get_mfs_status(const char *, struct storage *); |
| 125 | |
| 126 | struct disk *disk_new(struct storage *, const char *); |
| 127 | struct disk *disk_find(const struct storage *, const char *); |
| 128 | struct disk *disk_next(const struct disk *); |
| 129 | void disks_free(struct storage *); |
| 130 | void disk_set_desc(struct disk *, const char *); |
| 131 | const char *disk_get_desc(const struct disk *); |
| 132 | const char *disk_get_device_name(const struct disk *); |
| 133 | const char *disk_get_raw_device_name(const struct disk *); |
| 134 | struct slice *disk_slice_first(const struct disk *); |
| 135 | void disk_set_formatted(struct disk *, int); |
| 136 | int disk_get_formatted(const struct disk *); |
| 137 | void disk_set_geometry(struct disk *, int, int, int); |
| 138 | void disk_get_geometry(const struct disk *, int *, int *, int *); |
| 139 | |
| 140 | struct slice *slice_new(struct disk *, int, int, int, |
| 141 | unsigned long, unsigned long); |
| 142 | struct slice *slice_find(const struct disk *, int); |
| 143 | struct slice *slice_next(const struct slice *); |
| 144 | int slice_get_number(const struct slice *); |
| 145 | const char *slice_get_desc(const struct slice *); |
| 146 | const char *slice_get_device_name(const struct slice *); |
| 147 | const char *slice_get_raw_device_name(const struct slice *); |
| 148 | unsigned long slice_get_capacity(const struct slice *); |
| 149 | unsigned long slice_get_start(const struct slice *); |
| 150 | unsigned long slice_get_size(const struct slice *); |
| 151 | int slice_get_type(const struct slice *); |
| 152 | int slice_get_flags(const struct slice *); |
| 153 | void slices_free(struct slice *); |
| 154 | struct subpartition *slice_subpartition_first(const struct slice *); |
| 155 | |
| 156 | struct subpartition *subpartition_new(struct slice *, const char *, long, |
| 157 | int, long, long, int); |
| 158 | struct subpartition *subpartition_new_hammer(struct slice *, const char *, long); |
| 159 | int subpartition_count(const struct slice *); |
| 160 | struct subpartition *subpartition_find(const struct slice *, const char *, ...); |
| 161 | struct subpartition *subpartition_of(const struct slice *, const char *, ...); |
| 162 | struct subpartition *subpartition_find_capacity(const struct slice *, long); |
| 163 | void subpartitions_free(struct slice *); |
| 164 | struct subpartition *subpartition_next(const struct subpartition *); |
| 165 | int subpartition_get_pfs(const struct subpartition *); |
| 166 | const char *subpartition_get_mountpoint(const struct subpartition *); |
| 167 | const char *subpartition_get_device_name(const struct subpartition *); |
| 168 | const char *subpartition_get_raw_device_name(const struct subpartition *); |
| 169 | char subpartition_get_letter(const struct subpartition *); |
| 170 | unsigned long subpartition_get_fsize(const struct subpartition *); |
| 171 | unsigned long subpartition_get_bsize(const struct subpartition *); |
| 172 | unsigned long subpartition_get_capacity(const struct subpartition *); |
| 173 | int subpartition_is_swap(const struct subpartition *); |
| 174 | int subpartition_is_softupdated(const struct subpartition *); |
| 175 | int subpartition_is_mfsbacked(const struct subpartition *); |
| 176 | |
| 177 | long measure_activated_swap(const struct i_fn_args *); |
| 178 | long measure_activated_swap_from_slice(const struct i_fn_args *, |
| 179 | const struct disk *, const struct slice *); |
| 180 | long measure_activated_swap_from_disk(const struct i_fn_args *, |
| 181 | const struct disk *); |
| 182 | |
| 183 | int survey_storage(struct i_fn_args *); |
| 184 | |
| 185 | #endif /* !__DISKUTIL_H_ */ |