1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package fs 18 19 import "os" 20 21 // GetLinkInfo returns an identifier representing the node a hardlink is pointing 22 // to. If the file is not hard linked then 0 will be returned. 23 func GetLinkInfo(fi os.FileInfo) (uint64, bool) { 24 return getLinkInfo(fi) 25 } 26 27 // getLinkSource returns a path for the given name and 28 // file info to its link source in the provided inode 29 // map. If the given file name is not in the map and 30 // has other links, it is added to the inode map 31 // to be a source for other link locations. 32 func getLinkSource(name string, fi os.FileInfo, inodes map[uint64]string) (string, error) { 33 inode, isHardlink := getLinkInfo(fi) 34 if !isHardlink { 35 return "", nil 36 } 37 38 path, ok := inodes[inode] 39 if !ok { 40 inodes[inode] = name 41 } 42 return path, nil 43 } 44