public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bill Davidsen <davidsen@tmr.com>
To: Parag Warudkar <kernel-stuff@comcast.net>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: Compatible fstat()
Date: Sat, 12 Nov 2005 08:41:36 -0500	[thread overview]
Message-ID: <4375F110.705@tmr.com> (raw)
In-Reply-To: <93241CB9-F1EE-4D38-9194-C10B471FD02C@comcast.net>

Parag Warudkar wrote:

>
> On Nov 8, 2005, at 5:57 PM, Bill Davidsen wrote:
>
>> Parag Warudkar wrote:
>>
>>> On Nov 8, 2005, at 2:39 PM, Bob Copeland wrote:
>>>
>>>> Isn't this just because the device size is > 2**32?  What if you   
>>>> use fseeko(3)
>>>> and #define _FILE_OFFSET_BITS 64?
>>>>
>>> Yep. I got it to return the correct hard disk size (17Gb) using   
>>> lseek64 and
>>> #define _LARGEFILE64_SOURCE
>>> #define _FILE_OFFSET_BITS 64
>>> Here is what I did
>>> -------------------------------------------------
>>> #define _LARGEFILE64_SOURCE
>>> #define _FILE_OFFSET_BITS 64
>>> #include <stdio.h>
>>> #include <unistd.h>
>>> #include <fcntl.h>
>>> int main()
>>> {
>>>         int f;
>>>         off64_t off=0;
>>
>> Why is this initialized?
>>
>>>         f = open("/dev/hda", O_RDONLY );
>>>         if(f <= 0){
>>>                 perror("open");
>>>                 exit(0);
>>>         }
>>>         off = lseek64(f, 0, SEEK_SET);
>>
>> Why do this? it always returns zero.
>>
>>>         off = lseek64(f, 0, SEEK_END);
>>>         perror("llseek");
>>>         printf ("Size %lld\n", off);
>>>         close(f);
>>>         return 0;
>>> }
>>
>> RETURN VALUE
>>   Upon successful completion, lseek returns the resulting offset
>>   location as measured in bytes from the beginning of the  file.
>>   Otherwise,  a  value  of  (off_t)-1 is returned and errno is
>>   set to indicate the error.
>>
>
> You took it a little too seriously! It was from the scribble-and- 
> shuffle-till-it-works department ;) Sole purpose was to figure out a  
> way to print the disk size from the device - some how that is!
>
> But thanks for pointing out anyway - it doesn't hurt to be correct no  
> matter what the purpose is. 

You could look at how blockdev does it, the --getss (sector size) and 
--getsize (size in sectors) seem to work, based on trying it on a total 
of two machines ;-) Even gives correct size for software RAID arrays!

-- 
bill davidsen <davidsen@tmr.com>
  CTO TMR Associates, Inc
  Doing interesting things with small computers since 1979


  reply	other threads:[~2005-11-12 13:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-08 15:48 Compatible fstat() linux-os (Dick Johnson)
2005-11-08 17:10 ` Parag Warudkar
2005-11-08 17:22   ` Al Viro
2005-11-08 17:56     ` linux-os (Dick Johnson)
2005-11-08 17:58     ` Parag Warudkar
2005-11-08 18:10       ` linux-os (Dick Johnson)
2005-11-08 18:15         ` Parag Warudkar
2005-11-08 18:20           ` linux-os (Dick Johnson)
2005-11-08 19:39             ` Bob Copeland
2005-11-08 20:03               ` linux-os (Dick Johnson)
2005-11-08 21:06               ` Parag Warudkar
2005-11-08 22:57                 ` Bill Davidsen
2005-11-09  0:14                   ` Parag Warudkar
2005-11-12 13:41                     ` Bill Davidsen [this message]
2005-11-08 18:49     ` Theodore Ts'o
2005-11-08 19:12       ` Parag Warudkar
2005-11-09  3:23         ` Theodore Ts'o
2005-11-08 17:53   ` linux-os (Dick Johnson)
2005-11-08 18:04     ` Parag Warudkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4375F110.705@tmr.com \
    --to=davidsen@tmr.com \
    --cc=kernel-stuff@comcast.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox