ffs_subr.c (96506) | ffs_subr.c (98542) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_subr.c 8.5 (Berkeley) 3/21/95 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_subr.c 8.5 (Berkeley) 3/21/95 |
34 * $FreeBSD: head/sys/ufs/ffs/ffs_subr.c 96506 2002-05-13 09:22:31Z phk $ | 34 * $FreeBSD: head/sys/ufs/ffs/ffs_subr.c 98542 2002-06-21 06:18:05Z mckusick $ |
35 */ 36 37#include <sys/param.h> | 35 */ 36 37#include <sys/param.h> |
38#include <ufs/ffs/fs.h> | |
39 40#ifndef _KERNEL 41#include <ufs/ufs/dinode.h> | 38 39#ifndef _KERNEL 40#include <ufs/ufs/dinode.h> |
41#include <ufs/ffs/fs.h> |
|
42#else 43#include "opt_ddb.h" 44 45#include <sys/systm.h> | 42#else 43#include "opt_ddb.h" 44 45#include <sys/systm.h> |
46#include <sys/stdint.h> |
|
46#include <sys/lock.h> | 47#include <sys/lock.h> |
48#include <sys/malloc.h> 49#include <sys/mount.h> |
|
47#include <sys/vnode.h> 48#include <sys/bio.h> 49#include <sys/buf.h> 50#include <sys/ucred.h> 51 52#include <ufs/ufs/quota.h> 53#include <ufs/ufs/inode.h> | 50#include <sys/vnode.h> 51#include <sys/bio.h> 52#include <sys/buf.h> 53#include <sys/ucred.h> 54 55#include <ufs/ufs/quota.h> 56#include <ufs/ufs/inode.h> |
57#include <ufs/ufs/extattr.h> 58#include <ufs/ufs/ufsmount.h> 59#include <ufs/ufs/ufs_extern.h> |
|
54#include <ufs/ffs/ffs_extern.h> | 60#include <ufs/ffs/ffs_extern.h> |
61#include <ufs/ffs/fs.h> |
|
55 56#ifdef DDB 57void ffs_checkoverlap(struct buf *, struct inode *); 58#endif 59 60/* 61 * Return buffer with the contents of block "offset" from the beginning of 62 * directory "ip". If "res" is non-zero, fill it in with a pointer to the --- 4 unchanged lines hidden (view full) --- 67 struct vnode *vp; 68 off_t offset; 69 char **res; 70 struct buf **bpp; 71{ 72 struct inode *ip; 73 struct fs *fs; 74 struct buf *bp; | 62 63#ifdef DDB 64void ffs_checkoverlap(struct buf *, struct inode *); 65#endif 66 67/* 68 * Return buffer with the contents of block "offset" from the beginning of 69 * directory "ip". If "res" is non-zero, fill it in with a pointer to the --- 4 unchanged lines hidden (view full) --- 74 struct vnode *vp; 75 off_t offset; 76 char **res; 77 struct buf **bpp; 78{ 79 struct inode *ip; 80 struct fs *fs; 81 struct buf *bp; |
75 ufs_daddr_t lbn; | 82 ufs_lbn_t lbn; |
76 int bsize, error; 77 78 ip = VTOI(vp); 79 fs = ip->i_fs; 80 lbn = lblkno(fs, offset); 81 bsize = blksize(fs, ip, lbn); 82 83 *bpp = NULL; 84 error = bread(vp, lbn, bsize, NOCRED, &bp); 85 if (error) { 86 brelse(bp); 87 return (error); 88 } 89 if (res) 90 *res = (char *)bp->b_data + blkoff(fs, offset); 91 *bpp = bp; 92 return (0); 93} | 83 int bsize, error; 84 85 ip = VTOI(vp); 86 fs = ip->i_fs; 87 lbn = lblkno(fs, offset); 88 bsize = blksize(fs, ip, lbn); 89 90 *bpp = NULL; 91 error = bread(vp, lbn, bsize, NOCRED, &bp); 92 if (error) { 93 brelse(bp); 94 return (error); 95 } 96 if (res) 97 *res = (char *)bp->b_data + blkoff(fs, offset); 98 *bpp = bp; 99 return (0); 100} |
94#endif | |
95 96/* | 101 102/* |
103 * Load up the contents of an inode and copy the appropriate pieces 104 * to the incore copy. 105 */ 106void 107ffs_load_inode(bp, ip, mtype, fs, ino) 108 struct buf *bp; 109 struct inode *ip; 110 struct malloc_type *mtype; 111 struct fs *fs; 112 ino_t ino; 113{ 114 115 if (ip->i_ump->um_fstype == UFS1) { 116 if (mtype != NULL) 117 MALLOC(ip->i_din1, struct ufs1_dinode *, 118 sizeof(struct ufs1_dinode), mtype, M_WAITOK); 119 *ip->i_din1 = 120 *((struct ufs1_dinode *)bp->b_data + ino_to_fsbo(fs, ino)); 121 ip->i_mode = ip->i_din1->di_mode; 122 ip->i_nlink = ip->i_din1->di_nlink; 123 ip->i_size = ip->i_din1->di_size; 124 ip->i_flags = ip->i_din1->di_flags; 125 ip->i_gen = ip->i_din1->di_gen; 126 ip->i_uid = ip->i_din1->di_uid; 127 ip->i_gid = ip->i_din1->di_gid; 128 } else { 129 if (mtype != NULL) 130 MALLOC(ip->i_din2, struct ufs2_dinode *, 131 sizeof(struct ufs2_dinode), mtype, M_WAITOK); 132 *ip->i_din2 = 133 *((struct ufs2_dinode *)bp->b_data + ino_to_fsbo(fs, ino)); 134 ip->i_mode = ip->i_din2->di_mode; 135 ip->i_nlink = ip->i_din2->di_nlink; 136 ip->i_size = ip->i_din2->di_size; 137 ip->i_flags = ip->i_din2->di_flags; 138 ip->i_gen = ip->i_din2->di_gen; 139 ip->i_uid = ip->i_din2->di_uid; 140 ip->i_gid = ip->i_din2->di_gid; 141 } 142} 143#endif /* KERNEL */ 144 145/* |
|
97 * Update the frsum fields to reflect addition or deletion 98 * of some frags. 99 */ 100void 101ffs_fragacct(fs, fragmap, fraglist, cnt) 102 struct fs *fs; 103 int fragmap; 104 int32_t fraglist[]; --- 25 unchanged lines hidden (view full) --- 130 131#ifdef DDB 132void 133ffs_checkoverlap(bp, ip) 134 struct buf *bp; 135 struct inode *ip; 136{ 137 struct buf *ebp, *ep; | 146 * Update the frsum fields to reflect addition or deletion 147 * of some frags. 148 */ 149void 150ffs_fragacct(fs, fragmap, fraglist, cnt) 151 struct fs *fs; 152 int fragmap; 153 int32_t fraglist[]; --- 25 unchanged lines hidden (view full) --- 179 180#ifdef DDB 181void 182ffs_checkoverlap(bp, ip) 183 struct buf *bp; 184 struct inode *ip; 185{ 186 struct buf *ebp, *ep; |
138 ufs_daddr_t start, last; | 187 ufs2_daddr_t start, last; |
139 struct vnode *vp; 140 141 ebp = &buf[nbuf]; 142 start = bp->b_blkno; 143 last = start + btodb(bp->b_bcount) - 1; 144 for (ep = buf; ep < ebp; ep++) { 145 if (ep == bp || (ep->b_flags & B_INVAL) || 146 ep->b_vp == NULLVP) 147 continue; 148 vp = ip->i_devvp; 149 /* look for overlap */ 150 if (ep->b_bcount == 0 || ep->b_blkno > last || 151 ep->b_blkno + btodb(ep->b_bcount) <= start) 152 continue; 153 vprint("Disk overlap", vp); | 188 struct vnode *vp; 189 190 ebp = &buf[nbuf]; 191 start = bp->b_blkno; 192 last = start + btodb(bp->b_bcount) - 1; 193 for (ep = buf; ep < ebp; ep++) { 194 if (ep == bp || (ep->b_flags & B_INVAL) || 195 ep->b_vp == NULLVP) 196 continue; 197 vp = ip->i_devvp; 198 /* look for overlap */ 199 if (ep->b_bcount == 0 || ep->b_blkno > last || 200 ep->b_blkno + btodb(ep->b_bcount) <= start) 201 continue; 202 vprint("Disk overlap", vp); |
154 (void)printf("\tstart %lu, end %lu overlap start %lu, end %lu\n", 155 (u_long)start, (u_long)last, (u_long)ep->b_blkno, 156 (u_long)(ep->b_blkno + btodb(ep->b_bcount) - 1)); | 203 printf("\tstart %llu, end %llu overlap start %llu, end %llu\n", 204 (intmax_t)start, (intmax_t)last, (intmax_t)ep->b_blkno, 205 (intmax_t)(ep->b_blkno + btodb(ep->b_bcount) - 1)); |
157 panic("ffs_checkoverlap: Disk buffer overlap"); 158 } 159} 160#endif /* DDB */ 161 162/* 163 * block operations 164 * 165 * check if a block is available 166 */ 167int 168ffs_isblock(fs, cp, h) 169 struct fs *fs; 170 unsigned char *cp; | 206 panic("ffs_checkoverlap: Disk buffer overlap"); 207 } 208} 209#endif /* DDB */ 210 211/* 212 * block operations 213 * 214 * check if a block is available 215 */ 216int 217ffs_isblock(fs, cp, h) 218 struct fs *fs; 219 unsigned char *cp; |
171 ufs_daddr_t h; | 220 ufs1_daddr_t h; |
172{ 173 unsigned char mask; 174 175 switch ((int)fs->fs_frag) { 176 case 8: 177 return (cp[h] == 0xff); 178 case 4: 179 mask = 0x0f << ((h & 0x1) << 2); --- 12 unchanged lines hidden (view full) --- 192 193/* 194 * check if a block is free 195 */ 196int 197ffs_isfreeblock(fs, cp, h) 198 struct fs *fs; 199 unsigned char *cp; | 221{ 222 unsigned char mask; 223 224 switch ((int)fs->fs_frag) { 225 case 8: 226 return (cp[h] == 0xff); 227 case 4: 228 mask = 0x0f << ((h & 0x1) << 2); --- 12 unchanged lines hidden (view full) --- 241 242/* 243 * check if a block is free 244 */ 245int 246ffs_isfreeblock(fs, cp, h) 247 struct fs *fs; 248 unsigned char *cp; |
200 ufs_daddr_t h; | 249 ufs1_daddr_t h; |
201{ 202 203 switch ((int)fs->fs_frag) { 204 case 8: 205 return (cp[h] == 0); 206 case 4: 207 return ((cp[h >> 1] & (0x0f << ((h & 0x1) << 2))) == 0); 208 case 2: --- 8 unchanged lines hidden (view full) --- 217 218/* 219 * take a block out of the map 220 */ 221void 222ffs_clrblock(fs, cp, h) 223 struct fs *fs; 224 u_char *cp; | 250{ 251 252 switch ((int)fs->fs_frag) { 253 case 8: 254 return (cp[h] == 0); 255 case 4: 256 return ((cp[h >> 1] & (0x0f << ((h & 0x1) << 2))) == 0); 257 case 2: --- 8 unchanged lines hidden (view full) --- 266 267/* 268 * take a block out of the map 269 */ 270void 271ffs_clrblock(fs, cp, h) 272 struct fs *fs; 273 u_char *cp; |
225 ufs_daddr_t h; | 274 ufs1_daddr_t h; |
226{ 227 228 switch ((int)fs->fs_frag) { 229 case 8: 230 cp[h] = 0; 231 return; 232 case 4: 233 cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2)); --- 11 unchanged lines hidden (view full) --- 245 246/* 247 * put a block into the map 248 */ 249void 250ffs_setblock(fs, cp, h) 251 struct fs *fs; 252 unsigned char *cp; | 275{ 276 277 switch ((int)fs->fs_frag) { 278 case 8: 279 cp[h] = 0; 280 return; 281 case 4: 282 cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2)); --- 11 unchanged lines hidden (view full) --- 294 295/* 296 * put a block into the map 297 */ 298void 299ffs_setblock(fs, cp, h) 300 struct fs *fs; 301 unsigned char *cp; |
253 ufs_daddr_t h; | 302 ufs1_daddr_t h; |
254{ 255 256 switch ((int)fs->fs_frag) { 257 258 case 8: 259 cp[h] = 0xff; 260 return; 261 case 4: --- 12 unchanged lines hidden --- | 303{ 304 305 switch ((int)fs->fs_frag) { 306 307 case 8: 308 cp[h] = 0xff; 309 return; 310 case 4: --- 12 unchanged lines hidden --- |