1// +build windows
2
3/*
4Copyright 2019 The Kubernetes Authors.
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17*/
18
19package mounttest
20
21import (
22	"bytes"
23	"fmt"
24	"os"
25	"os/exec"
26	"strconv"
27	"strings"
28)
29
30func umask(mask int) int {
31	// noop for Windows.
32	return 0
33}
34
35func fileOwner(path string) error {
36	// Windows does not have owner UID / GID. However, it has owner SID.
37	// not currently implemented in Kubernetes, so noop.
38	return nil
39}
40
41func fileMode(path string) error {
42	if path == "" {
43		return nil
44	}
45
46	permissions, err := getFilePerm(path)
47	if err != nil {
48		return err
49	}
50
51	fmt.Printf("mode of Windows file %q: %v\n", path, permissions)
52	return nil
53}
54
55func filePerm(path string) error {
56	if path == "" {
57		return nil
58	}
59
60	permissions, err := getFilePerm(path)
61	if err != nil {
62		return err
63	}
64
65	fmt.Printf("perms of Windows file %q: %v\n", path, permissions)
66	return nil
67}
68
69func getFilePerm(path string) (os.FileMode, error) {
70	var (
71		out    bytes.Buffer
72		errOut bytes.Buffer
73	)
74
75	cmd := exec.Command("powershell.exe", "-NonInteractive", "./filePermissions.ps1",
76		"-FileName", path)
77	cmd.Stdout = &out
78	cmd.Stderr = &errOut
79	err := cmd.Run()
80
81	if err != nil {
82		fmt.Printf("error from PowerShell Script: %v, %v\n", err, errOut.String())
83		return 0, err
84	}
85
86	output := strings.TrimSpace(out.String())
87	val, err := strconv.ParseInt(output, 8, 32)
88	if err != nil {
89		fmt.Printf("error parsing string '%s' as int: %v\n", output, err)
90		return 0, err
91	}
92
93	return os.FileMode(val), nil
94}
95
96func fsType(path string) error {
97	// only NTFS is supported at the moment.
98	return nil
99}
100