On 7 Nov 2002, Michal Samek wrote:

> OK.
> Here is the full log.

Thanks, it turns out that your .exe locked a dbf file (using region
locking) with strange offsets. So it might not have been the problem with
there being a shared lock on the .exe but rather a conflict in the dbf it
was trying to manipulate.

Attached is a quick&dirty "proof of concept" 64-bit file offset patch. Of
course it will need to be changed to be compatible with older libc's and
kernels.

Bart
--- dosemu-1.1.3.7/src/dosext/mfs/mfs.c Fri Oct  4 11:16:06 2002
+++ dosemu-1.1.3.8/src/dosext/mfs/mfs.c Thu Nov  7 17:49:04 2002
@@ -153,6 +153,7 @@
 
 /* Modified by O.V.Zhirov at July 1998    */
 
+#define _FILE_OFFSET_BITS 64
 
 #if defined(__linux__)
 #define DOSEMU 1               /* this is a port to dosemu */
@@ -2937,7 +2938,7 @@
       fd = sft_fd(sft);
       Debug0((dbg_fd, "Read file fd=%x, dta=%p, cnt=%d\n",
              fd, (void *) dta, cnt));
-      Debug0((dbg_fd, "Read file pos = %ld\n",
+      Debug0((dbg_fd, "Read file pos = %lu\n",
              sft_position(sft)));
       Debug0((dbg_fd, "Handle cnt %d\n",
              sft_handle_cnt(sft)));
@@ -2971,7 +2972,7 @@
       sft_abs_cluster(sft) = 0x174a;   /* XXX a test */
 /*      Debug0((dbg_fd, "File data %02x %02x %02x\n",
              dta[0], dta[1], dta[2])); */
-      Debug0((dbg_fd, "Read file pos after = %ld\n",
+      Debug0((dbg_fd, "Read file pos after = %lu\n",
              sft_position(sft)));
       return (return_val);
     }
@@ -3004,7 +3005,7 @@
     }
     Debug0((dbg_fd, "Handle cnt %d\n",
            sft_handle_cnt(sft)));
-    Debug0((dbg_fd, "sft_size = %x, sft_pos = %x, dta = %p, cnt = %x\n", 
(int)sft_size(sft), (int)sft_position(sft), (void *) dta, (int)cnt));
+    Debug0((dbg_fd, "sft_size = %lx, sft_pos = %lx, dta = %p, cnt = %x\n", 
+sft_size(sft), sft_position(sft), (void *) dta, (int)cnt));
     if (us_debug_level > Debug_Level_0) {
       ret = dos_write(fd, dta, cnt);
       if ((ret + s_pos) > sft_size(sft)) {
@@ -3792,15 +3793,17 @@
     return TRUE;
   case SEEK_FROM_EOF:          /* 0x21 */
     {
-      int offset = (state->ecx << 16) + WORD(state->edx);
+      off_t offset = (unsigned long))((state->ecx << 16) + WORD(state->edx) + 
+sft_position(sft));
+      if (offset < 0) {
+       SETWORD(&(state->eax), SEEK_ERROR);
+       return (FALSE);
+      }
       fd = sft_fd(sft);
-      Debug0((dbg_fd, "Seek From EOF fd=%x ofs=%d\n",
-             fd, offset));
-      if (offset > 0)
-       offset = -offset;
-      offset = lseek(fd, offset, SEEK_END);
-      Debug0((dbg_fd, "Seek returns fs=%d ofs=%d\n",
-             fd, offset));
+      Debug0((dbg_fd, "Seek From EOF fd=%x ofs=%lld\n",
+             fd, (long long)offset));
+      offset = lseek(fd, offset, SEEK_SET);
+      Debug0((dbg_fd, "Seek returns fs=%d ofs=%lld\n",
+             fd, (long long)offset));
       if (offset != -1) {
        sft_position(sft) = offset;
        SETWORD(&(state->edx), offset >> 16);
@@ -3825,11 +3828,12 @@
                int fd = sft_fd(sft);
                int ret;
                struct LOCKREC{
-                       long offset,size;
+                       unsigned long offset,size;
                } *pt = (struct LOCKREC*) Addr (state,ds,edx);
                struct flock larg;
+#if 0                
                unsigned long mask = 0xC0000000;
-
+#endif
 
 #if 1   /* The kernel can't place F_WRLCK on files opened read-only and
          * FoxPro fails. IMHO the right solution is:         --Maxim Ruchko */
@@ -3848,6 +3852,7 @@
                larg.l_len = pt->size;
                larg.l_pid = 0;
 
+#if 0
                /*
                        This is a superdooper patch extract from the Samba project
                        We have no idea why this is there but it seem to work
@@ -3871,9 +3876,11 @@
                if ((larg.l_start & mask) != 0)
                        larg.l_start = (larg.l_start & ~mask) | ((larg.l_start & mask) 
>> 2);
 
+#endif
                ret = fcntl (fd,F_SETLK,&larg);
-               Debug0((dbg_fd, "lock fd=%x rc=%x type=%x whence=%x start=%lx, 
len=%lx\n",
-                       fd, ret, larg.l_type, larg.l_whence, larg.l_start,larg.l_len));
+               Debug0((dbg_fd, "lock fd=%x rc=%x type=%x whence=%x start=%llx, 
+len=%llx\n",
+                       fd, ret, larg.l_type, larg.l_whence, (long long)larg.l_start,
+                        (long long)larg.l_len));
                if (ret == -1) SETWORD(&(state->eax), ACCESS_DENIED);
                return ret != -1 ? TRUE : FALSE;
        }

Reply via email to