@@ -60,6 +60,8 @@ const (
6060 UDEV_DEVLINKS = "DEVLINKS" // udev attribute contain devlinks of a disk
6161 BY_ID_LINK = "by-id" // by-path devlink contains this string
6262 BY_PATH_LINK = "by-path" // by-path devlink contains this string
63+ BY_UUID_LINK = "by-uuid" // by-uuid devlink contains the string
64+ BY_PARTUUID_LINK = "by-partuuid" // by-partuuid devlink contains the string
6365 LINK_ID_INDEX = 4 // this is used to get link index from dev link
6466 UDEV_FS_TYPE = "ID_FS_TYPE" // file system type the partition
6567 UDEV_FS_UUID = "ID_FS_UUID" // UUID of the filesystem present
@@ -71,6 +73,8 @@ const (
7173 UDEV_DM_UUID = "DM_UUID" // udev attribute to get the device mapper uuid
7274 // UDEV_DM_NAME is udev attribute to get the name of the dm device. This is used to generate the device mapper path
7375 UDEV_DM_NAME = "DM_NAME"
76+ // SYMLINK is used to represent any manually created device symlinks
77+ SYMLINK = "symlink"
7478)
7579
7680// UdevDiskDetails struct contain different attribute of disk.
@@ -82,6 +86,7 @@ type UdevDiskDetails struct {
8286 Path string // Path is Path of a disk.
8387 ByIdDevLinks []string // ByIdDevLinks contains by-id devlinks
8488 ByPathDevLinks []string // ByPathDevLinks contains by-path devlinks
89+ SymLinks []string // SymLinks contains device symlinks if any
8590 DiskType string // DeviceType can be disk, partition
8691 // IDType is used for uuid generation using the legacy algorithm
8792 IDType string
@@ -112,6 +117,7 @@ func (device *UdevDevice) DiskInfoFromLibudev() UdevDiskDetails {
112117 Path : device .GetPropertyValue (UDEV_DEVNAME ),
113118 ByIdDevLinks : devLinks [BY_ID_LINK ],
114119 ByPathDevLinks : devLinks [BY_PATH_LINK ],
120+ SymLinks : devLinks [SYMLINK ],
115121 DiskType : device .GetDevtype (),
116122 IDType : device .GetPropertyValue (UDEV_TYPE ),
117123 FileSystem : device .GetFileSystemInfo (),
@@ -210,6 +216,7 @@ func (device *UdevDevice) GetDevLinks() map[string][]string {
210216 devLinkMap := make (map [string ][]string )
211217 byIdLink := make ([]string , 0 )
212218 byPathLink := make ([]string , 0 )
219+ symLink := make ([]string , 0 )
213220 for _ , link := range strings .Split (device .GetPropertyValue (UDEV_DEVLINKS ), " " ) {
214221 /*
215222 devlink is like - /dev/disk/by-id/scsi-0Google_PersistentDisk_demo-disk
@@ -228,12 +235,14 @@ func (device *UdevDevice) GetDevLinks() map[string][]string {
228235 } else {
229236 byIdLink = append (byIdLink , link )
230237 }
231- }
232- if util .Contains (parts , BY_PATH_LINK ) {
238+ } else if util .Contains (parts , BY_PATH_LINK ) {
233239 byPathLink = append (byPathLink , link )
234240 }
241+ // we can add very dev link in symlink map as there is a 1:1 mapping between the two links
242+ symLink = append (symLink , link )
235243 }
236244 devLinkMap [BY_ID_LINK ] = byIdLink
237245 devLinkMap [BY_PATH_LINK ] = byPathLink
246+ devLinkMap [SYMLINK ] = symLink
238247 return devLinkMap
239248}
0 commit comments