1 ? fusd-flag-for-more-data.patch
2 Index: fusd/include/fusd_msg.h
3 ===================================================================
4 RCS file: /home/cvs/cvsroot/cens/fusd/include/fusd_msg.h,v
5 retrieving revision 1.21
6 diff -u -r1.21 fusd_msg.h
7 --- fusd/include/fusd_msg.h 2003/01/02 01:05:47 1.21
8 +++ fusd/include/fusd_msg.h 2003/01/02 21:29:23
9 @@ -37,6 +37,10 @@
10
11 #define FUSD_FOPS_CALL_DROPREPLY 6 /* call that doesn't want a reply */
12
13 +/* this bit gets **OR'd** into the cmd if there are more kernel->user
14 + * messages waiting */
15 +#define FUSD_MORE_MESSAGES (1 << 7)
16 +
17 /* subcommands */
18 #define FUSD_OPEN 100
19 #define FUSD_CLOSE 101
20 @@ -47,7 +51,7 @@
21 #define FUSD_UNBLOCK 106
22
23 /* other constants */
24 -#define FUSD_MSG_MAGIC 0x7a6b93cd
25 +#define FUSD_MSG_MAGIC 0x7a6b93ce /* version number included :-) */
26
27 /* user->kernel: register a device */
28 typedef struct {
29 Index: fusd/kfusd/kfusd.c
30 ===================================================================
31 RCS file: /home/cvs/cvsroot/cens/fusd/kfusd/kfusd.c,v
32 retrieving revision 1.88
33 diff -u -r1.88 kfusd.c
34 --- fusd/kfusd/kfusd.c 2003/01/02 05:15:46 1.88
35 +++ fusd/kfusd/kfusd.c 2003/01/02 21:29:23
36 @@ -1796,16 +1796,20 @@
37
38
39 /* do a "header" read: used by fusd_read */
40 -static int fusd_read_header(char *user_buffer, size_t user_length, fusd_msg_t *msg)
41 +static int fusd_read_header(char *user_buffer, size_t user_length, fusd_msgC_t *container)
42 {
43 - int len = sizeof(fusd_msg_t);
44 -
45 - if (user_length != len) {
46 + /* sanity check */
47 + if (user_length != sizeof(fusd_msg_t)) {
48 RDEBUG(4, "bad length of %d sent to /dev/fusd for peek", user_length);
49 return -EINVAL;
50 }
51
52 - if (copy_to_user(user_buffer, msg, len))
53 + /* give a hint to the reader as to whether or not they should read
54 + * again after this read .. i.e. if there is more data waiting. */
55 + if (container->next)
56 + container->fusd_msg.cmd |= FUSD_MORE_MESSAGES;
57 +
58 + if (copy_to_user(user_buffer, &container->fusd_msg, sizeof(fusd_msg_t)))
59 return -EFAULT;
60
61 return sizeof(fusd_msg_t);
62 @@ -1813,8 +1817,9 @@
63
64
65 /* do a "data" read: used by fusd_read */
66 -static int fusd_read_data(char *user_buffer, size_t user_length, fusd_msg_t *msg)
67 +static int fusd_read_data(char *user_buffer, size_t user_length, fusd_msgC_t *container)
68 {
69 + fusd_msg_t *msg = &container->fusd_msg;
70 int len = msg->datalen;
71
72 if (len == 0 || msg->data == NULL) {
73 @@ -1881,11 +1886,11 @@
74 goto out;
75 }
76 }
77 -
78 +
79 /* is this a header read or data read? */
80 if (!msg_out->peeked) {
81 /* this is a header read (first read) */
82 - retval = fusd_read_header(user_buffer, user_length, &msg_out->fusd_msg);
83 + retval = fusd_read_header(user_buffer, user_length, msg_out);
84
85 /* is there data? if so, make sure next read gets data. if not,
86 * make sure message is dequeued now.*/
87 @@ -1897,7 +1902,7 @@
88 }
89 } else {
90 /* this is a data read (second read) */
91 - retval = fusd_read_data(user_buffer, user_length, &msg_out->fusd_msg);
92 + retval = fusd_read_data(user_buffer, user_length, msg_out);
93 dequeue = 1; /* message should be dequeued */
94 }
95
96 Index: fusd/libfusd/libfusd.c
97 ===================================================================
98 RCS file: /home/cvs/cvsroot/cens/fusd/libfusd/libfusd.c,v
99 retrieving revision 1.56
100 diff -u -r1.56 libfusd.c
101 --- fusd/libfusd/libfusd.c 2002/12/28 01:42:04 1.56
102 +++ fusd/libfusd/libfusd.c 2003/01/02 21:29:23
103 @@ -309,8 +309,11 @@
104 * back to the kernel, IF the return value from the callback is not
105 * FUSD_NOREPLY.
106 *
107 - * On success, returns 0.
108 + * On success, if there are no more messages queued in the kernel, returns 1.
109 + * On success, if there are additional messages waiting, returns 0.
110 * On failure, returns a negative number indicating the errno.
111 + *
112 + * Keep reading as long as you are getting 0 as the retval.
113 */
114 static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
115 {
116 @@ -318,6 +321,7 @@
117 fusd_msg_t *msg = NULL;
118 int driver_retval = 0; /* returned to the FUSD driver */
119 int user_retval = 0; /* returned to the user who made the syscall */
120 + int more_messages = 0;
121
122 /* check for valid, look up ops */
123 if (fops == NULL) {
124 @@ -338,6 +342,14 @@
125 if ((driver_retval = fusd_get_message(fd, msg)) < 0)
126 goto out_noreply;
127
128 + /* The kernel turns on a bit in the CMD field if there are more
129 + * messages waiting. If it is set, take note of it, and then clear
130 + * it. */
131 + if (msg->cmd & FUSD_MORE_MESSAGES) {
132 + more_messages = 1;
133 + msg->cmd &= ~(FUSD_MORE_MESSAGES); /* clear this bit */
134 + }
135 +
136 /* allocate file info struct */
137 file = malloc(sizeof(fusd_file_info_t));
138 if (NULL == file) {
139 @@ -460,6 +472,8 @@
140 if (driver_retval < 0) {
141 errno = -driver_retval;
142 driver_retval = -1;
143 + } else if (driver_retval == 0 && !more_messages) {
144 + driver_retval = 1;
145 }
146 return driver_retval;
147 }
148 @@ -490,10 +504,7 @@
149 /* now keep dispatching until a dispatch returns an error */
150 do {
151 retval = fusd_dispatch_one(fd, fops);
152 -
153 - if (retval >= 0)
154 - num_dispatches++;
155 - } while (retval >= 0 && num_dispatches <= MAX_MESSAGES_PER_DISPATCH);
156 + } while (!retval && ++num_dispatches <= MAX_MESSAGES_PER_DISPATCH);
157
158 /* if we've dispatched at least one message successfully, and then
159 * stopped because of EAGAIN - do not report an error. this is the
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.