~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to lib/file/fileIOPosix.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-23 15:32:00 UTC
  • mfrom: (1.1.2 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081023153200-gc1bfx89hj35c799
Tags: 2008.10.10-123053-2
* Correcting typo in dh_installinit call.
* Downgrading depends on module-assistant to recommends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
      return FILEIO_WRITE_ERROR_NOSPC;
162
162
   case EFBIG:
163
163
      return FILEIO_WRITE_ERROR_FBIG;
164
 
#ifdef EDQUOT
 
164
#if defined(VMX86_SERVER)
 
165
   case EBUSY:
 
166
      return FILEIO_LOCK_FAILED;
 
167
#endif
 
168
#if defined(EDQUOT)
165
169
   case EDQUOT:
166
170
      return FILEIO_WRITE_ERROR_DQUOT;
167
171
#endif
733
737
    * lockfiles.
734
738
    */
735
739
   if ((access & (FILEIO_OPEN_EXCLUSIVE_LOCK |
736
 
                  FILEIO_OPEN_MULTIWRITER_LOCK)) != 0 ||
 
740
                  FILEIO_OPEN_MULTIWRITER_LOCK)) != 0 ||
737
741
       (access & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE |
738
 
                  FILEIO_OPEN_LOCKED)) ==
 
742
                  FILEIO_OPEN_LOCKED)) ==
739
743
       (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_LOCKED)) {
740
744
      if (File_OnVMFS(pathName)) {
741
745
         access &= ~FILEIO_OPEN_LOCKED;
742
 
         if ((access & FILEIO_OPEN_MULTIWRITER_LOCK) != 0) {
743
 
            flags |= O_MULTIWRITER_LOCK;
744
 
         } else {
745
 
            flags |= O_EXCLUSIVE_LOCK;
746
 
         }
 
746
         if ((access & FILEIO_OPEN_MULTIWRITER_LOCK) != 0) {
 
747
            flags |= O_MULTIWRITER_LOCK;
 
748
         } else {
 
749
            flags |= O_EXCLUSIVE_LOCK;
 
750
         }
747
751
      }
748
752
   }
749
753
#endif
750
754
 
751
755
   FileIO_Init(file, pathName);
752
756
   ret = FileIO_Lock(file, access);
753
 
   if (ret != FILEIO_SUCCESS) {
 
757
   if (!FileIO_IsSuccess(ret)) {
754
758
      goto error;
755
759
   }
756
760
 
1245
1249
   return fsync(file->posix);
1246
1250
}
1247
1251
 
1248
 
/*
1249
 
 * readv & writev are not available in the FreeBSD or Solaris Tools builds
1250
 
 */
1251
 
#if !defined(VMX86_TOOLS) || (!defined(__FreeBSD__) && !defined(sun))
1252
 
 
1253
1252
 
1254
1253
/*
1255
1254
 *-----------------------------------------------------------------------------
1572
1571
}
1573
1572
 
1574
1573
 
1575
 
#if defined(GLIBC_VERSION_21) || defined(__APPLE__)
 
1574
#if defined(GLIBC_VERSION_21) || defined(__APPLE__) || defined(__FreeBSD__)
1576
1575
 
1577
1576
/*
1578
1577
 *----------------------------------------------------------------------
1778
1777
 
1779
1778
   return fret;
1780
1779
}
1781
 
#endif /* defined(GLIBC_VERSION_21) || defined(__APPLE__) */
1782
 
#endif /* !defined(VMX86_TOOLS) || !(defined(FreeBSD) || defined(sun)) */
 
1780
#endif /* defined(GLIBC_VERSION_21) || defined(__APPLE__) || defined(__FreeBSD__) */
1783
1781
#endif /* !defined(N_PLAT_NLM) */
1784
1782
 
1785
1783
/*
1856
1854
 */
1857
1855
 
1858
1856
FileIOResult
1859
 
FileIO_Access(ConstUnicode pathName,  // IN: path name to be tested
1860
 
              int accessMode)         // IN: access modes to be asserted
 
1857
FileIO_Access(ConstUnicode pathName,  // IN: Path name to be tested. May be NULL.
 
1858
              int accessMode)         // IN: Access modes to be asserted
1861
1859
{
1862
 
   int mode;
1863
 
 
1864
 
   mode = 0;
 
1860
   int mode = 0;
 
1861
 
 
1862
   if (pathName == NULL) {
 
1863
      errno = EFAULT;
 
1864
      return FILEIO_ERROR;
 
1865
   }
 
1866
 
1865
1867
   if (accessMode & FILEIO_ACCESS_READ) {
1866
1868
      mode |= R_OK;
1867
1869
   }
2023
2025
   return fd;
2024
2026
}
2025
2027
 
 
2028
 
 
2029
/*
 
2030
 *-----------------------------------------------------------------------------
 
2031
 *
 
2032
 * FileIO_DescriptorToStream
 
2033
 *
 
2034
 *      Return a FILE * stream equivalent to the given FileIODescriptor.
 
2035
 *      This is the logical equivalent of Posix dup() then fdopen().
 
2036
 *
 
2037
 *      Since the passed descriptor and returned FILE * represent the same
 
2038
 *      underlying file, and their cursor is shared, you should avoid
 
2039
 *      interleaving uses to both.
 
2040
 *
 
2041
 * Results:
 
2042
 *      A FILE * representing the same underlying file as the passed descriptor
 
2043
 *      NULL if there was an error.
 
2044
 *      Caller should fclose the returned descriptor when finished.
 
2045
 *
 
2046
 * Side effects:
 
2047
 *      New fd allocated.
 
2048
 *
 
2049
 *-----------------------------------------------------------------------------
 
2050
 */
 
2051
 
 
2052
FILE *
 
2053
FileIO_DescriptorToStream(FileIODescriptor *fdesc)    // IN
 
2054
{
 
2055
   int dupFd;
 
2056
   const char *mode;
 
2057
   int tmpFlags;
 
2058
   FILE *stream;
 
2059
 
 
2060
   /* The file you pass us should be valid and opened for *something* */
 
2061
   ASSERT(FileIO_IsValid(fdesc));
 
2062
   ASSERT((fdesc->flags & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE)) != 0);
 
2063
   tmpFlags = fdesc->flags & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE);
 
2064
 
 
2065
   dupFd = dup(fdesc->posix);
 
2066
   if (dupFd == -1) {
 
2067
      return NULL;
 
2068
   }
 
2069
 
 
2070
 
 
2071
 
 
2072
   if (tmpFlags == (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE)) {
 
2073
      mode = "r+";
 
2074
   } else if (tmpFlags == FILEIO_OPEN_ACCESS_WRITE) {
 
2075
      mode = "w";
 
2076
   } else {  /* therefore (tmpFlags == FILEIO_OPEN_ACCESS_READ) */
 
2077
      mode = "r";
 
2078
   }
 
2079
 
 
2080
   stream = fdopen(dupFd, mode);
 
2081
 
 
2082
   if (stream == NULL) {
 
2083
      close(dupFd);
 
2084
   }
 
2085
 
 
2086
   return stream;
 
2087
}
 
2088
 
 
2089
 
2026
2090
#if defined(__APPLE__)
2027
2091
 
2028
2092
/*