Skip to contentSkip to conversation

File size!!!

DISCUSSION shalini jain 2 participants 2 messages Mar 17, 2001 – Mar 18, 2001

lore
Share & tools
lore
#0 lore raw

hello list,

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.

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 ???

thanx,
Shalini

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

#1 lore raw
Quoted 1 line · shalini jain

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;
}
Quoted 1 line

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
[email protected]

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