fssvar.h revision 1.6.2.7 1 1.6.2.7 skrll /* $NetBSD: fssvar.h,v 1.6.2.7 2005/11/10 14:03:00 skrll Exp $ */
2 1.6.2.2 skrll
3 1.6.2.2 skrll /*-
4 1.6.2.2 skrll * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 1.6.2.2 skrll * All rights reserved.
6 1.6.2.2 skrll *
7 1.6.2.2 skrll * This code is derived from software contributed to The NetBSD Foundation
8 1.6.2.2 skrll * by Juergen Hannken-Illjes.
9 1.6.2.2 skrll *
10 1.6.2.2 skrll * Redistribution and use in source and binary forms, with or without
11 1.6.2.2 skrll * modification, are permitted provided that the following conditions
12 1.6.2.2 skrll * are met:
13 1.6.2.2 skrll * 1. Redistributions of source code must retain the above copyright
14 1.6.2.2 skrll * notice, this list of conditions and the following disclaimer.
15 1.6.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.2.2 skrll * notice, this list of conditions and the following disclaimer in the
17 1.6.2.2 skrll * documentation and/or other materials provided with the distribution.
18 1.6.2.2 skrll * 3. All advertising materials mentioning features or use of this software
19 1.6.2.2 skrll * must display the following acknowledgement:
20 1.6.2.2 skrll * This product includes software developed by the NetBSD
21 1.6.2.2 skrll * Foundation, Inc. and its contributors.
22 1.6.2.2 skrll * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.2.2 skrll * contributors may be used to endorse or promote products derived
24 1.6.2.2 skrll * from this software without specific prior written permission.
25 1.6.2.2 skrll *
26 1.6.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.2.2 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.2.2 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.2.2 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.2.2 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.2.2 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.2.2 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.2.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.2.2 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.2.2 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.2.2 skrll * POSSIBILITY OF SUCH DAMAGE.
37 1.6.2.2 skrll */
38 1.6.2.2 skrll
39 1.6.2.2 skrll #ifndef _SYS_DEV_FSSVAR_H
40 1.6.2.2 skrll #define _SYS_DEV_FSSVAR_H
41 1.6.2.2 skrll
42 1.6.2.7 skrll #define FSS_UNCONFIG_ON_CLOSE 0x01 /* Unconfigure on last close */
43 1.6.2.7 skrll
44 1.6.2.2 skrll struct fss_set {
45 1.6.2.2 skrll char *fss_mount; /* Mount point of file system */
46 1.6.2.2 skrll char *fss_bstore; /* Path of backing store */
47 1.6.2.2 skrll blksize_t fss_csize; /* Preferred cluster size */
48 1.6.2.2 skrll };
49 1.6.2.2 skrll
50 1.6.2.2 skrll struct fss_get {
51 1.6.2.2 skrll char fsg_mount[MNAMELEN]; /* Mount point of file system */
52 1.6.2.2 skrll struct timeval fsg_time; /* Time this snapshot was taken */
53 1.6.2.2 skrll blksize_t fsg_csize; /* Current cluster size */
54 1.6.2.2 skrll blkcnt_t fsg_mount_size; /* # clusters on file system */
55 1.6.2.2 skrll blkcnt_t fsg_bs_size; /* # clusters on backing store */
56 1.6.2.2 skrll };
57 1.6.2.2 skrll
58 1.6.2.2 skrll #define FSSIOCSET _IOW('F', 0, struct fss_set) /* Configure */
59 1.6.2.2 skrll #define FSSIOCGET _IOR('F', 1, struct fss_get) /* Status */
60 1.6.2.2 skrll #define FSSIOCCLR _IO('F', 2) /* Unconfigure */
61 1.6.2.7 skrll #define FSSIOFSET _IOW('F', 3, int) /* Set flags */
62 1.6.2.7 skrll #define FSSIOFGET _IOR('F', 4, int) /* Get flags */
63 1.6.2.2 skrll
64 1.6.2.2 skrll #ifdef _KERNEL
65 1.6.2.2 skrll
66 1.6.2.5 skrll #include <sys/bufq.h>
67 1.6.2.5 skrll
68 1.6.2.2 skrll #define FSS_CLUSTER_MAX (1<<24) /* Upper bound of clusters. The
69 1.6.2.2 skrll sc_copied map uses up to
70 1.6.2.2 skrll FSS_CLUSTER_MAX/NBBY bytes */
71 1.6.2.2 skrll
72 1.6.2.2 skrll #define FSS_LOCK(sc, s) \
73 1.6.2.2 skrll do { \
74 1.6.2.2 skrll (s) = splbio(); \
75 1.6.2.2 skrll simple_lock(&(sc)->sc_slock); \
76 1.6.2.2 skrll } while (/*CONSTCOND*/0)
77 1.6.2.2 skrll
78 1.6.2.2 skrll #define FSS_UNLOCK(sc, s) \
79 1.6.2.2 skrll do { \
80 1.6.2.2 skrll simple_unlock(&(sc)->sc_slock); \
81 1.6.2.2 skrll splx((s)); \
82 1.6.2.2 skrll } while (/*CONSTCOND*/0)
83 1.6.2.2 skrll
84 1.6.2.2 skrll /* Device to softc, NULL on error */
85 1.6.2.2 skrll #define FSS_DEV_TO_SOFTC(dev) \
86 1.6.2.2 skrll (minor((dev)) < 0 || minor((dev)) >= NFSS ? NULL : \
87 1.6.2.2 skrll &fss_softc[minor((dev))])
88 1.6.2.2 skrll
89 1.6.2.2 skrll /* Check if still valid */
90 1.6.2.2 skrll #define FSS_ISVALID(sc) \
91 1.6.2.2 skrll (((sc)->sc_flags & (FSS_ACTIVE|FSS_ERROR)) == FSS_ACTIVE)
92 1.6.2.2 skrll
93 1.6.2.2 skrll /* Offset to cluster */
94 1.6.2.2 skrll #define FSS_BTOCL(sc, off) \
95 1.6.2.2 skrll ((off) >> (sc)->sc_clshift)
96 1.6.2.2 skrll
97 1.6.2.2 skrll /* Cluster to offset */
98 1.6.2.2 skrll #define FSS_CLTOB(sc, cl) \
99 1.6.2.6 skrll ((off_t)(cl) << (sc)->sc_clshift)
100 1.6.2.2 skrll
101 1.6.2.2 skrll /* Offset from start of cluster */
102 1.6.2.2 skrll #define FSS_CLOFF(sc, off) \
103 1.6.2.2 skrll ((off) & (sc)->sc_clmask)
104 1.6.2.2 skrll
105 1.6.2.2 skrll /* Size of cluster */
106 1.6.2.2 skrll #define FSS_CLSIZE(sc) \
107 1.6.2.2 skrll (1 << (sc)->sc_clshift)
108 1.6.2.2 skrll
109 1.6.2.2 skrll /* Offset to backing store block */
110 1.6.2.2 skrll #define FSS_BTOFSB(sc, off) \
111 1.6.2.2 skrll ((off) >> (sc)->sc_bs_bshift)
112 1.6.2.2 skrll
113 1.6.2.2 skrll /* Backing store block to offset */
114 1.6.2.2 skrll #define FSS_FSBTOB(sc, blk) \
115 1.6.2.2 skrll ((off_t)(blk) << (sc)->sc_bs_bshift)
116 1.6.2.2 skrll
117 1.6.2.2 skrll /* Offset from start of backing store block */
118 1.6.2.2 skrll #define FSS_FSBOFF(sc, off) \
119 1.6.2.2 skrll ((off) & (sc)->sc_bs_bmask)
120 1.6.2.2 skrll
121 1.6.2.2 skrll /* Size of backing store block */
122 1.6.2.2 skrll #define FSS_FSBSIZE(sc) \
123 1.6.2.2 skrll (1 << (sc)->sc_bs_bshift)
124 1.6.2.2 skrll
125 1.6.2.2 skrll typedef enum {
126 1.6.2.2 skrll FSS_READ,
127 1.6.2.2 skrll FSS_WRITE
128 1.6.2.2 skrll } fss_io_type;
129 1.6.2.2 skrll
130 1.6.2.2 skrll typedef enum {
131 1.6.2.2 skrll FSS_CACHE_FREE = 0, /* Cache entry is free */
132 1.6.2.2 skrll FSS_CACHE_BUSY = 1, /* Cache entry is read from device */
133 1.6.2.2 skrll FSS_CACHE_VALID = 2 /* Cache entry contains valid data */
134 1.6.2.2 skrll } fss_cache_type;
135 1.6.2.2 skrll
136 1.6.2.2 skrll struct fss_cache {
137 1.6.2.2 skrll fss_cache_type fc_type; /* Current state */
138 1.6.2.2 skrll struct fss_softc *fc_softc; /* Backlink to our softc */
139 1.6.2.2 skrll volatile int fc_xfercount; /* Number of outstanding transfers */
140 1.6.2.2 skrll u_int32_t fc_cluster; /* Cluster number of this entry */
141 1.6.2.2 skrll caddr_t fc_data; /* Data */
142 1.6.2.2 skrll };
143 1.6.2.2 skrll
144 1.6.2.2 skrll struct fss_softc {
145 1.6.2.2 skrll int sc_unit; /* Logical unit number */
146 1.6.2.2 skrll struct simplelock sc_slock; /* Protect this softc */
147 1.6.2.2 skrll volatile int sc_flags; /* Flags */
148 1.6.2.2 skrll #define FSS_ACTIVE 0x01 /* Snapshot is active */
149 1.6.2.2 skrll #define FSS_ERROR 0x02 /* I/O error occurred */
150 1.6.2.2 skrll #define FSS_BS_THREAD 0x04 /* Kernel thread is running */
151 1.6.2.2 skrll #define FSS_EXCL 0x08 /* Exclusive access granted */
152 1.6.2.2 skrll #define FSS_PERSISTENT 0x20 /* File system internal snapshot */
153 1.6.2.7 skrll #define FSS_CDEV_OPEN 0x40 /* character device open */
154 1.6.2.7 skrll #define FSS_BDEV_OPEN 0x80 /* block device open */
155 1.6.2.7 skrll int sc_uflags; /* User visible flags */
156 1.6.2.2 skrll struct mount *sc_mount; /* Mount point */
157 1.6.2.2 skrll char sc_mntname[MNAMELEN]; /* Mount point */
158 1.6.2.2 skrll struct timeval sc_time; /* Time this snapshot was taken */
159 1.6.2.2 skrll dev_t sc_bdev; /* Underlying block device */
160 1.6.2.2 skrll struct vnode *sc_mount_vp; /* Underlying spec vnode */
161 1.6.2.2 skrll struct vnode *sc_bs_vp; /* Our backing store */
162 1.6.2.2 skrll off_t sc_bs_size; /* Its size in bytes */
163 1.6.2.2 skrll int sc_bs_bshift; /* Shift of backing store block */
164 1.6.2.2 skrll u_int32_t sc_bs_bmask; /* Mask of backing store block */
165 1.6.2.2 skrll struct proc *sc_bs_proc; /* Our kernel thread */
166 1.6.2.2 skrll int sc_clshift; /* Shift of cluster size */
167 1.6.2.2 skrll u_int32_t sc_clmask; /* Mask of cluster size */
168 1.6.2.2 skrll u_int32_t sc_clcount; /* # clusters in file system */
169 1.6.2.2 skrll u_int8_t *sc_copied; /* Map of clusters already copied */
170 1.6.2.2 skrll long sc_clresid; /* Bytes in last cluster */
171 1.6.2.2 skrll int sc_cache_size; /* Number of entries in sc_cache */
172 1.6.2.2 skrll struct fss_cache *sc_cache; /* Cluster cache */
173 1.6.2.7 skrll struct bufq_state *sc_bufq; /* Transfer queue */
174 1.6.2.2 skrll u_int32_t sc_clnext; /* Next free cluster on backing store */
175 1.6.2.2 skrll int sc_indir_size; /* # clusters for indirect mapping */
176 1.6.2.2 skrll u_int8_t *sc_indir_valid; /* Map of valid indirect clusters */
177 1.6.2.2 skrll u_int32_t sc_indir_cur; /* Current indir cluster number */
178 1.6.2.2 skrll int sc_indir_dirty; /* Current indir cluster modified */
179 1.6.2.2 skrll u_int32_t *sc_indir_data; /* Current indir cluster data */
180 1.6.2.2 skrll };
181 1.6.2.2 skrll
182 1.6.2.2 skrll int fss_umount_hook(struct mount *, int);
183 1.6.2.2 skrll
184 1.6.2.2 skrll #endif /* _KERNEL */
185 1.6.2.2 skrll
186 1.6.2.2 skrll #endif /* !_SYS_DEV_FSSVAR_H */
187