Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lseek to end on partition raw device returns 0
On 12/15/2010, "Antti Kantee" <pooka%homeworld.netbsd.org@localhost> wrote:
>On Wed, Dec 15, 2010 at 11:12:50AM -0500, Toby Karyadi wrote:
>> 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 seriously doubt lseek() trick works on a device file on 5.x
>either.
>
>The basic story is that getting the size of a device is a complete
>mess. lseek() doesn't work. Then there's stat() as is demonstrated
>by this snippet:
>
>pain-rustique:15:~> stat -x /dev/rwd0e
> File: "/dev/rwd0e"
> Size: 0 FileType: Character Device
> Mode: (0640/crw-r-----) Uid: ( 0/ root) Gid: ( 5/operator)
>Device: 0,0 Inode: 9586 Links: 1
>Access: Wed Feb 21 21:40:35 2007
>Modify: Wed Feb 21 21:40:35 2007
>Change: Wed Feb 21 21:40:35 2007
>pain-rustique:16:~> sleep 5 < /dev/rwd0e &
>[1] 11674
>pain-rustique:17:~> stat -x /dev/rwd0e
> File: "/dev/rwd0e"
> Size: 20974431744 FileType: Character Device
> Mode: (0640/crw-r-----) Uid: ( 0/ root) Gid: ( 5/operator)
>Device: 0,0 Inode: 9586 Links: 1
>Access: Wed Feb 21 21:40:35 2007
>Modify: Wed Feb 21 21:40:35 2007
>Change: Wed Feb 21 21:40:35 2007
>
>After opening the device stat will report the correct value *until*
>the vnode is reclaimed. So if you open+stat it, you should maybe
>get a correct value.
>
>But on NetBSD, I've found the best way is to use ioctl(DIOCGDINFO).
Hmm, you're right about lseek on 5.1: I tried on another raw partition
and I got a wrong result, i.e. it's unreliable at best. I don't know
what the expected behavior is on NetBSD, but on linux lseek to end on a
raw device returns 0 as well, based on my quick googling. Anyway, using
DIOCGDINFO is definitely the way to go to get the partition size.
Btw, your trick with open and stat didn't even work on current. I don't
know if that matters.
Thanks
Home |
Main Index |
Thread Index |
Old Index