MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / FindCIs

Function FindCIs

pkg/metadata/provider_cdrom.go:61–100  ·  view source on GitHub ↗

FindCIs goes through all known devices. Returns any that are either fat32 or iso9660 and have a filesystem label "CIDATA" or "cidata", per the spec here https://github.com/canonical/cloud-init/blob/master/doc/rtd/topics/datasources/nocloud.rst

()

Source from the content-addressed store, hash-verified

59// iso9660 and have a filesystem label "CIDATA" or "cidata", per the spec
60// here https://github.com/canonical/cloud-init/blob/master/doc/rtd/topics/datasources/nocloud.rst
61func FindCIs() []string {
62 devs, err := filepath.Glob(blockDevs)
63 log.Debugf("block devices found: %v", devs)
64 if err != nil {
65 // Glob can only error on invalid pattern
66 panic(fmt.Sprintf("Invalid glob pattern: %s", blockDevs))
67 }
68 var foundDevices []string
69 for _, device := range devs {
70 // get the base device name
71 dev := filepath.Base(device)
72 // ignore loop and ram devices
73 if strings.HasPrefix(dev, "loop") || strings.HasPrefix(dev, "ram") {
74 log.Debugf("ignoring loop or ram device: %s", dev)
75 continue
76 }
77 dev = fmt.Sprintf("/dev/%s", dev)
78 log.Debugf("checking device: %s", dev)
79 // open readonly, ignore errors
80 disk, err := diskfs.Open(dev, diskfs.WithOpenMode(diskfs.ReadOnly))
81 if err != nil {
82 log.Debugf("failed to open device read-only: %s: %v", dev, err)
83 continue
84 }
85 disk.DefaultBlocks = true // because this is passed through as a block device, we can get strange blocksize numbers from the OS
86 fs, err := disk.GetFilesystem(0)
87 if err != nil {
88 log.Debugf("failed to get filesystem on partition 0 for device: %s: %v", dev, err)
89 continue
90 }
91 // get the label
92 label := strings.TrimSpace(fs.Label())
93 log.Debugf("found trimmed filesystem label for device: %s: '%s'", dev, label)
94 if label == "cidata" || label == "CIDATA" {
95 log.Debugf("adding device: %s", dev)
96 foundDevices = append(foundDevices, dev)
97 }
98 }
99 return foundDevices
100}
101
102// NewCDROM returns a new ProviderCDROM
103func NewCDROM(device string) *ProviderCDROM {

Callers 1

ListCDROMsFunction · 0.85

Calls 1

OpenMethod · 0.65

Tested by

no test coverage detected