|
|
Jump to this file's LXR Page |
|
|
File: [CENS] / emstar / fusd / test / fusd-test.c
(download)
/
(as text)
Revision: 1.7, Fri Jun 11 00:58:43 2004 UTC (5 years, 5 months ago) by jelson Branch: MAIN CVS Tags: rdd_alpha_version_1, pregeonet, nims-lab-Sep07-2004, nims-jr-Sep05-04, mote, lessgps_release, 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, 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, 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.6: +10 -10 lines renamed functions that had confusing names |
/*
*
* 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.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "fusd.h"
int ID = 0;
int rID = 0;
#define EOK 0
struct device {
int some_data;
};
struct files {
int some_data;
};
int do_open(struct fusd_file_info *file)
{
struct files *f = malloc(sizeof(struct files));
f->some_data = ID++;
file->private_data = f;
return EOK;
}
int do_close(struct fusd_file_info *file)
{
free (file->private_data);
return EOK;
}
int do_read(struct fusd_file_info *file, char *buffer,
size_t length, loff_t *offset)
{
struct files *f = (struct files *)file->private_data;
return snprintf(buffer, lengthm "file#%d/read#%d\n", f->some_data, rID++);
}
int do_write(struct fusd_file_info *file, const char *buffer,
size_t length, loff_t *offset)
{
return length;
}
int do_ioctl(struct fusd_file_info *file, int request,
ssize_t len, void *data)
{
fusd_return(file,ENOSYS);
return FUSD_NOREPLY;
}
int notify(struct fusd_file_info *file, int flags)
{
return (flags & (FUSD_NOTIFY_INPUT | FUSD_NOTIFY_OUTPUT));
}
int unblock(struct fusd_file_info *file)
{
return EOK;
}
int main()
{
// init function table
struct fusd_file_operations
fops = {do_open,
do_close,
do_read,
do_write,
do_ioctl,
notify,
unblock};
struct device d;
// register the device...
int fd = fusd_register("test", 0600, &d, &fops);
if (fd < 0) {
fprintf(stderr, "fusd-test: fusd register failed.\n");
perror("fusd-test");
exit(1);
}
fusd_run(fd);
return 0;
}
| CENS CVS Mailing List |
Powered by ViewCVS 0.9.2 |