github.com/cs3org/reva/v2@v2.27.7/pkg/storage/utils/localfs/localfs_windows.go (about) 1 // Copyright 2018-2021 CERN 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 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 //go:build windows 20 // +build windows 21 22 package localfs 23 24 import ( 25 "context" 26 "crypto/md5" 27 "encoding/binary" 28 "fmt" 29 "os" 30 "strings" 31 32 provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" 33 "github.com/cs3org/reva/v2/pkg/appctx" 34 "golang.org/x/sys/windows" 35 ) 36 37 // calcEtag will create an etag based on the md5 of 38 // - mtime, 39 // - inode (if available), 40 // - device (if available) and 41 // - size. 42 // errors are logged, but an etag will still be returned 43 func calcEtag(ctx context.Context, fi os.FileInfo) string { 44 log := appctx.GetLogger(ctx) 45 h := md5.New() 46 err := binary.Write(h, binary.BigEndian, fi.ModTime().Unix()) 47 if err != nil { 48 log.Error().Err(err).Msg("error writing mtime") 49 } 50 // device and inode have no meaning on windows 51 err = binary.Write(h, binary.BigEndian, fi.Size()) 52 if err != nil { 53 log.Error().Err(err).Msg("error writing size") 54 } 55 etag := fmt.Sprintf(`"%x"`, h.Sum(nil)) 56 return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\"")) 57 } 58 59 func (fs *localfs) GetQuota(ctx context.Context, ref *provider.Reference) (uint64, uint64, uint64, error) { 60 // TODO quota of which storage space? 61 // we could use the logged in user, but when a user has access to multiple storages this falls short 62 // for now return quota of root 63 var free, total, avail uint64 64 65 pathPtr, err := windows.UTF16PtrFromString(fs.wrap(ctx, "/")) 66 if err != nil { 67 return 0, 0, 0, err 68 } 69 err = windows.GetDiskFreeSpaceEx(pathPtr, &avail, &total, &free) 70 if err != nil { 71 return 0, 0, 0, err 72 } 73 74 used := total - free 75 return total, used, free, nil 76 }