28#include "tdestandarddirs.h"
30#include "kmountpoint.h"
35#ifdef HAVE_SYS_MNTTAB_H
37#include <sys/mnttab.h>
41#elif defined(HAVE_SYS_MNTENT_H)
42#include <sys/mntent.h>
46#ifdef HAVE_SYS_MOUNT_H
47#ifdef HAVE_SYS_TYPES_H
50#ifdef HAVE_SYS_PARAM_H
60#include <sys/mntctl.h>
61#include <sys/vmount.h>
66int mntctl(
int command,
int size,
void* buffer);
69extern "C" struct vfs_ent *getvfsbytype(
int vfsType);
70extern "C" void endvfsent( );
74#ifndef HAVE_GETMNTINFO
78# define MNTTAB _PATH_MOUNTED
82# define MNTTAB MTAB_FILE
84# define MNTTAB "/etc/mnttab"
93#define FSTAB "/etc/vfstab"
95#define FSTAB "/etc/fstab"
100KMountPoint::KMountPoint()
109#define SETMNTENT setmntent
110#define ENDMNTENT endmntent
111#define STRUCT_MNTENT struct mntent *
112#define STRUCT_SETMNTENT FILE *
113#define GETMNTENT(file, var) ((var = getmntent(file)) != 0)
114#define MOUNTPOINT(var) var->mnt_dir
115#define MOUNTTYPE(var) var->mnt_type
116#define MOUNTOPTIONS(var) var->mnt_opts
117#define FSNAME(var) var->mnt_fsname
119#define SETMNTENT fopen
120#define ENDMNTENT fclose
121#define STRUCT_MNTENT struct mnttab
122#define STRUCT_SETMNTENT FILE *
123#define GETMNTENT(file, var) (getmntent(file, &var) == 0)
124#define MOUNTPOINT(var) var.mnt_mountp
125#define MOUNTTYPE(var) var.mnt_fstype
126#define MOUNTOPTIONS(var) var.mnt_mntopts
127#define FSNAME(var) var.mnt_special
132 KMountPoint::List result;
135 STRUCT_SETMNTENT fstab;
136 if ((fstab = SETMNTENT(FSTAB,
"r")) == 0)
140 while (GETMNTENT(fstab, fe))
143 mp->m_mountedFrom = TQFile::decodeName(FSNAME(fe));
145 mp->m_mountPoint = TQFile::decodeName(MOUNTPOINT(fe));
146 mp->m_mountType = TQFile::decodeName(MOUNTTYPE(fe));
150 if (infoNeeded & NeedMountOptions || (mp->m_mountType ==
"supermount"))
152 TQString options = TQFile::decodeName(MOUNTOPTIONS(fe));
153 mp->m_mountOptions = TQStringList::split(
',', options);
156 if(mp->m_mountType ==
"supermount")
159 if (infoNeeded & NeedRealDeviceName)
161 if (mp->m_mountedFrom.startsWith(
"/"))
170 if ( !f.open(IO_ReadOnly) )
178 s=t.readLine().simplifyWhiteSpace();
179 if ( s.isEmpty() || (s[0] ==
'#'))
183 TQStringList item = TQStringList::split(
' ', s);
186 if (item.count() < 5)
189 if (item.count() < 4)
196 mp->m_mountedFrom = item[i++];
201 mp->m_mountPoint = item[i++];
202 mp->m_mountType = item[i++];
203 TQString options = item[i++];
205 if (infoNeeded & NeedMountOptions)
207 mp->m_mountOptions = TQStringList::split(
',', options);
210 if (infoNeeded & NeedRealDeviceName)
212 if (mp->m_mountedFrom.startsWith(
"/"))
226 KMountPoint::List result;
228#ifdef HAVE_GETMNTINFO
230#ifdef GETMNTINFO_USES_STATVFS
231 struct statvfs *mounted;
233 struct statfs *mounted;
236 int num_fs = getmntinfo(&mounted, MNT_NOWAIT);
238 for (
int i=0;i<num_fs;i++)
241 mp->m_mountedFrom = TQFile::decodeName(mounted[i].f_mntfromname);
242 mp->m_mountPoint = TQFile::decodeName(mounted[i].f_mntonname);
243 mp->m_mountType = TQFile::decodeName(mounted[i].f_fstypename);
245 if (infoNeeded & NeedMountOptions)
247 struct fstab *ft = getfsfile(mounted[i].f_mntonname);
248 TQString options = TQFile::decodeName(ft->fs_mntops);
249 mp->m_mountOptions = TQStringList::split(
',', options);
252 if (infoNeeded & NeedRealDeviceName)
254 if (mp->m_mountedFrom.startsWith(
"/"))
263 struct vmount *mntctl_buffer;
270 mntctl_buffer = (
struct vmount*)malloc(buf_sz);
271 num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
274 buf_sz = *(
int*)mntctl_buffer;
276 mntctl_buffer = (
struct vmount*)malloc(buf_sz);
277 num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
283 vm = (
struct vmount *)mntctl_buffer;
284 for ( ; num > 0; num-- )
287 fsname_len = vmt2datasize(vm, VMT_STUB);
288 mountedto = (
char*)malloc(fsname_len + 1);
289 mountedto[fsname_len] =
'\0';
290 strncpy(mountedto, (
char *)vmt2dataptr(vm, VMT_STUB), fsname_len);
292 fsname_len = vmt2datasize(vm, VMT_OBJECT);
293 mountedfrom = (
char*)malloc(fsname_len + 1);
294 mountedfrom[fsname_len] =
'\0';
295 strncpy(mountedfrom, (
char *)vmt2dataptr(vm, VMT_OBJECT), fsname_len);
301 struct vfs_ent* ent = getvfsbytype(vm->vmt_gfstype);
304 mp->m_mountedFrom = TQFile::decodeName(mountedfrom);
305 mp->m_mountPoint = TQFile::decodeName(mountedto);
306 mp->m_mountType = TQFile::decodeName(ent->vfsent_name);
311 if (infoNeeded & NeedMountOptions)
316 if (infoNeeded & NeedRealDeviceName)
318 if (mp->m_mountedFrom.startsWith(
"/"))
325 vm = (
struct vmount *)((
char *)vm + vm->vmt_length);
331 free( mntctl_buffer );
332#elif defined(TQ_WS_WIN)
335 STRUCT_SETMNTENT mnttab;
336 if ((mnttab = SETMNTENT(MNTTAB,
"r")) == 0)
340 while (GETMNTENT(mnttab, fe))
343 mp->m_mountedFrom = TQFile::decodeName(FSNAME(fe));
345 mp->m_mountPoint = TQFile::decodeName(MOUNTPOINT(fe));
346 mp->m_mountType = TQFile::decodeName(MOUNTTYPE(fe));
350 if (infoNeeded & NeedMountOptions || (mp->m_mountType ==
"supermount"))
352 TQString options = TQFile::decodeName(MOUNTOPTIONS(fe));
353 mp->m_mountOptions = TQStringList::split(
',', options);
356 if (mp->m_mountType ==
"supermount")
359 if (infoNeeded & NeedRealDeviceName)
361 if (mp->m_mountedFrom.startsWith(
"/"))
375 for ( TQStringList::ConstIterator it = options.begin(); it != options.end(); ++it)
377 if( (*it).startsWith(
"dev="))
378 return TQString(*it).remove(
"dev=");
380 return TQString(
"none");
The KMountPoint class provides information about mounted and unmounted disks.
static TQString devNameFromOptions(const TQStringList &options)
When using supermount, the device name is in the options field as dev=/my/device.
static KMountPoint::List currentMountPoints(int infoNeeded=0)
This function gives a list of all currently used mountpoints.
~KMountPoint()
Destructor.
static KMountPoint::List possibleMountPoints(int infoNeeded=0)
This function gives a list of all possible mountpoints.
static TQString realPath(const TQString &dirname)
Expands all symbolic links and resolves references to '/.