#include "dynbuf.h"
#include "localconfig.h"
#include "hostType.h"
+#include "vmfs.h"
#include "unicodeOperations.h"
fullPath = File_FullPath(pathName);
if (fullPath == NULL) {
- ret = -1;
- goto end;
+ return -1;
}
- if (!FileGetStats(fullPath, doNotAscend, &statfsbuf)) {
+ if (FileGetStats(fullPath, doNotAscend, &statfsbuf)) {
+ ret = (uint64) statfsbuf.f_bavail * statfsbuf.f_bsize;
+ } else {
Warning("%s: Couldn't statfs %s\n", __func__, fullPath);
ret = -1;
- goto end;
- }
-
- ret = (uint64) statfsbuf.f_bavail * statfsbuf.f_bsize;
-
-#if defined(VMX86_SERVER)
- /*
- * The following test is never true on VMvisor but we do not care as
- * this is only intended for callers going through vmkfs. Direct callers
- * as we are always get the right answer from statfs above.
- */
-
- if (statfsbuf.f_type == VMFS_MAGIC_NUMBER) {
- int fd;
- FS_FreeSpaceArgs args = { 0 };
- Unicode specialPath = NULL;
-
- /*
- * If the file exists and can be opened we're all set. If the file
- * doesn't exist we can use the parent directory for the ioctl.
- * However, if the file exists and can't be opened (e.g. permissions
- * issues) a correct answer can only be returned if the target isn't a
- * directory. If the target is a directory its parent may be a mount
- * point - leading across a mount point to a different file system.
- * PR 412387
- */
-
- ret = -1;
-
- fd = Posix_Open(fullPath, O_RDONLY, 0);
-
- if (fd == -1) {
- switch (errno) {
- case EPERM:
- case EACCES:
- {
- int err = errno;
- struct stat statbuf;
-
- if (Posix_Stat(fullPath, &statbuf) == -1) {
- errno = err;
- break;
- }
-
- if (S_ISDIR(statbuf.st_mode)) {
- Warning(LGPFX" %s: directory (%s) present but inaccessible\n",
- __func__, UTF8(fullPath));
- errno = err;
- break;
- }
- }
- /* FALLTHROUGH */
-
- case ENOENT:
- default:
- File_SplitName(fullPath, NULL, &specialPath, NULL);
-
- fd = Posix_Open(specialPath, O_RDONLY, 0);
- }
- }
-
- if (fd == -1) {
- Warning(LGPFX" %s: open of %s failed with: %s\n", __func__,
- (specialPath == NULL) ? UTF8(fullPath) : UTF8(specialPath),
- Msg_ErrString());
- } else {
- if (ioctl(fd, IOCTLCMD_VMFS_GET_FREE_SPACE, &args) == -1) {
- Warning(LGPFX" %s: ioctl on %s failed with: %s\n", __func__,
- (specialPath == NULL) ? UTF8(fullPath) : UTF8(specialPath),
- Msg_ErrString());
- } else {
- ret = args.bytesFree;
- }
-
- close(fd);
- }
-
- Unicode_Free(specialPath);
}
-#endif
-end:
Unicode_Free(fullPath);
return ret;
char *
File_GetUniqueFileSystemID(char const *path) // IN: File path
{
-#if defined(VMX86_SERVER)
- char *canPath;
- char *existPath;
+ if (HostType_OSIsVMK()) {
+ char *canPath;
+ char *existPath;
- existPath = FilePosixNearestExistingAncestor(path);
- canPath = Posix_RealPath(existPath);
- free(existPath);
+ existPath = FilePosixNearestExistingAncestor(path);
+ canPath = Posix_RealPath(existPath);
+ free(existPath);
- if (canPath == NULL) {
- return NULL;
- }
+ if (canPath == NULL) {
+ return NULL;
+ }
- /*
- * VCFS doesn't have real mount points, so the mount point lookup below
- * returns "/vmfs", instead of the VCFS mount point.
- *
- * See bug 61646 for why we care.
- */
+ /*
+ * VCFS doesn't have real mount points, so the mount point lookup below
+ * returns "/vmfs", instead of the VCFS mount point.
+ *
+ * See bug 61646 for why we care.
+ */
- if (strncmp(canPath, VCFS_MOUNT_POINT, strlen(VCFS_MOUNT_POINT)) == 0) {
- char vmfsVolumeName[FILE_MAXPATH];
+ if (strncmp(canPath, VCFS_MOUNT_POINT, strlen(VCFS_MOUNT_POINT)) == 0) {
+ char vmfsVolumeName[FILE_MAXPATH];
- if (sscanf(canPath, VCFS_MOUNT_PATH "%[^/]%*s", vmfsVolumeName) == 1) {
- free(canPath);
+ if (sscanf(canPath, VCFS_MOUNT_PATH "%[^/]%*s",
+ vmfsVolumeName) == 1) {
+ free(canPath);
- return Str_SafeAsprintf(NULL, "%s/%s", VCFS_MOUNT_POINT,
- vmfsVolumeName);
+ return Str_SafeAsprintf(NULL, "%s/%s", VCFS_MOUNT_POINT,
+ vmfsVolumeName);
+ }
}
- }
- free(canPath);
-#endif
+ free(canPath);
+ }
return FilePosixGetBlockDevice(path);
}
--- /dev/null
+
+/*********************************************************
+ * Copyright (C) 2003 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.
+ *
+ *********************************************************/
+
+/*
+ * vmfs.h --
+ *
+ * assorted vmfs related helper functions needed by userlevel.
+ */
+
+#ifndef __VMFS_H__
+#define __VMFS_H__
+
+#define INCLUDE_ALLOW_USERLEVEL
+#define INCLUDE_ALLOW_VMKERNEL
+#include "includeCheck.h"
+
+#include "unicodeTypes.h"
+
+// Consolidate all path stuff here so it's consistent between user and kernel
+#define VMFS_ROOT_DIR_NAME "vmfs"
+#define VMFS_ROOT_DIR_PATH "/vmfs/"
+
+#define DEVFS_DIR_NAME "devices"
+#define VCFS_DIR_NAME "volumes"
+#define DELTADISK_DIR_NAME "deltadisks"
+#define CBT_DIR_NAME "cbt"
+#define MULTI_EXTENT_DIR_NAME "multiextent"
+#define FILE_DIR_NAME "file"
+#define RAMDISK_DIR_NAME "ramdisk"
+#define SVM_DIR_NAME "svm"
+
+#define DEVFS_MOUNT_POINT VMFS_ROOT_DIR_PATH DEVFS_DIR_NAME
+#define VCFS_MOUNT_POINT VMFS_ROOT_DIR_PATH VCFS_DIR_NAME
+
+#define DEVFS_MOUNT_PATH DEVFS_MOUNT_POINT "/"
+#define VCFS_MOUNT_PATH VCFS_MOUNT_POINT "/"
+
+#define DELTADISK_MOUNT_POINT DEVFS_MOUNT_PATH DELTADISK_DIR_NAME
+#define DELTADISK_MOUNT_PATH DELTADISK_MOUNT_POINT "/"
+
+#define CBT_MOUNT_POINT DEVFS_MOUNT_PATH CBT_DIR_NAME
+#define CBT_MOUNT_PATH CBT_MOUNT_POINT "/"
+
+#define FILE_MOUNT_POINT DEVFS_MOUNT_PATH FILE_DIR_NAME
+#define FILE_MOUNT_PATH FILE_MOUNT_POINT "/"
+
+#define RAMDISK_MOUNT_POINT DEVFS_MOUNT_PATH RAMDISK_DIR_NAME
+#define RAMDISK_MOUNT_PATH RAMDISK_MOUNT_POINT "/"
+
+#define SVM_MOUNT_POINT DEVFS_MOUNT_PATH SVM_DIR_NAME
+#define SVM_MOUNT_PATH SVM_MOUNT_POINT "/"
+
+#define CDROM_DRIVER_STRING "cdrom"
+#define SCSI_DISK_DRIVER_STRING "disks"
+#define SCSI_GENERIC_DRIVER_STRING "genscsi"
+#define OLD_SCSI_GENERIC_DRIVER_STRING "generic"
+#define COW_DRIVER_NAME "deltadisks"
+#define MULTI_EXTENT_DRIVER_NAME "multiextent"
+
+#define CDROM_MOUNT_POINT DEVFS_MOUNT_PATH CDROM_DRIVER_STRING
+#define DISKS_MOUNT_POINT DEVFS_MOUNT_PATH SCSI_DISK_DRIVER_STRING
+#define GENERIC_SCSI_MOUNT_POINT DEVFS_MOUNT_PATH SCSI_GENERIC_DRIVER_STRING
+#define MULTI_EXTENT_MOUNT_POINT DEVFS_MOUNT_PATH MULTI_EXTENT_DIR_NAME
+#define CDROM_MOUNT_PATH CDROM_MOUNT_POINT "/"
+#define DISKS_MOUNT_PATH DISKS_MOUNT_POINT "/"
+#define GENERIC_SCSI_MOUNT_PATH GENERIC_SCSI_MOUNT_POINT "/"
+#define MULTI_EXTENT_MOUNT_PATH MULTI_EXTENT_MOUNT_POINT "/"
+
+#define VISOR_DEVFS_MOUNT_PATH "/dev/"
+#define VISOR_CDROM_MOUNT_POINT VISOR_DEVFS_MOUNT_PATH CDROM_DRIVER_STRING
+#define VISOR_DISKS_MOUNT_POINT VISOR_DEVFS_MOUNT_PATH SCSI_DISK_DRIVER_STRING
+#define VISOR_GENERIC_SCSI_MOUNT_POINT VISOR_DEVFS_MOUNT_PATH SCSI_GENERIC_DRIVER_STRING
+#define VISOR_CDROM_MOUNT_PATH VISOR_CDROM_MOUNT_POINT "/"
+#define VISOR_DISKS_MOUNT_PATH VISOR_DISKS_MOUNT_POINT "/"
+#define VISOR_GENERIC_SCSI_MOUNT_PATH VISOR_GENERIC_SCSI_MOUNT_POINT "/"
+
+typedef enum {
+ VMFS_SYMBOLIC,
+ VMFS_SCSI_DEV,
+ VMFS_COS_SYMBOLIC,
+ VMFS_COS_SCSI_DEV,
+} Vmfs_VolNameType;
+
+#if defined(VMX86_SERVER)
+char *Vmfs_GetCOSFileName(const char *vmfsFile);
+Bool Vmfs_IsVMFSDir(ConstUnicode dir);
+Bool Vmfs_IsVMFSFile(ConstUnicode pathName);
+#else
+
+static INLINE Bool
+Vmfs_IsVMFSDir(ConstUnicode dir)
+{
+ return FALSE;
+}
+
+static INLINE Bool
+Vmfs_IsVMFSFile(ConstUnicode pathName)
+{
+ return FALSE;
+}
+#endif /* VM86_SERVER */
+
+#endif /* __VMFS_H__ */
+