github.com/intel/goresctrl@v0.5.0/pkg/cgroups/fsios.go (about) 1 // Copyright 2021 Intel Corporation. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // This module provides the native implementation of the filesystem 16 // interface (fsi). 17 18 package cgroups 19 20 import ( 21 "os" 22 "path/filepath" 23 ) 24 25 type fsOs struct{} 26 27 type osFile struct { 28 file *os.File 29 } 30 31 func newFsiOS() fsiIface { 32 return fsOs{} 33 } 34 35 func (fsOs) OpenFile(name string, flag int, perm os.FileMode) (fileIface, error) { 36 f, err := os.OpenFile(name, flag, perm) 37 return osFile{f}, err 38 } 39 40 func (fsOs) Open(name string) (fileIface, error) { 41 f, err := os.Open(name) 42 return osFile{f}, err 43 } 44 45 func (fsOs) Lstat(name string) (os.FileInfo, error) { 46 return os.Lstat(name) 47 } 48 49 func (fsOs) Walk(root string, walkFn filepath.WalkFunc) error { 50 return filepath.Walk(root, walkFn) 51 } 52 53 func (osf osFile) Write(b []byte) (n int, err error) { 54 return osf.file.Write(b) 55 } 56 57 func (osf osFile) Read(b []byte) (n int, err error) { 58 return osf.file.Read(b) 59 } 60 61 func (osf osFile) Close() error { 62 return osf.file.Close() 63 }