Blame IbAccess/Common/Public/iproc_fs.h

Packit 857059
/* BEGIN_ICS_COPYRIGHT4 ****************************************
Packit 857059
Packit 857059
Copyright (c) 2015, Intel Corporation
Packit 857059
Packit 857059
Redistribution and use in source and binary forms, with or without
Packit 857059
modification, are permitted provided that the following conditions are met:
Packit 857059
Packit 857059
    * Redistributions of source code must retain the above copyright notice,
Packit 857059
      this list of conditions and the following disclaimer.
Packit 857059
    * Redistributions in binary form must reproduce the above copyright
Packit 857059
      notice, this list of conditions and the following disclaimer in the
Packit 857059
     documentation and/or other materials provided with the distribution.
Packit 857059
    * Neither the name of Intel Corporation nor the names of its contributors
Packit 857059
      may be used to endorse or promote products derived from this software
Packit 857059
      without specific prior written permission.
Packit 857059
Packit 857059
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 857059
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 857059
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 857059
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit 857059
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 857059
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 857059
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit 857059
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit 857059
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 857059
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 857059
Packit 857059
** END_ICS_COPYRIGHT4   ****************************************/
Packit 857059
Packit 857059
/* [ICS VERSION STRING: unknown] */
Packit 857059
Packit 857059
#ifndef _IPROC_FS_H_
Packit 857059
#define _IPROC_FS_H_
Packit 857059
Packit 857059
#include "iba/public/iproc_fs_osd.h"
Packit 857059
Packit 857059
#ifdef __cplusplus
Packit 857059
extern "C" {
Packit 857059
#endif
Packit 857059
Packit 857059
Packit 857059
#define NULL_NODE   NULL
Packit 857059
Packit 857059
/* Below are descriptions of the functions which are provided by iproc_fs_osd.h
Packit 857059
 * On some platforms these may be defines, on others they may be actual
Packit 857059
 * functions.
Packit 857059
 */
Packit 857059
Packit 857059
/**********************************************************
Packit 857059
 *     IBA_PROC_READ_FUNC - "/proc node" read handler
Packit 857059
 * 
Packit 857059
 * A driver implements a function of this type to handle reads
Packit 857059
 * from its registered "/proc node". It should fill in the
Packit 857059
 * user data buffer with the data to be returned.
Packit 857059
 * 
Packit 857059
 * The 'off' argument indicates the byte position within
Packit 857059
 * the buffer where the current segment begins. This will
Packit 857059
 * always be zero on Darwin, since the entire user buffer
Packit 857059
 * is read in a single pass.
Packit 857059
 * 
Packit 857059
 * The 'eof' argument points to an End Of File flag that the
Packit 857059
 * driver should set to 1.
Packit 857059
 * 
Packit 857059
 * This function should return the number of bytes written into
Packit 857059
 * the user data buffer, to be displayed as read data.
Packit 857059
 * 
Packit 857059
 * Equivalent to Linux read_func_t:
Packit 857059
 * 
Packit 857059
 * "The read function should write its information into the page.
Packit 857059
 * For proper use, the function should start writing at an offset of off in
Packit 857059
 * page and write at most count bytes, but because most read functions are
Packit 857059
 * quite simple and only return a small amount of information, these two
Packit 857059
 * parameters are usually ignored (it breaks pagers like more
Packit 857059
 * and less, but cat still works).
Packit 857059
 * If the off and count parameters are properly used, eof should be used to
Packit 857059
 * signal that the end of the file has been reached by writing 1 to the memory
Packit 857059
 * location eof points to.
Packit 857059
 * 
Packit 857059
 * The read_func function must return the number of bytes written into the page.
Packit 857059
 * or a IBA_PROC_RET value to reflect an error code"
Packit 857059
 * typedef IBA_PROC_RET (IBA_PROC_READ_FUNC) (
Packit 857059
 *     char *buffer,           // User data buffer
Packit 857059
 *     char **start,           // Not used
Packit 857059
 *     IBA_PROC_OFFSET off,    // Byte offset into buffer
Packit 857059
 *     int count,              // max bytes to write
Packit 857059
 *     int *eof,               // Returned EOF flag
Packit 857059
 *     void *priv              ///Kernel private data
Packit 857059
 * );
Packit 857059
 ***********************************************************/
Packit 857059
Packit 857059
/**********************************************************
Packit 857059
 *     IBA_PROC_WRITE_FUNC - "/proc node" write handler
Packit 857059
 * 
Packit 857059
 * A driver implements a function of this type to handle
Packit 857059
 * writes to its registered "/proc node". It should copy the
Packit 857059
 * data in the user buffer for its own internal use.
Packit 857059
 * 
Packit 857059
 * Equivalent to Linux write_func_t:
Packit 857059
 * 
Packit 857059
 * "The write function should read count bytes at maximum from the buffer."
Packit 857059
 * 
Packit 857059
 * This function returns the number of bytes written
Packit 857059
 * or a IBA_PROC_RET value to reflect an error code
Packit 857059
 * typedef IBA_PROC_RET (IBA_PROC_WRITE_FUNC) (
Packit 857059
 *     IBA_PROC_FILE * file,   // File pointer
Packit 857059
 *     const char *buffer,     // User data buffer
Packit 857059
 *     unsigned long count,    // Max bytes to read
Packit 857059
 *     void *priv              // Kernel private data
Packit 857059
 * );
Packit 857059
 ***********************************************************/
Packit 857059
Packit 857059
/**********************************************************
Packit 857059
 *     iba_proc_mkdir() - Create a "/proc directory node".
Packit 857059
 * 
Packit 857059
 * A driver calls this function to create a directory node
Packit 857059
 * within the emulated "/proc file system" in IbAccess.  The
Packit 857059
 * directory node will be created with the specified file name,
Packit 857059
 * under the directory node specified by 'parent'.
Packit 857059
 * A NULL value for 'parent' implies the root node ("/proc").
Packit 857059
 * 
Packit 857059
 * IbAccess returns an opaque handle to that node.
Packit 857059
 * 
Packit 857059
 * IBA_PROC_NODE *
Packit 857059
 * iba_proc_mkdir(
Packit 857059
 *     const char              *name,      // File name
Packit 857059
 *     IBA_PROC_NODE           *parent     // Parent directory
Packit 857059
 * );
Packit 857059
 ***********************************************************/
Packit 857059
Packit 857059
/**********************************************************
Packit 857059
 *     iba_create_proc_entry() - Create a "/proc file node".
Packit 857059
 * 
Packit 857059
 * A driver calls this function to create a file node
Packit 857059
 * within the emulated "/proc file system" in IbAccess.  The
Packit 857059
 * file node will be created with the specified file name,
Packit 857059
 * under the directory node specified by 'parent'.
Packit 857059
 * A NULL value for 'parent' implies the root node ("/proc").
Packit 857059
 * 
Packit 857059
 * IbAccess returns an opaque handle to that node, which can
Packit 857059
 * be used later to remove it.
Packit 857059
 * 
Packit 857059
 * After the node has been created, IbAccess will accept
Packit 857059
 * PROC_READ and PROC_WRITE User Client commands directed to
Packit 857059
 * this node, calling the driver's registered read and write
Packit 857059
 * handlers, respectively. If a NULL handler was registered,
Packit 857059
 * then IbAccess will return an Access Error to the user
Packit 857059
 * instead. The 'priv' argument is a driver private data
Packit 857059
 * structure that IbAccess will associate with the node and
Packit 857059
 * return to the driver when calling its read or write
Packit 857059
 * handler.
Packit 857059
 * 
Packit 857059
 * IBA_PROC_NODE *
Packit 857059
 * iba_create_proc_entry(
Packit 857059
 *     const char              *name,      // File name
Packit 857059
 *     IBA_PROC_MODE           mode,       // File mode (N/U on Darwin)
Packit 857059
 *     IBA_PROC_NODE           *parent     // Parent directory
Packit 857059
 * );
Packit 857059
 ***********************************************************/
Packit 857059
Packit 857059
/**********************************************************
Packit 857059
 *     iba_get_proc_*(), iba_set_proc_*()
Packit 857059
 * 
Packit 857059
 * These are accessor functions for the opaque IBA_PROC_NODE
Packit 857059
 * structure.
Packit 857059
 * 
Packit 857059
 * void
Packit 857059
 * iba_set_proc_read_func(
Packit 857059
 *     IBA_PROC_NODE           *node,      // File proc node
Packit 857059
 *     IBA_PROC_READ_FUNC      *rd_func    // Read handler function
Packit 857059
 * );
Packit 857059
 * 
Packit 857059
 * void
Packit 857059
 * iba_set_proc_write_func(
Packit 857059
 *     IBA_PROC_NODE           *node,      // File proc node
Packit 857059
 *     IBA_PROC_WRITE_FUNC     *wr_func    // Write handler function
Packit 857059
 * );
Packit 857059
 * 
Packit 857059
 * // return >=0 for byte count on success, <0 is a PROC_IBA_RET_* value
Packit 857059
 * static _inline IBA_PROC_RET
Packit 857059
 * iba_proc_copy_user_data(
Packit 857059
 * 	char				*dest,			// kernel destination buffer
Packit 857059
 * 	const char*			userBuffer,		// user buffer from IBA_PROC_WRITE_FUNC
Packit 857059
 * 	unsigned			bytes			// number of bytes to copy
Packit 857059
 * );
Packit 857059
 * 
Packit 857059
 * void
Packit 857059
 * iba_set_proc_data(
Packit 857059
 *     IBA_PROC_NODE           *node,      // File proc node
Packit 857059
 *     void                    *data       // Private data struct
Packit 857059
 * );
Packit 857059
 * 
Packit 857059
 * void *
Packit 857059
 * iba_get_proc_data(
Packit 857059
 *     IBA_PROC_NODE           *node       // File proc node
Packit 857059
 * );
Packit 857059
 * 
Packit 857059
 * const char *
Packit 857059
 * iba_get_proc_name(
Packit 857059
 *     IBA_PROC_NODE           *node       // File proc node
Packit 857059
 * );
Packit 857059
 ***********************************************************/
Packit 857059
Packit 857059
/**********************************************************
Packit 857059
 *     iba_remove_proc_entry() - Remove a "/proc node".
Packit 857059
 * 
Packit 857059
 * A driver calls this function to remove a previously created
Packit 857059
 * "/proc node", of either file or directory type, specified
Packit 857059
 * by the node name and parent directory node.
Packit 857059
 * A NULL value for 'parent' implies the root node ("/proc").
Packit 857059
 * 
Packit 857059
 * void
Packit 857059
 * iba_remove_proc_entry(
Packit 857059
 *     const char              *name,      // Node name
Packit 857059
 *     IBA_PROC_NODE           *parent     // Parent directory
Packit 857059
 * );
Packit 857059
 ***********************************************************/
Packit 857059
Packit 857059
/* support function type for iba_proc_read_wrapper
Packit 857059
 * called in a premptable context
Packit 857059
 *
Packit 857059
 * Inputs:
Packit 857059
 *	data - context information
Packit 857059
 * Outputs:
Packit 857059
 *	total_size - returns size of proc text returned (not including any \0)
Packit 857059
 * Returns:
Packit 857059
 *   	a pointer to text array of data to output for /proc read
Packit 857059
 *	can be NULL if unable to allocate or no data available
Packit 857059
 *	if NULL is returned, *total_size should be unchanged or 0
Packit 857059
 *	caller will MemoryDeallocate when done
Packit 857059
 */
Packit 857059
typedef char * (*IBA_PROC_FORMAT_FUNC)(void *data, int* total_size);
Packit 857059
Packit 857059
/* General purpose function to support proc file reads
Packit 857059
 * for simple /proc files, this can be provided as the read_func
Packit 857059
 *
Packit 857059
 * config_data, config_alloc, total_size - static variables in proc function
Packit 857059
 *		will be managed here to maintain context across multiple read calls to
Packit 857059
 *		this file.
Packit 857059
 * func - function to allocate space to text contents and format it
Packit 857059
 * func_data - will be passed as argument to provide context of what to format
Packit 857059
 * buf, start, offset, maxlen, eof - standard proc read arguments
Packit 857059
 */
Packit 857059
Packit 857059
extern IBA_PROC_RET
Packit 857059
iba_proc_read_wrapper(char **config_data, char **config_alloc, int *total_size,
Packit 857059
		IBA_PROC_FORMAT_FUNC func, void* func_data,
Packit 857059
 		char *buf, char **start, IBA_PROC_OFFSET offset, int maxlen,
Packit 857059
		int *eof);
Packit 857059
Packit 857059
/* for simpler /proc interfaces, this provides a simplified
Packit 857059
 * interface.  Caller need only supply a format function and an optional
Packit 857059
 * clear function (to be called by write)
Packit 857059
 * The function provides all the necessary initialization and handler functions
Packit 857059
 * for the /proc interface itself
Packit 857059
 */
Packit 857059
Packit 857059
/* function type for optional clear function, used on write to /proc file */
Packit 857059
typedef void (*SIMPLE_PROC_CLEAR_FUNC)(void *context);
Packit 857059
Packit 857059
#define SIMPLE_PROC_NAME_LEN 80
Packit 857059
typedef struct _SIMPLE_PROC {
Packit 857059
	boolean			Initialized;
Packit 857059
	void 			*Context;	/* callback's context */
Packit 857059
	char 			Name[SIMPLE_PROC_NAME_LEN];/* relative file name */
Packit 857059
	IBA_PROC_NODE 		*ProcDir;	/* parent directory */
Packit 857059
	IBA_PROC_FORMAT_FUNC	FormatFunc;	/* callback function */
Packit 857059
	SIMPLE_PROC_CLEAR_FUNC 	ClearFunc;	/* callback function */
Packit 857059
	char 			*config_data;	/* for use in read */
Packit 857059
	char 			*config_alloc;	/* for use in read */
Packit 857059
	int 			total_size;	/* for use in read */
Packit 857059
} SIMPLE_PROC;
Packit 857059
Packit 857059
extern void
Packit 857059
SimpleProcInitState(SIMPLE_PROC *pProc);
Packit 857059
Packit 857059
/* create and initialize /proc file
Packit 857059
 * Inputs:
Packit 857059
 *	pProc - object to initialize
Packit 857059
 *	Name - relative filename in ProcDir
Packit 857059
 *	ProcDir - parent directory
Packit 857059
 *	Context - context to pass to FormatFunc and ClearFunc
Packit 857059
 *	FormatFunc - function to allocate and format /proc read data
Packit 857059
 *	ClearFunc - function to clear data in response to /proc write
Packit 857059
 * Outputs:
Packit 857059
 *	None
Packit 857059
 * Returns:
Packit 857059
 *	true - initialized and callbacks will begin on user access to /proc
Packit 857059
 *	false - unable to create
Packit 857059
 *
Packit 857059
 * must be called in a preemptable context
Packit 857059
 */
Packit 857059
extern boolean
Packit 857059
SimpleProcInit(SIMPLE_PROC *pProc, const char* Name, IBA_PROC_NODE *ProcDir, 
Packit 857059
		void *Context, IBA_PROC_FORMAT_FUNC FormatFunc,
Packit 857059
		OPTIONAL SIMPLE_PROC_CLEAR_FUNC ClearFunc);
Packit 857059
Packit 857059
extern void
Packit 857059
SimpleProcDestroy(SIMPLE_PROC *pProc);
Packit 857059
Packit 857059
#ifdef __cplusplus
Packit 857059
}
Packit 857059
#endif
Packit 857059
Packit 857059
#endif /* _IPROC_FS_H_ */