This source file includes following definitions.
- ext2fs_bufatoff
- ext2fs_checkoverlap
- ext2fs_vinit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/vnode.h>
40 #include <sys/mount.h>
41 #include <sys/buf.h>
42
43 #include <ufs/ufs/quota.h>
44 #include <ufs/ufs/inode.h>
45 #include <ufs/ufs/ufsmount.h>
46
47 #include <ufs/ext2fs/ext2fs.h>
48 #include <ufs/ext2fs/ext2fs_extern.h>
49
50 #include <miscfs/specfs/specdev.h>
51 #include <miscfs/fifofs/fifo.h>
52
53 union _qcvt {
54 int64_t qcvt;
55 int32_t val[2];
56 };
57
58 #define SETHIGH(q, h) { \
59 union _qcvt tmp; \
60 tmp.qcvt = (q); \
61 tmp.val[_QUAD_HIGHWORD] = (h); \
62 (q) = tmp.qcvt; \
63 }
64
65 #define SETLOW(q, l) { \
66 union _qcvt tmp; \
67 tmp.qcvt = (q); \
68 tmp.val[_QUAD_LOWWORD] = (l); \
69 (q) = tmp.qcvt; \
70 }
71
72 #ifdef _KERNEL
73
74
75
76
77
78
79 int
80 ext2fs_bufatoff(struct inode *ip, off_t offset, char **res, struct buf **bpp)
81 {
82 struct vnode *vp;
83 struct m_ext2fs *fs;
84 struct buf *bp;
85 int32_t lbn;
86 int error;
87
88 vp = ITOV(ip);
89 fs = ip->i_e2fs;
90 lbn = lblkno(fs, offset);
91
92 *bpp = NULL;
93 if ((error = bread(vp, lbn, fs->e2fs_bsize, NOCRED, &bp)) != 0) {
94 brelse(bp);
95 return (error);
96 }
97 if (res)
98 *res = (char *)bp->b_data + blkoff(fs, offset);
99 *bpp = bp;
100 return (0);
101 }
102 #endif
103
104 #if defined(_KERNEL) && defined(DIAGNOSTIC)
105 void
106 ext2fs_checkoverlap(struct buf *bp, struct inode *ip)
107 {
108 struct buf *ep;
109 int32_t start, last;
110 struct vnode *vp;
111
112 start = bp->b_blkno;
113 last = start + btodb(bp->b_bcount) - 1;
114 LIST_FOREACH(ep, &bufhead, b_list) {
115 if (ep == bp || (ep->b_flags & B_INVAL) ||
116 ep->b_vp == NULLVP)
117 continue;
118 if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0, NULL))
119 continue;
120 if (vp != ip->i_devvp)
121 continue;
122
123 if (ep->b_bcount == 0 || ep->b_blkno > last ||
124 ep->b_blkno + btodb(ep->b_bcount) <= start)
125 continue;
126 vprint("Disk overlap", vp);
127 printf("\tstart %d, end %d overlap start %d, end %ld\n",
128 start, last, ep->b_blkno,
129 ep->b_blkno + btodb(ep->b_bcount) - 1);
130 panic("Disk buffer overlap");
131 }
132 }
133 #endif
134
135
136
137
138 int
139 ext2fs_vinit(struct mount *mp, int (**specops)(void *),
140 int (**fifoops)(void *), struct vnode **vpp)
141 {
142 struct inode *ip;
143 struct vnode *vp, *nvp;
144 struct timeval tv;
145
146 vp = *vpp;
147 ip = VTOI(vp);
148 vp->v_type = IFTOVT(ip->i_e2fs_mode);
149
150 switch(vp->v_type) {
151 case VCHR:
152 case VBLK:
153 vp->v_op = specops;
154
155 nvp = checkalias(vp, fs2h32(ip->i_e2din->e2di_rdev), mp);
156 if (nvp != NULL) {
157
158
159
160
161
162 nvp->v_data = vp->v_data;
163 vp->v_data = NULL;
164 vp->v_op = spec_vnodeop_p;
165 #ifdef VFSDEBUG
166 vp->v_flag &= ~VLOCKSWORK;
167 #endif
168 vrele(vp);
169 vgone(vp);
170
171 vp = nvp;
172 ip->i_vnode = vp;
173 }
174
175 break;
176
177 case VFIFO:
178 #ifdef FIFO
179 vp->v_op = fifoops;
180 break;
181 #else
182 return (EOPNOTSUPP);
183 #endif
184
185 default:
186
187 break;
188 }
189
190 if (ip->i_number == EXT2_ROOTINO)
191 vp->v_flag |= VROOT;
192
193
194 getmicrouptime(&tv);
195 SETHIGH(ip->i_modrev, tv.tv_sec);
196 SETLOW(ip->i_modrev, tv.tv_usec * 4294);
197
198 *vpp = vp;
199
200 return (0);
201 }