26 #include <QtCore/QFile> 
   27 #include <QtCore/QTextIStream> 
   37 static Qt::CaseSensitivity 
cs = Qt::CaseInsensitive;
 
   39 static Qt::CaseSensitivity 
cs = Qt::CaseSensitive;
 
   45 #ifdef HAVE_SYS_MNTTAB_H 
   46 #include <sys/mnttab.h> 
   50 #elif defined(HAVE_SYS_MNTENT_H) 
   51 #include <sys/mntent.h> 
   55 #ifdef HAVE_SYS_MOUNT_H 
   56 #ifdef HAVE_SYS_TYPES_H 
   57 #include <sys/types.h> 
   59 #ifdef HAVE_SYS_PARAM_H 
   60 #include <sys/param.h> 
   62 #include <sys/mount.h> 
   69 #include <sys/mntctl.h> 
   70 #include <sys/vmount.h> 
   74 extern "C" int mntctl(
int command, 
int size, 
void* buffer);
 
   76 extern "C" struct vfs_ent *getvfsbytype(
int vfsType);
 
   77 extern "C" void endvfsent( );
 
   81 #ifndef HAVE_GETMNTINFO 
   85 #  define MNTTAB _PATH_MOUNTED 
   89 #    define MNTTAB MTAB_FILE 
   91 #    define MNTTAB "/etc/mnttab" 
  101 #define FSTAB "/etc/vfstab" 
  103 #define FSTAB "/etc/fstab" 
  106 class KMountPoint::Private {
 
  108     void finalizePossibleMountPoint(DetailsNeededFlags infoNeeded);
 
  109     void finalizeCurrentMountPoint(DetailsNeededFlags infoNeeded);
 
  118 KMountPoint::KMountPoint()
 
  135 #ifdef HAVE_SETMNTENT 
  136 #define SETMNTENT setmntent 
  137 #define ENDMNTENT endmntent 
  138 #define STRUCT_MNTENT struct mntent * 
  139 #define STRUCT_SETMNTENT FILE * 
  140 #define GETMNTENT(file, var) ((var = getmntent(file)) != 0) 
  141 #define MOUNTPOINT(var) var->mnt_dir 
  142 #define MOUNTTYPE(var) var->mnt_type 
  143 #define MOUNTOPTIONS(var) var->mnt_opts 
  144 #define FSNAME(var) var->mnt_fsname 
  146 #define SETMNTENT fopen 
  147 #define ENDMNTENT fclose 
  148 #define STRUCT_MNTENT struct mnttab 
  149 #define STRUCT_SETMNTENT FILE * 
  150 #define GETMNTENT(file, var) (getmntent(file, &var) == 0) 
  151 #define MOUNTPOINT(var) var.mnt_mountp 
  152 #define MOUNTTYPE(var) var.mnt_fstype 
  153 #define MOUNTOPTIONS(var) var.mnt_mntopts 
  154 #define FSNAME(var) var.mnt_special 
  164     for ( QStringList::ConstIterator it = options.begin(); it != options.end(); ++it)
 
  166         if( (*it).startsWith(QLatin1String(
"dev=")))
 
  169     return QString::fromLatin1(
"none");
 
  172 void KMountPoint::Private::finalizePossibleMountPoint(DetailsNeededFlags infoNeeded)
 
  174     if (mountType == QLatin1String(
"supermount")) {
 
  178     if (mountedFrom.startsWith(QLatin1String(
"UUID="))) {
 
  179         const QString uuid = mountedFrom.mid(5);
 
  180         const QString potentialDevice = QFile::symLinkTarget(QString::fromLatin1(
"/dev/disk/by-uuid/") + uuid);
 
  181         if (QFile::exists(potentialDevice)) {
 
  182             mountedFrom = potentialDevice;
 
  185     if (mountedFrom.startsWith(QLatin1String(
"LABEL="))) {
 
  186         const QString label = mountedFrom.mid(6);
 
  187         const QString potentialDevice = QFile::symLinkTarget(QString::fromLatin1(
"/dev/disk/by-label/") + label);
 
  188         if (QFile::exists(potentialDevice)) {
 
  189             mountedFrom = potentialDevice;
 
  193     if (infoNeeded & NeedRealDeviceName) {
 
  194         if (mountedFrom.startsWith(QLatin1Char(
'/')))
 
  200 void KMountPoint::Private::finalizeCurrentMountPoint(DetailsNeededFlags infoNeeded)
 
  202     if (infoNeeded & NeedRealDeviceName) {
 
  203         if (mountedFrom.startsWith(QLatin1Char(
'/')))
 
  216 #ifdef HAVE_SETMNTENT 
  225       mp->
d->mountedFrom = QFile::decodeName(
FSNAME(fe));
 
  227       mp->
d->mountPoint = QFile::decodeName(
MOUNTPOINT(fe));
 
  228       mp->
d->mountType = QFile::decodeName(
MOUNTTYPE(fe));
 
  232       if (infoNeeded & 
NeedMountOptions || (mp->
d->mountType == QLatin1String(
"supermount")))
 
  235          mp->
d->mountOptions = options.split( QLatin1Char(
',') );
 
  238       mp->
d->finalizePossibleMountPoint(infoNeeded);
 
  244    QFile f(QLatin1String(
FSTAB));
 
  245    if ( !f.open(QIODevice::ReadOnly) )
 
  253       s=t.readLine().simplified();
 
  254       if ( s.isEmpty() || (s[0] == QLatin1Char(
'#')))
 
  258       const QStringList item = s.split(QLatin1Char(
' '));
 
  261       if (item.count() < 5)
 
  264       if (item.count() < 4)
 
  271       mp->
d->mountedFrom = item[i++];
 
  276       mp->
d->mountPoint = item[i++];
 
  277       mp->
d->mountType = item[i++];
 
  282          mp->
d->mountOptions = options.split(QLatin1Char(
','));
 
  285       mp->
d->finalizePossibleMountPoint(infoNeeded);
 
  299 #ifdef HAVE_GETMNTINFO 
  301 #ifdef GETMNTINFO_USES_STATVFS 
  302     struct statvfs *mounted;
 
  304     struct statfs *mounted;
 
  307     int num_fs = getmntinfo(&mounted, MNT_NOWAIT);
 
  309     for (
int i=0;i< num_fs;i++)
 
  312       mp->
d->mountedFrom = QFile::decodeName(mounted[i].f_mntfromname);
 
  313       mp->
d->mountPoint = QFile::decodeName(mounted[i].f_mntonname);
 
  316       mp->
d->mountType = QFile::decodeName(mnt_names[mounted[i].f_type]);
 
  318       mp->
d->mountType = QFile::decodeName(mounted[i].f_fstypename);
 
  323          struct fstab *ft = getfsfile(mounted[i].f_mntonname);
 
  325              QString options = QFile::decodeName(ft->fs_mntops);
 
  326              mp->
d->mountOptions = options.split(QLatin1Char(
','));
 
  332       mp->
d->finalizeCurrentMountPoint(infoNeeded);
 
  339     struct vmount *mntctl_buffer;
 
  346     mntctl_buffer = (
struct vmount*)malloc(buf_sz);
 
  347     num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
 
  350     buf_sz = *(
int*)mntctl_buffer;
 
  352     mntctl_buffer = (
struct vmount*)malloc(buf_sz);
 
  353     num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
 
  359         vm = (
struct vmount *)mntctl_buffer;
 
  360         for ( ; num > 0; --num )
 
  363             fsname_len = vmt2datasize(vm, VMT_STUB);
 
  364             mountedto     = (
char*)malloc(fsname_len + 1);
 
  365         mountedto[fsname_len] = 
'\0';
 
  366             strncpy(mountedto, (
char *)vmt2dataptr(vm, VMT_STUB), fsname_len);
 
  368             fsname_len = vmt2datasize(vm, VMT_OBJECT);
 
  369             mountedfrom     = (
char*)malloc(fsname_len + 1);
 
  370         mountedfrom[fsname_len] = 
'\0';
 
  371             strncpy(mountedfrom, (
char *)vmt2dataptr(vm, VMT_OBJECT), fsname_len);
 
  377             struct vfs_ent* ent = getvfsbytype(vm->vmt_gfstype);
 
  380             mp->d->mountedFrom = QFile::decodeName(mountedfrom);
 
  381             mp->d->mountPoint = QFile::decodeName(mountedto);
 
  382             mp->d->mountType = QFile::decodeName(ent->vfsent_name);
 
  392             mp->d->finalizeCurrentMountPoint(infoNeeded);
 
  396             vm = (
struct vmount *)((
char *)vm + vm->vmt_length);
 
  402     free( mntctl_buffer );
 
  403 #elif defined(Q_WS_WIN) && !defined(_WIN32_WCE) 
  405     DWORD bits = GetLogicalDrives();
 
  409     for(
int i = 0; i < 26; i++)
 
  414             mp->
d->mountPoint = 
QString(QLatin1Char(
'A' + i) + QLatin1String(
":/"));
 
  419 #elif defined(_WIN32_WCE) 
  433       mp->
d->mountedFrom = QFile::decodeName(
FSNAME(fe));
 
  435       mp->
d->mountPoint = QFile::decodeName(
MOUNTPOINT(fe));
 
  436       mp->
d->mountType = QFile::decodeName(
MOUNTTYPE(fe));
 
  440       if (infoNeeded & 
NeedMountOptions || (mp->
d->mountType == QLatin1String(
"supermount")))
 
  443          mp->
d->mountOptions = options.split( QLatin1Char(
',') );
 
  445       mp->
d->finalizeCurrentMountPoint(infoNeeded);
 
  456     return d->mountedFrom;
 
  466     return d->mountPoint;
 
  476     return d->mountOptions;
 
  486     const QLatin1Char slash(
'/');
 
  487     if (child.startsWith(parent, 
cs)) {
 
  495         return parent.compare(child, 
cs) == 0 || parent.endsWith(slash) || child.at(parent.length()) == slash;
 
  498         return parent.endsWith(slash) && (parent.length() == child.length() + 1) && parent.startsWith(child, 
cs);
 
  508     const QString realname = QDir::fromNativeSeparators(QDir(path).absolutePath());
 
  513     for (const_iterator it = begin(); it != end(); ++it) {
 
  514         const QString mountpoint = (*it)->d->mountPoint;
 
  515         const int length = mountpoint.length();
 
  528     if (realDevice.isEmpty()) 
 
  530     for (const_iterator it = begin(); it != end(); ++it) {
 
  531         if (realDevice.compare((*it)->d->device, 
cs) == 0 ||
 
  532             realDevice.compare((*it)->d->mountedFrom, 
cs) == 0)
 
  540     bool nfs = d->mountType == QLatin1String(
"nfs");
 
  541     bool cifs = d->mountType == QLatin1String(
"cifs");
 
  542     bool autofs = d->mountType == QLatin1String(
"autofs") || d->mountType == QLatin1String(
"subfs");
 
  548     if (nfs || autofs || cifs) {
 
  556     const bool isMsDos = ( d->mountType == QLatin1String(
"msdos") || d->mountType == QLatin1String(
"fat") || d->mountType == QLatin1String(
"vfat") );
 
  557     const bool isNtfs = d->mountType.contains(QLatin1String(
"fuse.ntfs")) || d->mountType.contains(QLatin1String(
"fuseblk.ntfs"))
 
  559                         || d->mountType == QLatin1String(
"fuseblk");
 
  560     const bool isSmb = d->mountType == QLatin1String(
"cifs") || d->mountType == QLatin1String(
"smbfs");
 
  567         return !isMsDos && !isNtfs && !isSmb; 
 
Can be used to control the lifetime of an object that has derived QSharedData. 
bool probablySlow() const 
Checks if the filesystem that is probably slow (network mounts). 
The KMountPoint class provides information about mounted and unmounted disks. 
#define GETMNTENT(file, var)
static Qt::CaseSensitivity cs
static QString realFilePath(const QString &filename)
Expands all symbolic links and resolves references to '/. 
static List currentMountPoints(DetailsNeededFlags infoNeeded=BasicInfoNeeded)
This function gives a list of all currently used mountpoints. 
QString mountedFrom() const 
Where this filesystem gets mounted from. 
~KMountPoint()
Destructor. 
QString realDeviceName() const 
Canonical name of the device where the filesystem got mounted from. 
Ptr findByDevice(const QString &device) const 
Returns the mount point associated with device, i.e. 
QString mountType() const 
Type of filesystem. 
bool testFileSystemFlag(FileSystemFlag flag) const 
Checks the capabilities of the filesystem. 
static QString devNameFromOptions(const QStringList &options)
When using supermount, the device name is in the options field as dev=/my/device. ...
QString mountPoint() const 
Path where the filesystem is mounted or can be mounted. 
KSharedPtr< KMountPoint > Ptr
QStringList mountOptions() const 
Options used to mount the filesystem. 
static List possibleMountPoints(DetailsNeededFlags infoNeeded=BasicInfoNeeded)
This function gives a list of all possible mountpoints. 
#define MOUNTOPTIONS(var)
Ptr findByPath(const QString &path) const 
Find the mountpoint on which resides path For instance if /home is a separate partition, findByPath("/home/user/blah") will return /home. 
static bool pathsAreParentAndChildOrEqual(const QString &parent, const QString &child)