[Kos-cvs] kos/modules/lib/charfile libcharfile.c, 1.4, 1.5 libcharfile.h, 1.1, 1.2

thomas at kos.enix.org thomas at kos.enix.org
Sun Jan 30 18:14:24 CET 2005


Update of /home/kos/cvs/kos/modules/lib/charfile
In directory the-doors:/tmp/cvs-serv8990/modules/lib/charfile

Modified Files:
	libcharfile.c libcharfile.h 
Log Message:
2005-01-30  Thomas Petazzoni  <thomas at crazy.kos.nx>

	* modules/doc.cfg (INPUT): Add missing directories

	* modules/lib/charfile/libcharfile.h: Doxygen documentation + GPL
	Header

	* modules/lib/charfile/libcharfile.c: Doxygen documentation + GPL
	header.



Index: libcharfile.h
===================================================================
RCS file: /home/kos/cvs/kos/modules/lib/charfile/libcharfile.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- libcharfile.h	27 Oct 2003 15:39:30 -0000	1.1
+++ libcharfile.h	30 Jan 2005 17:14:22 -0000	1.2
@@ -1,3 +1,29 @@
+/*
+ * Copyright (C) 2000-2005
+ * David Decotigny, Julien Munier, Thomas Petazzoni
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *
+ * @(#) $Id$
+ */
+
+/** @file
+ * Public definitions for the char to file library
+ */
+
 #ifndef __LIBBLOCKFILE_H__
 #define __LIBBLOCKFILE_H__
 

Index: libcharfile.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/lib/charfile/libcharfile.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- libcharfile.c	30 Jan 2005 16:11:21 -0000	1.4
+++ libcharfile.c	30 Jan 2005 17:14:22 -0000	1.5
@@ -1,3 +1,41 @@
+/*
+ * Copyright (C) 2000-2005
+ * David Decotigny, Julien Munier, Thomas Petazzoni
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *
+ * @(#) $Id$
+ */
+
+/** @file
+ * Library that adds the FILE interface to a resource already having
+ * the CHAR interface.
+ *
+ * All character device drivers (like tty) register resources in Karm
+ * that only support the CHAR interface. The purpose of this module is
+ * to add the FILE interface to such a resource, so that user
+ * applications can transparently see a character device as a file,
+ * and use the regular read/write interface.
+ *
+ * Its use is simple : once you've registered the kernel resource of
+ * the character device and its CHAR view, open it using
+ * ures_open(). Then, call register_char_to_file_view() and it will add
+ * the FILE interface to the kernel resource.
+ */
+
 #include <kmem/kmem.h>
 #include <karm/interface/char.h>
 #include <karm/interface/file.h>
@@ -8,10 +46,22 @@
 /** The data associated with the FILE view we will instantiate. */
 struct lcf_view_data
 {
-  /** The URES of the char device */
+  /** The user resource of the char device */
   struct ures *char_ures;
 };
 
+/**
+ * Implementation of the read() method of the FILE interface
+ *
+ * @param ur The user resource
+ *
+ * @param buffer The buffer in which data should be read
+ *
+ * @param inout_len As input, the length of the data that should be
+ * read, as output the length of the data that has really been read
+ *
+ * @return ESUCCESS on success, an error code otherwise
+ */
 static result_t lcf_read(struct ures *ur, char *buffer, size_t *inout_len)
 {
   struct lcf_view_data *view_data;
@@ -23,10 +73,24 @@
 
   view_data = (struct lcf_view_data *) ur->view->view_data;
 
+  /* Call the read method of the CHAR interface */
   return CHAR_OPS(view_data->char_ures->view->ops)
     ->read(view_data->char_ures, buffer, inout_len);
 }
 
+/**
+ * Implementation of the write() method of the FILE interface
+ *
+ * @param ur The user resource
+ *
+ * @param buffer The buffer from which data should be read
+ *
+ * @param inout_len As input, the length of the data that should be
+ * written, as output the length of the data that has really been
+ * written
+ *
+ * @return ESUCCESS on success, an error code otherwise
+ */
 static result_t lcf_write(struct ures *ur, const char *buffer,
 			  size_t *inout_len)
 {
@@ -39,10 +103,24 @@
 
   view_data = (struct lcf_view_data *) ur->view->view_data;
 
+  /* Call the write method of the FILE interface */
   return CHAR_OPS(view_data->char_ures->view->ops)
     ->write(view_data->char_ures, buffer, inout_len);
 }
 
+/**
+ * Implementation of the seek() method of the FILE interface
+ *
+ * @param ur The user resource
+ *
+ * @param seek_type Type of the seek (SEEK_CUR, SEEK_SET, SEEK_END)
+ *
+ * @param inout_offset As input, the requested seek offset. The value
+ * is not modified.
+ *
+ * @return Always return -ESPIPE as character devices do not support
+ * seek.
+ */
 static result_t lcf_seek(struct ures *ur, seek_t seek_type,
 			 large_offset_t *inout_offset)
 {
@@ -53,12 +131,25 @@
   return -ESPIPE;
 }
 
+/**
+ * FILE interface implementation
+ */
 static struct INTERFACE_FILE char_file_ops = {
   .read = lcf_read,
   .write = lcf_write,
   .seek = lcf_seek
 };
 
+/**
+ * Add the FILE interface support to an user resource that already
+ * supports the CHAR interface.
+ *
+ * @param char_ures The user resource to which the FILE interface has
+ * to be added. It must have been opened using the open_ures()
+ * function.
+ *
+ * @return ESUCCESS on success, error code otherwise
+ */
 result_t register_char_to_file_view(struct ures * char_ures)
 {
   result_t result;
@@ -73,6 +164,8 @@
 
   CONCEPTION_ASSERT(char_ures->view && char_ures->view->kres);
 
+  /* Make sure the user resource has been opened using the CHAR
+     interface */
   if (char_ures->view->iid != INTERFACE_CHAR_ID)
     {
       return -EBADIFACE;



More information about the Kos-cvs mailing list