Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Tvrtko remind-nix.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Put mounted drives list into Glist

Function that gets list of mounted drives from '/etc/fstab' and '/etc/mtab' files and puts data in the GList object (from GLib library) that can be further used in GTK.

   1  
   2  #include <glib.h>
   3  #include <mntent.h>
   4  #include <string.h>
   5  
   6  GList * g_get_drives_list(GList * g) {
   7  	FILE *fstab = NULL;
   8  	struct mntent *part = NULL;
   9  	gchar *mntp = NULL;
  10  	
  11  	if ((fstab = setmntent( "/etc/fstab", "r" )) != NULL) {
  12  		while ((part = getmntent(fstab))  != NULL) {
  13  			if((strcmp(part->mnt_type, "proc")) != 0 && (strcmp(part->mnt_type, "devpts")) != 0 
  14  																					&& (strcmp(part->mnt_type, "swap")) != 0) {
  15  				mntp = g_strdup(part->mnt_dir);
  16  				g=g_list_append(g, mntp);
  17  			}
  18  		}
  19  		endmntent(fstab);
  20  	}
  21  	
  22  	if ((fstab = setmntent( "/etc/mtab", "r")) != NULL) {
  23  		while ((part = getmntent(fstab)) != NULL) {
  24  			if (part->mnt_type != NULL) {
  25  				if((strcmp(part->mnt_type, "proc")) != 0 && (strcmp(part->mnt_type, "devpts")) != 0
  26  						&& (strcmp(part->mnt_type, "swap")) != 0 && (strcmp(part->mnt_type, "sysfs")) != 0
  27  						&& (strcmp(part->mnt_type, "tmpfs")) != 0 && (strcmp(part->mnt_type, "fuseblk")) != 0
  28  						&& (strcmp(part->mnt_type, "securityfs")) != 0) {
  29  					if((g_list_find_custom(g, part->mnt_dir, (GCompareFunc)strcmp)) == 0) {
  30  						mntp=g_strdup(part->mnt_dir);
  31  						g=g_list_append(g, mntp);
  32  					}
  33  				}
  34  			}
  35  		}
  36  		endmntent(fstab);
  37  	}
  38  	return g;
  39  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS