1 /* 2 * Copyright (c) 2002 Juli Mallett. All rights reserved. 3 * 4 * This software was written by Juli Mallett <jmallett@FreeBSD.org> for the 5 * FreeBSD project. Redistribution and use in source and binary forms, with 6 * or without modification, are permitted provided that the following 7 * conditions are met: 8 * 9 * 1. Redistribution of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 2. Redistribution in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 /* 31 * libufs macros (internal, non-exported). 32 */ 33 #ifdef _LIBUFS 34 #ifdef _LIBUFS_DEBUGGING 35 /* 36 * Trace steps through libufs, to be used at entry and erroneous return. 37 */ 38 #define DEBUG(str) \ 39 do { \ 40 fprintf(stderr, "libufs in %s", __func__); \ 41 if (str != NULL) \ 42 fprintf(stderr, ": %s", str); \ 43 if (errno) \ 44 fprintf(stderr, ": %s", strerror(errno)); \ 45 fprintf(stderr, "\n"); \ 46 } while (0) 47 #else /* _LIBUFS_DEBUGGING */ 48 #define DEBUG(str) /* nil */ 49 #endif /* _LIBUFS_DEBUGGING */ 50 #endif /* _LIBUFS */ 51 52 /* 53 * libufs structures. 54 */ 55 56 /* 57 * userland ufs disk. 58 */ 59 struct uufsd { 60 const char *d_name; /* disk name */ 61 int d_ufs; /* decimal UFS version */ 62 int d_fd; /* raw device file descriptor */ 63 long d_bsize; /* device bsize */ 64 ufs2_daddr_t d_sblock; /* superblock location */ 65 caddr_t d_inoblock; /* inode block */ 66 ino_t d_inomin; /* low inode */ 67 ino_t d_inomax; /* high inode */ 68 union { 69 struct fs d_fs; /* filesystem information */ 70 char d_sb[MAXBSIZE]; 71 /* superblock as buffer */ 72 } d_sbunion; 73 #define d_fs d_sbunion.d_fs 74 #define d_sb d_sbunion.d_sb 75 }; 76 77 /* 78 * libufs prototypes. 79 */ 80 81 /* 82 * block.c 83 */ 84 ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t); 85 ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t); 86 87 /* 88 * inode.c 89 */ 90 int getino(struct uufsd *, void **, ino_t, int *); 91 92 /* 93 * sblock.c 94 */ 95 int sbread(struct uufsd *); 96 int sbwrite(struct uufsd *, int); 97 98 /* 99 * type.c 100 */ 101 struct uufsd *ufs_disk_ctor(const char *); 102 int ufs_disk_close(struct uufsd *); 103 void ufs_disk_dtor(struct uufsd **); 104 int ufs_disk_fillout(struct uufsd *, const char *); 105