libudev Reference Manual 참고
udev
Manual 을 토대로 번역 하였음.
vim ./usr/include/libudev.h
DeskTop PC ----$ udevd --version
204
다음과 같은 기능으로 나누어진다.
udev — libudev context
udev - udev 문맥에는 설정파읽을 읽은 기본값들이 들어있으며 모든라이브러리에 전달된다.
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 | /* * udev - library context * * reads the udev config and system environment * allows custom logging */ struct udev; struct udev *udev_ref(struct udev *udev); // 객체를 제거 후 인자인 udev 를 반환. 일반적으로 udev_unref사용. struct udev *udev_unref(struct udev *udev); //객체를 제거하며 NULL 반환 한다. struct udev *udev_new(void); //새로운 udev 객체를 할당하고 포인터를 반환한다. 성공시 컨텍스트 포인터 반환 실패시 NULL void udev_set_log_fn(struct udev *udev, void (*log_fn)(struct udev *udev, int priority, const char *file, int line, const char *fn, const char *format, va_list args)); // log_fn : 로그 표출할 함수 등록 int udev_get_log_priority(struct udev *udev); // 현재 로그 우선순위값 반환 void udev_set_log_priority(struct udev *udev, int priority); // 로그 우선순위 설정 void *udev_get_userdata(struct udev *udev); //저장된 사용자 데이터 반환 (콜백 액세스 용도) | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /* * udev_list * * access to libudev generated lists */ struct udev_list_entry; struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry); //현재 리스트 값을 인자로 사용, return 다음 리스트 ,NULL 일시 다음 엔트리 X struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name); // name 과 일치하는 값을 반환 , NULL 반환시 X const char *udev_list_entry_get_name(struct udev_list_entry *list_entry); // 해당 엔트리의 이름 반환 const char *udev_list_entry_get_value(struct udev_list_entry *list_entry); // 해당 엔트리의 스트링값 반환 /** * udev_list_entry_foreach: * @list_entry: entry to store the current position * @first_entry: first entry to start with * * Helper to iterate over all entries of a list. */ #define udev_list_entry_foreach(list_entry, first_entry) \ //list_entry : 현재 값을 저장 , first_entry : 시작값 for (list_entry = first_entry; \ list_entry != NULL; \ list_entry = udev_list_entry_get_next(list_entry)) | cs |
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 | /* * udev_device * * access to sysfs/kernel devices */ struct udev_device; struct udev_device *udev_device_ref(struct udev_device *udev_device); // udev 장치대 대한 참조를 가져온다. struct udev_device *udev_device_unref(struct udev_device *udev_device); // 참조된 디바이스 해제, zero 리턴시 해제되었음을 알수 있다. struct udev *udev_device_get_udev(struct udev_device *udev_device); // udev에 대한 정보를 획득 struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); // 새 udev 장치를 만들고sys 장치 및 udev 데이터 베이스 항목에 정보를 생성. 초기 refcount는 1이며 장치의 리소를 해제하기 위해 감소시켜야 한다. 새로운 udev 장치 Ehsms 존재하지 않는경우 NULL 반환 struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); // type: character or block, devnum : device major/ minor Number , return : 존재하지 않는 경우 NULL, 성공시 new udev device struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname); //subsystem : like "mem" /"zero", "block" /"sda" , sysname: 디바이스이름 , Return : udev_device , 존재하지 않는경우 NULL struct udev_device *udev_device_new_from_device_id(struct udev *udev, char *id); struct udev_device *udev_device_new_from_environment(struct udev *udev); /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */ struct udev_device *udev_device_get_parent(struct udev_device *udev_device); /* 서브시스템 및 디바이스 타입과 일치하는 장치를 검색 , devtype ="NULL" 일시 subsystem 함목만 검사 return : 일치하는 장치가 없는경우 NULL 반환 */ struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype); /* retrieve device properties */ const char *udev_device_get_devpath(struct udev_device *udev_device); const char *udev_device_get_subsystem(struct udev_device *udev_device); const char *udev_device_get_devtype(struct udev_device *udev_device); const char *udev_device_get_syspath(struct udev_device *udev_device); const char *udev_device_get_sysname(struct udev_device *udev_device); const char *udev_device_get_sysnum(struct udev_device *udev_device); const char *udev_device_get_devnode(struct udev_device *udev_device); int udev_device_get_is_initialized(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device); const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key); const char *udev_device_get_driver(struct udev_device *udev_device); dev_t udev_device_get_devnum(struct udev_device *udev_device); const char *udev_device_get_action(struct udev_device *udev_device); unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device); unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device); // 속성값을 가져온다. return : sys 속성파일의 내용, 속성 값이 없으면 NULL const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr); int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, char *value); int udev_device_has_tag(struct udev_device *udev_device, const char *tag); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /* * udev_monitor * * access to kernel uevents and udev events */ struct udev_monitor; // 이벤트 소스를 처리하는 객체 struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor); struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor); // destroy the udev monitor struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor); // monitor 가 참조한 udev 가져오기 /* kernel and udev generated events over netlink udev : udev 객체 name : 이벤트 소스 이름 ex)"udev" return : new udev monitor, NULL인경우 에러 */ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name); /* bind socket retrun: 0=success , -1 error */ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor); int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size); // udev_monitor 에 대한 파일디스크립터를 반환 int udev_monitor_get_fd(struct udev_monitor *udev_monitor); struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor); /* in-kernel socket filters to select messages that get delivered to a listener 모니터링 할 subsystem 과 devtype 을 등록한다. return : 0= Success , 음수값 오류 */ int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype); int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag); int udev_monitor_filter_update(struct udev_monitor *udev_monitor); int udev_monitor_filter_remove(struct udev_monitor *udev_monitor); | cs |
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 | /* * udev_enumerate * * search sysfs for specific devices and provide a sorted list */ struct udev_enumerate; struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate); struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate); struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate); struct udev_enumerate *udev_enumerate_new(struct udev *udev); /* device properties filter */ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); // 항목에 포함할 필터를 등록 0리턴시 성공 int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); /* 목록에 포함시킬 속성 필터를 등록한다. property : 해당 속성 value : 값 return: 0= Success, - Fail */ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value); int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname); int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag); int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent); int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate); int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath); /* run enumeration with active filters */ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate); // return= 0 Success, - Fail int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate); /* return device list */ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /* * udev_queue * * access to the currently running udev events */ struct udev_queue; struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue); struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue); struct udev *udev_queue_get_udev(struct udev_queue *udev_queue); struct udev_queue *udev_queue_new(struct udev *udev); unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue); unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue); int udev_queue_get_udev_is_active(struct udev_queue *udev_queue); int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue); int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum); int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, unsigned long long int start, unsigned long long int end); struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue); | cs |
1 2 3 4 5 6 7 8 9 10 | /* * udev_hwdb * * access to the static hardware properties database */ struct udev_hwdb; struct udev_hwdb *udev_hwdb_new(struct udev *udev); struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb); struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb); struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags); | cs |
1 2 3 4 5 6 7 | /* * udev_util * * udev specific utilities */ int udev_util_encode_string(const char *str, char *str_enc, size_t len); | cs |
참고사이트
libudev Reference Manual: https://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/ch01.html
'Linux' 카테고리의 다른 글
[Linux] 오픈소스 웹 스트리밍 감시카메라 (0) | 2018.07.13 |
---|---|
[Linux]Samba 설정 (0) | 2017.10.06 |
Gstreamer 파이프라인 디버깅 (0) | 2017.04.14 |
임베디드 시스템 엔지니어를 위한 리눅스 커널 분석 링크 (0) | 2016.08.09 |
Ubuntu16.04 ssh (0) | 2016.07.15 |