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

Re: [MiNT] Fopen("NUL:", 0) returns -33 (ENOENT)



I think i found the reason why cat behaved differently on my system. It was due to a patch that i applied some time ago to fix an issue with redirections on aranyms hostfs file system. It was only a small patch changing the internals of sys__ffstat_1_12 and sys__ffstat_1_16 (basically the only difference between the two is that the former fills a XATTR struct, and the latter a stat struct):


--- sys/dosfile.c.orig    2014-05-11 13:10:07.417000000 +0200
+++ sys/dosfile.c    2015-01-30 03:13:23.790000016 +0100
@@ -472,7 +472,9 @@ sys__ffstat_1_12 (struct file *f, XATTR
         return ENOSYS;
     }
 
-    ret = xfs_getxattr (f->fc.fs, &f->fc, xattr);
+    ret = xdd_ioctl(f, FSTAT, xattr);
+    if (ret == ENOSYS)
+        ret = xfs_getxattr (f->fc.fs, &f->fc, xattr);
     if ((ret == E_OK) && (f->fc.fs->fsflags & FS_EXT_3))
     {
         xtime_to_local_dos(xattr,m);
@@ -486,6 +488,8 @@ sys__ffstat_1_12 (struct file *f, XATTR
 static long
 sys__ffstat_1_16 (struct file *f, struct stat *st)
 {
+    long ret;
+
 # ifdef OLDSOCKDEVEMU
     if (f->dev == &sockdev || f->dev == &sockdevemu)
 # else
@@ -499,7 +503,10 @@ sys__ffstat_1_16 (struct file *f, struct
         return ENOSYS;
     }
 
-    return xfs_stat64 (f->fc.fs, &f->fc, st);
+    ret = xdd_ioctl(f, FSTAT64, st);
+    if (ret == ENOSYS)
+        ret = xfs_stat64 (f->fc.fs, &f->fc, st);
+    return ret;
 }
 
 long _cdecl


(the patch is also attached below)

Why was this change neccessary? Because originally, only xfs_getxattr()/xfs_stat64() were called, which only get information on the cookie, not the file handle. However, a cookie only represents a path name, which may not exist anymore (or never existed in case of a duped handle). The original version worked for tosfs and ext2fs because they were able to identify the file through a cached version of the cookie. The hostfs of aranym however does not cache cookies. That caused things like

cat <<EOF
hello
EOF

fail with

cat: -: no such file or directory

when run on a hostfs in aranym. So the correct handling should be to get the information from the file handle, not the path that was used to create it.

Greetings,
     Thorsten

--- sys/dosfile.c.orig	2014-05-11 13:10:07.417000000 +0200
+++ sys/dosfile.c	2015-01-30 03:13:23.790000016 +0100
@@ -472,7 +472,9 @@ sys__ffstat_1_12 (struct file *f, XATTR
 		return ENOSYS;
 	}
 
-	ret = xfs_getxattr (f->fc.fs, &f->fc, xattr);
+	ret = xdd_ioctl(f, FSTAT, xattr);
+	if (ret == ENOSYS)
+		ret = xfs_getxattr (f->fc.fs, &f->fc, xattr);
 	if ((ret == E_OK) && (f->fc.fs->fsflags & FS_EXT_3))
 	{
 		xtime_to_local_dos(xattr,m);
@@ -486,6 +488,8 @@ sys__ffstat_1_12 (struct file *f, XATTR
 static long
 sys__ffstat_1_16 (struct file *f, struct stat *st)
 {
+	long ret;
+
 # ifdef OLDSOCKDEVEMU
 	if (f->dev == &sockdev || f->dev == &sockdevemu)
 # else
@@ -499,7 +503,10 @@ sys__ffstat_1_16 (struct file *f, struct
 		return ENOSYS;
 	}
 
-	return xfs_stat64 (f->fc.fs, &f->fc, st);
+	ret = xdd_ioctl(f, FSTAT64, st);
+	if (ret == ENOSYS)
+		ret = xfs_stat64 (f->fc.fs, &f->fc, st);
+	return ret;
 }
 
 long _cdecl