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

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.

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

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;
} }

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;
} }

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.
* *
****************************************************************************/ ****************************************************************************/
@@ -104,8 +103,8 @@ int closedir(FAR DIR *dirp)
*/ */
if (inode->u.i_mops && inode->u.i_mops->closedir) if (inode->u.i_mops && inode->u.i_mops->closedir)
{ {
/* Perform the closedir() operation */ /* Perform the closedir() operation */
ret = inode->u.i_mops->closedir(inode, idir); ret = inode->u.i_mops->closedir(inode, idir);
if (ret < 0) if (ret < 0)
@@ -144,7 +143,6 @@ errout_with_inode:
#endif #endif
errout: errout:
errno = ret; set_errno(ret);
return ERROR; return ERROR;
} }

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;
} }

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;
} }
} }

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)
{ {
@@ -112,8 +116,8 @@ static inline int file_vfcntl(int fildes, int cmd, va_list ap)
* successful execution of one of the exec functions. * successful execution of one of the exec functions.
*/ */
err = ENOSYS; err = ENOSYS;
break; break;
case F_GETFL: case F_GETFL:
/* Get the file status flags and file access modes, defined in <fcntl.h>, /* Get the file status flags and file access modes, defined in <fcntl.h>,
@@ -158,8 +162,8 @@ static inline int file_vfcntl(int fildes, int cmd, va_list ap)
* fildes does not refer to a socket, the results are unspecified. * fildes does not refer to a socket, the results are unspecified.
*/ */
err = EBADF; /* Only valid on socket descriptors */ err = EBADF; /* Only valid on socket descriptors */
break; break;
case F_GETLK: case F_GETLK:
/* Get the first lock which blocks the lock description pointed to by the third /* Get the first lock which blocks the lock description pointed to by the third
@@ -188,20 +192,21 @@ static inline int file_vfcntl(int fildes, int cmd, va_list ap)
* not be done. * not be done.
*/ */
err = ENOSYS; /* Not implemented */ err = ENOSYS; /* Not implemented */
break; break;
default: default:
err = EINVAL; err = EINVAL;
break; break;
} }
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;

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;
} }

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,15 +85,15 @@ 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;
} }
/* Verify that fildes is a valid, open file descriptor */ /* Verify that fildes is a valid, open file descriptor */
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;
} }

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,15 +87,15 @@ 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;
} }
/* Verify that fildes is a valid, open file descriptor */ /* Verify that fildes is a valid, open file descriptor */
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;
} }

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);
} }
} }
@@ -124,16 +124,17 @@ static int _files_close(FAR struct file *filep)
ret = inode->u.i_ops->close(filep); ret = inode->u.i_ops->close(filep);
} }
/* And release the inode */ /* And release the inode */
inode_release(inode); inode_release(inode);
/* Release the file descriptor */ /* Release the file descriptor */
filep->f_oflags = 0; filep->f_oflags = 0;
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;
} }
@@ -188,18 +190,19 @@ int files_addreflist(FAR struct filelist *list)
{ {
if (list) if (list)
{ {
/* Increment the reference count on the list. /* Increment the reference count on the list.
* NOTE: that we disable interrupts to do this * NOTE: that we disable interrupts to do this
* (vs. taking the list semaphore). We do this * (vs. taking the list semaphore). We do this
* because file cleanup operations often must be * because file cleanup operations often must be
* done from the IDLE task which cannot wait * done from the IDLE task which cannot wait
* on semaphores. * on semaphores.
*/ */
register irqstate_t flags = irqsave(); register irqstate_t flags = irqsave();
list->fl_crefs++; list->fl_crefs++;
irqrestore(flags); irqrestore(flags);
} }
return OK; return OK;
} }
@@ -216,43 +219,44 @@ int files_releaselist(FAR struct filelist *list)
if (list) if (list)
{ {
/* Decrement the reference count on the list. /* Decrement the reference count on the list.
* NOTE: that we disable interrupts to do this * NOTE: that we disable interrupts to do this
* (vs. taking the list semaphore). We do this * (vs. taking the list semaphore). We do this
* because file cleanup operations often must be * because file cleanup operations often must be
* done from the IDLE task which cannot wait * done from the IDLE task which cannot wait
* on semaphores. * on semaphores.
*/ */
register irqstate_t flags = irqsave(); register irqstate_t flags = irqsave();
crefs = --(list->fl_crefs); crefs = --(list->fl_crefs);
irqrestore(flags); irqrestore(flags);
/* If the count decrements to zero, then there is no reference /* If the count decrements to zero, then there is no reference
* to the structure and it should be deallocated. Since there * to the structure and it should be deallocated. Since there
* are references, it would be an error if any task still held * are references, it would be an error if any task still held
* a reference to the list's semaphore. * a reference to the list's semaphore.
*/ */
if (crefs <= 0) if (crefs <= 0)
{ {
int i; int i;
/* Close each file descriptor .. Normally, you would need /* Close each file descriptor .. Normally, you would need
* take the list semaphore, but it is safe to ignore the * take the list semaphore, but it is safe to ignore the
* semaphore in this context because there are no references * semaphore in this context because there are no references
*/ */
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{ {
(void)_files_close(&list->fl_files[i]); (void)_files_close(&list->fl_files[i]);
} }
/* Destroy the semaphore and release the filelist */ /* Destroy the semaphore and release the filelist */
(void)sem_destroy(&list->fl_sem); (void)sem_destroy(&list->fl_sem);
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;
} }

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)
{ {
@@ -108,7 +109,7 @@ int find_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode
fdbg("%s is not a block driver\n", pathname); fdbg("%s is not a block driver\n", pathname);
ret = -ENOTBLK; ret = -ENOTBLK;
goto errout_with_inode; goto errout_with_inode;
} }
/* Make sure that the inode supports the requested access */ /* Make sure that the inode supports the requested access */

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
@@ -125,13 +125,14 @@ int fsync(int fd)
ret = inode->u.i_mops->sync(this_file); ret = inode->u.i_mops->sync(this_file);
if (ret >= 0) if (ret >= 0)
{ {
return OK; return OK;
} }
ret = -ret; ret = -ret;
errout: errout:
*get_errno_ptr() = ret; set_errno(ret);
return ERROR; return ERROR;
} }

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,31 +90,36 @@ 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 */ {
return 0; /* Yes.. return match */
}
else return 0;
{ }
/* No... return find name > node name */ else
return 1; {
} /* No... return find name > node name */
return 1;
}
} }
/* At end of find name?*/ /* At end of find name?*/
else if (!*fname || *fname == '/') else if (!*fname || *fname == '/')
{ {
/* Yes... return find name < node name */ /* Yes... return find name < node name */
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);
} }
} }
@@ -190,15 +196,15 @@ void inode_semtake(void)
void inode_semgive(void) void inode_semgive(void)
{ {
sem_post(&tree_sem); sem_post(&tree_sem);
} }
/**************************************************************************** /****************************************************************************
* 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;
} }

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).
* *
****************************************************************************/ ****************************************************************************/

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;
} }

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.
* *
****************************************************************************/ ****************************************************************************/
@@ -94,13 +93,13 @@ void inode_release(FAR struct inode *node)
if (node->i_crefs <= 0 && (node->i_flags & FSNODEFLAG_DELETED) != 0) if (node->i_crefs <= 0 && (node->i_flags & FSNODEFLAG_DELETED) != 0)
{ {
inode_semgive(); inode_semgive();
inode_free(node->i_child); inode_free(node->i_child);
kfree(node); kfree(node);
} }
else else
{ {
inode_semgive(); inode_semgive();
} }
} }
} }

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
@@ -74,27 +74,28 @@ static void inode_unlink(struct inode *node,
* of that peer node. * of that peer node.
*/ */
if (peer) if (peer)
{ {
peer->i_peer = node->i_peer; peer->i_peer = node->i_peer;
} }
/* If parent is non-null, then remove the node from head of /* If parent is non-null, then remove the node from head of
* of the list of children. * of the list of children.
*/ */
else if (parent) else if (parent)
{ {
parent->i_child = node->i_peer; parent->i_child = node->i_peer;
} }
/* Otherwise, we must be removing the root inode. */ /* Otherwise, we must be removing the root inode. */
else else
{ {
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)
@@ -132,16 +134,16 @@ int inode_remove(const char *path)
if (node->i_crefs) if (node->i_crefs)
{ {
/* In that case, we will mark it deleted, when the FS /* In that case, we will mark it deleted, when the FS
* releases the inode, we will then, finally delete * releases the inode, we will then, finally delete
* the subtree. * the subtree.
*/ */
node->i_flags |= FSNODEFLAG_DELETED; node->i_flags |= FSNODEFLAG_DELETED;
return -EBUSY; return -EBUSY;
} }
else else
{ {
/* And delete it now -- recursively to delete all of its children */ /* And delete it now -- recursively to delete all of its children */
inode_free(node->i_child); inode_free(node->i_child);

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;
} }
@@ -111,29 +112,29 @@ static void inode_insert(FAR struct inode *node,
* of that peer node. * of that peer node.
*/ */
if (peer) if (peer)
{ {
node->i_peer = peer->i_peer; node->i_peer = peer->i_peer;
peer->i_peer = node; peer->i_peer = node;
} }
/* If parent is non-null, then it must go at the head of its /* If parent is non-null, then it must go at the head of its
* list of children. * list of children.
*/ */
else if (parent) else if (parent)
{ {
node->i_peer = parent->i_child; node->i_peer = parent->i_child;
parent->i_child = node; parent->i_child = node;
} }
/* Otherwise, this must be the new root_inode */ /* Otherwise, this must be the new root_inode */
else else
{ {
node->i_peer = root_inode; node->i_peer = root_inode;
root_inode = node; root_inode = node;
} }
} }
/**************************************************************************** /****************************************************************************

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;
} }

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
@@ -124,52 +124,53 @@ off_t lseek(int fd, off_t offset, int whence)
if (inode->u.i_ops->seek) if (inode->u.i_ops->seek)
{ {
/* Yes, then let it perform the seek */ /* Yes, then let it perform the seek */
err = (int)inode->u.i_ops->seek(filep, offset, whence); err = (int)inode->u.i_ops->seek(filep, offset, whence);
if (err < 0) if (err < 0)
{ {
err = -err; err = -err;
goto errout; goto errout;
} }
} }
else else
{ {
/* No... there are a couple of default actions we can take */ /* No... there are a couple of default actions we can take */
switch (whence) switch (whence)
{ {
case SEEK_CUR: case SEEK_CUR:
offset += filep->f_pos; offset += filep->f_pos;
case SEEK_SET: case SEEK_SET:
if (offset >= 0) if (offset >= 0)
{ {
filep->f_pos = offset; /* Might be beyond the end-of-file */ filep->f_pos = offset; /* Might be beyond the end-of-file */
break; break;
} }
else else
{ {
err = EINVAL; err = EINVAL;
goto errout; goto errout;
} }
break; break;
case SEEK_END: case SEEK_END:
err = ENOSYS; err = ENOSYS;
goto errout; goto errout;
default: default:
err = EINVAL; err = EINVAL;
goto errout; goto errout;
} }
} }
} }
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

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;
} }

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
@@ -231,9 +233,9 @@ int mount(FAR const char *source, FAR const char *target,
ret = find_blockdriver(source, mountflags, &blkdrvr_inode); ret = find_blockdriver(source, mountflags, &blkdrvr_inode);
if (ret < 0) if (ret < 0)
{ {
fdbg("Failed to find block driver %s\n", source); fdbg("Failed to find block driver %s\n", source);
errcode = -ret; errcode = -ret;
goto errout; goto errout;
} }
} }
else else
@@ -304,7 +306,7 @@ int mount(FAR const char *source, FAR const char *target,
ret = mops->bind(NULL, data, &fshandle); ret = mops->bind(NULL, data, &fshandle);
#endif #endif
if (ret != 0) if (ret != 0)
{ {
/* The inode is unhappy with the blkdrvr for some reason. Back out /* The inode is unhappy with the blkdrvr for some reason. Back out
* the count for the reference we failed to pass and exit with an * the count for the reference we failed to pass and exit with an
* error. * error.
@@ -321,7 +323,7 @@ int mount(FAR const char *source, FAR const char *target,
#endif #endif
errcode = -ret; errcode = -ret;
goto errout_with_mountpt; goto errout_with_mountpt;
} }
/* We have it, now populate it with driver specific information. */ /* We have it, now populate it with driver specific information. */
@@ -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 */
} }

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;
} }

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;

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
*/ */
@@ -200,15 +199,15 @@ FAR DIR *opendir(FAR const char *path)
inode_semtake(); inode_semtake();
if (!path || *path == 0 || strcmp(path, "/") == 0) if (!path || *path == 0 || strcmp(path, "/") == 0)
{ {
inode = root_inode; inode = root_inode;
bisroot = true; bisroot = true;
relpath = NULL; relpath = NULL;
} }
else else
{ {
/* We don't know what to do with relative pathes */ /* We don't know what to do with relative pathes */
if (*path != '/') if (*path != '/')
{ {
ret = -ENOTDIR; ret = -ENOTDIR;
goto errout_with_semaphore; goto errout_with_semaphore;
@@ -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;
} }

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 */

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
} }

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
* *
@@ -187,10 +186,10 @@ FAR struct dirent *readdir(DIR *dirp)
*/ */
if (!inode->u.i_mops || !inode->u.i_mops->readdir) if (!inode->u.i_mops || !inode->u.i_mops->readdir)
{ {
ret = EACCES; ret = EACCES;
goto errout; goto errout;
} }
/* Perform the readdir() operation */ /* Perform the readdir() operation */
@@ -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;
} }

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"
/**************************************************************************** /****************************************************************************

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"
/**************************************************************************** /****************************************************************************

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;
} }

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);
} }
} }

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;
} }

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
@@ -70,13 +70,13 @@ static inline void seekpsuedodir(struct fs_dirent_s *idir, off_t offset)
if ( offset < idir->fd_position ) if ( offset < idir->fd_position )
{ {
pos = 0; pos = 0;
curr = idir->fd_root; curr = idir->fd_root;
} }
else else
{ {
pos = idir->fd_position; pos = idir->fd_position;
curr = idir->u.psuedo.fd_next; curr = idir->u.psuedo.fd_next;
} }
/* Traverse the peer list starting at the 'root' of the /* Traverse the peer list starting at the 'root' of the
@@ -137,7 +137,7 @@ static inline void seekmountptdir(struct fs_dirent_s *idir, off_t offset)
} }
else else
{ {
/* We can't do the seek and there is no way to return /* We can't do the seek and there is no way to return
* an error indication. * an error indication.
*/ */
@@ -146,7 +146,7 @@ static inline void seekmountptdir(struct fs_dirent_s *idir, off_t offset)
} }
else else
{ {
pos = idir->fd_position; pos = idir->fd_position;
} }
/* This is a brute force approach... we will just read /* This is a brute force approach... we will just read
@@ -155,19 +155,19 @@ static inline void seekmountptdir(struct fs_dirent_s *idir, off_t offset)
while (pos < offset) while (pos < offset)
{ {
if (!inode->u.i_mops || !inode->u.i_mops->readdir || if (!inode->u.i_mops || !inode->u.i_mops->readdir ||
inode->u.i_mops->readdir(inode, idir) < 0) inode->u.i_mops->readdir(inode, idir) < 0)
{ {
/* We can't read the next entry and there is no way to return /* We can't read the next entry and there is no way to return
* an error indication. * an error indication.
*/ */
return; return;
} }
/* Increment the position on each successful read */ /* Increment the position on each successful read */
pos++; pos++;
} }
/* If we get here the directory position has been successfully set */ /* If we get here the directory position has been successfully set */
@@ -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);
} }
} }

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;
} }
@@ -133,9 +133,9 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
if (readfds && FD_ISSET(fd, readfds)) if (readfds && FD_ISSET(fd, readfds))
{ {
pollset[npfds].fd = fd; pollset[npfds].fd = fd;
pollset[npfds].events |= POLLIN; pollset[npfds].events |= POLLIN;
incr = 1; incr = 1;
} }
/* The writefds set holds the set of FDs that the caller can be assured /* The writefds set holds the set of FDs that the caller can be assured
@@ -144,17 +144,17 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
if (writefds && FD_ISSET(fd, writefds)) if (writefds && FD_ISSET(fd, writefds))
{ {
pollset[npfds].fd = fd; pollset[npfds].fd = fd;
pollset[npfds].events |= POLLOUT; pollset[npfds].events |= POLLOUT;
incr = 1; incr = 1;
} }
/* The exceptfds set holds the set of FDs that are watched for exceptions */ /* The exceptfds set holds the set of FDs that are watched for exceptions */
if (exceptfds && FD_ISSET(fd, exceptfds)) if (exceptfds && FD_ISSET(fd, exceptfds))
{ {
pollset[npfds].fd = fd; pollset[npfds].fd = fd;
incr = 1; incr = 1;
} }
npfds += incr; npfds += incr;

View File

@@ -221,4 +221,3 @@ errout:
set_errno(ret); set_errno(ret);
return ERROR; return ERROR;
} }

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
@@ -191,16 +191,16 @@ int umount(const char *target)
/* 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 */
errout_with_semaphore: errout_with_semaphore:
inode_semgive(); inode_semgive();
errout_with_mountpt: errout_with_mountpt:
inode_release(mountpt_inode); inode_release(mountpt_inode);
if (blkdrvr_inode) if (blkdrvr_inode)
{ {
inode_release(blkdrvr_inode); inode_release(blkdrvr_inode);
} }
errout: errout:
*get_errno_ptr() = errcode; set_errno(errcode);
return ERROR; return ERROR;
} }

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;
} }

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;
} }

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;
} }

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
} }