Skip to contentSkip to conversation

Use correct UMNT protocol to do umount

PATCH In review Wei Yongjun 1 participant 2 messages Mar 14, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/4 Use correct UMNT protocol to do umount

This patch do following things:

1. When unmounting, we should try /proc/mounts first. Only then in /etc/mtab if it wasn't found.
2. Reject name passed to us which is not starts with a '/' or not contains a ':'
3. Fix the method to get UMNT protocol

mount/nfsumount.c renamed from mount/nfsumount.c.orig +27 -24
@@ -103,33 +103,28 @@
 	return 0;
 }
 
-u_int get_mntproto(const char *);
-u_int
-get_mntproto(const char *dirname)
+struct mntentchn *
+getmntentchn(const char *dir)
 {
-	FILE *mtab;
-	struct mntent mntbuf;
-	char tmpbuf[BUFSIZ];
-	u_int proto = IPPROTO_TCP; /* assume tcp */
-
-	 mtab = setmntent ("/proc/mounts", "r");
-	 if (mtab == NULL)
-	 	mtab = setmntent (_PATH_MOUNTED, "r");
-	if (mtab == NULL)
-		return proto;
+	mntFILE *mfp;
+	nfs_mntent_t *mnt;
+	struct mntentchn *mc = NULL;
+
+	mfp = nfs_setmntent ("/proc/mounts", "r");
+	if (mfp == NULL || mfp->mntent_fp == NULL)
+		return NULL;
 
-	while(getmntent_r(mtab, &mntbuf, tmpbuf, sizeof (tmpbuf))) {
-		if (strcmp(mntbuf.mnt_type, "nfs"))
+	while ((mnt = nfs_getmntent(mfp)) != NULL) {
+		if(strcmp(mnt->mnt_fsname, dir) && strcmp(mnt->mnt_dir, dir))
 			continue;
-		if (strcmp(dirname,  mntbuf.mnt_fsname))
-			continue;
-		if (hasmntopt(&mntbuf, "udp"))
-			proto = IPPROTO_UDP;
-		break;
+
+		if (!mc)
+			mc = (struct mntentchn *)xmalloc(sizeof(*mc));
+		mc->m = *mnt;
 	}
-	endmntent (mtab);
 
-	return proto;
+	nfs_endmntent(mfp);
+	return mc;
 }
 
 /* complain about a failed umount */
@@ -257,6 +252,7 @@
 	char *hostname;
 	char *dirname;
 	clnt_addr_t mnt_server = { &hostname, };
+	struct mntent mnt = {.mnt_opts = opts};
 	struct pmap *pmap = &mnt_server.pmap;
 	char *p;
 
@@ -291,7 +287,7 @@
 
 	pmap->pm_prog = MOUNTPROG;
 	pmap->pm_vers = MOUNTVERS;
-	pmap->pm_prot = get_mntproto(spec);
+	pmap->pm_prot = IPPROTO_TCP;
 	if (opts && (p = strstr(opts, "mountprog=")) && isdigit(*(p+10)))
 		pmap->pm_prog = atoi(p+10);
 	if (opts && (p = strstr(opts, "mountport=")) && isdigit(*(p+10)))
@@ -300,6 +296,8 @@
 		pmap->pm_vers = nfsvers_to_mnt(atoi(p+8));
 	if (opts && (p = strstr(opts, "mountvers=")) && isdigit(*(p+10)))
 		pmap->pm_vers = atoi(p+10);
+	if (opts && (hasmntopt(&mnt, "udp") || hasmntopt(&mnt, "proto=udp")))
+		pmap->pm_prot = IPPROTO_UDP;
 
 	if (!nfs_gethostbyname(hostname, &mnt_server.saddr))
 		goto out_bad;
@@ -368,8 +366,13 @@
 			return 0;
 		}
 	}
+	
+	if (spec == NULL || *spec != '/' || (strchr(spec,':') == NULL))
+		return 0;
 
-	mc = getmntdirbackward(spec, NULL);
+	mc = getmntentchn(spec);
+	if (!mc)
+		mc = getmntdirbackward(spec, NULL);
 	if (!mc)
 		mc = getmntdevbackward(spec, NULL);
 	if (!mc && verbose)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#1 lore raw

I'm so sorry to say that last post is an old patch. This is the new patch.

Quoted 8 lines

This patch do following things:

1. When unmounting, we should try /proc/mounts first. Only then in /etc/mtab if it wasn't found.
2. Reject name passed to us which is not starts with a '/' or not contains a ':'
3. Fix the method to get UMNT protocol

mount/nfsumount.c renamed from mount/nfsumount.c.orig +29 -24
@@ -103,33 +103,28 @@
 	return 0;
 }
 
-u_int get_mntproto(const char *);
-u_int
-get_mntproto(const char *dirname)
+struct mntentchn *
+getmntentchn(const char *dir)
 {
-	FILE *mtab;
-	struct mntent mntbuf;
-	char tmpbuf[BUFSIZ];
-	u_int proto = IPPROTO_TCP; /* assume tcp */
-
-	 mtab = setmntent ("/proc/mounts", "r");
-	 if (mtab == NULL)
-	 	mtab = setmntent (_PATH_MOUNTED, "r");
-	if (mtab == NULL)
-		return proto;
+	mntFILE *mfp;
+	nfs_mntent_t *mnt;
+	struct mntentchn *mc = NULL;
+
+	mfp = nfs_setmntent ("/proc/mounts", "r");
+	if (mfp == NULL || mfp->mntent_fp == NULL)
+		return NULL;
 
-	while(getmntent_r(mtab, &mntbuf, tmpbuf, sizeof (tmpbuf))) {
-		if (strcmp(mntbuf.mnt_type, "nfs"))
+	while ((mnt = nfs_getmntent(mfp)) != NULL) {
+		if(strcmp(mnt->mnt_fsname, dir) && strcmp(mnt->mnt_dir, dir))
 			continue;
-		if (strcmp(dirname,  mntbuf.mnt_fsname))
-			continue;
-		if (hasmntopt(&mntbuf, "udp"))
-			proto = IPPROTO_UDP;
-		break;
+
+		if (!mc)
+			mc = (struct mntentchn *)xmalloc(sizeof(*mc));
+		mc->m = *mnt;
 	}
-	endmntent (mtab);
 
-	return proto;
+	nfs_endmntent(mfp);
+	return mc;
 }
 
 /* complain about a failed umount */
@@ -257,6 +252,7 @@
 	char *hostname;
 	char *dirname;
 	clnt_addr_t mnt_server = { &hostname, };
+	struct mntent mnt = { .mnt_opts = opts };
 	struct pmap *pmap = &mnt_server.pmap;
 	char *p;
 
@@ -291,7 +287,7 @@
 
 	pmap->pm_prog = MOUNTPROG;
 	pmap->pm_vers = MOUNTVERS;
-	pmap->pm_prot = get_mntproto(spec);
+	pmap->pm_prot = IPPROTO_TCP;
 	if (opts && (p = strstr(opts, "mountprog=")) && isdigit(*(p+10)))
 		pmap->pm_prog = atoi(p+10);
 	if (opts && (p = strstr(opts, "mountport=")) && isdigit(*(p+10)))
@@ -300,6 +296,8 @@
 		pmap->pm_vers = nfsvers_to_mnt(atoi(p+8));
 	if (opts && (p = strstr(opts, "mountvers=")) && isdigit(*(p+10)))
 		pmap->pm_vers = atoi(p+10);
+	if (opts && (hasmntopt(&mnt, "udp") || hasmntopt(&mnt, "proto=udp")))
+		pmap->pm_prot = IPPROTO_UDP;
 
 	if (!nfs_gethostbyname(hostname, &mnt_server.saddr))
 		goto out_bad;
@@ -368,8 +366,15 @@
 			return 0;
 		}
 	}
+	
+	if (spec == NULL || (*spec != '/' && strchr(spec,':') == NULL)) {
+		printf(_("umount: %s: not found\n"), spec);
+		return 0;
+	}
 
-	mc = getmntdirbackward(spec, NULL);
+	mc = getmntentchn(spec);
+	if (!mc)
+		mc = getmntdirbackward(spec, NULL);
 	if (!mc)
 		mc = getmntdevbackward(spec, NULL);
 	if (!mc && verbose)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs