object.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * object.h
  3. *
  4. * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _OBJECT_H_
  20. #define _OBJECT_H_
  21. #include <common.h>
  22. #include <lock.h>
  23. #include <sdk/object.h>
  24. #include <sdk/list.h>
  25. #include <sdk/user.h>
  26. typedef struct
  27. {
  28. list_entry_t link;
  29. dword_t uid;
  30. access_flags_t access_mask;
  31. } access_control_entry_t;
  32. typedef struct
  33. {
  34. list_entry_t by_name_list;
  35. list_entry_t by_type_list;
  36. char *name;
  37. qword_t ref_count;
  38. dword_t open_count;
  39. object_type_t type;
  40. uid_t owner;
  41. lock_t acl_lock;
  42. list_entry_t acl;
  43. } object_t;
  44. static inline void init_object(object_t *object, const char *name, object_type_t type)
  45. {
  46. object->name = name ? strdup(name) : NULL;
  47. object->type = type;
  48. }
  49. dword_t create_object(object_t *object);
  50. void reference(object_t *object);
  51. void dereference(object_t *object);
  52. bool_t reference_by_name(const char *name, object_type_t type, object_t **object);
  53. bool_t reference_by_handle(handle_t handle, object_type_t type, object_t **object);
  54. dword_t open_object(object_t *obj, access_flags_t access_flags, handle_t *handle);
  55. dword_t open_object_by_name(const char *name, object_type_t type, access_flags_t access_flags, handle_t *handle);
  56. void close_object_internal(object_t *obj);
  57. dword_t enum_objects_by_type(object_type_t type, object_t **object);
  58. void object_init(void);
  59. #endif