EmuProxyZA / mfs attr.c

From TivoZA

Back to emuProxyZA.
Download source (You will need to rename it to: mfs_attr.c)

To update the below source file, select Upload file and upload your new mfs_attr.c file (there is no need to upload it as a .txt). If you do upload a new version, please add a brief description to the change log at the bottom of this page indicating what changes you made and why.

Source

  1. #include "mfs-utils/mfs.h"
  2. #include <string.h>
  3.  
  4. int mfs_init_done = 0;
  5.  
  6. void mfs_check_init() {
  7. if (mfs_init_done == 0) {
  8. mfs_init();
  9. mfs_init_done = 1;
  10. }
  11. }
  12.  
  13. int mfs_fsid(const char *pathin) {
  14. mfs_check_init();
  15. return mfs_resolve(pathin);
  16. }
  17.  
  18. int mfs_attr_set_int(char *object, char *attribute, int value) {
  19. mfs_check_init();
  20. return mfs_attr_set(object, attribute, &value);
  21. }
  22.  
  23. int mfs_attr_set_str(char *object, char *attribute, char *value) {
  24. mfs_check_init();
  25. return mfs_attr_set(object, attribute, value);
  26. }
  27.  
  28. int mfs_attr_get_int(char *object, char *attribute) {
  29. int fsid;
  30. mfs_check_init();
  31. fsid = mfs_resolve(object);
  32. return query_int(fsid, attribute);
  33. }
  34.  
  35. char *mfs_attr_get_str(char *object, char *attribute) {
  36. int fsid;
  37. mfs_check_init();
  38. fsid = mfs_resolve(object);
  39. return query_string(fsid, attribute);
  40. }
  41.  
  42.  
  43. int mfs_attr_set(char *object, char *attribute, void *value)
  44. {
  45. int fsid;
  46. int found = 0;
  47. char *err = NULL;
  48.  
  49. static void callback(int fsid, struct mfs_subobj_header *obj, struct mfs_attr_header *attr, void *data)
  50. {
  51. char *p = data;
  52. if(obj && attr) {
  53. if (attr->attr == 1) { // Version
  54. int ver = ntohl(*(int *)data);
  55. *(int *)p = htonl(++ver);
  56. }
  57. else if (!strcmp(schema_attrib(obj->obj_type,attr->attr), attribute)) { //Specified attribute
  58. switch (attr->eltype>>6) {
  59. case TYPE_STRING:
  60. strcpy((char *)&p[0], (char *)value);
  61. found = 1;
  62. break;
  63.  
  64. case TYPE_FILE:
  65. break;
  66.  
  67. case TYPE_INT:
  68. *(int *)p = htonl( *(int *)value );
  69. found = 1;
  70. break;
  71.  
  72. case TYPE_OBJECT:
  73. break;
  74. }
  75.  
  76. }
  77.  
  78. }
  79. }
  80.  
  81. mfs_check_init();
  82.  
  83. if (!object)
  84. err = "object is null";
  85. else if (!strcmp(object, ""))
  86. err = "object is an empty string";
  87. else if (!attribute)
  88. err = "attribute is null";
  89. else if (!strcmp(attribute, ""))
  90. err = "attribute is an empty string";
  91. else if (!value)
  92. err = "value is null";
  93.  
  94. if (err) {
  95. fprintf(stderr, "dbset error: %s (Object: '%s', Attribute: '%s', Value: '%s')\n", err, object, attribute, value);
  96. return 0;
  97. }
  98.  
  99. fsid = mfs_resolve(object);
  100. if (fsid > 0) {
  101. u32 size = mfs_fsid_size(fsid);
  102. char *buf=alloca(size);
  103. mfs_fsid_pread(fsid, buf, 0, size );
  104. parse_object(fsid, buf, callback);
  105. if (found)
  106. mfs_fsid_pwrite(fsid, buf, 0, size);
  107. }
  108.  
  109. return found;
  110. }

Change Log

20 Oct 2006 - TivoZA: Uploaded the file

Advertisement