SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

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

source navigation ] diff markup ] identifier search ] general search ]