98
#if defined(linux) && !defined(GLIBC_VERSION_21)
100
* Implements the system call (it is not wrapped by glibc 2.1.1)
103
_llseek(unsigned int fd,
104
unsigned long offset_high,
105
unsigned long offset_low,
109
return syscall(SYS__llseek, fd, offset_high, offset_low, result, whence);
114
103
* On Linux, we must wrap getdents64, as glibc does not wrap it for us. We use getdents64
115
104
* (rather than getdents) because with the latter, we'll get 64-bit offsets and inode
160
149
dirp[i].d_off = dirp_temp[i].d_off;
161
150
dirp[i].d_reclen = dirp_temp[i].d_reclen;
162
151
dirp[i].d_type = DT_UNKNOWN;
152
memset(dirp[i].d_name, 0, sizeof dirp->d_name);
163
153
memcpy(dirp[i].d_name, dirp_temp[i].d_name,
164
154
((sizeof dirp->d_name) < (sizeof dirp_temp->d_name))
165
155
? (sizeof dirp->d_name)
173
163
# define getdents getdents_linux
174
#elif defined(__FreeBSD__) || defined(__APPLE__)
164
#elif defined(__FreeBSD__)
175
165
#define getdents(fd, dirp, count) \
178
168
getdirentries(fd, dirp, count, &basep); \
170
#elif defined(__APPLE__)
172
getdents_apple(DIR *fd, // IN
173
DirectoryEntry *dirp, // OUT
174
unsigned int count) // IN: ignored
177
struct dirent *dirEntry;
178
dirEntry = readdir(fd);
179
if (NULL != dirEntry) {
180
memcpy(dirp, dirEntry, dirEntry->d_reclen);
181
res = dirEntry->d_reclen;
185
# define getdents getdents_apple
748
748
* file name still refers to the same pair
751
#if defined(__APPLE__)
753
* Can't use Posix_Stat because of inconsistent definition
754
* of _DARWIN_USE_64_BIT_INODE in this file and in other libraries.
756
if (stat(localName, &nodeStat) < 0) {
751
758
if (Posix_Stat(localName, &nodeStat) < 0) {
752
760
int error = errno;
754
762
LOG(4, ("%s: couldn't stat local file \"%s\": %s\n", __FUNCTION__,
1910
#if defined(__APPLE__)
1912
*-----------------------------------------------------------------------------
1914
* HgfsConvertStat64ToStat --
1916
* Helper function that converts data in stat64 format into stat format.
1917
* It returns creationTime in HGFS platform independent format.
1925
*-----------------------------------------------------------------------------
1929
HgfsConvertStat64ToStat(const struct stat64 *stats64, // IN: data in stat64 format
1930
struct stat *stats, // OUT: data in stat format
1931
uint64 *creationTime) // OUT: creation time
1933
stats->st_dev = stats64->st_dev;
1934
stats->st_ino = stats64->st_ino;
1935
stats->st_mode = stats64->st_mode;
1936
stats->st_nlink = stats64->st_nlink;
1937
stats->st_uid = stats64->st_uid;
1938
stats->st_gid = stats64->st_gid;
1939
stats->st_rdev = stats64->st_rdev;
1940
stats->st_atimespec = stats64->st_atimespec;
1941
stats->st_mtimespec = stats64->st_mtimespec;
1942
stats->st_ctimespec = stats64->st_ctimespec;
1943
stats->st_size = stats64->st_size;
1944
stats->st_blocks = stats64->st_blocks;
1945
stats->st_blksize = stats64->st_blksize;
1946
stats->st_flags = stats64->st_flags;
1947
stats->st_gen = stats64->st_gen;
1948
*creationTime = HgfsConvertTimeSpecToNtTime(&stats64->st_birthtimespec);
1954
1919
*-----------------------------------------------------------------------------
2027
* Wrapper function that invokes stat64 on Mac OS and stat on Linux (where stat64 is
1993
* Wrapper function that invokes stat on Mac OS and on Linux.
2029
1995
* Returns filled stat structure and a file creation time. File creation time is
2030
1996
* the birthday time for Mac OS and last write time for Linux (which does not support
2031
1997
* file creation time).
2050
2016
#if defined(__APPLE__)
2051
struct stat64 stats64;
2052
2017
if (followLink) {
2053
error = stat64(fileName, &stats64);
2018
error = stat(fileName, stats);
2055
error = lstat64(fileName, &stats64);
2058
HgfsConvertStat64ToStat(&stats64, stats, creationTime);
2020
error = lstat(fileName, stats);
2061
2023
if (followLink) {
2077
* Wrapper function that invokes stat64 on Mac OS and stat on Linux (where stat64 is
2039
* Wrapper function that invokes fstat.
2079
2041
* Returns filled stat structure and a file creation time. File creation time is
2080
2042
* the birthday time for Mac OS and last write time for Linux (which does not support
2081
2043
* file creation time).
2096
2058
uint64 *creationTime) // OUT: file creation time
2099
#if defined(__APPLE__)
2100
struct stat64 stats64;
2101
error = fstat64(fd, &stats64);
2103
HgfsConvertStat64ToStat(&stats64, stats, creationTime);
2106
2061
if (fstat(fd, stats) < 0) {
2109
2064
*creationTime = HgfsGetCreationTime(stats);
3142
/* NOOP on Linux where the name is already has the correct encoding. */
3098
* Buffer may contain invalid data after the null terminating character.
3099
* We need to check the validity of the buffer only till the null
3100
* terminating character (if any). Calculate the real size of the
3101
* string before calling Unicode_IsBufferValid().
3103
for (size = 0; size < bufferSize ; size++) {
3104
if ('\0' == buffer[size]) {
3109
return Unicode_IsBufferValid(buffer, size, STRING_ENCODING_UTF8);
3144
3110
#endif /* defined(__APPLE__) */
3156
3122
* symlinks. Instead, we'll open(2) the directory with O_DIRECTORY and
3157
3123
* O_NOFOLLOW, call getdents(2) directly, then close(2) the directory.
3125
* On Mac OS getdirentries became deprecated starting from 10.6 and
3126
* there is no similar API available. Thus on Mac OS readdir is used that
3127
* returns one directory entry at a time.
3160
3130
* Zero on success. numDents contains the number of directory entries found.
3161
3131
* Non-zero on error.
3173
3143
DirectoryEntry ***dents, // OUT: Array of DirectoryEntrys
3174
3144
int *numDents) // OUT: Number of DirectoryEntrys
3176
int fd = -1, result;
3146
#if defined(__APPLE__)
3150
int openFlags = O_NONBLOCK | O_RDONLY | O_DIRECTORY | O_NOFOLLOW;
3177
3153
DirectoryEntry **myDents = NULL;
3178
3154
int myNumDents = 0;
3179
3155
HgfsInternalStatus status = 0;
3180
int openFlags = O_NONBLOCK | O_RDONLY | O_DIRECTORY | O_NOFOLLOW;
3183
3158
* XXX: glibc uses 8192 (BUFSIZ) when it can't get st_blksize from a stat.
3186
3161
char buffer[8192];
3163
#if defined(__APPLE__)
3165
* Since opendir does not support O_NOFOLLOW flag need to explicitly verify
3166
* that we are not dealing with symlink if follow symlinks is
3169
if (!followSymlinks) {
3171
if (lstat(baseDir, &st) == -1) {
3173
LOG(4, ("%s: error in lstat: %d (%s)\n", __FUNCTION__, status,
3177
if (S_ISLNK(st.st_mode)) {
3179
LOG(4, ("%s: do not follow symlink\n", __FUNCTION__));
3183
fd = Posix_OpenDir(baseDir);
3186
LOG(4, ("%s: error in opendir: %d (%s)\n", __FUNCTION__, status,
3188
3191
/* Follow symlinks if config option is set. */
3189
3192
if (followSymlinks) {
3190
3193
openFlags &= ~O_NOFOLLOW;
3269
#if defined(__APPLE__)
3270
if (NULL != fd && closedir(fd) < 0) {
3265
3272
if (fd != -1 && close(fd) < 0) {
3266
3274
status = errno;
3267
3275
LOG(4, ("%s: error in close: %d (%s)\n", __FUNCTION__, status,
3268
3276
strerror(status)));
3380
#if defined(GLIBC_VERSION_21) || defined(__APPLE__)
3388
#if defined(__linux__) || defined(__APPLE__)
3381
3389
/* Read from the file. */
3382
3390
if (sequentialOpen) {
3383
3391
error = read(fd, payload, requiredSize);
3887
3895
HgfsRenameHint hints) // IN: rename hints
3889
3897
HgfsInternalStatus status = 0;
3892
3899
if (hints & HGFS_RENAME_HINT_NO_REPLACE_EXISTING) {
3893
status = HgfsPlatformFileExists(localTargetName);
3900
if (0 == HgfsPlatformFileExists(localTargetName)) {
3895
3901
status = EEXIST;
3900
LOG(4, ("%s: renaming \"%s\" to \"%s\"\n", __FUNCTION__,
3901
localSrcName, localTargetName));
3902
error = Posix_Rename(localSrcName, localTargetName);
3905
LOG(4, ("%s: error: %s\n", __FUNCTION__, strerror(status)));
3906
LOG(4, ("%s: renaming \"%s\" to \"%s\"\n", __FUNCTION__,
3907
localSrcName, localTargetName));
3908
status = Posix_Rename(localSrcName, localTargetName);
3911
LOG(4, ("%s: error: %s\n", __FUNCTION__, strerror(status)));
4402
4409
* HgfsGetHiddenXAttr --
4404
* Always returns EINVAL since there is no support for invisible files in Linux
4411
* Always returns 0 since there is no support for invisible files in Linux
4408
* Currently always returns EINVAL. Will return 0 when support for invisible files
4409
* is implemented in Linux server.
4415
* 0 always. This is required to allow apps that use the hidden feature to
4416
* continue to work. attribute value is set to FALSE always.
4411
4418
* Side effects:
4428
4436
* HgfsSetHiddenXAttr --
4430
4438
* Sets new value for the invisible attribute of a file.
4431
* Currently Linux server does not support invisible or hiddden files thus
4432
* the function fails when a attempt to mark a file as hidden is made.
4439
* Currently Linux server does not support invisible or hiddden files.
4435
* 0 if succeeded, error code otherwise.
4443
* 0 always. This is required to allow apps that use the hidden feature to
4437
4446
* Side effects: