probe.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2016 Jo-Philipp Wich <jo@mein.io>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License version 2.1
  6. * as published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <string.h>
  14. #include <libubox/utils.h>
  15. #include "probe.h"
  16. #include "libblkid-tiny/libblkid-tiny.h"
  17. static struct probe_info *
  18. probe_path_tiny(const char *path)
  19. {
  20. struct probe_info *info = NULL;
  21. struct blkid_struct_probe *pr;
  22. char *type, *dev, *uuid, *label, *version;
  23. pr = blkidtiny_new_probe();
  24. if (!pr)
  25. return NULL;
  26. if (probe_block((char *)path, pr) == 0 && pr->id && !pr->err) {
  27. info = calloc_a(sizeof(*info),
  28. &type, strlen(pr->id->name) + 1,
  29. &dev, strlen(path) + 1,
  30. &uuid, strlen(pr->uuid) + 1,
  31. &label, strlen(pr->label) + 1,
  32. &version, strlen(pr->version) + 1);
  33. if (info) {
  34. info->type = strcpy(type, pr->id->name);
  35. info->dev = strcpy(dev, path);
  36. if (pr->uuid[0])
  37. info->uuid = strcpy(uuid, pr->uuid);
  38. if (pr->label[0])
  39. info->label = strcpy(label, pr->label);
  40. if (pr->version[0])
  41. info->version = strcpy(version, pr->version);
  42. }
  43. }
  44. blkidtiny_free_probe(pr);
  45. return info;
  46. }
  47. struct probe_info *
  48. probe_path(const char *path)
  49. {
  50. struct probe_info *info;
  51. info = probe_path_tiny(path);
  52. if (!info)
  53. info = probe_path_libblkid(path);
  54. return info;
  55. }
  56. int
  57. make_devs(void)
  58. {
  59. return mkblkdev();
  60. }