diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-16 17:46:25 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-16 17:46:25 +0000 |
commit | 4077a70fc256a7dd65febe986f176b8ac62091fc (patch) | |
tree | 6f0e34d559c8fa2f07c686043df3494cd7fdcff2 /nuttx/fs/fs_ioctl.c | |
parent | 42027d080b72b8198072e7dc3933d8b70b6b40a5 (diff) | |
download | px4-nuttx-4077a70fc256a7dd65febe986f176b8ac62091fc.tar.gz px4-nuttx-4077a70fc256a7dd65febe986f176b8ac62091fc.tar.bz2 px4-nuttx-4077a70fc256a7dd65febe986f176b8ac62091fc.zip |
Add basic structure to support netdevice ioctls
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@344 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs/fs_ioctl.c')
-rw-r--r-- | nuttx/fs/fs_ioctl.c | 99 |
1 files changed, 83 insertions, 16 deletions
diff --git a/nuttx/fs/fs_ioctl.c b/nuttx/fs/fs_ioctl.c index e40ae25a5..52329d60c 100644 --- a/nuttx/fs/fs_ioctl.c +++ b/nuttx/fs/fs_ioctl.c @@ -1,5 +1,5 @@ -/************************************************************ - * fs_ioctl.c +/**************************************************************************** + * fs/fs_ioctl.c * * Copyright (C) 2007 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> @@ -31,39 +31,96 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Compilation Switches - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> #include <sched.h> #include <errno.h> #include <sys/ioctl.h> + +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 +# include <nuttx/net.h> +#endif + #include "fs_internal.h" -/************************************************************ +/**************************************************************************** * Global Functions - ************************************************************/ + ****************************************************************************/ + +/**************************************************************************** + * Name: ioctl + * + * Description: + * Perform device specific operations. + * + * Parameters: + * fd Filt/socket descriptor of device + * req The ioctl command + * arg The argument of the ioctl cmd + * + * Return: + * >=0 on success (positive non-zero values are cmd-specific) + * -1 on failure withi errno set properly: + * + * EBADF + * 'fd' is not a valid descriptor. + * EFAULT + * 'arg' references an inaccessible memory area. + * EINVAL + * 'cmd' or 'arg' is not valid. + * ENOTTY + * 'fd' is not associated with a character special device. + * ENOTTY + * The specified request does not apply to the kind of object that the + * descriptor 'fd' references. + * + ****************************************************************************/ int ioctl(int fd, int req, unsigned long arg) { + int err; +#if CONFIG_NFILE_DESCRIPTORS > 0 FAR struct filelist *list; - int ret = EBADF; + int ret = OK; + + /* Did we get a valid file descriptor? */ + + if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) +#endif + { + /* Perform the socket ioctl */ +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) + { + return netdev_ioctl(fd, req, (struct ifreq*)arg); + } + else +#endif + { + err = EBADF; + goto errout; + } + } + +#if CONFIG_NFILE_DESCRIPTORS > 0 /* Get the thread-specific file list */ list = sched_getfiles(); if (!list) { - *get_errno_ptr() = EMFILE; - return ERROR; + err = EMFILE; + goto errout; } /* Were we give a valid file descriptor? */ @@ -76,12 +133,22 @@ int ioctl(int fd, int req, unsigned long arg) /* Is a driver registered? Does it support the ioctl method? */ if (inode && inode->u.i_ops && inode->u.i_ops->ioctl) - { - /* Yes, then let it perform the ioctl */ + { + /* Yes, then let it perform the ioctl */ - ret = (int)inode->u.i_ops->ioctl(this_file, req, arg); - } + ret = (int)inode->u.i_ops->ioctl(this_file, req, arg); + if (ret < 0) + { + err = -ret; + goto errout; + } + } } return ret; +#endif + +errout: + *get_errno_ptr() = err; + return ERROR; } |