something odd with the order of files in a directory
Eric Sandeen
sandeen at redhat.com
Fri Jan 16 15:35:24 UTC 2009
Folkert van Heusden wrote:
> Hi,
>
> I noticed something odd with the order of files in a directory.
> When I put files in a directory in a certain order on an
> ext3-filesystem, the order is not kept. On fat-filesystem it does.
> E.g.:
> rm -rf t ; mkdir t
> touch a.a a.b a.c
> mv a.b t/ ; mv a.c t/ ; mv a.a t/
> ls -Ula t/
>
> I then would expect:
> a.b
> a.c
> a.a
>
> but instead I get
> drwxr-xr-x 3 root root 4096 2009-01-16 12:59 ..
> -rw-r--r-- 1 root root 0 2009-01-16 12:59 a.c
> -rw-r--r-- 1 root root 0 2009-01-16 12:59 a.b
> -rw-r--r-- 1 root root 0 2009-01-16 12:59 a.a
> drwxr-xr-x 2 root root 4096 2009-01-16 12:59 .
>
> I tried adding sync between each mv but that didn't help.
This is due to the dir_index feature; you're getting them back in hash
(read: random) order. If you turn it off:
[root at inode mnt]# tune2fs -O ^dir_index /dev/sdb4
you'll get what you expect:
[root at inode test]# rm -rf t ; mkdir t
[root at inode test]# touch a.a a.b a.c
[root at inode test]# mv a.b t/ ; mv a.c t/ ; mv a.a t/
[root at inode test]# ls -Ula t/
total 8
drwxr-xr-x 2 root root 4096 2009-01-16 15:30 .
drwxr-xr-x 4 root root 4096 2009-01-16 15:30 ..
-rw-r--r-- 1 root root 0 2009-01-16 15:30 a.b
-rw-r--r-- 1 root root 0 2009-01-16 15:30 a.c
-rw-r--r-- 1 root root 0 2009-01-16 15:30 a.a
but you'll lose the other efficiencies of the dir_index feature.
-Eric
More information about the Ext3-users
mailing list