/*= -*- c-file-style: "linux"; indent-tabs-mode: t; -*-
 *
 * n4: A fast userspace NFSv4 server and client library.
 * $Id: ftype.c,v 1.1 2001/07/19 03:56:55 mbp Exp $
 * 
 * Copyright (C) 2001 by Martin Pool <mbp@samba.org>
 * http://n4.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"

n4ftype_t n4ftype_from_mode(mode_t m)
{
	if (S_ISREG(m))
		return NF4REG;
	else if (S_ISDIR(m))
		return NF4DIR;
	else if (S_ISLNK(m))
		return NF4LNK;
	else if (S_ISCHR(m))
		return NF4CHR;
	else if (S_ISBLK(m))
		return NF4BLK;
	else if (S_ISSOCK(m))
		return NF4SOCK;
	else if (S_ISFIFO(m))
		return NF4FIFO;
	else {
		n4log_warning("can't work out n4ftype corresponding to mode %#o",
			      m);
		return NF4REG;
	}
}


/**
 * Return a character for this type of entry, as in "ls -l".
 **/
char n4ftype_to_char(n4ftype_t t)
{
	switch (t) {
	case NF4REG:
		return '-';
	case NF4DIR:
		return 'd';
	case NF4LNK:
		return 'l';
	case NF4CHR:
		return 'c';
	case NF4BLK:
		return 'b';
	case NF4SOCK:
		return 's';
	case NF4FIFO:
		return 'f';
	case NF4ATTRDIR:
		return 'D';
	case NF4NAMEDATTR:
		return 'A';
	default:
		return '?';
	}
}
