[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] symlinks and hostfs



On Fri, 2009-08-28 at 15:06 +0200, Vincent Rivière wrote:
> Hello.
> 
> I have noticed that symlinks are seen as regular files on hostfs :-(
> This can be verified easily by using "ls -l"
> 
> In most situations, symlinks are normally treated as the file pointed 
> to, except with the lstat() function used by ls.
> 
> The lstat() implementation is here:
> http://sparemint.atariforge.net/cgi-bin/cvsweb/mintlib/unix/lstat.c?rev=1.2&content-type=text/x-cvsweb-markup
> The implementation using MiNT syscalls is in __sys_stat()
> http://sparemint.atariforge.net/cgi-bin/cvsweb/mintlib/mintlib/do_stat.c?rev=1.11&content-type=text/x-cvsweb-markup
> 
> Since Fstat64() does not seem to be implemented in hostfs, we fall back 
> in Fxattr().
> 
> The implementation of Fxattr() is here inside sys_f_xattr():
> http://sparemint.atariforge.net/cgi-bin/cvsweb/freemint/sys/dosdir.c?rev=1.27.2.2&content-type=text/x-cvsweb-markup
> 
> And unfortunately the parameter "flag" set to 1 indicating that the 
> attributes of the symlink itself should be read is ignored :-(
> 
> Actually, I would be happy to use ARAnyM without any ext2 image, but 
> these limitations are annoying.
> 
> Since the UNIX file API is provided by the MiNTLib and properly 
> implemented in the hosts Linux/Cygwin/OSX, we should manage to get 
> something satisfying...

Actually, this is a bug in aranym.

It uses it's own host_stat64() implementation in host_getxattr() that
does a stat() on the file instead of lstat() in this case. And so aranym
ends up stat'ing the actual file rather than the symlink. Only if stat()
fails it falls back to an lstat() operation.

I think aranym should use lstat by default here as the filename cookie
that it gets from FreeMiNT is the one it should be operating on. 

As far as FreeMiNT and mintlib are concerned. They are correct.

Attached is a patch that fixes aranym here, although I'm unsure of why
all the other tricks are needed that I've removed, so I'll leave the
final patch up to the aranym folks. But I've tested it here and it
works.

Alan.
Index: hostfs.cpp
===================================================================
RCS file: /var/repos/aranym/src/natfeat/hostfs.cpp,v
retrieving revision 1.53
diff -u -r1.53 hostfs.cpp
--- hostfs.cpp	24 Aug 2009 12:27:48 -0000	1.53
+++ hostfs.cpp	28 Aug 2009 14:54:08 -0000
@@ -1810,26 +1810,7 @@
 
 int32 HostFs::host_stat64( XfsCookie *fc, const char *fpathName, struct stat *statBuf ) {
 
-	if ( lstat(fpathName, statBuf) )
-		return errnoHost2Mint(errno,TOS_EFILNF);
-
-	// symlink
-	if ( S_ISLNK(statBuf->st_mode) ) {
-		char target[MAXPATHNAMELEN];
-		if (!host_readlink(fpathName,target,sizeof(target)-1))
-			return errnoHost2Mint(errno,TOS_EFILNF);
-
-		// doesn't point to a mapped drive
-		if (!findDrive(fc, target)) {
-			D(bug( "HOSTFS: host_stat64: follow symlink -> %s", target ));
-
-			// get the information from the link target
-			if ( stat(target, statBuf) ) {
-				// on error just rollback to a symlink (broken one)
-				lstat(fpathName, statBuf);
-			}
-		}
-	}
+	lstat(fpathName, statBuf);
 
 	return TOS_E_OK;
 }