2012-03-28 20:27:24 -03:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/nfs/nfs_util.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <sys/types.h>
|
2012-04-16 20:01:21 -03:00
|
|
|
#include <sys/time.h>
|
2012-03-28 20:27:24 -03:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2012-04-16 20:01:21 -03:00
|
|
|
#include <queue.h>
|
2012-03-28 20:27:24 -03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/fs/dirent.h>
|
|
|
|
|
2012-04-16 20:01:21 -03:00
|
|
|
#include "nfs_proto.h"
|
|
|
|
#include "nfs_mount.h"
|
|
|
|
#include "nfs_node.h"
|
2012-03-28 20:27:24 -03:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Variables
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Variables
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_semtake
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void nfs_semtake(struct nfsmount *nmp)
|
|
|
|
{
|
|
|
|
/* Take the semaphore (perhaps waiting) */
|
|
|
|
|
|
|
|
while (sem_wait(&nmp->nm_sem) != 0)
|
|
|
|
{
|
|
|
|
/* The only case that an error should occur here is if
|
|
|
|
* the wait was awakened by a signal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ASSERT(*get_errno_ptr() == EINTR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_semgive
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void nfs_semgive(struct nfsmount *nmp)
|
|
|
|
{
|
|
|
|
sem_post(&nmp->nm_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_checkmount
|
|
|
|
*
|
|
|
|
* Desciption: Check if the mountpoint is still valid.
|
|
|
|
*
|
|
|
|
* The caller should hold the mountpoint semaphore
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int nfs_checkmount(struct nfsmount *nmp)
|
|
|
|
{
|
|
|
|
struct nfsnode *file;
|
|
|
|
|
2012-04-20 20:15:41 -03:00
|
|
|
/* If the nm_mounted flag is false, then we have already handled the loss
|
2012-03-28 20:27:24 -03:00
|
|
|
* of the mount.
|
|
|
|
*/
|
|
|
|
|
2012-04-20 20:15:41 -03:00
|
|
|
DEBUGASSERT(nmp);
|
2012-04-23 16:55:32 -03:00
|
|
|
if (!nmp->nm_mounted)
|
2012-03-28 20:27:24 -03:00
|
|
|
{
|
|
|
|
/* Make sure that this is flagged in every opened file */
|
|
|
|
|
|
|
|
for (file = nmp->nm_head; file; file = file->n_next)
|
|
|
|
{
|
|
|
|
file->n_open = false;
|
|
|
|
}
|
2012-04-23 20:21:30 -03:00
|
|
|
|
|
|
|
return -ENODEV;
|
2012-03-28 20:27:24 -03:00
|
|
|
}
|
2012-04-23 20:21:30 -03:00
|
|
|
|
|
|
|
return 0;
|
2012-03-28 20:27:24 -03:00
|
|
|
}
|
|
|
|
|