ABOUT "DU -SK" AND "DF" This document describes why numbers from "du -s" and "df" Disagree and is applicable to AIX version 3.2 and 4.1. On AIX versions prior to 4.1 df reports its statistics in 1024 byte units and du reports in 512 byte units. On AIX 4.1 and later both df and du default to 512 byte units. The following discussion uses 4.1.2 df and du thus all units are in 512-byte blocks. THE PROBLEM When you execute "du -s /filesystem_path" and subtract this value from the total block count as reported by df to get a free block value, the calculation yields a value that is greater than df's free block value. For example: % du -s /tmp 12920 /tmp % df /tmp Filesystem 512-blocks Free %Used Iused %Iused Mounted on /dev/hd3 57344 42208 26% 391 4% /tmp - = 57344 - 12920 = 44424 44424 is greater than 42208. The reason for this discrep- ancy has to do with the implementation of du and df. DU -SK du -sk transverses the file tree adding up the number of blocks allocated to each directory, symlink, and file as reported by the stat() system call. This is how du arrives at its total value. DF df looks at the file system disk block allocation maps to arrive at its total and free values. WHY THE NUMBERS DO NOT ADD UP The file system allocates some of the disk blocks in the file system to record its data; this data is referred to as meta data. Meta data is not visible to most user level pro- grams. Examples of meta data are inodes, disk maps, indirect blocks, and super blocks. du is an example of a user level program that is not aware of file system meta data. While df looks at the file system disk allocation maps, and is aware of file system meta data. df obtains the true file system statistics whereas du only sees a partial picture. For example, n empty 4 MB JFS file system created with frag=4096 and nbpi=4096 has the fol- lowing meta data allocated: 1 4k block for the LVM 2 4k super blocks 2 4k blocks for disk maps 2 4k blocks for inode maps 2 4k blocks for .indirect 32 4k blocks for inodes ------------------------- 41 4k blocks for meta data on an empty 4M file system # df /foo 8 /foo The 8 512 byte blocks reported for du on this empty file system are the blocks used by the root directory. In order to get du's output to match df's output we must add in the meta data. First, convert 42 4K blocks to 512 byte units: 41 * 8 = 328 328(meta data) + 8(from du) = 336 so there are 336 512-byte blocks allocated on this empty file system, thus: 8192(total blocks) - 336(used from du + meta data) = 7856 This does match the output from df's free column. This cal- culation was easy to perform on an empty file system. However, on a non-empty file system, the meta data for file indirect blocks comes into play and such calculations are very tedious and impractical. In conclusion du -s produces a value that reflects the number of disk blocks that are allocated to file and direc- tories. df reports on the actual allocation state of the file system. The true allocation state includes both user data (files and directories) plus meta data.