1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2002 Juli Mallett. All rights reserved. 5 * 6 * This software was written by Juli Mallett <jmallett@FreeBSD.org> for the 7 * FreeBSD project. Redistribution and use in source and binary forms, with 8 * or without modification, are permitted provided that the following 9 * conditions are met: 10 * 11 * 1. Redistribution of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 2. Redistribution in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $FreeBSD$ 30 */ 31 32 #ifndef __LIBUFS_H__ 33 #define __LIBUFS_H__ 34 35 /* 36 * libufs structures. 37 */ 38 39 /* 40 * userland ufs disk. 41 */ 42 struct uufsd { 43 const char *d_name; /* disk name */ 44 int d_ufs; /* decimal UFS version */ 45 int d_fd; /* raw device file descriptor */ 46 long d_bsize; /* device bsize */ 47 ufs2_daddr_t d_sblock; /* superblock location */ 48 struct csum *d_sbcsum; /* Superblock summary info */ 49 caddr_t d_inoblock; /* inode block */ 50 uint32_t d_inomin; /* low inode (not ino_t for ABI compat) */ 51 uint32_t d_inomax; /* high inode (not ino_t for ABI compat) */ 52 union { 53 struct fs d_fs; /* filesystem information */ 54 char d_sb[MAXBSIZE]; 55 /* superblock as buffer */ 56 } d_sbunion; 57 union { 58 struct cg d_cg; /* cylinder group */ 59 char d_buf[MAXBSIZE]; 60 /* cylinder group storage */ 61 } d_cgunion; 62 int d_ccg; /* current cylinder group */ 63 int d_lcg; /* last cylinder group (in d_cg) */ 64 const char *d_error; /* human readable disk error */ 65 int d_mine; /* internal flags */ 66 #define d_fs d_sbunion.d_fs 67 #define d_sb d_sbunion.d_sb 68 #define d_cg d_cgunion.d_cg 69 }; 70 71 /* 72 * libufs macros (internal, non-exported). 73 */ 74 #ifdef _LIBUFS 75 /* 76 * Trace steps through libufs, to be used at entry and erroneous return. 77 */ 78 static inline void 79 ERROR(struct uufsd *u, const char *str) 80 { 81 82 #ifdef _LIBUFS_DEBUGGING 83 if (str != NULL) { 84 fprintf(stderr, "libufs: %s", str); 85 if (errno != 0) 86 fprintf(stderr, ": %s", strerror(errno)); 87 fprintf(stderr, "\n"); 88 } 89 #endif 90 if (u != NULL) 91 u->d_error = str; 92 } 93 #endif /* _LIBUFS */ 94 95 __BEGIN_DECLS 96 97 /* 98 * libufs prototypes. 99 */ 100 101 /* 102 * block.c 103 */ 104 ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t); 105 ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t); 106 int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t); 107 108 /* 109 * cgroup.c 110 */ 111 ufs2_daddr_t cgballoc(struct uufsd *); 112 int cgbfree(struct uufsd *, ufs2_daddr_t, long); 113 ino_t cgialloc(struct uufsd *); 114 int cgread(struct uufsd *); 115 int cgread1(struct uufsd *, int); 116 int cgwrite(struct uufsd *); 117 int cgwrite1(struct uufsd *, int); 118 119 /* 120 * inode.c 121 */ 122 int getino(struct uufsd *, void **, ino_t, int *); 123 int putino(struct uufsd *); 124 125 /* 126 * sblock.c 127 */ 128 int sbread(struct uufsd *); 129 int sbwrite(struct uufsd *, int); 130 131 /* 132 * type.c 133 */ 134 int ufs_disk_close(struct uufsd *); 135 int ufs_disk_fillout(struct uufsd *, const char *); 136 int ufs_disk_fillout_blank(struct uufsd *, const char *); 137 int ufs_disk_write(struct uufsd *); 138 139 /* 140 * ffs_subr.c 141 */ 142 void ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t); 143 void ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int); 144 void ffs_fragacct(struct fs *, int, int32_t [], int); 145 int ffs_isblock(struct fs *, u_char *, ufs1_daddr_t); 146 int ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t); 147 void ffs_setblock(struct fs *, u_char *, ufs1_daddr_t); 148 149 /* 150 * crc32c.c 151 */ 152 uint32_t calculate_crc32c(uint32_t, const void *, size_t); 153 154 __END_DECLS 155 156 #endif /* __LIBUFS_H__ */ 157