File size!!!

Brad Boyer flar at pants.nu
Mon Mar 19 05:08:19 EST 2001


shalini  jain wrote:
> can someone suggest the way to find the file size in ext2fs ? actually, want to find the file size in bytes,i.e, the true file size and not in terms of the blocks allocated to the file.

In the kernel:

inode->i_size

In a regular application ( in C ):

#include <sys/stat.h>
#include <unistd.h>

off_t getfilesize(char *myfile)
{
	struct stat fileinfo;
	int err;

	err = stat(myfile, &fileinfo);
	if(err == -1) {
		/* Do something about the error */
		return 0;
	}
	return fileinfo.st_size;
}

> is there any EOF char in ext2fs files ? if yes. what is it ? is there any other way of knowing the file size than to count  up to EOF ???

No.

The file size is kept in filesystem metadata, not in the file.

(Every sane filesystem handles file size this way. Even HFS/HFS+)

	Brad Boyer
	flar at pants.nu

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/






More information about the Linuxppc-dev mailing list