func OpenRelative(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
	f, err := openRelativeInternal(path, root, accessMask, shareFlags, createDisposition, flags)
	if err != nil {
		err = &os.PathError{Op: "open", Path: filepath.Join(root.Name(), path), Err: err}
	}
	return f, err
}
OpenRelative opens a relative path from the given root, failing if
any of the intermediate path components are reparse points.
package safefile
import (
	"errors"
	"io"
	"os"
	"path/filepath"
	"strings"
	"syscall"
	"unicode/utf16"
	"unsafe"
	"github.com/Microsoft/hcsshim/internal/longpath"
	"github.com/Microsoft/hcsshim/internal/winapi"
	winio "github.com/Microsoft/go-winio"
)
func OpenRoot(path string) (*os.File, error) {
	longpath, err := longpath.LongAbs(path)
	if err != nil {
		return nil, err
	}
	return winio.OpenForBackup(longpath, syscall.GENERIC_READ, syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, syscall.OPEN_EXISTING)
}
func cleanGoStringRelativePath(path string) (string, error) {
	path = filepath.Clean(path)
	if strings.Contains(path, ":") {
		return "", errors.New("path contains invalid character `:`")
	}
	fspath := filepath.FromSlash(path)
	if len(fspath) > 0 && fspath[0] == '\\' {
		return "", errors.New("expected relative path")
	}
	return fspath, nil
}
func ntRelativePath(path string) ([]uint16, error) {
	fspath, err := cleanGoStringRelativePath(path)
	if err != nil {
		return nil, err
	}
	path16 := utf16.Encode(([]rune)(fspath))
	if len(path16) > 32767 {
		return nil, syscall.ENAMETOOLONG
	}
	return path16, nil
}
func openRelativeInternal(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
	var (
		h    uintptr
		iosb winapi.IOStatusBlock
		oa   winapi.ObjectAttributes
	)
	cleanRelativePath, err := cleanGoStringRelativePath(path)
	if err != nil {
		return nil, err
	}
	if root == nil || root.Fd() == 0 {
		return nil, errors.New("missing root directory")
	}
	pathUnicode, err := winapi.NewUnicodeString(cleanRelativePath)
	if err != nil {
		return nil, err
	}
	oa.Length = unsafe.Sizeof(oa)
	oa.ObjectName = pathUnicode
	oa.RootDirectory = uintptr(root.Fd())
	oa.Attributes = winapi.OBJ_DONT_REPARSE
	status := winapi.NtCreateFile(
		&h,
		accessMask|syscall.SYNCHRONIZE,
		&oa,
		&iosb,
		nil,
		0,
		shareFlags,
		createDisposition,
		winapi.FILE_OPEN_FOR_BACKUP_INTENT|winapi.FILE_SYNCHRONOUS_IO_NONALERT|flags,
		nil,
		0,
	)
	if status != 0 {
		return nil, winapi.RtlNtStatusToDosError(status)
	}
	fullPath, err := longpath.LongAbs(filepath.Join(root.Name(), path))
	if err != nil {
		syscall.Close(syscall.Handle(h))
		return nil, err
	}
	return os.NewFile(h, fullPath), nil
}