home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / aix / 11520 < prev    next >
Encoding:
Text File  |  1992-11-12  |  3.4 KB  |  121 lines

  1. Xref: sparky comp.unix.aix:11520 comp.unix.questions:13278 comp.unix.wizards:4626 comp.unix.programmer:5263
  2. Newsgroups: comp.unix.aix,comp.unix.questions,comp.unix.wizards,comp.unix.programmer
  3. Path: sparky!uunet!walter!porthos!pyuxd!esg
  4. From: esg@pyuxd.uucp (25235-gokhman)
  5. Subject: mmap() with shared access fails over NFS using AIX 3.2 on RS 6000
  6. Organization: Bellcore, Livingston, NJ
  7. Date: Thu, 12 Nov 92 15:27:10 GMT
  8. Message-ID: <1992Nov12.152710.26146@porthos.cc.bellcore.com>
  9. Keywords: memory mapped files over NFS - is there a problem for write ?
  10. Sender: netnews@porthos.cc.bellcore.com (USENET System Software)
  11. Lines: 108
  12.  
  13. Hello netters,
  14.  
  15. I am trying to do mmap-ing to a file accross NFS using the following
  16. arguments:
  17.  
  18.  caddr_t pointer = mmap(0, file_length, PROT_READ | PROT_WRITE,
  19.                 MAP_FILE | MAP_VARIABLE | MAP_SHARED, fd, 0);
  20.  
  21. It appears to be successful. However, when I am trying to write
  22. to the pointed region I get segmentation faults. Segmentation faults
  23. do not necessarily occur right at the start of the region but also
  24. in the middle and almost at the end at what seems to be page breaks,
  25. e.g. location 4096 with 0-4095 bytes written successfully. The problem
  26. does not occur when files are not NFS mounted. I am aware of the fact
  27. that the earlier versions of mmap() under AIX 3.1.X were not allowing
  28. writes over NFS, but my understanding is that AIX 3.2 and up do not
  29. have this limitations - manuals at least do not mention it. Could it
  30. be a router-related problem ? Help !!!
  31.  
  32. Following is the program that I use to examine this situation. Again,
  33. it always failed over NFS and always worked locally on the same set
  34. of files:
  35.  
  36. =========================== CUT HERE ==============================
  37.  
  38.                 Thanx in advance,
  39.                 Ed Gokhman
  40.  
  41. #    include        <stdio.h>
  42. #    include        <stdlib.h>
  43.  
  44. #    include        <sys/stat.h>
  45. #    include        <sys/signal.h>
  46. #    include        <fcntl.h>
  47. #       include     <unistd.h>
  48.  
  49. #    include        <errno.h>
  50.  
  51. #    include        <sys/mman.h>
  52. #       include         <sys/stat.h>
  53. #       include         <sys/mode.h>
  54. #       include         <sys/file.h>
  55. #    include        <unistd.h>
  56.  
  57. char *ptr;
  58.  
  59. caddr_t pointer;
  60.  
  61. void bus_err_or_segment (int sig)
  62. {
  63.    fprintf (stderr, "Can not finish this test at byte=%ld", ptr - (char *)pointer);
  64. }
  65.  
  66. main (int argc, char **argv)
  67. {
  68.     size_t    file_length;
  69.     struct stat  statbuf;
  70.     int    fd;
  71.  
  72.     if (argc < 2) {
  73.       fprintf (stderr, "Usage: check <filename>\n");
  74.       exit (1);
  75.     }
  76.     (void) signal ((int) SIGBUS, (void (*)(int)) bus_err_or_segment);
  77.     (void) signal ((int) SIGSEGV, (void (*)(int)) bus_err_or_segment);
  78.  
  79.     if (!stat(argv[1], &statbuf))
  80.     {
  81.        if (!(file_length = statbuf . st_size))
  82.        {
  83.           fprintf (stderr, "%s - empty file\n", argv[1]);
  84.           return;
  85.        }
  86.     }
  87.     else
  88.     {
  89.           fprintf (stderr, "%s - does not exists\n", argv[1]);
  90.           return;
  91.     }
  92.  
  93.     fprintf (stderr, "Mapping %ld bytes in %s\n", file_length, argv[1]);
  94.  
  95.     if ((fd = open ( argv[1], O_RDWR, 0660 )) == -1)
  96.     {
  97.        fprintf(stderr, "Can not open %s with O_RDWR - %s\n", argv[1], strerror(errno));
  98.        exit (1);
  99.     }
  100.  
  101.     errno = 0;
  102.  
  103.     pointer = mmap(0, file_length, PROT_READ | PROT_WRITE,
  104.         MAP_FILE | MAP_VARIABLE | MAP_SHARED, fd, 0);
  105.  
  106.     if (pointer == (caddr_t) -1 || errno)
  107.     {
  108.        fprintf(stderr, "Can not map %s - %s\n", argv[1], strerror(errno));
  109.        return;
  110.     }
  111.  
  112.     for (ptr = (char *)pointer; ptr < (char *)pointer + (int) file_length; ptr++) {
  113.        char a = *ptr;
  114.        *ptr = a;
  115.     }
  116.     munmap (pointer, file_length);
  117.     fprintf(stderr, "Success for %s\n", argv[1]);
  118. }
  119.  
  120.  
  121.