]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/9p/protocol.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6
[linux-2.6-omap-h63xx.git] / net / 9p / protocol.c
index 4ebeffd21d3d170f56053943b9949b0625936f28..dcd7666824ba57708df3fa9e9f4a8d6893539712 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/uaccess.h>
+#include <linux/sched.h>
 #include <net/9p/9p.h>
 #include <net/9p/client.h>
 #include "protocol.h"
@@ -52,8 +53,7 @@
 static int
 p9pdu_writef(struct p9_fcall *pdu, int optional, const char *fmt, ...);
 
-#define PACKET_DEBUG 0
-
+#ifdef CONFIG_NET_9P_DEBUG
 void
 p9pdu_dump(int way, struct p9_fcall *pdu)
 {
@@ -78,10 +78,16 @@ p9pdu_dump(int way, struct p9_fcall *pdu)
        n += scnprintf(buf + n, buflen - n, "\n");
 
        if (way)
-               printk(KERN_NOTICE "[[(%d)[ %s\n", datalen, buf);
+               P9_DPRINTK(P9_DEBUG_PKT, "[[[(%d) %s\n", datalen, buf);
        else
-               printk(KERN_NOTICE "]](%d)] %s\n", datalen, buf);
+               P9_DPRINTK(P9_DEBUG_PKT, "]]](%d) %s\n", datalen, buf);
+}
+#else
+void
+p9pdu_dump(int way, struct p9_fcall *pdu)
+{
 }
+#endif
 EXPORT_SYMBOL(p9pdu_dump);
 
 void p9stat_free(struct p9_wstat *stbuf)
@@ -180,7 +186,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
                        }
                        break;
                case 's':{
-                               char **ptr = va_arg(ap, char **);
+                               char **sptr = va_arg(ap, char **);
                                int16_t len;
                                int size;
 
@@ -190,17 +196,17 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
 
                                size = MAX(len, 0);
 
-                               *ptr = kmalloc(size + 1, GFP_KERNEL);
-                               if (*ptr == NULL) {
+                               *sptr = kmalloc(size + 1, GFP_KERNEL);
+                               if (*sptr == NULL) {
                                        errcode = -EFAULT;
                                        break;
                                }
-                               if (pdu_read(pdu, *ptr, size)) {
+                               if (pdu_read(pdu, *sptr, size)) {
                                        errcode = -EFAULT;
-                                       kfree(*ptr);
-                                       *ptr = NULL;
+                                       kfree(*sptr);
+                                       *sptr = NULL;
                                } else
-                                       (*ptr)[size] = 0;
+                                       (*sptr)[size] = 0;
                        }
                        break;
                case 'Q':{
@@ -216,9 +222,9 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
                                struct p9_wstat *stbuf =
                                    va_arg(ap, struct p9_wstat *);
 
-                               stbuf->extension = NULL;
+                               memset(stbuf, 0, sizeof(struct p9_wstat));
                                stbuf->n_uid = stbuf->n_gid = stbuf->n_muid =
-                                   -1;
+                                                                       -1;
                                errcode =
                                    p9pdu_readf(pdu, optional,
                                                "wwdQdddqssss?sddd",
@@ -374,13 +380,13 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
                        }
                        break;
                case 's':{
-                               const char *ptr = va_arg(ap, const char *);
+                               const char *sptr = va_arg(ap, const char *);
                                int16_t len = 0;
-                               if (ptr)
-                                       len = MIN(strlen(ptr), USHORT_MAX);
+                               if (sptr)
+                                       len = MIN(strlen(sptr), USHORT_MAX);
 
                                errcode = p9pdu_writef(pdu, optional, "w", len);
-                               if (!errcode && pdu_write(pdu, ptr, len))
+                               if (!errcode && pdu_write(pdu, sptr, len))
                                        errcode = -EFAULT;
                        }
                        break;
@@ -420,7 +426,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap)
                case 'U':{
                                int32_t count = va_arg(ap, int32_t);
                                const char __user *udata =
-                                               va_arg(ap, const void *);
+                                               va_arg(ap, const void __user *);
                                errcode =
                                    p9pdu_writef(pdu, optional, "d", count);
                                if (!errcode && pdu_write_u(pdu, udata, count))
@@ -509,6 +515,26 @@ p9pdu_writef(struct p9_fcall *pdu, int optional, const char *fmt, ...)
        return ret;
 }
 
+int p9stat_read(char *buf, int len, struct p9_wstat *st, int dotu)
+{
+       struct p9_fcall fake_pdu;
+       int ret;
+
+       fake_pdu.size = len;
+       fake_pdu.capacity = len;
+       fake_pdu.sdata = buf;
+       fake_pdu.offset = 0;
+
+       ret = p9pdu_readf(&fake_pdu, dotu, "S", st);
+       if (ret) {
+               P9_DPRINTK(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret);
+               p9pdu_dump(1, &fake_pdu);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(p9stat_read);
+
 int p9pdu_prepare(struct p9_fcall *pdu, int16_t tag, int8_t type)
 {
        return p9pdu_writef(pdu, 0, "dbw", 0, type, tag);
@@ -523,8 +549,13 @@ int p9pdu_finalize(struct p9_fcall *pdu)
        err = p9pdu_writef(pdu, 0, "d", size);
        pdu->size = size;
 
-       if (PACKET_DEBUG)
+#ifdef CONFIG_NET_9P_DEBUG
+       if ((p9_debug_level & P9_DEBUG_PKT) == P9_DEBUG_PKT)
                p9pdu_dump(0, pdu);
+#endif
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> size=%d type: %d tag: %d\n", pdu->size,
+                                                       pdu->id, pdu->tag);
 
        return err;
 }