Messages in this thread | | | From | Parag Warudkar <> | Subject | Re: Compatible fstat() | Date | Tue, 8 Nov 2005 16:06:51 -0500 |
| |
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; f = open("/dev/hda", O_RDONLY ); if(f <= 0){ perror("open"); exit(0); } off = lseek64(f, 0, SEEK_SET); off = lseek64(f, 0, SEEK_END); perror("llseek"); printf ("Size %lld\n", off); close(f); return 0; }
> Okay, still not portable and there is probably a better way that > doesn't rely > on such nonsense. For example, since you have a minimum size in mind, > just seek that much and see if it works - you don't really need to > know the > whole disk size for that. Or figure out the best way on all of > your platforms > and abstract it.
Now this gives me a clue what Ted was referring to as binary search in e2fsprogs. If nothing works this should work portably I guess.
Thanks Parag - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |