~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/fusd/test/fusd-test.c


  1 /*
  2  *
  3  * Copyright (c) 2003 The Regents of the University of California.  All 
  4  * rights reserved.
  5  *
  6  * Redistribution and use in source and binary forms, with or without
  7  * modification, are permitted provided that the following conditions
  8  * are met:
  9  *
 10  * - Redistributions of source code must retain the above copyright
 11  *   notice, this list of conditions and the following disclaimer.
 12  *
 13  * - Neither the name of the University nor the names of its
 14  *   contributors may be used to endorse or promote products derived
 15  *   from this software without specific prior written permission.
 16  *
 17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 20  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28  *
 29  */
 30  
 31 
 32 #include <stdio.h>
 33 #include <stdlib.h>
 34 #include <unistd.h>
 35 #include <errno.h>
 36 
 37 #include "fusd.h"
 38 
 39 int ID = 0;
 40 int rID = 0;
 41 
 42 #define EOK 0
 43 
 44 struct device {
 45   int some_data;
 46 };
 47 
 48 struct files {
 49   int some_data;
 50 };
 51 
 52 
 53 int do_open(struct fusd_file_info *file)
 54 {
 55   struct files *f = malloc(sizeof(struct files));
 56   f->some_data = ID++;
 57   file->private_data = f;
 58   return EOK;
 59 }
 60 
 61 int do_close(struct fusd_file_info *file)
 62 {
 63   free (file->private_data);
 64   return EOK;
 65 }
 66 
 67 int do_read(struct fusd_file_info *file, char *buffer, 
 68          size_t length, loff_t *offset)
 69 {
 70   struct files *f = (struct files *)file->private_data;
 71   return snprintf(buffer, lengthm "file#%d/read#%d\n", f->some_data, rID++);
 72 }
 73 
 74 int do_write(struct fusd_file_info *file, const char *buffer,
 75           size_t length, loff_t *offset)
 76 {
 77   return length;
 78 }
 79 
 80 int do_ioctl(struct fusd_file_info *file, int request, 
 81           ssize_t len, void *data)
 82 {
 83   fusd_return(file,ENOSYS);
 84   return FUSD_NOREPLY;
 85 }
 86 
 87 
 88 int notify(struct fusd_file_info *file, int flags)
 89 {
 90   return (flags & (FUSD_NOTIFY_INPUT | FUSD_NOTIFY_OUTPUT));
 91 }
 92 
 93 int unblock(struct fusd_file_info *file)
 94 {
 95   return EOK;
 96 }
 97 
 98 
 99 int main() 
100 {
101   // init function table

102   struct fusd_file_operations
103     fops = {do_open, 
104             do_close,
105             do_read, 
106             do_write,
107             do_ioctl,
108             notify,
109             unblock};
110 
111   struct device d;
112 
113   // register the device...

114   int fd = fusd_register("test", 0600, &d, &fops);
115   if (fd < 0) {
116     fprintf(stderr, "fusd-test: fusd register failed.\n");
117     perror("fusd-test");
118     exit(1);
119   }
120 
121   fusd_run(fd);
122   
123   return 0;
124 }
125 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.