home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards
- Path: sparky!uunet!krfiny!jeffj
- From: jeffj@krfiny.uucp (J. Jonas)
- Subject: Re: A few UNIX questions
- Message-ID: <1992Aug27.162220.16130@krfiny.uucp>
- Summary: sounds like a woops to me!
- Organization: Jeff's house of computer pieces
- References: <32176@adm.brl.mil> <1992Aug26.081414.6932@sniap.mchp.sni.de>
- Date: Thu, 27 Aug 1992 16:22:20 GMT
- Lines: 66
-
- >mike@BRL.MIL ( Mike Muuss) writes:
- >:
- >: From: Michael Panosh <mwp.michael@melpn1.prime.com> PrimeService, Australia
- >:
- >: > Can *anyone* tell me why the file size is a signed integer. Surely there
- >: > is no need for negative sized files!!
- >:
- >: Because lseek() needs to be able to return -1 on error, and not have it
- >: look like a valid file offset.
-
- >Umm, and a *signed* file size helps, does it?
-
- The external type used for file size (as used for system calls)
- and the internal one used in the on-disk inode don't have to be the same.
-
- I agree that the type used for the return value for lseek()
- needs to be signed so that errors can be returned
- (0 and >0 are valid values).
-
- But in the 'classic' S5 file system, look at ino.h
- /*
- * Inode structure as it appears on a disk block.
- */
- struct dinode
- {
- off_t di_size; /* number of bytes in file */
-
- in types.h,
- typedef long off_t; /* ?<offset> type */
-
- I know of no possible time a file could have a negative size.
- The type should have been unsigned.
- With triple indirect blocks, the file size is limited by the
- highest integer you can put in a long.
- Making it unsigned would double the allowable file size,
- but then lseek would start returning negative values for large files.
-
- A fine point about this variable: it's not really the file size,
- it's the offset of the last valid byte.
-
- For example:
- create a file
- lseek 1000000 bytes into the file
- write ONE byte
- The di_size will be 1000000, yet only one block was allocated.
- The file has a 'hole' in it (which always reads as all nulls).
- The disk space consumed is one block (512, 1k, 2k, 4k or 8k),
- which may be less than 'di_size'.
- Even 'du' is wrong since it only rounds up 'di_size' to the next
- highest block count.
- The only way to truly determine the disk space a file occupies is to
- count the number of non zero block addresses in the inode.
- Some file systems make this distinction and maintain
- both counts in the inode.
- That's why SVR4 expanded stat to return a generic stat structure
- with provisions for reporting file size (in blocks), block size,
- and offset to last byte.
- (I'm not running SVR4 so I can't elaborate on the new and improved stat).
-
- - Jeffrey Jonas
- jeffj@synsys.uucp
- --
- --
- Jeffrey Jonas
-
- jeffj@synsys.uucp
-