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

#ifndef __MOUNTABLEDEVICE_H
#define __MOUNTABLEDEVICE_H

#include <fsdevice.h>

#include <stdexcept>	/* std::out_of_range */
#include <qptrlist.h>
#include <size.h>

class QString;
class QStringList;

/** @brief Mountable device.
 *
 * CD-ROM devices aren't handled like disks, raids
 * or usb sticks. They are set to the CDROM type
 * by default. The file system type is probed at
 * mount time.
 *
 * This class also assumes that floppy disks (fd) are
 * formatted with the FAT(12) file system.
 */
class MntDevice : public FSDevice {
public:
   enum Type {
      MntDev     = 0,
      Slice      = 1,
      Partition  = 2
   };
   enum MountOptions {
      ReadOnly    = 1,
      Synchronous = 2,
      NoSUID      = 4,
      NoDevices   = 8,
		Large       = 16
   };

   MntDevice(const QString&);

   bool	unmount(bool = false);
   bool	mount(int flags = 0,  QString mntpnt = "");

   virtual QString	getDesc()  const;

   bool		isMounted()  const;
   QString	mountedOn()  const;

	bool  isATAPICAMDevice()  const;

   uint	subdevCount()  const;
   MntDevice*  operator[] (uint)  throw(std::out_of_range);
   MntDevice&  operator= (const MntDevice&);

	static QPtrList<MntDevice>	getAllDevices();
	static QStringList			getAllDeviceNames();

protected:
   MntDevice();
   MntDevice(const QString&,  Type,  FSType,  Size);

   bool  _mount(int,  QString,  FSType);

   void  readSubDevices();

   bool     rmMountDir(const QString&);
   QString  newMountDir(const QString&,  mode_t = 0660);


private:
   Type    devtype;

   QPtrList <MntDevice>  subdevs;
};

#endif /* __MOUNTABLEDEVICE_H */
