func createDiskImage(dest string, size int, r io.Reader) error {
	// Convert a raw image from stdin to the dest VMDK image.
	sizeBytes := int64(size) << 20 // usually won't fit in 32-bit int (max 2GB)
	// FIXME: why isn't this just using the vbm*() functions?
	cmd := exec.Command(vboxManageCmd, "convertfromraw", "stdin", dest,
		fmt.Sprintf("%d", sizeBytes), "--format", "VMDK")

	log.Debug(cmd)

	if os.Getenv("MACHINE_DEBUG") != "" {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
	}

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return err
	}

	log.Debug("Starting command")

	if err := cmd.Start(); err != nil {
		return err
	}

	log.Debug("Copying to stdin")

	n, err := io.Copy(stdin, r)
	if err != nil {
		return err
	}

	log.Debug("Filling zeroes")

	// The total number of bytes written to stdin must match sizeBytes, or
	// VBoxManage.exe on Windows will fail. Fill remaining with zeros.
	if left := sizeBytes - n; left > 0 {
		if err := zeroFill(stdin, left); err != nil {
			return err
		}
	}

	log.Debug("Closing STDIN")

	// cmd won't exit until the stdin is closed.
	if err := stdin.Close(); err != nil {
		return err
	}

	log.Debug("Waiting on cmd")

	return cmd.Wait()
}
func createDiskImage(dest string, size int, r io.Reader) error {
	
	sizeBytes := int64(size) << 20 
	
	cmd := exec.Command(vboxManageCmd, "convertfromraw", "stdin", dest,
		fmt.Sprintf("%d", sizeBytes), "--format", "VMDK")

	log.Debug(cmd)

	if os.Getenv("MACHINE_DEBUG") != "" {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
	}

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return err
	}

	log.Debug("Starting command")

	if err := cmd.Start(); err != nil {
		return err
	}

	log.Debug("Copying to stdin")

	n, err := io.Copy(stdin, r)
	if err != nil {
		return err
	}

	log.Debug("Filling zeroes")

	
	
	if left := sizeBytes - n; left > 0 {
		if err := zeroFill(stdin, left); err != nil {
			return err
		}
	}

	log.Debug("Closing STDIN")

	
	if err := stdin.Close(); err != nil {
		return err
	}

	log.Debug("Waiting on cmd")

	return cmd.Wait()
}
func createDiskImage ( dest string , size int , r io . Reader ) error { // Convert a raw image from stdin to the dest VMDK image. sizeBytes := int64 ( size ) << 20 // usually won't fit in 32-bit int (max 2GB) // FIXME: why isn't this just using the vbm*() functions? cmd := exec . Command ( vboxManageCmd , " " , " " , dest , fmt . Sprintf ( " " , sizeBytes ) , " " , " " ) log . Debug ( cmd ) if os . Getenv ( " " ) != " " { cmd . Stdout = os . Stdout cmd . Stderr = os . Stderr } stdin , err := cmd . StdinPipe ( ) if err != nil { return err } log . Debug ( " " ) if err := cmd . Start ( ) ; err != nil { return err } log . Debug ( " " ) n , err := io . Copy ( stdin , r ) if err != nil { return err } log . Debug ( " " ) // The total number of bytes written to stdin must match sizeBytes, or // VBoxManage.exe on Windows will fail. Fill remaining with zeros. if left := sizeBytes - n ; left > 0 { if err := zeroFill ( stdin , left ) ; err != nil { return err } } log . Debug ( " " ) // cmd won't exit until the stdin is closed. if err := stdin . Close ( ) ; err != nil { return err } log . Debug ( " " ) return cmd . Wait ( ) }
// createDiskImage makes a disk image at dest with the given size in MB. If r is
// not nil, it will be read as a raw disk image to convert from.
createDiskImage makes a disk image at dest with the given size in MB . If r is not nil it will be read as a raw disk image to convert from .