func MountsForDevices()

in plugins/internal/mount/device_mounts.go [33:69]


func MountsForDevices(devices []*discovery.Device) []*pluginapi.Mount {

	mounts := []*pluginapi.Mount{}

	for _, device := range devices {

		// Generates the mounts for a list of runtime files
		generateMounts := func(files []*discovery.RuntimeFile, destinationRoot string) {
			for _, file := range files {

				// Resolve the absolute paths to the host source file and the container destination file
				source := filepath.Join(device.DriverStorePath, file.SourcePath)
				destination := filepath.Join(destinationRoot, file.DestinationFilename)

				// Only mount the file if it exists on the host and can be accessed, and isn't a duplicate
				// (Note that duplicate container paths can occur not only when mounting multiple devices
				// from a single vendor, but also when device drivers from different vendors mount files
				// to the same target path, which means that a container will only see the files from the
				// first device's vendor when collisions occur between different device drivers)
				_, err := os.Stat(source)
				if err == nil {
					mounts = appendUniqueMount(mounts, &pluginapi.Mount{
						HostPath:      source,
						ContainerPath: destination,
						ReadOnly:      true,
					})
				}
			}
		}

		// Generate the mounts for both the System32 and SysWOW64 runtime files
		generateMounts(device.RuntimeFiles, "C:\\Windows\\System32")
		generateMounts(device.RuntimeFilesWow64, "C:\\Windows\\SysWOW64")
	}

	return mounts
}