diff options
Diffstat (limited to 'src/drivers/Posix')
| -rw-r--r-- | src/drivers/Posix/Fl_Posix_System_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/Posix/Fl_Posix_System_Driver.cxx | 154 |
2 files changed, 154 insertions, 1 deletions
diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index 829b292b0..8d0eb5e97 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -75,6 +75,7 @@ public: virtual int use_tooltip_timeout_condition() {return 1;} // this one is in fl_shortcut.cxx virtual const char *shortcut_add_key_name(unsigned key, char *p, char *buf, const char **); + virtual int file_browser_load_filesystem(Fl_File_Browser *browser, char *filename, Fl_File_Icon *icon); }; #endif // FL_POSIX_SYSTEM_DRIVER_H diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx index 98897e41e..658587fe6 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx +++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx @@ -19,6 +19,8 @@ #include <config.h> #include "Fl_Posix_System_Driver.H" #include "../../flstring.h" +#include <FL/Fl_File_Browser.H> +#include <FL/Fl_File_Icon.H> #include <FL/filename.H> #include <FL/Fl.H> #include <X11/Xlib.h> @@ -28,7 +30,33 @@ #include <pwd.h> #include <unistd.h> -// Pointers you can use to change FLTK to a foreign language. +#if defined(_AIX) +extern "C" { +# include <sys/types.h> +# include <sys/vmount.h> +# include <sys/mntctl.h> + // Older AIX versions don't expose this prototype + int mntctl(int, int, char *); +} +#endif // _AIX + +#if defined(__NetBSD__) +extern "C" { +# include <sys/param.h> // For '__NetBSD_Version__' definition +# if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 300000000) +# include <sys/types.h> +# include <sys/statvfs.h> +# if defined(HAVE_PTHREAD) && defined(HAVE_PTHREAD_H) +# include <pthread.h> +# endif // HAVE_PTHREAD && HAVE_PTHREAD_H +# ifdef HAVE_PTHREAD + static pthread_mutex_t getvfsstat_mutex = PTHREAD_MUTEX_INITIALIZER; +# endif // HAVE_PTHREAD/ +# endif // __NetBSD_Version__ +} +#endif // __NetBSD__ + +// Pointers you can use to change FLTK to another language. // Note: Similar pointers are defined in FL/fl_ask.H and src/fl_ask.cxx const char* fl_local_alt = "Alt"; const char* fl_local_ctrl = "Ctrl"; @@ -284,6 +312,130 @@ int Fl_Posix_System_Driver::open_uri(const char *uri, char *msg, int msglen) return run_program(command, argv, msg, msglen) != 0; } + + +int Fl_Posix_System_Driver::file_browser_load_filesystem(Fl_File_Browser *browser, char *filename, Fl_File_Icon *icon) +{ + int num_files = 0; +#if defined(_AIX) + // AIX don't write the mounted filesystems to a file like '/etc/mnttab'. + // But reading the list of mounted filesystems from the kernel is possible: + // http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.aix.basetechref/doc/basetrf1/mntctl.htm + int res = -1, len; + char *list = NULL, *name; + struct vmount *vp; + + // We always have the root filesystem + add("/", icon); + // Get the required buffer size for the vmount structures + res = mntctl(MCTL_QUERY, sizeof(len), (char *) &len); + if (!res) { + // Allocate buffer ... + list = (char *) malloc((size_t) len); + if (NULL == list) { + res = -1; + } else { + // ... and read vmount structures from kernel + res = mntctl(MCTL_QUERY, len, list); + if (0 >= res) { + res = -1; + } else { + for (i = 0, vp = (struct vmount *) list; i < res; ++i) { + name = (char *) vp + vp->vmt_data[VMT_STUB].vmt_off; + strlcpy(filename, name, sizeof(filename)); + // Skip the already added root filesystem + if (strcmp("/", filename) != 0) { + strlcat(filename, "/", sizeof(filename)); + browser->add(filename, icon); + } + vp = (struct vmount *) ((char *) vp + vp->vmt_length); + } + } + } + } + // Note: Executing 'free(NULL)' is allowed and simply do nothing + free((void *) list); +#elif defined(__NetBSD__) && defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 300000000) + // NetBSD don't write the mounted filesystems to a file like '/etc/mnttab'. + // Since NetBSD 3.0 the system call getvfsstat(2) has replaced getfsstat(2) + // that is used by getmntinfo(3): + // http://www.daemon-systems.org/man/getmntinfo.3.html + int res = -1; + struct statvfs *list; + + // We always have the root filesystem + browser->add("/", icon); +# ifdef HAVE_PTHREAD + // Lock mutex for thread safety + if (!pthread_mutex_lock(&getvfsstat_mutex)) { +# endif // HAVE_PTHREAD + // Get list of statvfs structures + res = getmntinfo(&list, ST_WAIT); + if(0 < res) { + for (i = 0; i < res; ++i) { + strlcpy(filename, list[i].f_mntonname, sizeof(filename)); + // Skip the already added root filesystem + if (strcmp("/", filename) != 0) { + strlcat(filename, "/", sizeof(filename)); + browser->add(filename, icon); + } + } + } else { + res = -1; + } +# ifdef HAVE_PTHREAD + pthread_mutex_unlock(&getvfsstat_mutex); + } +# endif // HAVE_PTHREAD +#else + // + // UNIX code uses /etc/fstab or similar... + // + FILE *mtab; // /etc/mtab or /etc/mnttab file + char line[FL_PATH_MAX]; // Input line + + // + // Open the file that contains a list of mounted filesystems... + // + + mtab = fl_fopen("/etc/mnttab", "r"); // Fairly standard + if (mtab == NULL) + mtab = fl_fopen("/etc/mtab", "r"); // More standard + if (mtab == NULL) + mtab = fl_fopen("/etc/fstab", "r"); // Otherwise fallback to full list + if (mtab == NULL) + mtab = fl_fopen("/etc/vfstab", "r"); // Alternate full list file + + if (mtab != NULL) + { + while (fgets(line, sizeof(line), mtab) != NULL) + { + if (line[0] == '#' || line[0] == '\n') + continue; + if (sscanf(line, "%*s%4095s", filename) != 1) + continue; + + // Add a trailing slash (except for the root filesystem) + if (strcmp("/", filename) != 0) { + strlcat(filename, "/", sizeof(filename)); + } + + // printf("Fl_File_Browser::load() - adding \"%s\" to list...\n", filename); + browser->add(filename, icon); + num_files ++; + } + + fclose(mtab); + } else { + // Every Unix has a root filesystem '/'. + // This last stage fallback ensures that the user don't get an empty + // window after requesting filesystem list. + browser->add("/", icon); + } +#endif // _AIX || ... + return num_files; +} + // // End of "$Id$". // |
