~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/blktap2/drivers/blk_netbsd.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <sys/param.h>
 
2
#include <sys/ioctl.h>
 
3
#include <sys/disklabel.h>
 
4
#include <errno.h>
 
5
#include <inttypes.h>
 
6
#include "tapdisk.h"
 
7
#include "blk.h"
 
8
 
 
9
int blk_getimagesize(int fd, uint64_t *size)
 
10
{
 
11
        int rc;
 
12
        struct disklabel dl;
 
13
 
 
14
        *size = 0;
 
15
        rc = ioctl(fd, DIOCGDINFO, &dl);
 
16
        if (rc) {
 
17
                DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
 
18
                return -EINVAL;
 
19
        }
 
20
 
 
21
        *size = dl.d_secsize * dl.d_secpercyl;
 
22
 
 
23
        return 0;
 
24
}
 
25
 
 
26
int blk_getsectorsize(int fd, uint64_t *sector_size)
 
27
{
 
28
        int rc;
 
29
        struct disklabel dl;
 
30
 
 
31
        *sector_size = DEV_BSIZE;
 
32
        rc = ioctl(fd, DIOCGDINFO, &dl);
 
33
        if (rc) {
 
34
                DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
 
35
                return 0; /* fallback to DEV_BSIZE */
 
36
        }
 
37
 
 
38
        *sector_size = dl.d_secsize;
 
39
        return 0;
 
40
}
 
41