~ubuntu-branches/ubuntu/utopic/xfsprogs/utopic-proposed

« back to all changes in this revision

Viewing changes to db/dbread.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2009-05-06 11:29:18 UTC
  • mfrom: (8.1.1 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090506112918-uzoyzcp90rtr8td7
Tags: 3.0.2
New bugfix release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3
 
 * All Rights Reserved.
4
 
 *
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
7
 
 * published by the Free Software Foundation.
8
 
 *
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.
13
 
 *
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
17
 
 */
18
 
 
19
 
#include <xfs/libxfs.h>
20
 
#include "bmap.h"
21
 
#include "dbread.h"
22
 
#include "io.h"
23
 
#include "init.h"
24
 
 
25
 
int
26
 
dbread(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
 
}