LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Finding Directroy size using system call (https://www.linuxquestions.org/questions/linux-newbie-8/finding-directroy-size-using-system-call-733339/)

HeartBeat 06-16-2009 08:51 AM

Finding Directroy size using system call
 
All,

My application needs to find out a directory size. As running system command du may slow down the performance of my application I dont want to use it. But I am interested in using the system call which may return the directory size.

I went through the man page of system calls such as statfs and stat but they are not say anything about the size of the directory. Probably they may be used for finding out the file size in a directory.
:)Please suggest me on how to get the size of a directory.

Regrads,
HeartBeat

BeacoN 06-16-2009 08:57 AM

what exact command do you run that slows it down?

whenever I want to find the size of a directory I use

du -sch *directory*

normally I just put a * in there to get all the files and dirs in the folder-doesn't seem to be slow at all. But like I did above you can ask just for one file, that would be faster.

I don't believe the ext3 filesystem (I may be wrong) keeps directory size with the inode information in the file-hence you can't just read a part of the disk in the file to get the directory size. I believe the system has to poll and find all the files in it and add it up before it tells you. It does this very fast, you won't even notice a lag unless there double digit gigs in the directory.

HeartBeat 06-17-2009 04:04 AM

Many thanks to BeacoN,

I am interested in using the system call instead the system commands which would print the directory size on the console.

As you said ext3 inode doesn't keep the directory size. So to find out the directory size we just need to sum up all the files size with in that directory. Please correct me if am wrong.

Thanks,
HeartBeat


All times are GMT -5. The time now is 07:58 PM.