]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: remove more unnecessary COS support code
authorVMware, Inc <>
Mon, 22 Mar 2010 19:15:08 +0000 (12:15 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 22 Mar 2010 19:15:08 +0000 (12:15 -0700)
A few more COS support pieces that can be removed. Also remove
an "ifdef VMX86_SERVER" as a dynamic check can now be used.

With this change all of the COS support pieces are out and quite
a few improvements are in (i.e. far less "ifdef VMX86_SERVER").

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/file/filePosix.c
open-vm-tools/lib/include/vmfs.h [new file with mode: 0644]

index 3d83e4b4a16843421b6bc78ee5d20f666fa4956f..1ef972bf6ce81a2b9e0130c7227074e3f4710b73 100644 (file)
@@ -67,6 +67,7 @@
 #include "dynbuf.h"
 #include "localconfig.h"
 #include "hostType.h"
+#include "vmfs.h"
 
 #include "unicodeOperations.h"
 
@@ -1029,95 +1030,16 @@ File_GetFreeSpace(ConstUnicode pathName,  // IN: File name
 
    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;
@@ -1457,38 +1379,39 @@ File_GetCapacity(ConstUnicode pathName)  // IN: Path name
 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);
 }
diff --git a/open-vm-tools/lib/include/vmfs.h b/open-vm-tools/lib/include/vmfs.h
new file mode 100644 (file)
index 0000000..937b9bf
--- /dev/null
@@ -0,0 +1,120 @@
+
+/*********************************************************
+ * 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__ */
+