|
|
Jump to this file's LXR Page |
|
|
File: [CENS] / emstar / fusd / test / zero.c
(download)
/
(as text)
Revision: 1.9, Wed May 12 04:02:58 2004 UTC (5 years, 6 months ago) by girod Branch: MAIN CVS Tags: scale_radio_channel, rdd_alpha_version_1, pregeonet, nims-lab-Sep07-2004, nims-jr-Sep05-04, mote, lessgps_release, kiss_release, bp_scale_radio_channel, acoustic-05-18-06, PRE_TOSNIC_FIX, PRE_NOMEGA_MOTENIC, PRE_CEILING_FIX, PRE_64BIT, MOTENIC_PRE_BUGFIX_20050415, LESSGPS_1_00, LAURA_CALIBRATION_EXPERIMENTS, KISS_1_0, HOSTMOTE_V_6_EXPERIMENTAL, HOSTMOTE_PROTOCOL_VERSION_7, HOSTMOTE_PROTOCOL_VERSION_6_WITH_HOSTMOAP, HOSTMOTE_PROTOCOL_VERSION_5_WITH_HOSTMOAP, HOSTMOTE_PROTOCOL_VERSION_5, HOSTMOTE_PROTOCOL_VERSION_4, HOSTMOTE_PROTOCOL_VERSION_3, HEAD, ESS_RELEASE_3_5, ESS_RELEASE_3_4, ESS_RELEASE_3_3, ESS_RELEASE_3_2, ESS_RELEASE_3_1, ESS_RELEASE_3_0, ESS_RELEASE_2_0, ESS_CONNECTIVITY, ESS_CENTROUTE_TESTING, ESS2-CMS-V1_5_pretest, ESS2-CMS-V1_4cMergeSympathy_2, ESS2-CMS-V1_4c, ESS2-CMS-V1_4b, ESS2-CMS-V1_4a, ESS2-CMS-V1_3, ESS2-CMS-V1_2, ESS2-CMS-V1_1, ESS2-CMS-V1_0, EMSTAR_RELEASE_2_5, EMSTAR_RELEASE_2_1_BRANCH, EMSTAR_RELEASE_2_1, EMSTAR_RELEASE_2_0, EMSTAR_PRE_HTML, CYCLOPS_RELEASE_CANDIDATE_2_0, CYCLOPS_PRERELEASE_STABLE, CENTROUTE_EMSTAR_SOCKETS, BG_1_0, BANGLADESH_ARSENIC_1_2, BANGLADESH_ARSENIC_1_1, AMARSS_JR_DEPLOYMENT_6_05_07 Changes since 1.8: +10 -4 lines zero |
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* /proc/zero test program
*
* $Id: zero.c,v 1.9 2004/05/12 05:02:58 girod Exp $
*/
#include <linux/config.h>
#include <linux/stddef.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
#include <linux/tqueue.h>
#endif
#include <linux/sched.h>
#include <linux/kernel.h>
#ifdef MODULE
#include <linux/module.h>
#endif
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/devfs_fs_kernel.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
# ifndef MODULE
# define MOD_INC_USE_COUNT
# define MOD_DEC_USE_COUNT
# endif
#endif
/************************************************************************/
static ssize_t zero_read(struct file *file,
char *user_buffer, /* The buffer to fill with data */
size_t user_length, /* The length of the buffer */
loff_t *offset) /* Our offset in the file */
{
int retval = 0;
char *buffer;
buffer = kmalloc(user_length, GFP_KERNEL);
if (buffer == NULL) {
return -ENOMEM;
}
memset(buffer, 0, user_length);
if (copy_to_user(user_buffer, buffer, user_length)) {
retval = -EFAULT;
goto out;
}
retval = user_length;
out:
kfree(buffer);
return retval;
}
static unsigned int zero_poll(struct file *file, poll_table *wait)
{
return POLLIN | POLLRDNORM;
}
static int zero_open(struct inode *inode, struct file *file)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
MOD_INC_USE_COUNT;
#endif
return 0;
}
static int zero_release(struct inode *inode, struct file *file)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
MOD_DEC_USE_COUNT;
#endif
return 0;
}
static struct file_operations zero_fops = {
owner: THIS_MODULE,
read: zero_read,
poll: zero_poll,
open: zero_open,
release: zero_release
};
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
static devfs_handle_t zero_handle = 0;
#else
static int devfs_major;
#endif /* VERSION < 2.6.0 */
int init_module(void)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
zero_handle = devfs_register(NULL, "zero2",
DEVFS_FL_AUTO_DEVNUM,
0, 0,
S_IFCHR | S_IRUSR | S_IWUSR, //| 0666,
&zero_fops, NULL);
if (zero_handle == 0) {
printk("zero2: unable to register character device\n");
return -EIO;
}
#else
/* try to register the zero device */
if((devfs_major=register_chrdev(0, "zero2", &zero_fops)) < 0) {
printk("zero2: unable to register character device\n");
return -EIO;
}
/* register the zero device with devfs */
if (devfs_mk_cdev(MKDEV(devfs_major, 0),
S_IFCHR | S_IRUSR | S_IWUSR, "zero2") < 0) {
printk("zero2: unable to register zero2 devfs device\n");
unregister_chrdev(devfs_major, "zero2");
return -EIO;
}
#endif /* VERSION < 2.6.0 */
return 0;
}
void cleanup_module(void)
{
/* unregister the character device */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
devfs_unregister(zero_handle);
#else
devfs_remove("zero2");
unregister_chrdev(devfs_major, "zero2");
#endif /* VERSION < 2.6.0 */
printk("done..\n");
}
| CENS CVS Mailing List |
Powered by ViewCVS 0.9.2 |