28 #include "kstandarddirs.h" 30 #include "kmountpoint.h" 35 #ifdef HAVE_SYS_MNTTAB_H 36 #include <sys/mnttab.h> 40 #elif defined(HAVE_SYS_MNTENT_H) 41 #include <sys/mntent.h> 45 #ifdef HAVE_SYS_MOUNT_H 46 #ifdef HAVE_SYS_TYPES_H 47 #include <sys/types.h> 49 #ifdef HAVE_SYS_PARAM_H 50 #include <sys/param.h> 52 #include <sys/mount.h> 59 #include <sys/mntctl.h> 60 #include <sys/vmount.h> 65 int mntctl(
int command,
int size,
void* buffer);
68 extern "C" struct vfs_ent *getvfsbytype(
int vfsType);
69 extern "C" void endvfsent( );
73 #ifndef HAVE_GETMNTINFO 77 # define MNTTAB _PATH_MOUNTED 81 # define MNTTAB MTAB_FILE 83 # define MNTTAB "/etc/mnttab" 92 #define FSTAB "/etc/vfstab" 94 #define FSTAB "/etc/fstab" 99 KMountPoint::KMountPoint()
107 #ifdef HAVE_SETMNTENT 108 #define SETMNTENT setmntent 109 #define ENDMNTENT endmntent 110 #define STRUCT_MNTENT struct mntent * 111 #define STRUCT_SETMNTENT FILE * 112 #define GETMNTENT(file, var) ((var = getmntent(file)) != 0) 113 #define MOUNTPOINT(var) var->mnt_dir 114 #define MOUNTTYPE(var) var->mnt_type 115 #define MOUNTOPTIONS(var) var->mnt_opts 116 #define FSNAME(var) var->mnt_fsname 118 #define SETMNTENT fopen 119 #define ENDMNTENT fclose 120 #define STRUCT_MNTENT struct mnttab 121 #define STRUCT_SETMNTENT FILE * 122 #define GETMNTENT(file, var) (getmntent(file, &var) == 0) 123 #define MOUNTPOINT(var) var.mnt_mountp 124 #define MOUNTTYPE(var) var.mnt_fstype 125 #define MOUNTOPTIONS(var) var.mnt_mntopts 126 #define FSNAME(var) var.mnt_special 131 KMountPoint::List result;
133 #ifdef HAVE_SETMNTENT 134 STRUCT_SETMNTENT fstab;
135 if ((fstab = SETMNTENT(FSTAB,
"r")) == 0)
139 while (GETMNTENT(fstab, fe))
142 mp->m_mountedFrom = TQFile::decodeName(FSNAME(fe));
144 mp->m_mountPoint = TQFile::decodeName(MOUNTPOINT(fe));
145 mp->m_mountType = TQFile::decodeName(MOUNTTYPE(fe));
149 if (infoNeeded & NeedMountOptions || (mp->m_mountType ==
"supermount"))
151 TQString options = TQFile::decodeName(MOUNTOPTIONS(fe));
152 mp->m_mountOptions = TQStringList::split(
',', options);
155 if(mp->m_mountType ==
"supermount")
158 if (infoNeeded & NeedRealDeviceName)
160 if (mp->m_mountedFrom.startsWith(
"/"))
169 if ( !f.open(IO_ReadOnly) )
177 s=t.readLine().simplifyWhiteSpace();
178 if ( s.isEmpty() || (s[0] ==
'#'))
182 TQStringList item = TQStringList::split(
' ', s);
185 if (item.count() < 5)
188 if (item.count() < 4)
195 mp->m_mountedFrom = item[i++];
200 mp->m_mountPoint = item[i++];
201 mp->m_mountType = item[i++];
202 TQString options = item[i++];
204 if (infoNeeded & NeedMountOptions)
206 mp->m_mountOptions = TQStringList::split(
',', options);
209 if (infoNeeded & NeedRealDeviceName)
211 if (mp->m_mountedFrom.startsWith(
"/"))
225 KMountPoint::List result;
227 #ifdef HAVE_GETMNTINFO 229 #ifdef GETMNTINFO_USES_STATVFS 230 struct statvfs *mounted;
232 struct statfs *mounted;
235 int num_fs = getmntinfo(&mounted, MNT_NOWAIT);
237 for (
int i=0;i<num_fs;i++)
240 mp->m_mountedFrom = TQFile::decodeName(mounted[i].f_mntfromname);
241 mp->m_mountPoint = TQFile::decodeName(mounted[i].f_mntonname);
244 mp->m_mountType = TQFile::decodeName(mnt_names[mounted[i].f_type]);
246 mp->m_mountType = TQFile::decodeName(mounted[i].f_fstypename);
249 if (infoNeeded & NeedMountOptions)
251 struct fstab *ft = getfsfile(mounted[i].f_mntonname);
252 TQString options = TQFile::decodeName(ft->fs_mntops);
253 mp->m_mountOptions = TQStringList::split(
',', options);
256 if (infoNeeded & NeedRealDeviceName)
258 if (mp->m_mountedFrom.startsWith(
"/"))
267 struct vmount *mntctl_buffer;
274 mntctl_buffer = (
struct vmount*)malloc(buf_sz);
275 num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
278 buf_sz = *(
int*)mntctl_buffer;
280 mntctl_buffer = (
struct vmount*)malloc(buf_sz);
281 num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
287 vm = (
struct vmount *)mntctl_buffer;
288 for ( ; num > 0; num-- )
291 fsname_len = vmt2datasize(vm, VMT_STUB);
292 mountedto = (
char*)malloc(fsname_len + 1);
293 mountedto[fsname_len] =
'\0';
294 strncpy(mountedto, (
char *)vmt2dataptr(vm, VMT_STUB), fsname_len);
296 fsname_len = vmt2datasize(vm, VMT_OBJECT);
297 mountedfrom = (
char*)malloc(fsname_len + 1);
298 mountedfrom[fsname_len] =
'\0';
299 strncpy(mountedfrom, (
char *)vmt2dataptr(vm, VMT_OBJECT), fsname_len);
305 struct vfs_ent* ent = getvfsbytype(vm->vmt_gfstype);
308 mp->m_mountedFrom = TQFile::decodeName(mountedfrom);
309 mp->m_mountPoint = TQFile::decodeName(mountedto);
310 mp->m_mountType = TQFile::decodeName(ent->vfsent_name);
315 if (infoNeeded & NeedMountOptions)
320 if (infoNeeded & NeedRealDeviceName)
322 if (mp->m_mountedFrom.startsWith(
"/"))
329 vm = (
struct vmount *)((
char *)vm + vm->vmt_length);
335 free( mntctl_buffer );
336 #elif defined(Q_WS_WIN) 339 STRUCT_SETMNTENT mnttab;
340 if ((mnttab = SETMNTENT(MNTTAB,
"r")) == 0)
344 while (GETMNTENT(mnttab, fe))
347 mp->m_mountedFrom = TQFile::decodeName(FSNAME(fe));
349 mp->m_mountPoint = TQFile::decodeName(MOUNTPOINT(fe));
350 mp->m_mountType = TQFile::decodeName(MOUNTTYPE(fe));
354 if (infoNeeded & NeedMountOptions || (mp->m_mountType ==
"supermount"))
356 TQString options = TQFile::decodeName(MOUNTOPTIONS(fe));
357 mp->m_mountOptions = TQStringList::split(
',', options);
360 if (mp->m_mountType ==
"supermount")
363 if (infoNeeded & NeedRealDeviceName)
365 if (mp->m_mountedFrom.startsWith(
"/"))
379 for ( TQStringList::ConstIterator it = options.begin(); it != options.end(); ++it)
381 if( (*it).startsWith(
"dev="))
382 return TQString(*it).remove(
"dev=");
384 return TQString(
"none");
The KMountPoint class provides information about mounted and unmounted disks.
~KMountPoint()
Destructor.
static KMountPoint::List currentMountPoints(int infoNeeded=0)
This function gives a list of all currently used mountpoints.
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 '/.
static TQString devNameFromOptions(const TQStringList &options)
When using supermount, the device name is in the options field as dev=/my/device. ...