Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lseek to end on partition raw device returns 0



Hi all,

Does anyone know why doing lseek(fd, 0, SEEK_END), where fd is a
descriptor to a raw disk partition, always returns 0 on current? This is
not the behavior I noticed with netbsd-5.1. Does anyone else notice
this? I am using the 201012071900Z/amd64 version of the HEAD (5.99.41),
downloaded from nyftp.netbsd.org. I'm just dabbling with unix system
programming, so I might be just blowing hot air here, but it seems like
a bug to me. 

I was trying to setup lvm on raidframe and couldn't get pass 'lvm
pvcreate' to setup the raid partition. Doing 'lvm pvcreate -v -v -v
/dev/rraid0d' showed that lseek(fd, 0, SEEK_END) always returns 0 and I
got the error '/dev/rraid0d: Skipping: Too small to hold a PV' (well
it's 0 byte). This detection is done in
src/external/gpl2/lvm2/dist/lib/filters/filter_netbsd.c, which calls
dev_get_size() which is implemented in device/dev-io.c using lseek. 

The code snippet towards the end of the emai shows the problem quickly.
It takes a filename as the first argument. On current, if you use a
regular file it'll return the actual size, but passing any raw device
partition (e.g. /dev/rwd0a, /dev/rraid0d) will always return 0. On 5.1,
passing a raw device name will return the partition size in bytes. 

I might be able to hack around the lvm problem using ioctl to get the
size of the partition, but this seems like a bug with lseek. Thanks for
any comments, help, or patch. 

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, void *argv[]) {
    int fd;
    off_t size;
    char *devname;

    if (argc <= 1) {
        printf("error: device name required\n");
        return -1;
    } else {
        devname = argv[1];
    }

    if ((fd = open(devname, 0, 0)) < 0) {
        printf("error opening %s\n", devname);
    } else {
        if ((size = lseek(fd, 0, SEEK_END)) < 0) {
            printf("error seeking to end of %s\n", devname);
        } else {
            printf("sizeof %s: %d\n", devname, size);
        }
    }
}


Home | Main Index | Thread Index | Old Index