sf...@users.sourceforge.net wrote: > Joe Krahn: >> Maybe it is an XFS issue for symlinks, but what about cases where >> st_size is zero for regular non-empty files? > > I am confused. > Your problem may be unrelated to symlink on XFS. > > (from your first mail) > ---------------------------------------------------------------------- > There is a bug in aufs where fstat() returns a st_size value of zero. > This causes cpio to fail on symlinks because st_size is supposed to be > the symlink string length. It also causes 'du' to return usage sizes of > zero unless the "--apparent" option is used. > ---------------------------------------------------------------------- > > fstat(2) for symlink returns the data of its target file instead of the > symlink itself. > > $ ln -s real_file symlink > and run the C program. > { > fd = open("symlink"); > fstat(fd) > } > Then you will get the data of "real_file" instead of "symlink". > If you (or cpio) want the data of "symlink", you need to issue > lstat("symlink"). > When you do fstat() on a symlink, st_size is supposed to return the length of the stored symlink-target string, rather than the file data size. So, if you want to read the symlink string to store it in the archive as a symlink, you use this function:
ssize_t readlink(const char *path, char *buf, size_t bufsiz); The proper way to call readlink() is to allocate a string buffer according to the value of st_size. So, any code that reads the actual symlink value may fail if st_size is wrong. The command-line "stat" and other coreutils succeed because they will guess and iteratively increase bufsiz until readlink succeeds. Joe ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com