]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/io.h
7618be43b77fc5bd1f96738a88c824bca002fd66
[thirdparty/xfsprogs-dev.git] / db / io.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 struct typ;
8
9 #define BBMAP_SIZE (XFS_MAX_BLOCKSIZE / BBSIZE)
10 typedef struct bbmap {
11 int nmaps;
12 struct xfs_buf_map b[BBMAP_SIZE];
13 } bbmap_t;
14
15 typedef struct iocur {
16 int64_t bb; /* BB number in filesystem of buf */
17 int blen; /* length of "buf", bb's */
18 int boff; /* data - buf */
19 void *buf; /* base address of buffer */
20 void *data; /* current interesting data */
21 xfs_ino_t dirino; /* current directory inode number */
22 xfs_ino_t ino; /* current inode number */
23 int len; /* length of "data", bytes */
24 uint16_t mode; /* current inode's mode */
25 xfs_off_t off; /* fs offset of "data" in bytes */
26 const struct typ *typ; /* type of "data" */
27 bbmap_t *bbmap; /* map daddr if fragmented */
28 struct xfs_buf *bp; /* underlying buffer */
29 bool ino_crc_ok;
30 bool ino_buf;
31 bool dquot_buf;
32 bool need_crc;
33 } iocur_t;
34
35 #define DB_RING_ADD 1 /* add to ring on set_cur */
36 #define DB_RING_IGN 0 /* do not add to ring on set_cur */
37
38 extern iocur_t *iocur_base; /* base of stack */
39 extern iocur_t *iocur_top; /* top element of stack */
40 extern int iocur_sp; /* current top of stack */
41 extern int iocur_len; /* length of stack array */
42
43 extern void io_init(void);
44 extern void off_cur(int off, int len);
45 extern void pop_cur(void);
46 extern void print_iocur(char *tag, iocur_t *ioc);
47 extern void push_cur(void);
48 extern void push_cur_and_set_type(void);
49 extern int read_buf(int64_t daddr, int count, void *bufp);
50 extern void write_cur(void);
51 extern void set_cur(const struct typ *type, xfs_daddr_t blknum,
52 int len, int ring_add, bbmap_t *bbmap);
53 extern void ring_add(void);
54 extern void set_iocur_type(const struct typ *type);
55 extern void xfs_dummy_verify(struct xfs_buf *bp);
56 extern void xfs_verify_recalc_crc(struct xfs_buf *bp);
57
58 /*
59 * returns -1 for unchecked, 0 for bad and 1 for good
60 */
61 static inline int
62 iocur_crc_valid(void)
63 {
64 if (!iocur_top->bp)
65 return -1;
66 if (iocur_top->bp->b_flags & LIBXFS_B_UNCHECKED)
67 return -1;
68 return (iocur_top->bp->b_error != -EFSBADCRC &&
69 (!iocur_top->ino_buf || iocur_top->ino_crc_ok));
70 }