1 1.32 hannken /* $NetBSD: fssvar.h,v 1.32 2019/02/20 10:03:25 hannken Exp $ */ 2 1.1 hannken 3 1.1 hannken /*- 4 1.14 ad * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. 5 1.1 hannken * All rights reserved. 6 1.1 hannken * 7 1.1 hannken * This code is derived from software contributed to The NetBSD Foundation 8 1.1 hannken * by Juergen Hannken-Illjes. 9 1.1 hannken * 10 1.1 hannken * Redistribution and use in source and binary forms, with or without 11 1.1 hannken * modification, are permitted provided that the following conditions 12 1.1 hannken * are met: 13 1.1 hannken * 1. Redistributions of source code must retain the above copyright 14 1.1 hannken * notice, this list of conditions and the following disclaimer. 15 1.1 hannken * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 hannken * notice, this list of conditions and the following disclaimer in the 17 1.1 hannken * documentation and/or other materials provided with the distribution. 18 1.1 hannken * 19 1.1 hannken * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 hannken * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 hannken * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 hannken * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 hannken * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 hannken * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 hannken * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 hannken * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 hannken * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 hannken * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 hannken * POSSIBILITY OF SUCH DAMAGE. 30 1.1 hannken */ 31 1.1 hannken 32 1.1 hannken #ifndef _SYS_DEV_FSSVAR_H 33 1.1 hannken #define _SYS_DEV_FSSVAR_H 34 1.1 hannken 35 1.29 dholland #include <sys/ioccom.h> 36 1.29 dholland 37 1.9 hannken #define FSS_UNCONFIG_ON_CLOSE 0x01 /* Unconfigure on last close */ 38 1.25 hannken #define FSS_UNLINK_ON_CREATE 0x02 /* Unlink backing store on create */ 39 1.9 hannken 40 1.1 hannken struct fss_set { 41 1.1 hannken char *fss_mount; /* Mount point of file system */ 42 1.1 hannken char *fss_bstore; /* Path of backing store */ 43 1.1 hannken blksize_t fss_csize; /* Preferred cluster size */ 44 1.25 hannken int fss_flags; /* Initial flags */ 45 1.1 hannken }; 46 1.1 hannken 47 1.1 hannken struct fss_get { 48 1.1 hannken char fsg_mount[MNAMELEN]; /* Mount point of file system */ 49 1.1 hannken struct timeval fsg_time; /* Time this snapshot was taken */ 50 1.1 hannken blksize_t fsg_csize; /* Current cluster size */ 51 1.1 hannken blkcnt_t fsg_mount_size; /* # clusters on file system */ 52 1.1 hannken blkcnt_t fsg_bs_size; /* # clusters on backing store */ 53 1.1 hannken }; 54 1.1 hannken 55 1.25 hannken #define FSSIOCSET _IOW('F', 5, struct fss_set) /* Configure */ 56 1.1 hannken #define FSSIOCGET _IOR('F', 1, struct fss_get) /* Status */ 57 1.1 hannken #define FSSIOCCLR _IO('F', 2) /* Unconfigure */ 58 1.9 hannken #define FSSIOFSET _IOW('F', 3, int) /* Set flags */ 59 1.9 hannken #define FSSIOFGET _IOR('F', 4, int) /* Get flags */ 60 1.27 bouyer #ifdef _KERNEL 61 1.27 bouyer #include <compat/sys/time_types.h> 62 1.27 bouyer 63 1.27 bouyer struct fss_set50 { 64 1.27 bouyer char *fss_mount; /* Mount point of file system */ 65 1.27 bouyer char *fss_bstore; /* Path of backing store */ 66 1.27 bouyer blksize_t fss_csize; /* Preferred cluster size */ 67 1.27 bouyer }; 68 1.27 bouyer 69 1.27 bouyer struct fss_get50 { 70 1.27 bouyer char fsg_mount[MNAMELEN]; /* Mount point of file system */ 71 1.27 bouyer struct timeval50 fsg_time; /* Time this snapshot was taken */ 72 1.27 bouyer blksize_t fsg_csize; /* Current cluster size */ 73 1.27 bouyer blkcnt_t fsg_mount_size; /* # clusters on file system */ 74 1.27 bouyer blkcnt_t fsg_bs_size; /* # clusters on backing store */ 75 1.27 bouyer }; 76 1.27 bouyer 77 1.26 bouyer #define FSSIOCSET50 _IOW('F', 0, struct fss_set50) /* Old configure */ 78 1.27 bouyer #define FSSIOCGET50 _IOR('F', 1, struct fss_get50) /* Old Status */ 79 1.1 hannken 80 1.7 hannken #include <sys/bufq.h> 81 1.7 hannken 82 1.1 hannken #define FSS_CLUSTER_MAX (1<<24) /* Upper bound of clusters. The 83 1.2 hannken sc_copied map uses up to 84 1.1 hannken FSS_CLUSTER_MAX/NBBY bytes */ 85 1.2 hannken 86 1.2 hannken /* Offset to cluster */ 87 1.2 hannken #define FSS_BTOCL(sc, off) \ 88 1.2 hannken ((off) >> (sc)->sc_clshift) 89 1.2 hannken 90 1.2 hannken /* Cluster to offset */ 91 1.2 hannken #define FSS_CLTOB(sc, cl) \ 92 1.8 perry ((off_t)(cl) << (sc)->sc_clshift) 93 1.2 hannken 94 1.2 hannken /* Offset from start of cluster */ 95 1.2 hannken #define FSS_CLOFF(sc, off) \ 96 1.2 hannken ((off) & (sc)->sc_clmask) 97 1.2 hannken 98 1.2 hannken /* Size of cluster */ 99 1.2 hannken #define FSS_CLSIZE(sc) \ 100 1.2 hannken (1 << (sc)->sc_clshift) 101 1.2 hannken 102 1.2 hannken /* Offset to backing store block */ 103 1.2 hannken #define FSS_BTOFSB(sc, off) \ 104 1.2 hannken ((off) >> (sc)->sc_bs_bshift) 105 1.2 hannken 106 1.2 hannken /* Backing store block to offset */ 107 1.2 hannken #define FSS_FSBTOB(sc, blk) \ 108 1.2 hannken ((off_t)(blk) << (sc)->sc_bs_bshift) 109 1.2 hannken 110 1.2 hannken /* Offset from start of backing store block */ 111 1.2 hannken #define FSS_FSBOFF(sc, off) \ 112 1.2 hannken ((off) & (sc)->sc_bs_bmask) 113 1.2 hannken 114 1.2 hannken /* Size of backing store block */ 115 1.2 hannken #define FSS_FSBSIZE(sc) \ 116 1.2 hannken (1 << (sc)->sc_bs_bshift) 117 1.2 hannken 118 1.1 hannken typedef enum { 119 1.4 hannken FSS_READ, 120 1.4 hannken FSS_WRITE 121 1.4 hannken } fss_io_type; 122 1.4 hannken 123 1.4 hannken typedef enum { 124 1.1 hannken FSS_CACHE_FREE = 0, /* Cache entry is free */ 125 1.1 hannken FSS_CACHE_BUSY = 1, /* Cache entry is read from device */ 126 1.1 hannken FSS_CACHE_VALID = 2 /* Cache entry contains valid data */ 127 1.1 hannken } fss_cache_type; 128 1.1 hannken 129 1.1 hannken struct fss_cache { 130 1.1 hannken fss_cache_type fc_type; /* Current state */ 131 1.1 hannken u_int32_t fc_cluster; /* Cluster number of this entry */ 132 1.21 hannken kcondvar_t fc_state_cv; /* Signals state change from busy */ 133 1.15 christos void * fc_data; /* Data */ 134 1.1 hannken }; 135 1.1 hannken 136 1.30 hannken typedef enum { 137 1.30 hannken FSS_IDLE, /* Device is unconfigured */ 138 1.31 hannken FSS_CREATING, /* Device is currently configuring */ 139 1.30 hannken FSS_ACTIVE, /* Device is configured */ 140 1.32 hannken FSS_DESTROYING /* Device is currently unconfiguring */ 141 1.30 hannken } fss_state_t; 142 1.30 hannken 143 1.1 hannken struct fss_softc { 144 1.23 hannken device_t sc_dev; /* Self */ 145 1.21 hannken kmutex_t sc_slock; /* Protect this softc */ 146 1.21 hannken kcondvar_t sc_work_cv; /* Signals work for the kernel thread */ 147 1.21 hannken kcondvar_t sc_cache_cv; /* Signals free cache slot */ 148 1.30 hannken fss_state_t sc_state; /* Current state */ 149 1.1 hannken volatile int sc_flags; /* Flags */ 150 1.32 hannken #define FSS_ERROR 0x01 /* Device had errors. */ 151 1.1 hannken #define FSS_BS_THREAD 0x04 /* Kernel thread is running */ 152 1.6 hannken #define FSS_PERSISTENT 0x20 /* File system internal snapshot */ 153 1.9 hannken #define FSS_CDEV_OPEN 0x40 /* character device open */ 154 1.9 hannken #define FSS_BDEV_OPEN 0x80 /* block device open */ 155 1.9 hannken int sc_uflags; /* User visible flags */ 156 1.22 hannken struct disk *sc_dkdev; /* Generic disk device info */ 157 1.1 hannken struct mount *sc_mount; /* Mount point */ 158 1.1 hannken char sc_mntname[MNAMELEN]; /* Mount point */ 159 1.1 hannken struct timeval sc_time; /* Time this snapshot was taken */ 160 1.1 hannken dev_t sc_bdev; /* Underlying block device */ 161 1.1 hannken struct vnode *sc_bs_vp; /* Our backing store */ 162 1.2 hannken int sc_bs_bshift; /* Shift of backing store block */ 163 1.2 hannken u_int32_t sc_bs_bmask; /* Mask of backing store block */ 164 1.16 ad struct lwp *sc_bs_lwp; /* Our kernel thread */ 165 1.2 hannken int sc_clshift; /* Shift of cluster size */ 166 1.2 hannken u_int32_t sc_clmask; /* Mask of cluster size */ 167 1.1 hannken u_int32_t sc_clcount; /* # clusters in file system */ 168 1.1 hannken u_int8_t *sc_copied; /* Map of clusters already copied */ 169 1.2 hannken long sc_clresid; /* Bytes in last cluster */ 170 1.1 hannken int sc_cache_size; /* Number of entries in sc_cache */ 171 1.1 hannken struct fss_cache *sc_cache; /* Cluster cache */ 172 1.10 yamt struct bufq_state *sc_bufq; /* Transfer queue */ 173 1.1 hannken u_int32_t sc_clnext; /* Next free cluster on backing store */ 174 1.1 hannken int sc_indir_size; /* # clusters for indirect mapping */ 175 1.1 hannken u_int8_t *sc_indir_valid; /* Map of valid indirect clusters */ 176 1.1 hannken u_int32_t sc_indir_cur; /* Current indir cluster number */ 177 1.1 hannken int sc_indir_dirty; /* Current indir cluster modified */ 178 1.1 hannken u_int32_t *sc_indir_data; /* Current indir cluster data */ 179 1.1 hannken }; 180 1.1 hannken 181 1.1 hannken #endif /* _KERNEL */ 182 1.1 hannken 183 1.1 hannken #endif /* !_SYS_DEV_FSSVAR_H */ 184