...yeah and then i found out _PATH_MNTTAB actually points to /etc/fstab,
and that the mtab doesn't contain current swap partitions. also the file
probably shouldn't be read again for each partition, but highly likely it
is still cached in ram anyways.. 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-06-30 02:09:27.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 Jun 29 22:30:56 CEST 2008 <mpartap@xxxxxxx>
+ * Show mount point for mounted partitions
*
****************************************************************************/
@@ -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;
@@ -737,6 +743,37 @@
}
static void
+get_mount_point(int i) {
+ FILE *mtab;
+ struct mntent *entry;
+#define MAXPARTSZ 32
+ char part_name[MAXPARTSZ+1];
+ char buf[MAXPARTSZ+1];
+
+ int l = strlen(disk_device);
+ int digitend = isdigit(disk_device[l-1]);
+ snprintf(part_name, MAXPARTSZ, "%s%s%d", disk_device, (digitend ? "p" : "") , p_info[i].num+1);
+
+ if ((mtab = setmntent(_PATH_MOUNTED, "r")) != NULL)
+ while ((entry = getmntent(mtab)) != NULL)
+ if (strcmp(part_name, entry->mnt_fsname) == 0) {
+ strncpy(p_info[i].mntpath, entry->mnt_dir, MNTPTHSZ);
+ break;
+ }
+ endmntent(mtab);
+
+ if (p_info[i].mntpath[0] == 0) { /* might be swap partition */
+ if (mtab = fopen("/proc/swaps", "r")) {
+ l = strlen(part_name);
+ while (fgets(buf, l+1, mtab) != NULL)
+ if (strncmp(buf, part_name, l) == 0)
+ strcpy(p_info[i].mntpath, "(act. swap)");
+ fclose(mtab);
+ }
+ }
+}
+
+static void
check_part_info(void) {
int i, pri = 0, log = 0;
@@ -845,6 +882,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 +1026,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,12 +1085,14 @@
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);
else if (id == LINUX)
get_linux_label(i);
}
+ get_mount_point(i);
check_part_info();
@@ -2549,6 +2590,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 +2628,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 +2652,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 +2713,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"));