]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/dbread.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / db / dbread.c
CommitLineData
2bd0ea18 1/*
da23017d
NS
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
2bd0ea18 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
dfc130f3 13 *
da23017d
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2bd0ea18
NS
17 */
18
1d7e80ee 19#include <xfs/libxfs.h>
2bd0ea18 20#include "bmap.h"
2bd0ea18
NS
21#include "dbread.h"
22#include "io.h"
4ca431fc 23#include "init.h"
2bd0ea18
NS
24
25int
26dbread(void *buf, int nblocks, xfs_fileoff_t bno, int whichfork)
27{
28 bmap_ext_t bm;
29 char *bp;
30 xfs_dfiloff_t eb;
31 xfs_dfiloff_t end;
32 int i;
33 int nex;
34
35 nex = 1;
36 end = bno + nblocks;
37 bp = buf;
38 while (bno < end) {
39 bmap(bno, end - bno, whichfork, &nex, &bm);
40 if (nex == 0) {
41 bm.startoff = end;
42 bm.blockcount = 1;
43 }
44 if (bm.startoff > bno) {
45 eb = end < bm.startoff ? end : bm.startoff;
46 i = (int)XFS_FSB_TO_B(mp, eb - bno);
47 memset(bp, 0, i);
48 bp += i;
49 bno = eb;
50 }
51 if (bno == end)
52 break;
53 if (bno > bm.startoff) {
54 bm.blockcount -= bno - bm.startoff;
55 bm.startblock += bno - bm.startoff;
56 bm.startoff = bno;
57 }
58 if (bm.startoff + bm.blockcount > end)
59 bm.blockcount = end - bm.startoff;
60 i = read_bbs(XFS_FSB_TO_DADDR(mp, bm.startblock),
61 (int)XFS_FSB_TO_BB(mp, bm.blockcount),
62 (void **)&bp, NULL);
63 if (i)
64 return i;
65 bp += XFS_FSB_TO_B(mp, bm.blockcount);
66 bno += bm.blockcount;
67 }
68 return 0;
69}