1*d65f6f70SBen Gras /* $NetBSD: ext2fs_subr.c,v 1.27 2009/10/19 18:41:17 bouyer Exp $ */ 2*d65f6f70SBen Gras 3*d65f6f70SBen Gras /* 4*d65f6f70SBen Gras * Copyright (c) 1982, 1986, 1989, 1993 5*d65f6f70SBen Gras * The Regents of the University of California. All rights reserved. 6*d65f6f70SBen Gras * 7*d65f6f70SBen Gras * Redistribution and use in source and binary forms, with or without 8*d65f6f70SBen Gras * modification, are permitted provided that the following conditions 9*d65f6f70SBen Gras * are met: 10*d65f6f70SBen Gras * 1. Redistributions of source code must retain the above copyright 11*d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer. 12*d65f6f70SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 13*d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer in the 14*d65f6f70SBen Gras * documentation and/or other materials provided with the distribution. 15*d65f6f70SBen Gras * 3. Neither the name of the University nor the names of its contributors 16*d65f6f70SBen Gras * may be used to endorse or promote products derived from this software 17*d65f6f70SBen Gras * without specific prior written permission. 18*d65f6f70SBen Gras * 19*d65f6f70SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20*d65f6f70SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*d65f6f70SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*d65f6f70SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23*d65f6f70SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24*d65f6f70SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25*d65f6f70SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26*d65f6f70SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27*d65f6f70SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28*d65f6f70SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29*d65f6f70SBen Gras * SUCH DAMAGE. 30*d65f6f70SBen Gras * 31*d65f6f70SBen Gras * @(#)ffs_subr.c 8.2 (Berkeley) 9/21/93 32*d65f6f70SBen Gras * Modified for ext2fs by Manuel Bouyer. 33*d65f6f70SBen Gras */ 34*d65f6f70SBen Gras 35*d65f6f70SBen Gras /* 36*d65f6f70SBen Gras * Copyright (c) 1997 Manuel Bouyer. 37*d65f6f70SBen Gras * 38*d65f6f70SBen Gras * Redistribution and use in source and binary forms, with or without 39*d65f6f70SBen Gras * modification, are permitted provided that the following conditions 40*d65f6f70SBen Gras * are met: 41*d65f6f70SBen Gras * 1. Redistributions of source code must retain the above copyright 42*d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer. 43*d65f6f70SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 44*d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer in the 45*d65f6f70SBen Gras * documentation and/or other materials provided with the distribution. 46*d65f6f70SBen Gras * 47*d65f6f70SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 48*d65f6f70SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 49*d65f6f70SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 50*d65f6f70SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 51*d65f6f70SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 52*d65f6f70SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 53*d65f6f70SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 54*d65f6f70SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 55*d65f6f70SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 56*d65f6f70SBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57*d65f6f70SBen Gras * 58*d65f6f70SBen Gras * @(#)ffs_subr.c 8.2 (Berkeley) 9/21/93 59*d65f6f70SBen Gras * Modified for ext2fs by Manuel Bouyer. 60*d65f6f70SBen Gras */ 61*d65f6f70SBen Gras 62*d65f6f70SBen Gras #include <sys/cdefs.h> 63*d65f6f70SBen Gras __KERNEL_RCSID(0, "$NetBSD: ext2fs_subr.c,v 1.27 2009/10/19 18:41:17 bouyer Exp $"); 64*d65f6f70SBen Gras 65*d65f6f70SBen Gras #include <sys/param.h> 66*d65f6f70SBen Gras #include <sys/systm.h> 67*d65f6f70SBen Gras #include <sys/vnode.h> 68*d65f6f70SBen Gras #include <sys/buf.h> 69*d65f6f70SBen Gras #include <sys/inttypes.h> 70*d65f6f70SBen Gras #include <sys/kauth.h> 71*d65f6f70SBen Gras 72*d65f6f70SBen Gras #include <ufs/ufs/inode.h> 73*d65f6f70SBen Gras #include <ufs/ext2fs/ext2fs.h> 74*d65f6f70SBen Gras #include <ufs/ext2fs/ext2fs_extern.h> 75*d65f6f70SBen Gras 76*d65f6f70SBen Gras /* 77*d65f6f70SBen Gras * Return buffer with the contents of block "offset" from the beginning of 78*d65f6f70SBen Gras * directory "ip". If "res" is non-zero, fill it in with a pointer to the 79*d65f6f70SBen Gras * remaining space in the directory. 80*d65f6f70SBen Gras */ 81*d65f6f70SBen Gras int 82*d65f6f70SBen Gras ext2fs_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp) 83*d65f6f70SBen Gras { 84*d65f6f70SBen Gras struct inode *ip; 85*d65f6f70SBen Gras struct m_ext2fs *fs; 86*d65f6f70SBen Gras struct buf *bp; 87*d65f6f70SBen Gras daddr_t lbn; 88*d65f6f70SBen Gras int error; 89*d65f6f70SBen Gras 90*d65f6f70SBen Gras ip = VTOI(vp); 91*d65f6f70SBen Gras fs = ip->i_e2fs; 92*d65f6f70SBen Gras lbn = lblkno(fs, offset); 93*d65f6f70SBen Gras 94*d65f6f70SBen Gras *bpp = NULL; 95*d65f6f70SBen Gras if ((error = bread(vp, lbn, fs->e2fs_bsize, NOCRED, 0, &bp)) != 0) { 96*d65f6f70SBen Gras brelse(bp, 0); 97*d65f6f70SBen Gras return (error); 98*d65f6f70SBen Gras } 99*d65f6f70SBen Gras if (res) 100*d65f6f70SBen Gras *res = (char *)bp->b_data + blkoff(fs, offset); 101*d65f6f70SBen Gras *bpp = bp; 102*d65f6f70SBen Gras return (0); 103*d65f6f70SBen Gras } 104*d65f6f70SBen Gras 105*d65f6f70SBen Gras void 106*d65f6f70SBen Gras ext2fs_itimes(struct inode *ip, const struct timespec *acc, 107*d65f6f70SBen Gras const struct timespec *mod, const struct timespec *cre) 108*d65f6f70SBen Gras { 109*d65f6f70SBen Gras struct timespec now; 110*d65f6f70SBen Gras 111*d65f6f70SBen Gras if (!(ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY))) { 112*d65f6f70SBen Gras return; 113*d65f6f70SBen Gras } 114*d65f6f70SBen Gras 115*d65f6f70SBen Gras vfs_timestamp(&now); 116*d65f6f70SBen Gras if (ip->i_flag & IN_ACCESS) { 117*d65f6f70SBen Gras if (acc == NULL) 118*d65f6f70SBen Gras acc = &now; 119*d65f6f70SBen Gras ip->i_e2fs_atime = acc->tv_sec; 120*d65f6f70SBen Gras } 121*d65f6f70SBen Gras if (ip->i_flag & (IN_UPDATE | IN_MODIFY)) { 122*d65f6f70SBen Gras if (mod == NULL) 123*d65f6f70SBen Gras mod = &now; 124*d65f6f70SBen Gras ip->i_e2fs_mtime = mod->tv_sec; 125*d65f6f70SBen Gras ip->i_modrev++; 126*d65f6f70SBen Gras } 127*d65f6f70SBen Gras if (ip->i_flag & (IN_CHANGE | IN_MODIFY)) { 128*d65f6f70SBen Gras if (cre == NULL) 129*d65f6f70SBen Gras cre = &now; 130*d65f6f70SBen Gras ip->i_e2fs_ctime = cre->tv_sec; 131*d65f6f70SBen Gras } 132*d65f6f70SBen Gras if (ip->i_flag & (IN_ACCESS | IN_MODIFY)) 133*d65f6f70SBen Gras ip->i_flag |= IN_ACCESSED; 134*d65f6f70SBen Gras if (ip->i_flag & (IN_UPDATE | IN_CHANGE)) 135*d65f6f70SBen Gras ip->i_flag |= IN_MODIFIED; 136*d65f6f70SBen Gras ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY); 137*d65f6f70SBen Gras } 138