github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/daemon/graphdriver/lcow/remotefs_filedriver.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  package lcow // import "github.com/docker/docker/daemon/graphdriver/lcow"
     5  
     6  import (
     7  	"bytes"
     8  	"encoding/json"
     9  	"os"
    10  	"strconv"
    11  
    12  	"github.com/Microsoft/opengcs/service/gcsutils/remotefs"
    13  
    14  	"github.com/containerd/continuity/driver"
    15  	"github.com/sirupsen/logrus"
    16  )
    17  
    18  var _ driver.Driver = &lcowfs{}
    19  
    20  func (l *lcowfs) Readlink(p string) (string, error) {
    21  	logrus.Debugf("removefs.readlink args: %s", p)
    22  
    23  	result := &bytes.Buffer{}
    24  	if err := l.runRemoteFSProcess(nil, result, remotefs.ReadlinkCmd, p); err != nil {
    25  		return "", err
    26  	}
    27  	return result.String(), nil
    28  }
    29  
    30  func (l *lcowfs) Mkdir(path string, mode os.FileMode) error {
    31  	return l.mkdir(path, mode, remotefs.MkdirCmd)
    32  }
    33  
    34  func (l *lcowfs) MkdirAll(path string, mode os.FileMode) error {
    35  	return l.mkdir(path, mode, remotefs.MkdirAllCmd)
    36  }
    37  
    38  func (l *lcowfs) mkdir(path string, mode os.FileMode, cmd string) error {
    39  	modeStr := strconv.FormatUint(uint64(mode), 8)
    40  	logrus.Debugf("remotefs.%s args: %s %s", cmd, path, modeStr)
    41  	return l.runRemoteFSProcess(nil, nil, cmd, path, modeStr)
    42  }
    43  
    44  func (l *lcowfs) Remove(path string) error {
    45  	return l.remove(path, remotefs.RemoveCmd)
    46  }
    47  
    48  func (l *lcowfs) RemoveAll(path string) error {
    49  	return l.remove(path, remotefs.RemoveAllCmd)
    50  }
    51  
    52  func (l *lcowfs) remove(path string, cmd string) error {
    53  	logrus.Debugf("remotefs.%s args: %s", cmd, path)
    54  	return l.runRemoteFSProcess(nil, nil, cmd, path)
    55  }
    56  
    57  func (l *lcowfs) Link(oldname, newname string) error {
    58  	return l.link(oldname, newname, remotefs.LinkCmd)
    59  }
    60  
    61  func (l *lcowfs) Symlink(oldname, newname string) error {
    62  	return l.link(oldname, newname, remotefs.SymlinkCmd)
    63  }
    64  
    65  func (l *lcowfs) link(oldname, newname, cmd string) error {
    66  	logrus.Debugf("remotefs.%s args: %s %s", cmd, oldname, newname)
    67  	return l.runRemoteFSProcess(nil, nil, cmd, oldname, newname)
    68  }
    69  
    70  func (l *lcowfs) Lchown(name string, uid, gid int64) error {
    71  	uidStr := strconv.FormatInt(uid, 10)
    72  	gidStr := strconv.FormatInt(gid, 10)
    73  
    74  	logrus.Debugf("remotefs.lchown args: %s %s %s", name, uidStr, gidStr)
    75  	return l.runRemoteFSProcess(nil, nil, remotefs.LchownCmd, name, uidStr, gidStr)
    76  }
    77  
    78  // Lchmod changes the mode of an file not following symlinks.
    79  func (l *lcowfs) Lchmod(path string, mode os.FileMode) error {
    80  	modeStr := strconv.FormatUint(uint64(mode), 8)
    81  	logrus.Debugf("remotefs.lchmod args: %s %s", path, modeStr)
    82  	return l.runRemoteFSProcess(nil, nil, remotefs.LchmodCmd, path, modeStr)
    83  }
    84  
    85  func (l *lcowfs) Mknod(path string, mode os.FileMode, major, minor int) error {
    86  	modeStr := strconv.FormatUint(uint64(mode), 8)
    87  	majorStr := strconv.FormatUint(uint64(major), 10)
    88  	minorStr := strconv.FormatUint(uint64(minor), 10)
    89  
    90  	logrus.Debugf("remotefs.mknod args: %s %s %s %s", path, modeStr, majorStr, minorStr)
    91  	return l.runRemoteFSProcess(nil, nil, remotefs.MknodCmd, path, modeStr, majorStr, minorStr)
    92  }
    93  
    94  func (l *lcowfs) Mkfifo(path string, mode os.FileMode) error {
    95  	modeStr := strconv.FormatUint(uint64(mode), 8)
    96  	logrus.Debugf("remotefs.mkfifo args: %s %s", path, modeStr)
    97  	return l.runRemoteFSProcess(nil, nil, remotefs.MkfifoCmd, path, modeStr)
    98  }
    99  
   100  func (l *lcowfs) Stat(p string) (os.FileInfo, error) {
   101  	return l.stat(p, remotefs.StatCmd)
   102  }
   103  
   104  func (l *lcowfs) Lstat(p string) (os.FileInfo, error) {
   105  	return l.stat(p, remotefs.LstatCmd)
   106  }
   107  
   108  func (l *lcowfs) stat(path string, cmd string) (os.FileInfo, error) {
   109  	logrus.Debugf("remotefs.stat inputs: %s %s", cmd, path)
   110  
   111  	output := &bytes.Buffer{}
   112  	err := l.runRemoteFSProcess(nil, output, cmd, path)
   113  	if err != nil {
   114  		return nil, err
   115  	}
   116  
   117  	var fi remotefs.FileInfo
   118  	if err := json.Unmarshal(output.Bytes(), &fi); err != nil {
   119  		return nil, err
   120  	}
   121  
   122  	logrus.Debugf("remotefs.stat success. got: %v\n", fi)
   123  	return &fi, nil
   124  }