github.com/Cloud-Foundations/Dominator@v0.3.4/cmd/imagetool/traceInodeHistory.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/Cloud-Foundations/Dominator/lib/filesystem" 7 "github.com/Cloud-Foundations/Dominator/lib/image" 8 "github.com/Cloud-Foundations/Dominator/lib/log" 9 ) 10 11 func traceInodeHistorySubcommand(args []string, logger log.DebugLogger) error { 12 if err := traceInodeHistory(args[0], args[1]); err != nil { 13 return fmt.Errorf("error tracing image inode: %s", err) 14 } 15 return nil 16 } 17 18 func getInodeInImage(img *image.Image, inodePath string) ( 19 filesystem.GenericInode, uint64, error) { 20 fs := img.FileSystem 21 filenameToInodeTable := fs.FilenameToInodeTable() 22 if inum, ok := filenameToInodeTable[inodePath]; !ok { 23 return nil, 0, 24 fmt.Errorf("path: \"%s\" not present in image", inodePath) 25 } else if inode, ok := fs.InodeTable[inum]; !ok { 26 return nil, 0, fmt.Errorf("inode: %d not present in image", inum) 27 } else { 28 return inode, inum, nil 29 } 30 } 31 32 func traceInodeHistory(imageName, inodePath string) error { 33 imageSClient, _ := getClients() 34 img, err := getTypedImage(imageName) 35 if err != nil { 36 return err 37 } 38 sourceImageName := img.SourceImage 39 if sourceImageName == "" { 40 return fmt.Errorf("image: %s has no source: history cannot be traced", 41 imageName) 42 } 43 lastImageName := imageName 44 lastInode, inum, err := getInodeInImage(img, inodePath) 45 if err != nil { 46 return err 47 } 48 lastNumLinks := img.FileSystem.BuildNumLinksTable()[inum] 49 for { 50 if sourceImageName == "" { 51 fmt.Printf("Inode originated in: %s\n", lastImageName) 52 return listInode(lastInode, inodePath, lastNumLinks) 53 } 54 img, err = getImage(imageSClient, sourceImageName) 55 if err != nil { 56 return err 57 } 58 inode, inum, err := getInodeInImage(img, inodePath) 59 if err != nil { 60 fmt.Printf("Inode originated in: %s\n", lastImageName) 61 return listInode(lastInode, inodePath, lastNumLinks) 62 } 63 sameType, sameMetadata, sameData := filesystem.CompareInodes(lastInode, 64 inode, nil) 65 if !sameType || !sameMetadata || !sameData { 66 fmt.Printf("Inode changed in: %s\n", lastImageName) 67 if e := listInode(lastInode, inodePath, lastNumLinks); e != nil { 68 return e 69 } 70 } 71 lastImageName = sourceImageName 72 lastInode = inode 73 lastNumLinks = img.FileSystem.BuildNumLinksTable()[inum] 74 sourceImageName = img.SourceImage 75 } 76 return nil 77 }