mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
Clean-up files in fs/ directory
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4942 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -2993,3 +2993,4 @@
|
||||
descriptors (sure, why not?).
|
||||
* sched/: Stylistic clean-up of all files. Some of these files are pretty old
|
||||
and do not follow current NuttX coding standards in detail.
|
||||
* fs/: More stylistic file clean-up.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
# fs/Makefile
|
||||
#
|
||||
# Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
|
||||
+2
-2
@@ -55,7 +55,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: close
|
||||
* Name: close
|
||||
*
|
||||
* Description:
|
||||
* close() closes a file descriptor, so that it no longer refers to any
|
||||
@@ -127,7 +127,7 @@ int close(int fd)
|
||||
#endif
|
||||
|
||||
errout:
|
||||
errno = err;
|
||||
set_errno(err);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* fs/fs_closeblockdriver.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in pathname and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -75,6 +75,7 @@ int close_blockdriver(FAR struct inode *inode)
|
||||
int ret = 0; /* Assume success */
|
||||
|
||||
/* Sanity checks */
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!inode || !inode->u.i_bops)
|
||||
{
|
||||
@@ -105,6 +106,7 @@ int close_blockdriver(FAR struct inode *inode)
|
||||
/* Then release the reference on the inode */
|
||||
|
||||
inode_release(inode);
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
+9
-11
@@ -2,7 +2,7 @@
|
||||
* fs/fs_closedir.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -57,20 +57,19 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: seekdir
|
||||
* Name: closedir
|
||||
*
|
||||
* Description:
|
||||
* The closedir() function closes the directory stream
|
||||
* associated with 'dirp'. The directory stream
|
||||
* descriptor 'dirp' is not available after this call.
|
||||
* The closedir() function closes the directory stream associated with
|
||||
* 'dirp'. The directory stream descriptor 'dirp' is not available after
|
||||
* this call.
|
||||
*
|
||||
* Inputs:
|
||||
* dirp -- An instance of type DIR created by a previous
|
||||
* call to opendir();
|
||||
* dirp -- An instance of type DIR created by a previous call to opendir();
|
||||
*
|
||||
* Return:
|
||||
* The closedir() function returns 0 on success. On error,
|
||||
* -1 is returned, and errno is set appropriately.
|
||||
* The closedir() function returns 0 on success. On error, -1 is
|
||||
* returned, and errno is set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -144,7 +143,6 @@ errout_with_inode:
|
||||
#endif
|
||||
|
||||
errout:
|
||||
errno = ret;
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
* fs/fs_dup.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -98,10 +98,10 @@ int dup(int fildes)
|
||||
{
|
||||
/* No.. then it is a bad descriptor number */
|
||||
|
||||
errno = EBADF;
|
||||
set_errno(EBADF);
|
||||
ret = ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -2,7 +2,7 @@
|
||||
* fs/fs_dup2.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -76,7 +76,8 @@
|
||||
int dup2(int fildes1, int fildes2)
|
||||
{
|
||||
/* Check the range of the descriptor to see if we got a file or a socket
|
||||
* descriptor. */
|
||||
* descriptor.
|
||||
*/
|
||||
|
||||
if ((unsigned int)fildes1 >= CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
@@ -92,7 +93,7 @@ int dup2(int fildes1, int fildes2)
|
||||
{
|
||||
/* No.. then it is a bad descriptor number */
|
||||
|
||||
errno = EBADF;
|
||||
set_errno(EBADF);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -53,6 +53,10 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: file_vfcntl
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
static inline int file_vfcntl(int fildes, int cmd, va_list ap)
|
||||
{
|
||||
@@ -199,9 +203,10 @@ static inline int file_vfcntl(int fildes, int cmd, va_list ap)
|
||||
errout:
|
||||
if (err != 0)
|
||||
{
|
||||
errno = err;
|
||||
set_errno(err);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */
|
||||
@@ -210,6 +215,10 @@ errout:
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fcntl
|
||||
****************************************************************************/
|
||||
|
||||
int fcntl(int fildes, int cmd, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
+1
-1
@@ -205,6 +205,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
|
||||
if (stream->fs_filedes < 0)
|
||||
{
|
||||
/* Zero the structure */
|
||||
|
||||
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
||||
memset(stream, 0, sizeof(FILE));
|
||||
#elif CONFIG_NUNGET_CHARS > 0
|
||||
@@ -258,4 +259,3 @@ errout:
|
||||
errout_with_errno:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -2,7 +2,7 @@
|
||||
* fs/fs_filedup.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -85,7 +85,7 @@ int file_dup(int fildes, int minfd)
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
errno = EMFILE;
|
||||
set_errno(EMFILE);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ int file_dup(int fildes, int minfd)
|
||||
|
||||
if (!DUP_ISOPEN(fildes, list))
|
||||
{
|
||||
errno = EBADF;
|
||||
set_errno(EBADF);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
@@ -109,10 +109,11 @@ int file_dup(int fildes, int minfd)
|
||||
minfd);
|
||||
if (fildes2 < 0)
|
||||
{
|
||||
errno = EMFILE;
|
||||
set_errno(EMFILE);
|
||||
inode_release(list->fl_files[fildes].f_inode);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return fildes2;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -2,7 +2,7 @@
|
||||
* fs/fs_filedup2.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -87,7 +87,7 @@ int dup2(int fildes1, int fildes2)
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
errno = EMFILE;
|
||||
set_errno(EMFILE);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ int dup2(int fildes1, int fildes2)
|
||||
|
||||
if (!DUP_ISOPEN(fildes1, list))
|
||||
{
|
||||
errno = EBADF;
|
||||
set_errno(EBADF);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ int dup2(int fildes1, int fildes2)
|
||||
|
||||
if ((unsigned int)fildes2 >= CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
errno = EBADF;
|
||||
set_errno(EBADF);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -85,7 +85,7 @@ static void _files_semtake(FAR struct filelist *list)
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
ASSERT(*get_errno_ptr() == EINTR);
|
||||
ASSERT(get_errno() == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ static int _files_close(FAR struct file *filep)
|
||||
filep->f_pos = 0;
|
||||
filep->f_inode = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -174,6 +175,7 @@ FAR struct filelist *files_alloclist(void)
|
||||
|
||||
(void)sem_init(&list->fl_sem, 0, 1);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -200,6 +202,7 @@ int files_addreflist(FAR struct filelist *list)
|
||||
list->fl_crefs++;
|
||||
irqrestore(flags);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -253,6 +256,7 @@ int files_releaselist(FAR struct filelist *list)
|
||||
sched_free(list);
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -361,7 +365,7 @@ errout_with_ret:
|
||||
err = -ret;
|
||||
_files_semgive(list);
|
||||
errout:
|
||||
errno = err;
|
||||
set_errno(err);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* fs/fs_openblockdriver.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in pathname and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -83,6 +83,7 @@ int find_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode
|
||||
int ret = 0; /* Assume success */
|
||||
|
||||
/* Sanity checks */
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!pathname || !ppinode)
|
||||
{
|
||||
|
||||
+4
-3
@@ -2,7 +2,7 @@
|
||||
* fs/fs_fsync.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -128,10 +128,11 @@ int fsync(int fd)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
ret = -ret;
|
||||
|
||||
errout:
|
||||
*get_errno_ptr() = ret;
|
||||
errout:
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+42
-12
@@ -2,7 +2,7 @@
|
||||
* fs/fs_inode.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -90,17 +90,21 @@ static int _inode_compare(const char *fname,
|
||||
for (;;)
|
||||
{
|
||||
/* At end of node name? */
|
||||
|
||||
if (!*nname)
|
||||
{
|
||||
/* Yes.. also end of find name? */
|
||||
|
||||
if (!*fname || *fname == '/')
|
||||
{
|
||||
/* Yes.. return match */
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No... return find name > node name */
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -114,7 +118,8 @@ static int _inode_compare(const char *fname,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* check for non-matching characters */
|
||||
/* Check for non-matching characters */
|
||||
|
||||
else if (*fname > *nname)
|
||||
{
|
||||
return 1;
|
||||
@@ -127,6 +132,7 @@ static int _inode_compare(const char *fname,
|
||||
/* Not at the end of either string and all of the
|
||||
* characters still match. keep looking.
|
||||
*/
|
||||
|
||||
else
|
||||
{
|
||||
fname++;
|
||||
@@ -143,8 +149,8 @@ static int _inode_compare(const char *fname,
|
||||
* Name: fs_initialize
|
||||
*
|
||||
* Description:
|
||||
* This is called from the OS initialization logic to configure
|
||||
* the file system.
|
||||
* This is called from the OS initialization logic to configure the file
|
||||
* system.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -180,7 +186,7 @@ void inode_semtake(void)
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
ASSERT(errno == EINTR);
|
||||
ASSERT(get_errno() == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,8 +203,8 @@ void inode_semgive(void)
|
||||
* Name: inode_search
|
||||
*
|
||||
* Description:
|
||||
* Find the inode associated with 'path' returning the
|
||||
* inode references and references to its companion nodes.
|
||||
* Find the inode associated with 'path' returning the inode references
|
||||
* and references to its companion nodes.
|
||||
*
|
||||
* Assumptions:
|
||||
* The caller holds the tree_sem
|
||||
@@ -293,8 +299,16 @@ FAR struct inode *inode_search(const char **path,
|
||||
* (4) When the node matching the full path is found
|
||||
*/
|
||||
|
||||
if (peer) *peer = left;
|
||||
if (parent) *parent = above;
|
||||
if (peer)
|
||||
{
|
||||
*peer = left;
|
||||
}
|
||||
|
||||
if (parent)
|
||||
{
|
||||
*parent = above;
|
||||
}
|
||||
|
||||
*path = name;
|
||||
return node;
|
||||
}
|
||||
@@ -322,10 +336,26 @@ void inode_free(FAR struct inode *node)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
const char *inode_nextname(const char *name)
|
||||
FAR const char *inode_nextname(FAR const char *name)
|
||||
{
|
||||
while (*name && *name != '/') name++;
|
||||
if (*name) name++;
|
||||
/* Search for the '/' delimiter or the NUL terminator at the end of the
|
||||
* string.
|
||||
*/
|
||||
|
||||
while (*name && *name != '/')
|
||||
{
|
||||
name++;
|
||||
}
|
||||
|
||||
/* If we found the '/' delimiter, then the path segment we want begins at
|
||||
* the next character (which might also be the NUL terminator).
|
||||
*/
|
||||
|
||||
if (*name)
|
||||
{
|
||||
name++;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
* fs_inodeaddref.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -67,8 +67,8 @@
|
||||
* Name: inode_addref
|
||||
*
|
||||
* Description:
|
||||
* Increment the reference count on an inode (as when a file
|
||||
* descriptor is dup'ed.
|
||||
* Increment the reference count on an inode (as when a file descriptor
|
||||
* is dup'ed).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
+6
-5
@@ -2,7 +2,7 @@
|
||||
* fs/fs_inodefind.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -68,8 +68,8 @@
|
||||
* Name: inode_find
|
||||
*
|
||||
* Description:
|
||||
* This is called from the open() logic to get a reference
|
||||
* to the inode associated with a path.
|
||||
* This is called from the open() logic to get a reference to the inode
|
||||
* associated with a path.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -82,8 +82,8 @@ FAR struct inode *inode_find(FAR const char *path, FAR const char **relpath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find the node matching the path. If found,
|
||||
* increment the count of references on the node.
|
||||
/* Find the node matching the path. If found, increment the count of
|
||||
* references on the node.
|
||||
*/
|
||||
|
||||
inode_semtake();
|
||||
@@ -92,6 +92,7 @@ FAR struct inode *inode_find(FAR const char *path, FAR const char **relpath)
|
||||
{
|
||||
node->i_crefs++;
|
||||
}
|
||||
|
||||
inode_semgive();
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* fs_inoderelease.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -70,8 +70,7 @@
|
||||
* Name: inode_release
|
||||
*
|
||||
* Description:
|
||||
* This is called from close() logic when it no longer refers
|
||||
* to the inode.
|
||||
* This is called from close() logic when it no longer refers to the inode.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
+3
-1
@@ -2,7 +2,7 @@
|
||||
* fs/fs_inoderemove.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -94,6 +94,7 @@ static void inode_unlink(struct inode *node,
|
||||
{
|
||||
root_inode = node->i_peer;
|
||||
}
|
||||
|
||||
node->i_peer = NULL;
|
||||
}
|
||||
|
||||
@@ -105,6 +106,7 @@ static void inode_unlink(struct inode *node,
|
||||
* Name: inode_remove
|
||||
*
|
||||
* NOTE: Caller must hold the inode semaphore
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int inode_remove(const char *path)
|
||||
|
||||
@@ -96,6 +96,7 @@ static FAR struct inode *inode_alloc(FAR const char *name)
|
||||
{
|
||||
inode_namecpy(node->i_name, name);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -139,11 +139,12 @@ int ioctl(int fd, int req, unsigned long arg)
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
errout:
|
||||
*get_errno_ptr() = err;
|
||||
set_errno(err);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -2,7 +2,7 @@
|
||||
* fs/fs_lseek.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -165,11 +165,12 @@ off_t lseek(int fd, off_t offset, int whence)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filep->f_pos;
|
||||
|
||||
errout:
|
||||
*get_errno_ptr() = err;
|
||||
set_errno(err);
|
||||
return (off_t)ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
* fs/fs_mkdir.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -124,7 +124,7 @@ int mkdir(const char *pathname, mode_t mode)
|
||||
errout_with_inode:
|
||||
inode_release(inode);
|
||||
errout:
|
||||
*get_errno_ptr() = ret;
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -160,6 +160,7 @@ static FAR const struct mountpt_operations *
|
||||
mount_findfs(FAR const struct fsmap_t *fstab, FAR const char *filesystemtype)
|
||||
{
|
||||
FAR const struct fsmap_t *fsmap;
|
||||
|
||||
for (fsmap = fstab; fsmap->fs_filesystemtype; fsmap++)
|
||||
{
|
||||
if (strcmp(filesystemtype, fsmap->fs_filesystemtype) == 0)
|
||||
@@ -167,6 +168,7 @@ mount_findfs(FAR const struct fsmap_t *fstab, FAR const char *filesystemtype)
|
||||
return fsmap->fs_mops;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -348,6 +350,7 @@ int mount(FAR const char *source, FAR const char *target,
|
||||
inode_release(blkdrvr_inode);
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
|
||||
/* A lot of goto's! But they make the error handling much simpler */
|
||||
@@ -364,6 +367,7 @@ errout_with_mountpt:
|
||||
inode_release(blkdrvr_inode);
|
||||
}
|
||||
#endif
|
||||
|
||||
inode_release(mountpt_inode);
|
||||
goto errout;
|
||||
|
||||
@@ -379,12 +383,12 @@ errout_with_semaphore:
|
||||
#endif
|
||||
|
||||
errout:
|
||||
errno = errcode;
|
||||
set_errno(errcode);
|
||||
return ERROR;
|
||||
|
||||
#else
|
||||
fdbg("No filesystems enabled\n");
|
||||
ernno = ENOSYS;
|
||||
set_errno(ENOSYS);
|
||||
return error;
|
||||
#endif /* BDFS_SUPPORT || NONBDFS_SUPPORT */
|
||||
}
|
||||
|
||||
+6
-3
@@ -2,7 +2,7 @@
|
||||
* fs_open.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -56,6 +56,10 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inode_checkflags
|
||||
****************************************************************************/
|
||||
|
||||
int inode_checkflags(FAR struct inode *inode, int oflags)
|
||||
{
|
||||
if (((oflags & O_RDOK) != 0 && !inode->u.i_ops->read) ||
|
||||
@@ -185,7 +189,6 @@ int open(const char *path, int oflags, ...)
|
||||
errout_with_inode:
|
||||
inode_release(inode);
|
||||
errout:
|
||||
errno = ret;
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* fs/fs_openblockdriver.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in pathname and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -76,14 +76,15 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int open_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode **ppinode)
|
||||
int open_blockdriver(FAR const char *pathname, int mountflags,
|
||||
FAR struct inode **ppinode)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
int ret;
|
||||
|
||||
/* Minimal sanity checks */
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!ppinode)
|
||||
{
|
||||
ret = -EINVAL;
|
||||
|
||||
+2
-4
@@ -2,7 +2,7 @@
|
||||
* fs/fs_opendir.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -81,7 +81,6 @@ static inline int open_mountpoint(FAR struct inode *inode,
|
||||
/* The inode itself as the 'root' of mounted volume. The actually
|
||||
* directory is at relpath into the* mounted filesystem.
|
||||
*
|
||||
*
|
||||
* Verify that the mountpoint inode supports the opendir() method
|
||||
*/
|
||||
|
||||
@@ -308,7 +307,6 @@ errout_with_direntry:
|
||||
|
||||
errout_with_semaphore:
|
||||
inode_semgive();
|
||||
errno = ret;
|
||||
set_errno(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -79,7 +79,7 @@ static void poll_semtake(FAR sem_t *sem)
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
ASSERT(errno == EINTR);
|
||||
ASSERT(get_errno() == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +220,7 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count)
|
||||
|
||||
fds[i].sem = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -309,13 +310,14 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
|
||||
ret = poll_teardown(fds, nfds, &count);
|
||||
}
|
||||
|
||||
sem_destroy(&sem);
|
||||
|
||||
/* Check for errors */
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
errno = -ret;
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
@@ -323,4 +325,3 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
}
|
||||
|
||||
#endif /* CONFIG_DISABLE_POLL */
|
||||
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ ssize_t read(int fd, FAR void *buf, size_t nbytes)
|
||||
#else
|
||||
/* No networking... it is a bad descriptor in any event */
|
||||
|
||||
errno = EBADF;
|
||||
set_errno(EBADF);
|
||||
return ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
+10
-11
@@ -2,7 +2,7 @@
|
||||
* fs/fs_readdir.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -140,19 +140,18 @@ static inline int readpsuedodir(struct fs_dirent_s *idir)
|
||||
* Name: readdir
|
||||
*
|
||||
* Description:
|
||||
* The readdir() function returns a pointer to a dirent
|
||||
* structure representing the next directory entry in the
|
||||
* directory stream pointed to by dir. It returns NULL on
|
||||
* reaching the end-of-file or if an error occurred.
|
||||
* The readdir() function returns a pointer to a dirent structure
|
||||
* representing the next directory entry in the directory stream pointed
|
||||
* to by dir. It returns NULL on reaching the end-of-file or if an error
|
||||
* occurred.
|
||||
*
|
||||
* Inputs:
|
||||
* dirp -- An instance of type DIR created by a previous
|
||||
* call to opendir();
|
||||
* dirp -- An instance of type DIR created by a previous call to opendir();
|
||||
*
|
||||
* Return:
|
||||
* The readdir() function returns a pointer to a dirent
|
||||
* structure, or NULL if an error occurs or end-of-file
|
||||
* is reached. On error, errno is set appropriately.
|
||||
* The readdir() function returns a pointer to a dirent structure, or NULL
|
||||
* if an error occurs or end-of-file is reached. On error, errno is set
|
||||
* appropriately.
|
||||
*
|
||||
* EBADF - Invalid directory stream descriptor dir
|
||||
*
|
||||
@@ -225,7 +224,7 @@ FAR struct dirent *readdir(DIR *dirp)
|
||||
return &idir->fd_dir;
|
||||
|
||||
errout:
|
||||
*get_errno_ptr() = ret;
|
||||
set_errno(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,12 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "fs_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -38,9 +38,12 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "fs_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
+2
-3
@@ -2,7 +2,7 @@
|
||||
* fs/fs_rename.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -148,7 +148,6 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
|
||||
errout_with_oldinode:
|
||||
inode_release(oldinode);
|
||||
errout:
|
||||
*get_errno_ptr() = ret;
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -2,7 +2,7 @@
|
||||
* fs/fs_rewinddir.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -143,4 +143,3 @@ void rewinddir(FAR DIR *dirp)
|
||||
rewindpsuedodir(idir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
* fs/fs_rmdir.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -124,7 +124,7 @@ int rmdir(FAR const char *pathname)
|
||||
errout_with_inode:
|
||||
inode_release(inode);
|
||||
errout:
|
||||
*get_errno_ptr() = ret;
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -2,7 +2,7 @@
|
||||
* fs/fs_seekdir.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -184,10 +184,9 @@ static inline void seekmountptdir(struct fs_dirent_s *idir, off_t offset)
|
||||
* Name: seekdir
|
||||
*
|
||||
* Description:
|
||||
* The seekdir() function sets the location in the
|
||||
* directory stream from which the next readdir() call will
|
||||
* start. seekdir() should be used with an offset returned
|
||||
* by telldir().
|
||||
* The seekdir() function sets the location in the directory stream from
|
||||
* which the next readdir() call will start. seekdir() should be used with
|
||||
* an offset returned by telldir().
|
||||
*
|
||||
* Inputs:
|
||||
* dirp -- An instance of type DIR created by a previous
|
||||
@@ -229,4 +228,3 @@ void seekdir(FAR DIR *dirp, off_t offset)
|
||||
seekpsuedodir(idir, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
|
||||
pollset = (struct pollfd *)kzalloc(nfds * sizeof(struct pollfd));
|
||||
if (!pollset)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -221,4 +221,3 @@ errout:
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -2,7 +2,7 @@
|
||||
* fs/fs_umount.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -191,16 +191,16 @@ int umount(const char *target)
|
||||
|
||||
/* A lot of goto's! But they make the error handling much simpler */
|
||||
|
||||
errout_with_semaphore:
|
||||
errout_with_semaphore:
|
||||
inode_semgive();
|
||||
errout_with_mountpt:
|
||||
errout_with_mountpt:
|
||||
inode_release(mountpt_inode);
|
||||
if (blkdrvr_inode)
|
||||
{
|
||||
inode_release(blkdrvr_inode);
|
||||
}
|
||||
errout:
|
||||
*get_errno_ptr() = errcode;
|
||||
errout:
|
||||
set_errno(errcode);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
* fs_unlink.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -124,7 +124,7 @@ int unlink(FAR const char *pathname)
|
||||
errout_with_inode:
|
||||
inode_release(inode);
|
||||
errout:
|
||||
*get_errno_ptr() = ret;
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* fs/fs_unregisterblockdriver.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -74,9 +74,9 @@
|
||||
int unregister_blockdriver(const char *path)
|
||||
{
|
||||
int ret;
|
||||
|
||||
inode_semtake();
|
||||
ret = inode_remove(path);
|
||||
inode_semgive();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,9 +74,9 @@
|
||||
int unregister_driver(FAR const char *path)
|
||||
{
|
||||
int ret;
|
||||
|
||||
inode_semtake();
|
||||
ret = inode_remove(path);
|
||||
inode_semgive();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -2,7 +2,7 @@
|
||||
* fs/fs_write.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -102,7 +102,7 @@ static inline ssize_t file_write(int fd, FAR const void *buf, size_t nbytes)
|
||||
return ret;
|
||||
|
||||
errout:
|
||||
*get_errno_ptr() = err;
|
||||
set_errno(err);
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
@@ -112,7 +112,7 @@ errout:
|
||||
****************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* Function: write
|
||||
* Name: write
|
||||
*
|
||||
* Description:
|
||||
* write() writes up to nytes bytes to the file referenced by the file
|
||||
@@ -174,7 +174,7 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
|
||||
#if defined(CONFIG_NET_TCP) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
return send(fd, buf, nbytes, 0);
|
||||
#else
|
||||
errno = EBADF;
|
||||
set_errno(EBADF);
|
||||
return ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user