|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2005 David Decotigny, Th 001 /* Copyright (C) 2005 David Decotigny, Thomas Petazzoni 002 002 003 This program is free software; you can redi 003 This program is free software; you can redistribute it and/or 004 modify it under the terms of the GNU Genera 004 modify it under the terms of the GNU General Public License 005 as published by the Free Software Foundatio 005 as published by the Free Software Foundation; either version 2 006 of the License, or (at your option) any lat 006 of the License, or (at your option) any later version. 007 007 008 This program is distributed in the hope tha 008 This program is distributed in the hope that it will be useful, 009 but WITHOUT ANY WARRANTY; without even the 009 but WITHOUT ANY WARRANTY; without even the implied warranty of 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 011 GNU General Public License for more details 011 GNU General Public License for more details. 012 012 013 You should have received a copy of the GNU 013 You should have received a copy of the GNU General Public License 014 along with this program; if not, write to t 014 along with this program; if not, write to the Free Software 015 Foundation, Inc., 59 Temple Place - Suite 3 015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 016 USA. 016 USA. 017 */ 017 */ 018 #ifndef _SOS_CHARDEV_H_ 018 #ifndef _SOS_CHARDEV_H_ 019 #define _SOS_CHARDEV_H_ 019 #define _SOS_CHARDEV_H_ 020 020 021 /** 021 /** 022 * @file chardev.h 022 * @file chardev.h 023 * 023 * 024 * Interface between the VFS and the "characte 024 * Interface between the VFS and the "character" devices. The 025 * following functions provide the mechanisms 025 * following functions provide the mechanisms to bind the "character 026 * device" nodes (@see mknod) to their device 026 * device" nodes (@see mknod) to their device driver. 027 * 027 * 028 * The VFS layer must be perceived as an unifo 028 * The VFS layer must be perceived as an uniform access library on top 029 * of a set of specialized FS. The "chardev" l 029 * of a set of specialized FS. The "chardev" layer is to be perceived 030 * as a FS-agnostic layer on top of the FS tha 030 * as a FS-agnostic layer on top of the FS that binds the special 031 * "character device" nodes to a set of system 031 * "character device" nodes to a set of system-wide read/write/seek 032 * functions. 032 * functions. 033 */ 033 */ 034 034 035 #include "fs.h" 035 #include "fs.h" 036 036 037 /** 037 /** 038 * The fundamental callbacks for a character d 038 * The fundamental callbacks for a character device: they are common 039 * to all the character devices of the same cl 039 * to all the character devices of the same class. One is free to do 040 * whatever she likes with the "custom_data" o 040 * whatever she likes with the "custom_data" of the opened file passed 041 * as argument 041 * as argument 042 */ 042 */ 043 struct sos_chardev_ops { 043 struct sos_chardev_ops { 044 /** 044 /** 045 * @note also called upon a "duplicate_opene 045 * @note also called upon a "duplicate_opened_file", aka upon a 046 * fork() 046 * fork() 047 * @note When this callback is called, of is 047 * @note When this callback is called, of is NOT bound to any 048 * nscache_node, so don't ever call any sos_ 048 * nscache_node, so don't ever call any sos_fs_nscache_* function ! 049 * @note To get the fsnode associated to "of 049 * @note To get the fsnode associated to "of", don't call 050 * sos_fs_nscache_get_fs_node(): it is alrea 050 * sos_fs_nscache_get_fs_node(): it is already given by the "fsnode" 051 * argument 051 * argument 052 * @note MANDATORY ! 052 * @note MANDATORY ! 053 */ 053 */ 054 sos_ret_t (*open)(struct sos_fs_node 054 sos_ret_t (*open)(struct sos_fs_node * fsnode, 055 struct sos_fs_opened_file 055 struct sos_fs_opened_file * of, 056 void * chardev_class_custo 056 void * chardev_class_custom_data); 057 057 058 /** 058 /** 059 * Called each time an opened "character dev 059 * Called each time an opened "character device" is declared unused 060 * by user space 060 * by user space 061 * @note Optional (might be NULL) 061 * @note Optional (might be NULL) 062 */ 062 */ 063 sos_ret_t (*close)(struct sos_fs_opened_file 063 sos_ret_t (*close)(struct sos_fs_opened_file * of, 064 void * chardev_class_cust 064 void * chardev_class_custom_data); 065 065 066 /** 066 /** 067 * @note Optional (might be NULL), may block 067 * @note Optional (might be NULL), may block. Appropriate locking 068 * MUST be implemented 068 * MUST be implemented 069 */ 069 */ 070 sos_ret_t (*seek)(struct sos_fs_opened_file 070 sos_ret_t (*seek)(struct sos_fs_opened_file *this, 071 sos_lsoffset_t offset, 071 sos_lsoffset_t offset, 072 sos_seek_whence_t whence, 072 sos_seek_whence_t whence, 073 /* out */ sos_lsoffset_t * 073 /* out */ sos_lsoffset_t * result_position); 074 074 075 /** 075 /** 076 * @note Optional (might be NULL), may block 076 * @note Optional (might be NULL), may block. Appropriate locking 077 * MUST be implemented 077 * MUST be implemented 078 */ 078 */ 079 sos_ret_t (*read)(struct sos_fs_opened_file 079 sos_ret_t (*read)(struct sos_fs_opened_file *this, 080 sos_uaddr_t dest_buf, 080 sos_uaddr_t dest_buf, 081 sos_size_t * /* in/out */l 081 sos_size_t * /* in/out */len); 082 082 083 /** 083 /** 084 * @note Optional (might be NULL), may block 084 * @note Optional (might be NULL), may block. Appropriate locking 085 * MUST be implemented 085 * MUST be implemented 086 * @note Please call sos_fs_mark_dirty() if 086 * @note Please call sos_fs_mark_dirty() if disk contents is changed 087 */ 087 */ 088 sos_ret_t (*write)(struct sos_fs_opened_file 088 sos_ret_t (*write)(struct sos_fs_opened_file *this, 089 sos_uaddr_t src_buf, 089 sos_uaddr_t src_buf, 090 sos_size_t * /* in/out */ 090 sos_size_t * /* in/out */len); 091 091 092 /** 092 /** 093 * @note Optional (might be NULL), may block 093 * @note Optional (might be NULL), may block. Appropriate locking 094 * MUST be implemented 094 * MUST be implemented 095 * @note Please call sos_fs_mark_dirty() if 095 * @note Please call sos_fs_mark_dirty() if disk contents is changed 096 */ 096 */ 097 sos_ret_t (*mmap)(struct sos_fs_opened_file 097 sos_ret_t (*mmap)(struct sos_fs_opened_file *this, 098 sos_uaddr_t *uaddr, sos_si 098 sos_uaddr_t *uaddr, sos_size_t size, 099 sos_ui32_t access_rights, 099 sos_ui32_t access_rights, 100 sos_ui32_t flags, 100 sos_ui32_t flags, 101 sos_luoffset_t offset); 101 sos_luoffset_t offset); 102 102 103 /** 103 /** 104 * @note Optional (might be NULL), may block 104 * @note Optional (might be NULL), may block. Appropriate locking 105 * MUST be implemented 105 * MUST be implemented 106 * @note Please call sos_fs_mark_dirty() if 106 * @note Please call sos_fs_mark_dirty() if disk contents is changed 107 */ 107 */ 108 sos_ret_t (*fcntl)(struct sos_fs_opened_file 108 sos_ret_t (*fcntl)(struct sos_fs_opened_file *this, 109 int req_id, 109 int req_id, 110 sos_ui32_t req_arg /* Usu 110 sos_ui32_t req_arg /* Usually: sos_uaddr_t */); 111 111 112 /** 112 /** 113 * @note Optional (might be NULL), may block 113 * @note Optional (might be NULL), may block. Appropriate locking 114 * MUST be implemented 114 * MUST be implemented 115 * @note Please call sos_fs_mark_dirty() if 115 * @note Please call sos_fs_mark_dirty() if disk contents is changed 116 */ 116 */ 117 sos_ret_t (*ioctl)(struct sos_fs_opened_file 117 sos_ret_t (*ioctl)(struct sos_fs_opened_file *this, 118 int req_id, 118 int req_id, 119 sos_ui32_t req_arg /* Usu 119 sos_ui32_t req_arg /* Usually: sos_uaddr_t */); 120 }; 120 }; 121 121 122 122 123 /** 123 /** 124 * Associate the given set of operations to th 124 * Associate the given set of operations to the given major number. 125 * 125 * 126 * @note Character device drivers are register 126 * @note Character device drivers are registered for a complete class 127 * of character devices (up to 4 billion devic 127 * of character devices (up to 4 billion devices per class) 128 */ 128 */ 129 sos_ret_t sos_chardev_register_class (sos_ui32 129 sos_ret_t sos_chardev_register_class (sos_ui32_t device_class, 130 struct s 130 struct sos_chardev_ops * ops, 131 void * c 131 void * chardev_class_custom_data); 132 132 133 133 134 /** 134 /** 135 * Unbind the given set of operations with the 135 * Unbind the given set of operations with the given major number 136 * 136 * 137 * @return SOS_EBUSY when the character device 137 * @return SOS_EBUSY when the character device is still opened by any 138 * process. 138 * process. 139 */ 139 */ 140 sos_ret_t sos_chardev_unregister_class (sos_ui 140 sos_ret_t sos_chardev_unregister_class (sos_ui32_t device_class); 141 141 142 142 143 /* 143 /* 144 * Callbacks restricted to fs.c internals 144 * Callbacks restricted to fs.c internals 145 */ 145 */ 146 146 147 /** 147 /** 148 * Update the FS node ops_blockdev callbacks a 148 * Update the FS node ops_blockdev callbacks after an FS 149 * allocate_new_node or fetch_node_from_disk, 149 * allocate_new_node or fetch_node_from_disk, in order to point to 150 * the block layer API functions 150 * the block layer API functions 151 */ 151 */ 152 sos_ret_t sos_chardev_helper_ref_new_fsnode(st 152 sos_ret_t sos_chardev_helper_ref_new_fsnode(struct sos_fs_node * this); 153 sos_ret_t sos_chardev_helper_release_fsnode(st 153 sos_ret_t sos_chardev_helper_release_fsnode(struct sos_fs_node * this); 154 154 155 #endif 155 #endif
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |