Messages in this thread | | | Date | Sat, 5 Apr 1997 11:37:11 -0500 (EST) | From | "Richard B. Johnson" <> | Subject | Re: POSIX Compliance |
| |
On Sat, 5 Apr 1997, Regis Duchesne wrote:
> On Thu, 3 Apr 1997, Richard B. Johnson wrote: > > > dev_end = lseek(fd, 0, SEEK_END); > > Returns the file size or the device size (if a disk or disk partition) > > on my Sun running SunOs 5.5.1. > > On Linux machines of various versions, including the latest, it returns > > zero (0). > > ISO/IEC 9945-1:1996(E) > ANSI/IEEE > Std 1003.1, 1996 Edition > > specifies at paragraph 6.5.3.2 line 563 : > "Some devices are incapable of seeking. [...] The behavior of the lseek() > function on such devices is implementation defined. [...] If fd refers to > a shared memory object, the result of the lseek() function is > unspecified." > > and at paragraph 6.5.3.3 line 583 : > "Upon successful completion, the function shall return the resulting > offset location as measured in bytes from the beginning of the file. > Otherwise, it shall return a value of ((off_t)-1), shall set errno to > indicate the error, and the file offset shall remain unchanged by this > function call" > > > I do not know what is correct. However, if POSIX requires the > > observed behavior, I think we no longer have a generic means of finding > > out the size of a disk device or disk partition. This is not good. > > Are you sure there is no other way to do this? It seems that my 'df' works > pretty well on various versions of Linux.
Yes, but `df` only looks at mounted file-systems. Once mounted, they can be 'stat()ed`. Note that fstat() also returns (0) on a block device, but not so with SunOs.
Now, this situation came up after the discussion of using a "private" disk for a database application. The disk would be owned by the application and it would not have a "file-system" on it. It therefore would not be "mounted" Instead, the application would read/write whatever and wherever it wanted to it's disk. It could implement any kind of storage matrix that it deemed optimum without disturbing operating system file systems.
But.... How does it "know" the logical length of the disk it owns?
On Linux we know how to get that information because we have access to platform-specific ioctls which can be deduced from the source code. However, there is, was, or should be, a generic way to obtain this information. Both lseek() and fstat() will provide this information using SunOs. On Linux, the returned value shows a 0 length device.
I believe that if the function cannot or does not return the size of the device in bytes, then it MUST return -1 and set errno. Therefore, returning a value of zero is a BUG.
Cheers, Dick Johnson -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Richard B. Johnson Project Engineer Analogic Corporation Voice : (508) 977-3000 ext. 3754 Fax : (508) 532-6097 Modem : (508) 977-6870 Ftp : ftp@boneserver.analogic.com Email : rjohnson@analogic.com, johnson@analogic.com Penguin : Linux version 2.1.31 on an i586 machine (66.15 BogoMips). Warning : I read unsolicited mail for $350.00 per hour. Supply billing address. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| |