1 /* 2 * Copyright (c) 1991 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)lfs_subr.c 7.4 (Berkeley) 12/06/91 8 */ 9 10 #include <sys/param.h> 11 #include <sys/namei.h> 12 #include <sys/vnode.h> 13 #include <sys/buf.h> 14 15 #include <ufs/ufs/quota.h> 16 #include <ufs/ufs/inode.h> 17 18 #include <ufs/lfs/lfs.h> 19 #include <ufs/lfs/lfs_extern.h> 20 21 /* 22 * Return buffer with the contents of block "offset" from the beginning of 23 * directory "ip". If "res" is non-zero, fill it in with a pointer to the 24 * remaining space in the directory. 25 */ 26 int 27 lfs_blkatoff(vp, offset, res, bpp) 28 struct vnode *vp; 29 off_t offset; 30 char **res; 31 struct buf **bpp; 32 { 33 register struct lfs *fs; 34 struct inode *ip; 35 struct buf *bp; 36 daddr_t lbn; 37 int bsize, error; 38 39 ip = VTOI(vp); 40 fs = ip->i_lfs; 41 lbn = lblkno(fs, offset); 42 bsize = blksize(fs); 43 44 *bpp = NULL; 45 if (error = bread(vp, lbn, bsize, NOCRED, &bp)) { 46 brelse(bp); 47 return (error); 48 } 49 if (res) 50 *res = bp->b_un.b_addr + blkoff(fs, offset); 51 *bpp = bp; 52 return (0); 53 } 54 55 /* Search a block for a specific dinode. */ 56 DINODE * 57 lfs_ifind(fs, ino, page) 58 struct lfs *fs; 59 ino_t ino; 60 void *page; 61 { 62 register DINODE *dip; 63 register int cnt; 64 65 #ifdef VERBOSE 66 printf("lfs_ifind: inode %d\n", ino); 67 #endif 68 dip = page; 69 for (cnt = INOPB(fs); cnt--; ++dip) 70 if (dip->di_inum == ino) 71 return (dip); 72 73 panic("lfs_ifind: dinode %u not found", ino); 74 /* NOTREACHED */ 75 } 76 77 /* Set values in the ifile for the inode. */ 78 void 79 lfs_iset(ip, daddr, atime) 80 INODE *ip; 81 daddr_t daddr; 82 time_t atime; 83 { 84 BUF *bp; 85 IFILE *ifp; 86 struct lfs *fs; 87 ino_t ino; 88 89 #ifdef VERBOSE 90 printf("lfs_iset: setting ino %d daddr %lx time %lx\n", 91 ip->i_number, daddr, atime); 92 #endif 93 94 fs = ip->i_lfs; 95 ino = ip->i_number; 96 LFS_IENTRY(ifp, fs, ino, bp); 97 98 ifp->if_daddr = daddr; 99 ifp->if_st_atime = atime; 100 lfs_bwrite(bp); 101 } 102 103 /* Translate an inode number to a disk address. */ 104 daddr_t 105 lfs_itod(fs, ino) 106 struct lfs *fs; 107 ino_t ino; 108 { 109 BUF *bp; 110 IFILE *ifp; 111 daddr_t iaddr; 112 113 #ifdef VERBOSE 114 printf("lfs_itod %d\n", ino); 115 #endif 116 /* Read the appropriate block from the ifile. */ 117 LFS_IENTRY(ifp, fs, ino, bp); 118 119 if (ifp->if_daddr == LFS_UNUSED_DADDR) 120 panic("lfs_itod: unused disk address"); 121 iaddr = ifp->if_daddr; 122 brelse(bp); 123 return (iaddr); 124 } 125