123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
- * char_device.h
- *
- * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef _CHAR_DEVICE_H_
- #define _CHAR_DEVICE_H_
- #include <common.h>
- #include <list.h>
- #include <sync.h>
- #define MAX_CHAR_DEV_NAME 32
- #define IOCTL_CHAR_DEV_CHECK_INPUT 0xC0000000
- #define IOCTL_CHAR_DEV_CHECK_OUTPUT 0xC0000001
- typedef struct _char_device_t char_device_t;
- typedef dword_t (*char_dev_init_proc_t)(void);
- typedef dword_t (*char_dev_cleanup_proc_t)(void);
- typedef dword_t (*char_dev_read_proc_t)(char_device_t *device, void *buffer, size_t length, size_t *bytes_read);
- typedef dword_t (*char_dev_write_proc_t)(char_device_t *device, const void *buffer, size_t length, size_t *bytes_written);
- typedef dword_t (*char_dev_ioctl_proc_t)(
- char_device_t *device,
- dword_t control_code,
- const void *in_buffer,
- size_t in_length,
- void *out_buffer,
- size_t out_length
- );
- typedef struct
- {
- list_entry_t list;
- char_dev_init_proc_t init_proc;
- char_dev_cleanup_proc_t cleanup_proc;
- char_dev_read_proc_t read_proc;
- char_dev_write_proc_t write_proc;
- char_dev_ioctl_proc_t ioctl_proc;
- } char_dev_driver_t;
- struct _char_device_t
- {
- list_entry_t list;
- char_dev_driver_t *driver;
- char name[MAX_CHAR_DEV_NAME];
- resource_t resource;
- };
- dword_t register_char_dev_driver(char_dev_driver_t *driver);
- dword_t unregister_char_dev_driver(char_dev_driver_t *driver);
- char_device_t *get_char_device(const char *name);
- dword_t register_char_device(char_device_t *device);
- dword_t unregister_char_device(char_device_t *device);
- dword_t enum_char_devices(char *device_names, size_t *size);
- dword_t char_device_read(const char *name, void *buffer, size_t length, size_t *bytes_read);
- dword_t char_device_write(const char *name, const void *buffer, size_t length, size_t *bytes_written);
- dword_t char_device_ioctl(const char *name, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
- #endif
|