summaryrefslogtreecommitdiff
path: root/src/lib/eeze_disk_udev.c
blob: ef7b16029e647d0c2935b1af3e4a8ccc8c54a035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <Ecore.h>
#include <Eeze.h>
#include <Eeze_Disk.h>

#include "eeze_udev_private.h"
#include "eeze_disk_private.h"

EAPI const char *
eeze_disk_udev_get_property(Eeze_Disk *disk, const char *property)
{
   const char *ret;
   EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
   EINA_SAFETY_ON_NULL_RETURN_VAL(property, NULL);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(!*property, NULL);

   ret = udev_device_get_property_value(disk->device, property);
   return eina_stringshare_add(ret);
}

EAPI const char *
eeze_disk_udev_get_sysattr(Eeze_Disk *disk, const char *sysattr)
{
   const char *ret;
   EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
   EINA_SAFETY_ON_NULL_RETURN_VAL(sysattr, NULL);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(!*sysattr, NULL);

   ret = udev_device_get_sysattr_value(disk->device, sysattr);
   return eina_stringshare_add(ret);
}

EAPI const char *
eeze_disk_udev_get_parent(Eeze_Disk *disk)
{
   _udev_device *parent;
   EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);

   parent = udev_device_get_parent(disk->device);
   return eina_stringshare_add(udev_device_get_syspath(parent));
}

EAPI Eina_Bool
eeze_disk_udev_walk_check_sysattr(Eeze_Disk *disk,
                                  const char *sysattr,
                                  const char *value)
{
   _udev_device *child, *parent;
   const char *test = NULL;

   EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
   EINA_SAFETY_ON_NULL_RETURN_VAL(sysattr, EINA_FALSE);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(!*sysattr, EINA_FALSE);

   for (parent = disk->device; parent;
        child = parent, parent = udev_device_get_parent(child))
     {
        if (!(test = udev_device_get_sysattr_value(parent, sysattr)))
          continue;
        if ((value && (!strcmp(test, value))) || (!value))
          {
             return EINA_TRUE;
             break;
          }
     }
   return EINA_FALSE;
}

EAPI const char *
eeze_disk_udev_walk_get_sysattr(Eeze_Disk *disk,
                                  const char *sysattr)
{
   _udev_device *child, *parent;
   const char *test = NULL;

   EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
   EINA_SAFETY_ON_NULL_RETURN_VAL(sysattr, NULL);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(!*sysattr, NULL);

   for (parent = disk->device; parent;
        child = parent, parent = udev_device_get_parent(child))
     {
        test = udev_device_get_sysattr_value(parent, sysattr);
        if (test) return eina_stringshare_add(test);
     }
   return EINA_FALSE;
}