Re: PATCH: add display of current mount point to cfdisk (updated)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



okay and now i now i changed that brain dead code to not read the mtab up to 60 times but only once.. but something strange happens for p_info[i>4], seems they are shifted.. can somehow help me find and fix this?
regards_marcel


--
<div id="signature">
"Obstacles are those frightful things you see when you take your eyes off your goal." -- Henry Ford (1863-1947)
  Change the world! Vote revolution: http://hfopi.org/vote-future
</div>
--- cfdisk.c.orig	2008-06-30 01:31:43.000000000 +0200
+++ cfdisk.c	2008-07-01 11:53:35.000000000 +0200
@@ -53,6 +53,8 @@
  *  ext3 and ReiserFS recognition.
  * Sun Oct 12 17:43:43 CEST 2003 <flavio.stanchina@xxxxxx>
  *  JFS recognition; ReiserFS label recognition.
+ * Sun Jul 1 11:51:50 CEST 2008 <mpartap@xxxxxxx>
+ *  Mount point display.
  *
  ****************************************************************************/
 
@@ -78,6 +80,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <mntent.h>
 
 #include "nls.h"
 #include "blkdev.h"
@@ -289,6 +292,8 @@
     char ostype[OSTYPESZ+1];
 #define FSTYPESZ 8
     char fstype[FSTYPESZ+1];
+#define MNTPTHSZ 16
+    char mntpath[MNTPTHSZ+1];
 } partition_info;
 
 char *disk_device = DEFAULT_DEVICE;
@@ -327,10 +332,11 @@
 int COMMAND_LINE_Y = 21;
 
 /* X coordinates */
-int NAME_START = 4;
-int FLAGS_START = 16;
-int PTYPE_START = 28;
-int FSTYPE_START = 38;
+int NAME_START = 2;
+int MNTPATH_START = 8;
+int FLAGS_START = 22;
+int PTYPE_START = 30;
+int FSTYPE_START = 40;
 int LABEL_START = 54;
 int SIZE_START = 68;
 int COMMAND_LINE_X = 5;
@@ -845,6 +851,7 @@
     p_info[i].volume_label[0] = 0;
     p_info[i].fstype[0] = 0;
     p_info[i].ostype[0] = 0;
+    p_info[i].mntpath[0] = 0;
 
     num_parts++;
 }
@@ -988,6 +995,7 @@
 	    ext_info.volume_label[0] = 0;
 	    ext_info.fstype[0] = 0;
 	    ext_info.ostype[0] = 0;
+	    ext_info.mntpath[0] = 0;
 	    return 0;
 	} else {
 	    return -1;		/* explicit extended logical */
@@ -1046,6 +1054,7 @@
     p_info[i].volume_label[0] = 0;
     p_info[i].fstype[0] = 0;
     p_info[i].ostype[0] = 0;
+    p_info[i].mntpath[0] = 0;
     if (want_label) {
 	 if (may_have_dos_label(id))
 	      get_dos_label(i);
@@ -1638,6 +1647,53 @@
 }
 
 static void
+get_mount_points(void) {
+    FILE *mtab;
+    struct mntent *entry;
+#define MAXPARTSZ 32
+    char part_name[MAXPARTSZ+1];
+    char buf[MAXPARTSZ+1];
+    int i, digitend, l, pnum;
+
+    l = strlen(disk_device);
+    digitend = isdigit(disk_device[l-1]);
+
+    if ((mtab = setmntent(_PATH_MOUNTED, "r")) != NULL) {
+	while ((entry = getmntent(mtab)) != NULL)
+	    if (strncmp(entry->mnt_fsname, disk_device, l) == 0)
+		if (digitend) {
+		    if (entry->mnt_fsname[l] == 'p') {
+			pnum = atoi(entry->mnt_fsname+l+1);
+			strncpy(p_info[pnum-1].mntpath, entry->mnt_dir, MNTPTHSZ);
+		    }
+		} else {
+		    pnum = atoi(entry->mnt_fsname+l);
+		    strncpy(p_info[pnum-1].mntpath, entry->mnt_dir, MNTPTHSZ);
+		    /* very strange error: sometimes mount points sink one entry??? uncomment this to see..
+		    sprintf(p_info[pnum-1].mntpath, "(pnum = %d )", pnum); */
+		}
+	endmntent(mtab);
+    }
+
+    if (mtab = fopen("/proc/swaps", "r")) {
+	while (fgets(buf, MAXPARTSZ, mtab) != NULL)
+	    if (strncmp(buf, disk_device, l) == 0)
+		if (digitend) {
+		    if (buf[l] == 'p') {
+			pnum = atoi(buf+l+1);
+			strcpy(p_info[pnum-1].mntpath, "(act. swap)");
+		    }
+		} else {
+		    pnum = atoi(buf+l);
+		    strcpy(p_info[pnum-1].mntpath, "(act. swap)");
+		    /* very strange error: sometimes this sinks one entry??? uncomment this to see..
+		    sprintf(p_info[pnum-1].mntpath, "(pnum = %d )", pnum); */
+		}
+	fclose(mtab);
+    }
+}
+
+static void
 clear_p_info(void) {
     num_parts = 1;
     p_info[0].first_sector = 0;
@@ -1771,6 +1827,7 @@
 		}
 	    } while (pn < 4 && logical < MAXIMUM_PARTS-4);
 	}
+	get_mount_points();
     }
 }
 
@@ -2549,6 +2606,7 @@
 	mvprintw(y, NAME_START,
 		 "%s%s%d", dbn, (digit_last ? "p" : ""),
 		 p_info[i].num+1);
+	mvprintw(y, MNTPATH_START, "%s", p_info[i].mntpath);
 	if (p_info[i].flags) {
 	    if (p_info[i].flags == ACTIVE_FLAG)
 		mvaddstr(y, FLAGS_START, _("Boot"));
@@ -2586,7 +2644,7 @@
 
     if (p_info[i].volume_label[0]) {
 	int l = strlen(p_info[i].volume_label);
-	int s = SIZE_START-5-l;
+	int s = SIZE_START-2-l;
 	mvprintw(y, (s > LABEL_START) ? LABEL_START : s,
 		 " [%s]  ", p_info[i].volume_label);
     }
@@ -2610,6 +2668,7 @@
 init_const(void) {
     if (!defined) {
 	NAME_START = (((float)NAME_START)/COLUMNS)*COLS;
+	MNTPATH_START = (((float)MNTPATH_START)/COLUMNS)*COLS;
 	FLAGS_START = (((float)FLAGS_START)/COLUMNS)*COLS;
 	PTYPE_START = (((float)PTYPE_START)/COLUMNS)*COLS;
 	FSTYPE_START = (((float)FSTYPE_START)/COLUMNS)*COLS;
@@ -2670,6 +2729,7 @@
     mvaddstr(HEADER_START+4, (COLS-strlen(line))/2, line);
 
     mvaddstr(DISK_TABLE_START, NAME_START, _("Name"));
+    mvaddstr(DISK_TABLE_START, MNTPATH_START, _("Mounted as"));
     mvaddstr(DISK_TABLE_START, FLAGS_START, _("Flags"));
     mvaddstr(DISK_TABLE_START, PTYPE_START-1, _("Part Type"));
     mvaddstr(DISK_TABLE_START, FSTYPE_START, _("FS Type"));

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux