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