summaryrefslogtreecommitdiff
path: root/open-vm-tools/lib/include/file.h
blob: db60e6888ed3aa00cf9c4ebd67d4e6dae129d947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*********************************************************
 * Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation version 2.1 and no later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *********************************************************/

/*
 * file.h --
 *
 *	Interface to host file system and related utility functions.
 */

#ifndef _FILE_H_
#define _FILE_H_

#ifdef __cplusplus
extern "C"{
#endif

#include <stdio.h>
#define INCLUDE_ALLOW_USERLEVEL
#define INCLUDE_ALLOW_VMCORE
#include "includeCheck.h"

#include "fileIO.h"
#include "unicodeTypes.h"
#include "err.h"

#if defined(_WIN32)
#define FILE_MAXPATH	MAX_PATH
#else
# ifdef __FreeBSD__
#  include <sys/param.h> // For __FreeBSD_version
# endif
# if defined(__FreeBSD__)
#  include <sys/syslimits.h>  // PATH_MAX
# else
#  include <limits.h>  // PATH_MAX
# endif
#define FILE_MAXPATH	PATH_MAX
#endif

#define FILE_SEARCHPATHTOKEN ";"


/*
 * Opaque, platform-specific stucture for supporting the directory walking API.
 */

typedef struct WalkDirContextImpl WalkDirContextImpl;
typedef const WalkDirContextImpl *WalkDirContext;

/*
 * When File_MakeTempEx2 is called, it creates a temporary file or a directory
 * in a specified directory. File_MakeTempEx2 calls a user-specified callback
 * function to get the filename. Callback function should be of type
 * File_MakeTempCreateNameFunc.
 *
 * 'num' specifies nth time this function is called.
 *
 * 'data' specifies the payload that the user specified when executing
 * File_MakeTempEx2 function.
 *
 * If successful, this function should return a dynamically allocated string
 * with the filename.
 *
 * File_MakeTempEx2 frees the pathName after a successful call to this
 * function.
 *
 */

typedef Unicode File_MakeTempCreateNameFunc(uint32 num,
                                            void *data);

#if defined(__APPLE__)
typedef enum {
   FILEMACOS_UNMOUNT_SUCCESS,
   FILEMACOS_UNMOUNT_SUCCESS_ALREADY,
   FILEMACOS_UNMOUNT_ERROR,
} FileMacosUnmountStatus;

FileMacosUnmountStatus FileMacos_UnmountDev(char const *bsdDev,
                                            Bool wholeDev,
                                            Bool eject,
                                            Bool su);

void FileMacos_MountDevAsyncNoResult(char const *bsdDev,
                                     Bool su);

Bool FileMacos_IsOnExternalDevice(int fd);
Bool FileMacos_IsOnSparseDmg(int fd);
Bool FileMacos_IsSliceDevice(char const *bsdDev);

char *FileMacos_DiskDevToUserFriendlyName(char const *bsdDiskDev);
char *FileMacos_DiskDevToVolumeName(char const *bsdDiskDev);

char *FileMacos_DiskDeviceToUniqueID(char const *bsdPath);
char *FileMacos_UniqueIDToDiskDevice(char const *identifier);
Bool FileMacOS_MakeSecureLibraryCopies(const char   *inDir,
                                       const char  **dylibName,
                                       unsigned      numDylibs,
                                       char        **outDir);
#elif defined VMX86_SERVER
struct FS_PartitionListResult;

int File_GetVMFSAttributes(ConstUnicode pathName,
                           struct FS_PartitionListResult **fsAttrs);
int File_GetVMFSFSType(ConstUnicode pathName,
                       int fd,
                       uint16 *fsTypeNum);
int File_GetVMFSVersion(ConstUnicode pathName,
                        uint32 *versionNum);
int File_GetVMFSBlockSize(ConstUnicode pathName,
                          uint32 *blockSize);

int File_GetVMFSMountInfo(ConstUnicode pathName,
                          char **fsType,
                          uint32 *version,
                          char **remoteIP,
                          char **remoteMountPoint,
                          char **localMountPoint);
#endif

Bool File_SupportsZeroedThick(ConstUnicode pathName);

Bool File_SupportsMultiWriter(ConstUnicode pathName);

Bool File_SupportsMandatoryLock(ConstUnicode pathName);

Bool File_Exists(ConstUnicode pathName);

int File_Unlink(ConstUnicode pathName);

int File_UnlinkIfExists(ConstUnicode pathName);

int File_UnlinkDelayed(ConstUnicode pathName);

int File_UnlinkNoFollow(ConstUnicode pathName);

void File_SplitName(ConstUnicode pathName,
                    Unicode *volume,
                    Unicode *dir,
                    Unicode *base);

void File_GetPathName(ConstUnicode fullPath,
                      Unicode *pathName,
                      Unicode *base);

Unicode File_StripSlashes(ConstUnicode path);

Unicode File_PathJoin(ConstUnicode dirName,
                      ConstUnicode baseName);

Bool File_CreateDirectory(ConstUnicode pathName);

Bool File_CreateDirectoryEx(ConstUnicode pathName, int mask);

Bool File_EnsureDirectory(ConstUnicode pathName);

Bool File_DeleteEmptyDirectory(ConstUnicode pathName);

Bool File_CreateDirectoryHierarchy(ConstUnicode pathName,
                                   Unicode *topmostCreated);

Bool File_CreateDirectoryHierarchyEx(ConstUnicode pathName,
                                     int mask,
                                     Unicode *topmostCreated);

Bool File_DeleteDirectoryTree(ConstUnicode pathName);

int File_ListDirectory(ConstUnicode pathName,
                       Unicode **ids);

Bool File_IsOsfsVolumeEmpty(ConstUnicode pathName);

/*
 * Simple file-system walk.
 */

WalkDirContext File_WalkDirectoryStart(ConstUnicode parentPath);

Bool File_WalkDirectoryNext(WalkDirContext context,
                            Unicode *path);

void File_WalkDirectoryEnd(WalkDirContext context);

Bool File_IsDirectory(ConstUnicode pathName);

Bool File_IsFile(ConstUnicode pathName);

Bool File_IsSymLink(ConstUnicode pathName);

Bool File_IsCharDevice(ConstUnicode pathName);

Bool File_GetParent(Unicode *canPath);

Bool File_IsRemote(ConstUnicode pathName);

Bool File_IsEmptyDirectory(ConstUnicode pathName);

Unicode File_Cwd(ConstUnicode drive); // XXX belongs to `process' module

Unicode File_FullPath(ConstUnicode pathName);

Bool File_IsFullPath(ConstUnicode pathName);

uint64 File_GetFreeSpace(ConstUnicode pathName,
                         Bool doNotAscend);

uint64 File_GetCapacity(ConstUnicode pathName);

int File_MakeTempEx(ConstUnicode dir,
                    ConstUnicode pathName,
                    Unicode *presult);

int File_MakeTempEx2(ConstUnicode dir,
                     Bool createTempFile,
                     File_MakeTempCreateNameFunc *createNameFunc,
                     void *createFuncData,
                     Unicode *presult);

Unicode File_MakeSafeTempDir(ConstUnicode prefix);

int64 File_GetModTime(ConstUnicode pathName);

char *File_GetModTimeString(ConstUnicode pathName);

char *File_GetUniqueFileSystemID(const char *pathName);

#ifdef _WIN32
Unicode File_GetVolumeGUID(ConstUnicode pathName);
#endif

Bool File_GetTimes(ConstUnicode pathName,
                   VmTimeType *createTime,
                   VmTimeType *accessTime,
                   VmTimeType *writeTime,
                   VmTimeType *attrChangeTime);

Bool File_SetTimes(ConstUnicode pathName,
                   VmTimeType createTime,
                   VmTimeType accessTime,
                   VmTimeType writeTime,
                   VmTimeType attrChangeTime);

Bool File_GetFilePermissions(ConstUnicode pathName,
                            int *mode);

Bool File_SetFilePermissions(ConstUnicode pathName,
                             int mode);

Bool File_SupportsFileSize(ConstUnicode pathName,
                           uint64 fileSize);

Bool File_GetMaxFileSize(ConstUnicode pathName,
                         uint64 *maxFileSize);

Bool File_SupportsLargeFiles(ConstUnicode pathName);

char *File_MapPathPrefix(const char *oldPath,
                         const char **oldPrefixes,
                         const char **newPrefixes,
                         size_t numPrefixes);

Bool File_CopyFromFdToFd(FileIODescriptor src,
                         FileIODescriptor dst);

FileIOResult File_CreatePrompt(FileIODescriptor *file,
                               ConstUnicode pathName,
                               int access,
                               int prompt);

Bool File_CopyFromFd(FileIODescriptor src,
                     ConstUnicode dstName,
                     Bool overwriteExisting);

Bool File_Copy(ConstUnicode srcName,
               ConstUnicode dstName,
               Bool overwriteExisting);

Bool File_CopyFromFdToName(FileIODescriptor src,
                           ConstUnicode dstName,
                           int dstDispose);

Bool File_CopyFromNameToName(ConstUnicode srcName,
                             ConstUnicode dstName,
                             int dstDispose);

Bool File_MoveTree(ConstUnicode srcName,
                   ConstUnicode dstName,
                   Bool overwriteExisting,
                   Bool *asMove);

Bool File_CopyTree(ConstUnicode srcName,
                   ConstUnicode dstName,
                   Bool overwriteExisting,
                   Bool followSymlinks);

Bool File_Replace(ConstUnicode oldFile,
                  ConstUnicode newFile);

int File_Rename(ConstUnicode oldFile,
                ConstUnicode newFile);

int File_RenameRetry(ConstUnicode oldFile,
                     ConstUnicode newFile,
                     uint32 msecMaxWaitTime);

Bool File_Move(ConstUnicode oldFile,
               ConstUnicode newFile,
               Bool *asRename);

void File_Rotate(const char *pathName,
                 int n,
                 Bool noRename,
                 char **newFileName);

int File_GetFSMountInfo(ConstUnicode pathName,
                        char **fsType,
                        uint32 *version,
                        char **remoteIP,
                        char **remoteMountPoint,
                        char **localMountPoint);

/* Get size only for regular file. */
int64 File_GetSize(ConstUnicode pathName);

/* Get size for file or directory. */
int64 File_GetSizeEx(ConstUnicode pathName);

int64 File_GetSizeByPath(ConstUnicode pathName);

int64 File_GetSizeAlternate(ConstUnicode pathName);

/* file change notification module */
typedef void (*CbFunction)(void *clientData);

typedef void (*NotifyCallback)(ConstUnicode pathName,
                               int err,
                               void *data);

typedef void (*PollTimeout) (CbFunction f,
                             void *clientData,
                             int delay);

typedef void (*PollRemoveTimeout) (CbFunction f,
                                   void *clientData);

void File_PollInit(PollTimeout pt,
                   PollRemoveTimeout prt);

void File_PollExit(void);

void File_PollImpersonateOnCheck(Bool check);

Bool File_PollAddFile(ConstUnicode pathName,
                      uint32 pollPeriod,
                      NotifyCallback callback,
                      void *data,
                      Bool fPeriodic);

Bool File_PollAddDirFile(ConstUnicode pathName,
                         uint32 pollPeriod,
                         NotifyCallback callback,
                         void *data,
                         Bool fPeriodic);

Bool File_PollRemoveFile(ConstUnicode pathName,
                         uint32 pollPeriod,
                         NotifyCallback callback);

Bool File_IsSameFile(ConstUnicode path1,
                     ConstUnicode path2);

char *File_PrependToPath(const char *searchPath,
                         const char *elem);

Bool File_FindFileInSearchPath(const char *file,
                               const char *searchPath,
                               const char *cwd,
                               char **result);

Unicode File_ReplaceExtension(ConstUnicode pathName,
                              ConstUnicode newExtension,
                              uint32 numExtensions,
                              ...);

Unicode File_RemoveExtension(ConstUnicode pathName);

Bool File_MakeCfgFileExecutable(ConstUnicode pathName);

char *File_ExpandAndCheckDir(const char *dirName);

char *File_GetSafeTmpDir(Bool useConf);

int File_MakeSafeTemp(ConstUnicode tag,
                      Unicode *presult);

Bool File_DoesVolumeSupportAcls(ConstUnicode pathName);

#ifdef __cplusplus
} // extern "C" {
#endif

#endif // ifndef _FILE_H_