00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include <libhal.h>
00031
00032 #include "mntd_volume_manager_helper.h"
00033 #include "mntd_volume.h"
00034 #include "errmanager.h"
00035
00036
00050 int
00051 vmh_hal_device_is_safe(const char *udi)
00052 {
00053 g_assert(udi!=NULL);
00054
00055
00056 if (hal_device_exists(udi)) {
00057
00058 return 1;
00059 }
00060
00061
00062 return 0;
00063 }
00064
00065
00071 int
00072 vmh_hal_device_is_volume(const char *udi)
00073 {
00074 char *cat = NULL;
00075 int res = 0;
00076
00077 g_assert(udi!=NULL);
00078
00079 if (vmh_hal_device_is_safe_property(udi, HAL_PROPERTY_INFO_CATEGORY)) {
00080 cat = hal_device_get_property_string(udi, HAL_PROPERTY_INFO_CATEGORY);
00081 if (cat != NULL) {
00082 if (strcmp(cat, HAL_PROPERTY_INFO_CATEGORY_VOLUME)==0) {
00083 if (hal_device_get_property_bool(udi, HAL_PROPERTY_BLOCK_IS_VOLUME)) {
00084 res = 1;
00085 }
00086 }
00087 free(cat);
00088 cat = NULL;
00089 }
00090 }
00091
00092 return res;
00093 }
00094
00095
00102 int
00103 vmh_hal_device_is_safe_property(const char *udi, const char *key)
00104 {
00105 g_assert(udi!=NULL);
00106 g_assert(key!=NULL);
00107
00108
00109 if (vmh_hal_device_is_safe(udi)) {
00110 if (hal_device_property_exists(udi, key)) {
00111
00112 return 1;
00113 }
00114 }
00115
00116
00117 return 0;
00118 }
00119
00120
00128 int
00129 vmh_hal_device_get_safe_property_string(const char *udi, const char *key, char **result)
00130 {
00131 char *hal_string = NULL;
00132 char *tmp = NULL;
00133
00134 g_assert(udi!=NULL);
00135 g_assert(key!=NULL);
00136 g_assert(result!=NULL);
00137
00138 if (vmh_hal_device_is_safe_property(udi, key)) {
00139 hal_string = hal_device_get_property_string(udi, key);
00140 if (hal_string != NULL) {
00141 tmp = strdup(hal_string);
00142 if (tmp != NULL) {
00143 *result = tmp;
00144 return 1;
00145 } else {
00146 *result = NULL;
00147 }
00148 }
00149 }
00150
00151 if (hal_string != NULL) hal_free_string(hal_string);
00152 if (tmp != NULL) free(tmp);
00153
00154
00155 return 0;
00156 }
00157
00158
00166 int
00167 vmh_hal_device_get_safe_property_int(const char *udi, const char *key, int *result)
00168 {
00169 g_assert(udi!=NULL);
00170 g_assert(key!=NULL);
00171 g_assert(result!=NULL);
00172
00173 if (vmh_hal_device_is_safe_property(udi, key)) {
00174 *result = hal_device_get_property_int(udi, key);
00175 return 1;
00176 }
00177
00178 return 0;
00179 }
00180
00181
00189 int
00190 vmh_hal_device_get_safe_property_double(const char *udi, const char *key, double *result)
00191 {
00192 g_assert(udi!=NULL);
00193 g_assert(key!=NULL);
00194 g_assert(result!=NULL);
00195
00196 if (vmh_hal_device_is_safe_property(udi, key)) {
00197 *result = hal_device_get_property_double(udi, key);
00198 return 1;
00199 }
00200
00201 return 0;
00202 }
00203
00204
00212 int
00213 vmh_hal_device_get_safe_property_bool(const char *udi, const char *key, int *result)
00214 {
00215 g_assert(udi!=NULL);
00216 g_assert(key!=NULL);
00217 g_assert(result!=NULL);
00218
00219 if (vmh_hal_device_is_safe_property(udi, key)) {
00220 *result = hal_device_get_property_bool(udi, key);
00221 return 1;
00222 }
00223
00224 return 0;
00225 }
00226
00227
00234 int
00235 vmh_try_n_set_volumes_device(PVOLUME pv, const char *udi)
00236 {
00237 char *key = HAL_PROPERTY_BLOCK_DEVICE;
00238 char *device = NULL;
00239 int res = 0;
00240
00241 g_assert(pv!=NULL);
00242 g_assert(udi!=NULL);
00243
00244
00245 if (vmh_hal_device_get_safe_property_string(udi, key, &device)) {
00246 if ((pv->set_device(pv, device)) == -1) {
00247 MSG_WARNING("Couldn't set device '%s' for '%s'", device, udi);
00248 goto error;
00249 }
00250 } else {
00251 if ((pv->set_device(pv, NULL)) == -1) {
00252 MSG_WARNING("Couldn't remove device for '%s'", udi);
00253 goto error;
00254 }
00255 }
00256
00257 goto cleanup;
00258
00259 error:
00260 res = -1;
00261
00262 cleanup:
00263 if (device != NULL) {
00264 free(device);
00265 device = NULL;
00266 }
00267
00268 return res;
00269 }
00270
00271
00278 int
00279 vmh_try_n_set_volumes_mntpnt(PVOLUME pv, const char *udi)
00280 {
00281 char *key = HAL_PROPERTY_BLOCK_MOUNT_POINT;
00282 char *mntpnt = NULL;
00283 int res = 0;
00284
00285 g_assert(pv!=NULL);
00286 g_assert(udi!=NULL);
00287
00288
00289 if (vmh_hal_device_get_safe_property_string(udi, key, &mntpnt)) {
00290 if ((pv->set_mntpnt(pv, mntpnt)) == -1) {
00291 MSG_WARNING("Couldn't set mntpnt '%s' for '%s'", mntpnt, udi);
00292 goto error;
00293 }
00294 } else {
00295 if ((pv->set_mntpnt(pv, NULL)) == -1) {
00296 MSG_WARNING("Couldn't remove mount point for '%s'", udi);
00297 goto error;
00298 }
00299 }
00300
00301 goto cleanup;
00302
00303 error:
00304 res = -1;
00305
00306 cleanup:
00307 if (mntpnt != NULL) {
00308 free(mntpnt);
00309 mntpnt = NULL;
00310 }
00311
00312 return res;
00313 }
00314
00315
00322 int
00323 vmh_try_n_set_volumes_fstype(PVOLUME pv, const char *udi)
00324 {
00325 char *key = HAL_PROPERTY_BLOCK_FSTYPE;
00326 char *fstype = NULL;
00327 int res = 0;
00328
00329 g_assert(pv!=NULL);
00330 g_assert(udi!=NULL);
00331
00332
00333 if (vmh_hal_device_get_safe_property_string(udi, key, &fstype)) {
00334 if ((pv->set_fstype(pv, fstype)) == -1) {
00335 MSG_WARNING("Couldn't set fstype '%s' for '%s'", fstype, udi);
00336 goto error;
00337 }
00338 } else {
00339 if ((pv->set_fstype(pv, NULL)) == -1) {
00340 MSG_WARNING("Couldn't remove filesystem type for '%s'", udi);
00341 goto error;
00342 }
00343 }
00344
00345 goto cleanup;
00346
00347 error:
00348 res = -1;
00349
00350 cleanup:
00351 if (fstype != NULL) {
00352 free(fstype);
00353 fstype = NULL;
00354 }
00355
00356 return res;
00357 }
00358
00359
00366 int
00367 vmh_try_n_set_volumes_data(PVOLUME pv, const char *udi)
00368 {
00369 g_assert(pv!=NULL);
00370 g_assert(udi!=NULL);
00371
00372
00373 vmh_try_n_set_volumes_mntpnt(pv, udi);
00374
00375
00376 vmh_try_n_set_volumes_fstype(pv, udi);
00377
00378
00379 vmh_try_n_set_volumes_device(pv, udi);
00380
00381 return 0;
00382 }
00383
00384
00392 int
00393 vmh_try_n_set_volumes_data_by_property(PVOLUME pv, const char *udi, const char *property)
00394 {
00395 g_assert(pv!=NULL);
00396 g_assert(udi!=NULL);
00397 g_assert(property!=NULL);
00398
00399
00400 if (strcmp(property, HAL_PROPERTY_BLOCK_MOUNT_POINT)==0) {
00401 vmh_try_n_set_volumes_mntpnt(pv, udi);
00402 }
00403
00404
00405 if (strcmp(property, HAL_PROPERTY_BLOCK_FSTYPE)==0) {
00406 vmh_try_n_set_volumes_fstype(pv, udi);
00407 }
00408
00409
00410 if (strcmp(property, HAL_PROPERTY_BLOCK_DEVICE)==0) {
00411 vmh_try_n_set_volumes_device(pv, udi);
00412 }
00413
00414 return 0;
00415 }
00416
00417