github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/pkg/udev/listentry.go (about)

     1  /*
     2  Copyright 2018 OpenEBS 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  // +build linux,cgo
    18  
    19  package udev
    20  
    21  /*
    22    #cgo LDFLAGS: -ludev
    23    #include <libudev.h>
    24  */
    25  import "C"
    26  
    27  // UdevListEntry wraps a libudev udev_list_entry object
    28  type UdevListEntry struct {
    29  	listEntry *C.struct_udev_list_entry
    30  }
    31  
    32  // newUdevListEntry a private helper function and returns a pointer to a new udev
    33  func newUdevListEntry(ptr *C.struct_udev_list_entry) (le *UdevListEntry) {
    34  	if ptr == nil {
    35  		return nil
    36  	}
    37  	le = &UdevListEntry{
    38  		listEntry: ptr,
    39  	}
    40  	return
    41  }
    42  
    43  // GetNextEntry returns UdevListEntry struct if next device is present else it returns nil pointer.
    44  func (le *UdevListEntry) GetNextEntry() *UdevListEntry {
    45  	return newUdevListEntry(C.udev_list_entry_get_next(le.listEntry))
    46  }
    47  
    48  // GetName return Udevice syspath.
    49  func (le *UdevListEntry) GetName() string {
    50  	return C.GoString(C.udev_list_entry_get_name(le.listEntry))
    51  }