/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
 *
 * n4: A fast userspace NFSv4 server.
 * $Id: error.c,v 1.3 2001/06/08 09:03:24 mbp Exp $
 * 
 * Copyright (C) 2001 by Martin Pool <mbp@samba.org>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "includes.h"

n4err n4err_from_unix(int e)
{
    switch (e) {
    case EACCES:
        return NFS4ERR_ACCES;
        
    case EINVAL:
        return NFS4ERR_INVAL;

    case EIO:
    case EBADF:
    case EBADFD:                /* this is not the error you think it is! */
        return NFS4ERR_IO;

    case ENAMETOOLONG:
        return NFS4ERR_NAMETOOLONG;

    case EMFILE:    /*  Too many file descriptors in use by process. */
    case ENFILE:    /* Too many files are currently open in the system. */
    case ENOMEM:    /* Insufficient memory to complete the operation. */
        return NFS4ERR_RESOURCE;

    case ENOENT:    /* Directory does not exist, or name is an empty
                       string. */
        return NFS4ERR_NOENT;

    case ENOTDIR:   /* name is not a directory. */
        return NFS4ERR_NOTDIR;

    default:
        return NFS4ERR_SERVERFAULT;
    }
}
