/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *			(C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#include "fsdevice.h"

#include <dbsdtranslator.h>
#include <size.h>


FSDevice::FSDevice()
	:	fstype(Unknown)
{
}



FSDevice::FSDevice(const QString &  devname,
						 Size size,
						 FSType fstype)
	:	Device(devname),

	size(size),
	fstype(fstype)
{
}



FSDevice::FSDevice(const QString &  name)
	: Device(name),

	fstype(Unknown)
{
}



QString  FSDevice::getDesc()  const {
	switch(fstype) {
		case  Whole:		return NonUITr::tr("(Whole)");
		case  Unused:		return NonUITr::tr("- Unused -");
		case  Unknown:		return NonUITr::tr("(Unknown)");

		case  UFS:			return NonUITr::tr("UFS");
		case  FAT:			return NonUITr::tr("FAT");
		case  NTFS:			return NonUITr::tr("NTFS");
		case  Linux:		return NonUITr::tr("Linux");
		case  ext2fs:		return NonUITr::tr("ext2");
		case  ReiserFS:		return NonUITr::tr("ReiserFS");
		case  ISO9660:		return NonUITr::tr("ISO 9660");
		case  UDF:			return NonUITr::tr("UDF");
		case  CDROM:		return NonUITr::tr("CD, DVD");
		case  Extended:	return NonUITr::tr("Extended");

		default:
			return	"";
	}
}



Size  FSDevice::getSize()  const {
	return  size;
}



FSDevice::FSType  FSDevice::getFSType()  const {
	return  fstype;
}



/** Converts a system id to a FSType value. */
FSDevice::FSType  FSDevice::typeFromSysId(uint  sysid)  const {
	switch(sysid) {
		case 1:
		case 4:
		case 5:
		case 6:
		case 11:
		case 12:
		case 14:		return  FAT;

		case 7:		return  NTFS;
		case 15:		return  Extended;
		case 131:	return  Linux;
		case 165:	return  UFS;

		default:
			return  Unknown;
	}
}

/** Converts the given FSType into a sysid value.
  *
  * Returns 0 when the type is Whole, CD9660, UDF,
  * Unused, CDROM or unknown.
  */
uint  FSDevice::sysIdFromType(FSType fs)  const {
	switch(fs) {
		case FAT:		return 6;	/* sysid proposed by sysinstall */
		case NTFS:		return 7;
		case Extended:	return 15;
		case Linux:
		case ReiserFS:
		case ext2fs:	return 131;
		case UFS:		return 165;

		default:
			return 0;
	}

	// -- Not reached
	return 0;
}



/** @returns A file system string that can be
  *			 used for mount(8).
  */
QString  FSDevice::mountType(FSType  fstype)  const {
	switch(fstype) {
		case  UFS:		return "ufs";
		case  FAT:		return "msdosfs";
		case  NTFS:	  return "ntfs";
		case  ext2fs:	return "ext2fs";
		case  ReiserFS:	return "reiserfs";
		case  ISO9660:  return "cd9660";
		case  UDF:		return "udf";

		default:
			return	"";
	}
}
