Module: xenomai-gch
Branch: for-forge
Commit: 3008babc4282a53a8636f6b05d1b428dc581e2fe
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=3008babc4282a53a8636f6b05d1b428dc581e2fe

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Fri Dec 27 10:24:17 2013 +0100

cobalt/fd: move accessors to fd callbacks to fd.c

---

 include/cobalt/kernel/fd.h |   10 +++++++
 kernel/cobalt/fd.c         |   67 +++++++++++++++++++++++++++++++++++++++++---
 kernel/cobalt/posix/fdio.c |   52 +++-------------------------------
 3 files changed, 77 insertions(+), 52 deletions(-)

diff --git a/include/cobalt/kernel/fd.h b/include/cobalt/kernel/fd.h
index bb8d94d..4f004f5 100644
--- a/include/cobalt/kernel/fd.h
+++ b/include/cobalt/kernel/fd.h
@@ -51,6 +51,8 @@ struct xnfd {
        struct list_head link;   /* Link in per-process queue */
 };
 
+#define XNFD_MAGIC_ANY 0
+
 int xnfd_enter(struct xnfd *xnfd, unsigned magic, int ufd, 
        struct xnsys_ppd *p, struct xnfd_ops *ops);
 
@@ -58,6 +60,14 @@ struct xnfd *xnfd_get(int ufd, struct mm_struct *mm, 
unsigned magic);
 
 int xnfd_put(struct xnfd *xnfd);
 
+int xnfd_ioctl(int fd, struct mm_struct *mm, 
+       unsigned request, void __user *arg);
+
+int xnfd_read(int fd, struct mm_struct *mm, void __user *buf, size_t size);
+
+int xnfd_write(int fd, struct mm_struct *mm, 
+       const void __user *buf, size_t size);
+
 int xnfd_close(int ufd, struct mm_struct *mm, unsigned magic);
 
 static inline int xnfd_getfd(struct xnfd *xnfd)
diff --git a/kernel/cobalt/fd.c b/kernel/cobalt/fd.c
index ebc0af6..c350492 100644
--- a/kernel/cobalt/fd.c
+++ b/kernel/cobalt/fd.c
@@ -70,7 +70,7 @@ int xnfd_enter(struct xnfd *xnfd, unsigned magic, int ufd,
        spl_t s;
        int err;
 
-       if (magic == 0) {
+       if (magic == XNFD_MAGIC_ANY) {
                err = -EINVAL;
                goto err;
        }
@@ -142,7 +142,7 @@ struct xnfd *xnfd_get(int ufd, struct mm_struct *mm, 
unsigned magic)
        
        xnlock_get_irqsave(&xnfd_lock, s);
        res = xnfd_hash_search(ufd, mm);
-       if (res == NULL || (magic && res->magic != magic)) {
+       if (res == NULL || (magic != XNFD_MAGIC_ANY && res->magic != magic)) {
                res = ERR_PTR(-EBADF);
                goto err_unlock;
        }
@@ -187,6 +187,65 @@ int xnfd_put(struct xnfd *xnfd)
        return 0;
 }
 
+int xnfd_ioctl(int fd, struct mm_struct *mm, 
+               unsigned int request, void __user *arg)
+{
+       struct xnfd *xnfd;
+       int err;
+       
+       xnfd = xnfd_get(fd, mm, XNFD_MAGIC_ANY);
+       if (IS_ERR(xnfd))
+               return PTR_ERR(xnfd);
+       
+       if (ipipe_root_p)
+               err = xnfd->ops->ioctl_nrt(xnfd, request, arg);
+       else
+               err = xnfd->ops->ioctl_rt(xnfd, request, arg);
+       
+       xnfd_put(xnfd);
+       
+       return err;
+}
+
+ssize_t xnfd_read(int fd, struct mm_struct *mm, void __user *buf, size_t size)
+{
+       struct xnfd *xnfd;
+       ssize_t err;
+       
+       xnfd = xnfd_get(fd, mm, XNFD_MAGIC_ANY);
+       if (IS_ERR(xnfd))
+               return PTR_ERR(xnfd);
+       
+       if (ipipe_root_p)
+               err = xnfd->ops->read_nrt(xnfd, buf, size);
+       else
+               err = xnfd->ops->read_rt(xnfd, buf, size);
+       
+       xnfd_put(xnfd);
+       
+       return err;
+}
+
+ssize_t xnfd_write(int fd, struct mm_struct *mm, 
+               const void __user *buf, size_t size)
+{
+       struct xnfd *xnfd;
+       ssize_t err;
+       
+       xnfd = xnfd_get(fd, mm, XNFD_MAGIC_ANY);
+       if (IS_ERR(xnfd))
+               return PTR_ERR(xnfd);
+       
+       if (ipipe_root_p)
+               err = xnfd->ops->write_nrt(xnfd, buf, size);
+       else
+               err = xnfd->ops->write_rt(xnfd, buf, size);
+       
+       xnfd_put(xnfd);
+       
+       return err;
+}
+
 int xnfd_close(int ufd, struct mm_struct *mm, unsigned magic)
 {
        struct xnfd *xnfd;
@@ -194,7 +253,7 @@ int xnfd_close(int ufd, struct mm_struct *mm, unsigned 
magic)
        
        xnlock_get_irqsave(&xnfd_lock, s);
        xnfd = xnfd_hash_search(ufd, mm);
-       if (xnfd == NULL || (magic && xnfd->magic != magic)) {
+       if (xnfd == NULL || (magic != XNFD_MAGIC_ANY && xnfd->magic != magic)) {
                xnlock_put_irqrestore(&xnfd_lock, s);
                return -EBADF;
        }
@@ -231,7 +290,7 @@ int xnfd_select_bind(int ufd, struct mm_struct *mm,
        xnfd = xnfd_hash_search(ufd, mm);
        if (xnfd == NULL) {
                xnlock_put_irqrestore(&xnfd_lock, s);
-               return -ENOENT;
+               return -EBADF;
        }
        xnfd->refs++;
        xnlock_put_irqrestore(&xnfd_lock, s);
diff --git a/kernel/cobalt/posix/fdio.c b/kernel/cobalt/posix/fdio.c
index 479401b..8a13771 100644
--- a/kernel/cobalt/posix/fdio.c
+++ b/kernel/cobalt/posix/fdio.c
@@ -7,64 +7,20 @@
 
 int cobalt_ioctl(int fd, unsigned int request, void __user *arg)
 {
-       struct xnfd *xnfd;
-       int err;
-       
-       xnfd = xnfd_get(fd, current->mm, 0);
-       if (IS_ERR(xnfd))
-               return PTR_ERR(xnfd);
-       
-       if (ipipe_root_p)
-               err = xnfd->ops->ioctl_nrt(xnfd, request, arg);
-       else
-               err = xnfd->ops->ioctl_rt(xnfd, request, arg);
-       
-       xnfd_put(xnfd);
-       
-       return err;
+       return xnfd_ioctl(fd, current->mm, request, arg);
 }
 
 ssize_t cobalt_read(int fd, void __user *buf, size_t size)
 {
-       struct xnfd *xnfd;
-       ssize_t err;
-       
-       xnfd = xnfd_get(fd, current->mm, 0);
-       if (IS_ERR(xnfd))
-               return PTR_ERR(xnfd);
-       
-       if (ipipe_root_p)
-               err = xnfd->ops->read_nrt(xnfd, buf, size);
-       else
-               err = xnfd->ops->read_rt(xnfd, buf, size);
-       
-       xnfd_put(xnfd);
-       
-       return err;
+       return xnfd_read(fd, current->mm, buf, size);
 }
 
 ssize_t cobalt_write(int fd, const void __user *buf, size_t size)
 {
-       struct xnfd *xnfd;
-       ssize_t err;
-       
-       xnfd = xnfd_get(fd, current->mm, 0);
-       if (IS_ERR(xnfd))
-               return PTR_ERR(xnfd);
-       
-       if (ipipe_root_p)
-               err = xnfd->ops->write_nrt(xnfd, buf, size);
-       else
-               err = xnfd->ops->write_rt(xnfd, buf, size);
-       
-       xnfd_put(xnfd);
-       
-       return err;
+       return xnfd_write(fd, current->mm, buf, size);
 }
 
 int cobalt_close(int fd)
 {
-       return xnfd_close(fd, current->mm, 0);
+       return xnfd_close(fd, current->mm, XNFD_MAGIC_ANY);
 }
-
-


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to