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]

ftell() fails on files in shared folders


Hi all,

I have recently ran into a problem with Cygwin accessing files located
in shared folders. The attached program does fwrite() and then checks
file size with ftell(). Ftell() returns correct results in any of
following situations:
1) I access local file: c:/test.bin
2) I access file via UNC-address from the same computer:
//server-name/dir/test.out
  gribov.y@s-cw-head ~/build/upc/opt
  $ ./a.exe
  success

But when I try to access file via UNC-address from a different machine
ftell() starts returning 0 instead of expected 8:
  gribov.y@s-cw-head ~/build/upc/opt
  $ gcc io.c && run_ms_job -n 1 -network smp a.exe
  ftell(p) == sizeof(data) failed at io.c:26

Note that the file is created and data is written correctly:
  gribov.y@s-cw-head ~/build/upc/opt
  $ xxd ~/pgas/test.bin
  0000000: ffff ffff ffff ffff                      ........
so there seem to be a problem with ftell() itself.

Any help/ideas will be much appreciated. I have tried searching the
MLs but have not found anything similiar to my problem.

-Yuri

Attachment: cygcheck.out
Description: Binary data

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

#define CHECK(cond) if( !(cond) ) { printf("%s failed at %s:%d\n", #cond, __FILE__, __LINE__); exit(1); }

const char *fname = "//s-cw-head/pgas/test.bin"; // Works with simple "c:/test.bin"

int main() {
  // Without this snippet everything works
  int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
  int mode = O_WRONLY | O_CREAT | O_TRUNC;
  int fd = open(fname, mode, perm);
  CHECK( -1 != fd );
  close(fd);

  // Main part

  FILE *p = fopen(fname, "rb+");
  CHECK(p);

  long long data = -1;
  CHECK( sizeof(data) == fwrite(&data, 1, sizeof(data), p) );

  CHECK( 0 == fseek(p, 0, SEEK_END) );
  CHECK( ftell(p) == sizeof(data) );

  printf("success\n");

  return 0;
}
--
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]