~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to lib/file/fileInt.h

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "fileIO.h"
32
32
#include "fileLock.h"
33
33
#include "unicodeTypes.h"
 
34
#include "memaligned.h"
34
35
 
35
36
#if defined __linux__
36
37
/*
100
101
} FileData;
101
102
 
102
103
#if defined(_WIN32)
103
 
EXTERN int FileMapErrorToErrno(char *functionName,
104
 
                               DWORD status);
105
 
 
106
 
EXTERN Bool FileRetryThisError(DWORD error,
107
 
                               uint32 numCodes,
108
 
                               DWORD *codes);
109
 
 
110
 
EXTERN int FileAttributesRetry(ConstUnicode pathName,
111
 
                               uint32 msecMaxWaitTime,
112
 
                               FileData *fileData);
113
 
 
114
 
EXTERN int FileRenameRetry(ConstUnicode fromPath,
115
 
                           ConstUnicode toPath,
116
 
                           uint32 msecMaxWaitTime);
117
 
 
118
 
EXTERN int FileDeletionRetry(ConstUnicode pathName,
119
 
                             Bool handleLink,
120
 
                             uint32 msecMaxWaitTime);
121
 
 
122
 
EXTERN int FileCreateDirectoryRetry(ConstUnicode pathName,
123
 
                                    uint32 msecMaxWaitTime);
124
 
 
125
 
EXTERN int FileRemoveDirectoryRetry(ConstUnicode pathName,
126
 
                                    uint32 msecMaxWaitTime);
127
 
 
128
 
EXTERN int FileListDirectoryRetry(ConstUnicode pathName,
129
 
                                  uint32 msecMaxWaitTime,
130
 
                                  Unicode **ids);
 
104
int FileMapErrorToErrno(char *functionName,
 
105
                        DWORD status);
 
106
 
 
107
Bool FileRetryThisError(DWORD error,
 
108
                        uint32 numCodes,
 
109
                        DWORD *codes);
 
110
 
 
111
int FileAttributesRetry(ConstUnicode pathName,
 
112
                        uint32 msecMaxWaitTime,
 
113
                        FileData *fileData);
 
114
 
 
115
int FileRenameRetry(ConstUnicode fromPath,
 
116
                    ConstUnicode toPath,
 
117
                    uint32 msecMaxWaitTime);
 
118
 
 
119
int FileDeletionRetry(ConstUnicode pathName,
 
120
                      Bool handleLink,
 
121
                      uint32 msecMaxWaitTime);
 
122
 
 
123
int FileCreateDirectoryRetry(ConstUnicode pathName,
 
124
                             uint32 msecMaxWaitTime);
 
125
 
 
126
int FileRemoveDirectoryRetry(ConstUnicode pathName,
 
127
                             uint32 msecMaxWaitTime);
 
128
 
 
129
int FileListDirectoryRetry(ConstUnicode pathName,
 
130
                           uint32 msecMaxWaitTime,
 
131
                           Unicode **ids);
131
132
 
132
133
#define FileAttributes(a, b)    FileAttributesRetry((a), 0, (b))
133
134
#define FileRename(a, b)        FileRenameRetry((a), (b), 0)
150
151
#define FileRemoveDirectoryRobust(a) \
151
152
                    FileRemoveDirectoryRetry((a), FILE_MAX_WAIT_TIME_MS)
152
153
#else
153
 
EXTERN char *FilePosixGetBlockDevice(char const *path);
154
 
 
155
 
EXTERN int FileAttributes(ConstUnicode pathName,
156
 
                          FileData *fileData);
157
 
 
158
 
EXTERN int FileRename(ConstUnicode fromPath,
159
 
                      ConstUnicode toPath);
160
 
 
161
 
EXTERN int FileDeletion(ConstUnicode pathName,
162
 
                        Bool handleLink);
163
 
 
164
 
EXTERN int FileCreateDirectory(ConstUnicode pathName);
165
 
 
166
 
EXTERN int FileRemoveDirectory(ConstUnicode pathName);
 
154
char *FilePosixGetBlockDevice(char const *path);
 
155
 
 
156
int FileAttributes(ConstUnicode pathName,
 
157
                   FileData *fileData);
 
158
 
 
159
int FileRename(ConstUnicode fromPath,
 
160
               ConstUnicode toPath);
 
161
 
 
162
int FileDeletion(ConstUnicode pathName,
 
163
                 Bool handleLink);
 
164
 
 
165
int FileCreateDirectory(ConstUnicode pathName);
 
166
 
 
167
int FileRemoveDirectory(ConstUnicode pathName);
167
168
 
168
169
#define FileListDirectoryRobust(a, b) File_ListDirectory((a), (b))
169
170
#define FileAttributesRobust(a, b)    FileAttributes((a), (b))
207
208
typedef int FILELOCK_FILE_HANDLE;
208
209
#endif
209
210
 
210
 
EXTERN uint32 FileSleeper(uint32 msecMinSleepTime,
211
 
                          uint32 msecMaxSleepTime);
212
 
 
213
 
EXTERN uint32 FileSimpleRandom(void);
214
 
 
215
 
EXTERN const char *FileLockGetMachineID(void);
216
 
 
217
 
EXTERN char *FileLockGetExecutionID(void);
218
 
 
219
 
EXTERN Bool FileLockMachineIDMatch(char *host,
220
 
                                   char *second);
221
 
 
222
 
EXTERN int FileLockMemberValues(ConstUnicode lockDir, 
223
 
                                ConstUnicode fileName,
224
 
                                char *buffer,
225
 
                                uint32 size,
226
 
                                LockValues *memberValues);
227
 
 
228
 
EXTERN int FileLockHackVMX(ConstUnicode filePathName);
229
 
 
230
 
EXTERN int FileLockOpenFile(ConstUnicode pathName,
231
 
                            int flags,
232
 
                            FILELOCK_FILE_HANDLE *handle);
233
 
 
234
 
EXTERN int FileLockCloseFile(FILELOCK_FILE_HANDLE handle);
235
 
 
236
 
EXTERN int FileLockReadFile(FILELOCK_FILE_HANDLE handle,
237
 
                            void *buf,
238
 
                            uint32 requestedBytes,
239
 
                            uint32 *resultantBytes);
240
 
 
241
 
EXTERN int FileLockWriteFile(FILELOCK_FILE_HANDLE handle,
242
 
                             void *buf,
243
 
                             uint32 requestedBytes,
244
 
                             uint32 *resultantBytes);
245
 
 
246
 
EXTERN void *FileLockIntrinsic(ConstUnicode filePathName,
247
 
                               Bool exclusivity,
248
 
                               uint32 msecMaxWaitTime,
249
 
                               const char *payload,
250
 
                               int *err);
251
 
 
252
 
EXTERN int FileUnlockIntrinsic(ConstUnicode filePathName,
253
 
                               const void *lockToken);
254
 
 
255
 
EXTERN Bool FileLockIsLocked(ConstUnicode filePath,
256
 
                             int *err);
257
 
 
258
 
EXTERN Bool FileLockValidOwner(const char *executionID,
259
 
                               const char *payload);
260
 
 
261
 
EXTERN Bool FileLockValidName(ConstUnicode fileName);
262
 
 
263
 
EXTERN Bool FileIsWritableDir(ConstUnicode dirName);
 
211
uint32 FileSleeper(uint32 msecMinSleepTime,
 
212
                   uint32 msecMaxSleepTime);
 
213
 
 
214
uint32 FileSimpleRandom(void);
 
215
 
 
216
const char *FileLockGetMachineID(void);
 
217
 
 
218
char *FileLockGetExecutionID(void);
 
219
 
 
220
Bool FileLockMachineIDMatch(char *host,
 
221
                            char *second);
 
222
 
 
223
int FileLockMemberValues(ConstUnicode lockDir, 
 
224
                         ConstUnicode fileName,
 
225
                         char *buffer,
 
226
                         uint32 size,
 
227
                         LockValues *memberValues);
 
228
 
 
229
int FileLockHackVMX(ConstUnicode filePathName);
 
230
 
 
231
int FileLockOpenFile(ConstUnicode pathName,
 
232
                     int flags,
 
233
                     FILELOCK_FILE_HANDLE *handle);
 
234
 
 
235
int FileLockCloseFile(FILELOCK_FILE_HANDLE handle);
 
236
 
 
237
int FileLockReadFile(FILELOCK_FILE_HANDLE handle,
 
238
                     void *buf,
 
239
                     uint32 requestedBytes,
 
240
                     uint32 *resultantBytes);
 
241
 
 
242
int FileLockWriteFile(FILELOCK_FILE_HANDLE handle,
 
243
                      void *buf,
 
244
                      uint32 requestedBytes,
 
245
                      uint32 *resultantBytes);
 
246
 
 
247
FileLockToken *FileLockIntrinsic(ConstUnicode filePathName,
 
248
                                 Bool exclusivity,
 
249
                                 uint32 msecMaxWaitTime,
 
250
                                 const char *payload,
 
251
                                 int *err);
 
252
 
 
253
int FileUnlockIntrinsic(FileLockToken *tokenPtr);
 
254
 
 
255
Bool FileLockIsLocked(ConstUnicode filePath,
 
256
                      int *err);
 
257
 
 
258
Bool FileLockValidOwner(const char *executionID,
 
259
                        const char *payload);
 
260
 
 
261
Bool FileLockValidName(ConstUnicode fileName);
 
262
 
 
263
Bool FileIsWritableDir(ConstUnicode dirName);
 
264
 
 
265
 
 
266
/*
 
267
 * FileIOAligned_* are useful on hosted platforms where malloc/memalign/valloc
 
268
 * for "large buffers" (in the range 64 KiB - 1 MiB) will generally fall
 
269
 * through to mmap/munmap, which is expensive due to page table modifications
 
270
 * and the attendant TLB flushing (which requires IPIs and possibly world
 
271
 * switches) on other threads running in the same address space.  In particular,
 
272
 * on Mac OS 10.6.6 on a Westmere-class Mac Pro, mmap + memcpy + munmap adds
 
273
 * around a millisecond of CPU time and a hundred IPIs to a 512 KiB write.  See
 
274
 * PR#685845.
 
275
 *
 
276
 * This isn't applicable to ESX because
 
277
 * 1. we don't use this path for disk IO
 
278
 * 2. we don't want to do extra large allocations
 
279
 * 3. we don't have the same alignment constraints
 
280
 * so simply define it away to nothing.
 
281
 *
 
282
 * Tools is another case, we can use this path for IO but we don't want to add
 
283
 * MXUserExclLock dependencies.
 
284
 */
 
285
 
 
286
#if defined(VMX86_TOOLS) || defined(VMX86_SERVER)
 
287
#define FileIOAligned_PoolInit()     /* nothing */
 
288
#define FileIOAligned_PoolExit()     /* nothing */
 
289
#define FileIOAligned_PoolMalloc(sz) NULL
 
290
#define FileIOAligned_PoolFree(ptr)  FALSE
 
291
#else
 
292
void FileIOAligned_PoolInit(void);
 
293
void FileIOAligned_PoolExit(void);
 
294
void *FileIOAligned_PoolMalloc(size_t);
 
295
Bool FileIOAligned_PoolFree(void *);
 
296
#endif
 
297
 
 
298
static INLINE void *
 
299
FileIOAligned_Malloc(size_t sz)  // IN:
 
300
{
 
301
   void *buf = FileIOAligned_PoolMalloc(sz);
 
302
 
 
303
   if (!buf) {
 
304
      buf = Aligned_Malloc(sz);
 
305
   }
 
306
   return buf;
 
307
}
 
308
 
 
309
static INLINE void
 
310
FileIOAligned_Free(void *ptr)  // IN:
 
311
{
 
312
   if (!FileIOAligned_PoolFree(ptr)) {
 
313
      Aligned_Free(ptr);
 
314
   }
 
315
}
264
316
 
265
317
#if defined(__APPLE__)
266
 
EXTERN int PosixFileOpener(ConstUnicode pathName,
267
 
                           int flags,
268
 
                           mode_t mode);
 
318
int PosixFileOpener(ConstUnicode pathName,
 
319
                    int flags,
 
320
                    mode_t mode);
269
321
#else
270
322
#define PosixFileOpener(a, b, c) Posix_Open(a, b, c);
271
323
#endif