~ubuntu-branches/debian/jessie/ufsutils/jessie

« back to all changes in this revision

Viewing changes to lib/port/blockdev.c

  • Committer: Bazaar Package Importer
  • Author(s): Guillem Jover, Robert Millan, Guillem Jover, Peter Pentchev
  • Date: 2011-05-31 03:50:05 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110531035005-wyiyk25p99ivd0k0
Tags: 8.2-1
[ Robert Millan ]
* Set ufsutils-udeb to kfreebsd-any.

[ Guillem Jover ]
* New upstream version (based on FreeBSD 8.2)
* Now using Standards-Version 3.9.2 (no changes needed).
* Switch to source format “3.0 (quilt)”.
  - Remove quilt from Build-Depends.
  - Remove patch target in debian/rules.
  - Remove now unneeded README.source.
  - Refresh all patches.
* Reorganize source code:
  - Switch from debian/upstream.sh to debian/rules get-orig-source target.
  - Switch from CVS to Subversion to retrieve the source code.
  - Use the same source layout as upstream (no more relocations),
    i.e. lib/, sbin/, sys/sys, sys/ufs.
  - Move libport/ to port/.
  - Merge libdisklabel/ into port/.
* Remove unneeded linking against libtermcap, thus removing the need for
  ncurses.
* Add an empty debian/watch file explaining that there's no packaged
  upstream releases. Suggested by Peter Pentchev.
* Update CVS to Subversion reference to upstream source code in
  debian/copyright.
* Remove unused lib variable from debian/rules.
* Use dpkg-buildflags to set CPPFLAGS, CFLAGS and LDFLAGS.
  Based on a patch by Peter Pentchev.
* Remove bogus reference to BSD license in /usr/share/common-licenses.
* Always set -I../../sys, even on GNU/kFreeBSD systems.

[ Peter Pentchev ]
* Remove duplicate section “utils” from ufsutils binary package.
* Remove XC- prefix from Package-Type.
* Honour CPPFLAGS and LDFLAGS and do not link with CFLAGS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004 Guillem Jover <guillem@debian.org>
 
3
 * All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
9
 * 1. Redistributions of source code must retain the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer.
 
11
 * 2. Redistributions in binary form must reproduce the above copyright
 
12
 *    notice, this list of conditions and the following disclaimer in the
 
13
 *    documentation and/or other materials provided with the distribution.
 
14
 * 3. The name of the author may not be used to endorse or promote products
 
15
 *    derived from this software without specific prior written permission.
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
18
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 
19
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 
20
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
21
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
22
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
23
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
24
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
25
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
26
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
 
 
29
#include <sys/types.h>
 
30
#include <sys/ioctl.h>
 
31
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__)
 
32
#include <sys/param.h>
 
33
#if defined(__FreeBSD_kernel__) && __FreeBSD_kernel_version >= 500000
 
34
#include <sys/disk.h>
 
35
#endif
 
36
#include <sys/disklabel.h>
 
37
#ifndef DIOCGMEDIASIZE
 
38
#define DIOCGMEDIASIZE _IOR('d', 129, off_t)
 
39
#endif
 
40
#elif defined(__linux__)
 
41
#ifndef BLKGETSIZE
 
42
#define BLKGETSIZE _IO(0x12,96)
 
43
#endif
 
44
#endif
 
45
#include <sys/stat.h>
 
46
#include <unistd.h>
 
47
#include "blockdev.h"
 
48
 
 
49
static const int sector_size = 512;
 
50
 
 
51
int64_t
 
52
get_block_device_size(int fd)
 
53
{
 
54
        int64_t size = 0;
 
55
        struct stat64 st;
 
56
 
 
57
#if defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__NetBSD__)
 
58
        {
 
59
                struct disklabel disklabel;
 
60
                off_t device_size;
 
61
 
 
62
                if (!ioctl(fd, DIOCGMEDIASIZE, &device_size))
 
63
                        return device_size;
 
64
 
 
65
                if (!ioctl(fd, DIOCGDINFO, &disklabel)) {
 
66
                        size = ((int64_t)disklabel.d_secperunit) * sector_size;
 
67
                        return size;
 
68
                }
 
69
        }
 
70
#elif defined(__linux__)
 
71
        {
 
72
                long int device_sectors;
 
73
 
 
74
                if (!ioctl(fd, BLKGETSIZE, &device_sectors)) {
 
75
                        size = ((int64_t)device_sectors) * sector_size;
 
76
                        return size;
 
77
                }
 
78
        }
 
79
#else
 
80
        /* XXX: Implement a generic seek binary test for targets currently
 
81
         *      not supported.
 
82
         */
 
83
#error "Do not know how to get block device size"
 
84
#endif
 
85
 
 
86
        /* Regular files or devices under the Hurd.  */
 
87
        if (fstat64(fd, &st) == 0) {
 
88
                return st.st_size;
 
89
        }
 
90
 
 
91
        return size;
 
92
}