This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ftell() fails on files in shared folders


> First of all, there's a bug in your testcase.

Nice catch. With fixed code O_RDWR and O_WRONLY no longer influence
the result but the bug still remains.

> What filesystem is your remote FS? ?Please run

Done. All nodes seem to have same volume attributes.

> You could also run the testcase under strace, like this:

Done, here's the relevant part: for local (successful) run:
  write: write(3, 0x402080, 8)
  write: 8 = write(3, 0x402080, 8)
  fhandler_base::lseek: setting file pointer to 8
  lseek64: 8 = lseek(0, 3, 0)
  fhandler_base::lseek: setting file pointer to 8
  lseek64: 8 = lseek(0, 3, 0)
and for remote:
  write: write(3, 0x402080, 8)
  write: 8 = write(3, 0x402080, 8)
  fhandler_base::lseek: setting file pointer to 0
  lseek64: 0 = lseek(0, 3, 0)

-- 
Best regards,
Yuri

Attachment: volinfo.txt
Description: Text document

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

#define CHECK(cond) if( !(cond) ) { printf("%s failed at %s:%d\n", #cond, __FILE__, __LINE__); return; }
#define CMP(a, b) { int _a = (a), _b = (b); if( (_a) != (_b) ) { printf("%s != %s (%d != %d) at %s:%d\n", #a, #b, _a, _b, __FILE__, __LINE__); return; } }

const char *fname;

const long long data = -1;
const int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;

int main(int argc, char *argv[]) {
  if( argc < 2 ) {
    fprintf(stderr, "Syntax: a.exe fname\n");
    exit(1);
  }

  fname = argv[1];

  int mode = O_WRONLY | O_CREAT | O_TRUNC;

  int fd = open(fname, mode, perm);
  CHECK( -1 != fd );
  close(fd);

#if 0
  FILE *p = fopen(fname, "rb+");
  CMP( sizeof(data), fwrite(&data, 1, sizeof(data), p) );
  CMP( 0, fseek(p, 0, SEEK_END) );
  CMP( sizeof(data), ftell(p) );
#elif 1
  fd = open(fname, perm, mode);
  CMP( sizeof(data), write(fd, &data, sizeof(data)) );
  CMP( sizeof(data), lseek(fd, 0, SEEK_END) );
  CMP( sizeof(data), lseek(fd, 0, SEEK_CUR) );
#endif

  printf("success\n");

  return 0;
}
 

Attachment: strace_local.log
Description: Binary data

Attachment: strace_remote.log
Description: Binary data

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]