2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef __LIBXFS_IO_H_
20 #define __LIBXFS_IO_H_
23 * Kernel equivalent buffer based I/O interface
31 * IO verifier callbacks need the xfs_mount pointer, so we have to behave
32 * somewhat like the kernel now for userspace IO in terms of having buftarg
36 struct xfs_mount
*bt_mount
;
40 extern void libxfs_buftarg_init(struct xfs_mount
*mp
, dev_t ddev
,
41 dev_t logdev
, dev_t rtdev
);
43 #define LIBXFS_BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
47 xfs_daddr_t bm_bn
; /* block number for I/O */
48 int bm_len
; /* size of I/O */
51 #define DEFINE_SINGLE_BUF_MAP(map, blkno, numblk) \
52 struct xfs_buf_map (map) = { .bm_bn = (blkno), .bm_len = (numblk) };
56 void (*verify_read
)(struct xfs_buf
*);
57 void (*verify_write
)(struct xfs_buf
*);
60 typedef struct xfs_buf
{
61 struct cache_node b_node
;
65 unsigned int b_length
;
66 struct xfs_buftarg
*b_target
;
67 #define b_dev b_target->dev
68 pthread_mutex_t b_lock
;
76 const struct xfs_buf_ops
*b_ops
;
77 struct xfs_perag
*b_pag
;
78 struct xfs_buf_map
*b_map
;
80 #ifdef XFS_BUF_TRACING
81 struct list_head b_lock_list
;
88 enum xfs_buf_flags_t
{ /* b_flags bits */
89 LIBXFS_B_EXIT
= 0x0001, /* ==LIBXFS_EXIT_ON_FAILURE */
90 LIBXFS_B_DIRTY
= 0x0002, /* buffer has been modified */
91 LIBXFS_B_STALE
= 0x0004, /* buffer marked as invalid */
92 LIBXFS_B_UPTODATE
= 0x0008, /* buffer is sync'd to disk */
93 LIBXFS_B_DISCONTIG
= 0x0010, /* discontiguous buffer */
94 LIBXFS_B_UNCHECKED
= 0x0020, /* needs verification */
97 #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))
99 #define XFS_BUF_PTR(bp) ((char *)(bp)->b_addr)
100 #define xfs_buf_offset(bp, offset) ((bp)->b_addr + (offset))
101 #define XFS_BUF_ADDR(bp) ((bp)->b_bn)
102 #define XFS_BUF_SIZE(bp) ((bp)->b_bcount)
103 #define XFS_BUF_COUNT(bp) ((bp)->b_bcount)
104 #define XFS_BUF_TARGET(bp) ((bp)->b_dev)
105 #define XFS_BUF_SET_PTR(bp,p,cnt) ({ \
106 (bp)->b_addr = (char *)(p); \
107 XFS_BUF_SET_COUNT(bp,cnt); \
110 #define XFS_BUF_SET_ADDR(bp,blk) ((bp)->b_bn = (blk))
111 #define XFS_BUF_SET_COUNT(bp,cnt) ((bp)->b_bcount = (cnt))
113 #define XFS_BUF_FSPRIVATE(bp,type) ((type)(bp)->b_fspriv)
114 #define XFS_BUF_SET_FSPRIVATE(bp,val) (bp)->b_fspriv = (void *)(val)
115 #define XFS_BUF_FSPRIVATE2(bp,type) ((type)(bp)->b_fsprivate2)
116 #define XFS_BUF_SET_FSPRIVATE2(bp,val) (bp)->b_fsprivate2 = (void *)(val)
117 #define XFS_BUF_FSPRIVATE3(bp,type) ((type)(bp)->b_fsprivate3)
118 #define XFS_BUF_SET_FSPRIVATE3(bp,val) (bp)->b_fsprivate3 = (void *)(val)
120 #define XFS_BUF_SET_PRIORITY(bp,pri) cache_node_set_priority( \
122 (struct cache_node *)(bp), \
124 #define XFS_BUF_PRIORITY(bp) (cache_node_get_priority( \
125 (struct cache_node *)(bp)))
126 #define xfs_buf_set_ref(bp,ref) ((void) 0)
127 #define xfs_buf_ioerror(bp,err) ((bp)->b_error = (err))
129 #define xfs_daddr_to_agno(mp,d) \
130 ((xfs_agnumber_t)(XFS_BB_TO_FSBT(mp, d) / (mp)->m_sb.sb_agblocks))
131 #define xfs_daddr_to_agbno(mp,d) \
132 ((xfs_agblock_t)(XFS_BB_TO_FSBT(mp, d) % (mp)->m_sb.sb_agblocks))
134 /* Buffer Cache Interfaces */
136 extern struct cache
*libxfs_bcache
;
137 extern struct cache_operations libxfs_bcache_operations
;
139 #define LIBXFS_GETBUF_TRYLOCK (1 << 0)
141 #ifdef XFS_BUF_TRACING
143 #define libxfs_readbuf(dev, daddr, len, flags, ops) \
144 libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, \
145 (dev), (daddr), (len), (flags), (ops))
146 #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \
147 libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \
148 (dev), (map), (nmaps), (flags), (ops))
149 #define libxfs_writebuf(buf, flags) \
150 libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, \
152 #define libxfs_getbuf(dev, daddr, len) \
153 libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
154 (dev), (daddr), (len))
155 #define libxfs_getbuf_map(dev, map, nmaps, flags) \
156 libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \
157 (dev), (map), (nmaps), (flags))
158 #define libxfs_getbuf_flags(dev, daddr, len, flags) \
159 libxfs_trace_getbuf_flags(__FUNCTION__, __FILE__, __LINE__, \
160 (dev), (daddr), (len), (flags))
161 #define libxfs_putbuf(buf) \
162 libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
164 extern xfs_buf_t
*libxfs_trace_readbuf(const char *, const char *, int,
165 struct xfs_buftarg
*, xfs_daddr_t
, int, int,
166 const struct xfs_buf_ops
*);
167 extern xfs_buf_t
*libxfs_trace_readbuf_map(const char *, const char *, int,
168 struct xfs_buftarg
*, struct xfs_buf_map
*, int, int,
169 const struct xfs_buf_ops
*);
170 extern int libxfs_trace_writebuf(const char *, const char *, int,
172 extern xfs_buf_t
*libxfs_trace_getbuf(const char *, const char *, int,
173 struct xfs_buftarg
*, xfs_daddr_t
, int);
174 extern xfs_buf_t
*libxfs_trace_getbuf_map(const char *, const char *, int,
175 struct xfs_buftarg
*, struct xfs_buf_map
*, int, int);
176 extern xfs_buf_t
*libxfs_trace_getbuf_flags(const char *, const char *, int,
177 struct xfs_buftarg
*, xfs_daddr_t
, int, unsigned int);
178 extern void libxfs_trace_putbuf (const char *, const char *, int,
183 extern xfs_buf_t
*libxfs_readbuf(struct xfs_buftarg
*, xfs_daddr_t
, int, int,
184 const struct xfs_buf_ops
*);
185 extern xfs_buf_t
*libxfs_readbuf_map(struct xfs_buftarg
*, struct xfs_buf_map
*,
186 int, int, const struct xfs_buf_ops
*);
187 extern int libxfs_writebuf(xfs_buf_t
*, int);
188 extern xfs_buf_t
*libxfs_getbuf(struct xfs_buftarg
*, xfs_daddr_t
, int);
189 extern xfs_buf_t
*libxfs_getbuf_map(struct xfs_buftarg
*,
190 struct xfs_buf_map
*, int, int);
191 extern xfs_buf_t
*libxfs_getbuf_flags(struct xfs_buftarg
*, xfs_daddr_t
,
193 extern void libxfs_putbuf (xfs_buf_t
*);
197 extern void libxfs_readbuf_verify(struct xfs_buf
*bp
,
198 const struct xfs_buf_ops
*ops
);
199 extern xfs_buf_t
*libxfs_getsb(struct xfs_mount
*, int);
200 extern void libxfs_bcache_purge(void);
201 extern void libxfs_bcache_flush(void);
202 extern void libxfs_purgebuf(xfs_buf_t
*);
203 extern int libxfs_bcache_overflowed(void);
204 extern int libxfs_bcache_usage(void);
206 /* Buffer (Raw) Interfaces */
207 extern xfs_buf_t
*libxfs_getbufr(struct xfs_buftarg
*, xfs_daddr_t
, int);
208 extern void libxfs_putbufr(xfs_buf_t
*);
210 extern int libxfs_writebuf_int(xfs_buf_t
*, int);
211 extern int libxfs_writebufr(struct xfs_buf
*);
212 extern int libxfs_readbufr(struct xfs_buftarg
*, xfs_daddr_t
, xfs_buf_t
*, int, int);
213 extern int libxfs_readbufr_map(struct xfs_buftarg
*, struct xfs_buf
*, int);
215 extern int libxfs_device_zero(struct xfs_buftarg
*, xfs_daddr_t
, uint
);
217 extern int libxfs_bhash_size
;
219 #define LIBXFS_BREAD 0x1
220 #define LIBXFS_BWRITE 0x2
221 #define LIBXFS_BZERO 0x4
223 extern void libxfs_iomove (xfs_buf_t
*, uint
, int, void *, int);
226 xfs_buf_verify_cksum(struct xfs_buf
*bp
, unsigned long cksum_offset
)
228 return xfs_verify_cksum(bp
->b_addr
, BBTOB(bp
->b_length
),
233 xfs_buf_update_cksum(struct xfs_buf
*bp
, unsigned long cksum_offset
)
235 xfs_update_cksum(bp
->b_addr
, BBTOB(bp
->b_length
),
239 #endif /* __LIBXFS_IO_H__ */