Module Name:    othersrc
Committed By:   stacktic
Date:           Fri Apr  3 10:46:36 UTC 2009

Modified Files:
        othersrc/bin/fsu_ecp: fsu_ecp.c fsu_flist.c fsu_flist.h

Log Message:
- Used sys/queue.h
- Removed useless strdup/free
- Removed #include in fsu_flist.h
- Used only one entry by hardlink source
- BUFSIZE -> sizeof(buf)
- Fixed progname check


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 othersrc/bin/fsu_ecp/fsu_ecp.c
cvs rdiff -u -r1.1 -r1.2 othersrc/bin/fsu_ecp/fsu_flist.c \
    othersrc/bin/fsu_ecp/fsu_flist.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/bin/fsu_ecp/fsu_ecp.c
diff -u othersrc/bin/fsu_ecp/fsu_ecp.c:1.3 othersrc/bin/fsu_ecp/fsu_ecp.c:1.4
--- othersrc/bin/fsu_ecp/fsu_ecp.c:1.3	Thu Apr  2 07:48:35 2009
+++ othersrc/bin/fsu_ecp/fsu_ecp.c	Fri Apr  3 10:46:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: fsu_ecp.c,v 1.3 2009/04/02 07:48:35 stacktic Exp $ */
+/* $NetBSD: fsu_ecp.c,v 1.4 2009/04/03 10:46:35 stacktic Exp $ */
 
 /*
  * Copyright (c) 2008 Arnaud Ysmal.  All Rights Reserved.
@@ -25,14 +25,14 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/syslimits.h>
+#include <sys/queue.h>
 #include <sys/stat.h>
+#include <sys/syslimits.h>
 
 #include <dirent.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -72,8 +72,9 @@
 
 struct hardlink_s {
 	char *hl_from;
-	char *hl_to;
-	struct hardlink_s *next;
+	char **hl_to;
+	int hl_nlink;
+	SLIST_ENTRY(hardlink_s) next;
 };
 
 int
@@ -82,6 +83,7 @@
 	size_t len;
 	int cur_arg, flags, rv;
 
+	setprogname(argv[0]);
 	FSU_MOUNT(argc, argv, ukfs);
 
 	flags = fsu_ecp_parse_arg(&argc, &argv);
@@ -104,14 +106,15 @@
 fsu_ecp_parse_arg(int *argc, char ***argv)
 {
 	int flags, rv;
+	const char *progname;
 
 	flags = 0;
+	progname = getprogname();
 
-	if (strcmp((*argv)[0], "get") == 0 ||
-	    strcmp((*argv)[0], "fsu_get") == 0)
+	if (strcmp(progname, "get") == 0 || strcmp(progname, "fsu_get") == 0)
 		flags |= FSU_ECP_GET;
-	else if (strcmp((*argv)[0], "put") == 0 ||
-		 strcmp((*argv)[0], "fsu_put") == 0)
+	else if (strcmp(progname, "put") == 0 ||
+		 strcmp(progname, "fsu_put") == 0)
 		flags |= FSU_ECP_PUT;
 
 	while ((rv = getopt(*argc, *argv, "gPpRv")) != -1) {
@@ -248,12 +251,13 @@
 {
 	FSU_FENT *root, *cur, *cur2, *tmp;
 	size_t len;
-	int flist_options, res, rv, off, hl_supported;
-	struct hardlink_s *hl_l, *last, *new;
+	int flist_options, res, rv, off, hl_supported, curlink;
+	struct hardlink_s *new;
 	char hlfrom[PATH_MAX + 1], hlto[PATH_MAX + 1];
 
-	hl_l = last = NULL;
-	res = 0;
+	SLIST_HEAD(, hardlink_s) hl_l = SLIST_HEAD_INITIALIZER(hl_l);
+
+	curlink = res = 0;
 	hl_supported = 1;
 
 	if (flags & FSU_ECP_COPY_LINK)
@@ -278,34 +282,43 @@
 	for (cur = root->next; cur != NULL; cur = cur->next) {
 		if (cur->sb.st_nlink == 1)
 			continue;
-		for (cur2 = cur; cur2->next != NULL;) {
+		new = malloc(sizeof(struct hardlink_s));
+		if (new == NULL) {
+			warn("malloc");
+			return -1;
+		}
+		new->hl_nlink = cur->sb.st_nlink - 1;
+		new->hl_to = malloc(new->hl_nlink * sizeof(char *));
+		if (new->hl_to == NULL) {
+			warn("malloc");
+			free(new);
+			return -1;
+		}
+
+		new->hl_from = cur->path;
+
+		for (curlink = 0, cur2 = cur; cur2->next != NULL;) {
 			if (cur2->next->sb.st_nlink == 1) {
 				cur2 = cur2->next;
 				continue;
 			}
 			if (cur->sb.st_ino == cur2->next->sb.st_ino &&
 			    cur->sb.st_dev == cur2->next->sb.st_dev) {
-				new = malloc(sizeof(struct hardlink_s));
-				if (new == NULL) {
-					warn("malloc");
-					return -1;
-				}
-				new->hl_from = strdup(cur->path);
-				new->hl_to = strdup(cur2->next->path);
-				new->next = NULL;
 				
-				if (hl_l == NULL)
-					hl_l = last = new;
-				else 
-					last = last->next = new;
+				new->hl_to[curlink] = cur2->next->path;
+				if (new->hl_to[curlink] == NULL)
+					warn("%s", cur2->next->path);
+				else
+					curlink++;
 				tmp = cur2->next;
 				cur2->next = cur2->next->next;
-				fsu_flist_free_entry(tmp);
-				if (cur->sb.st_nlink == 2)
+				free(tmp);
+				if (curlink + 1 == cur->sb.st_nlink)
 					break;
 			} else
 				cur2 = cur2->next;
 		}
+		SLIST_INSERT_HEAD(&hl_l, new, next);
 	}
 	
 	if (flags & FSU_ECP_GET)
@@ -365,38 +378,48 @@
 		}
 		to_p[len + 1] = '\0';
 	}
+	
+	memcpy(hlfrom, to_p, len + 1);
+	memcpy(hlto, to_p, len + 1);
+
+	while (!SLIST_EMPTY(&hl_l)) {
+		new = SLIST_FIRST(&hl_l);
+		SLIST_REMOVE_HEAD(&hl_l, next);
 
-	while ((new = hl_l) != NULL) {
-		hl_l = hl_l->next;
-		
-		memcpy(hlfrom, to_p, len + 1);
-		memcpy(hlto, to_p, len + 1);
 		hlfrom[len + 1] = '\0';
-		hlto[len + 1] = '\0';
-			
 		strlcat(hlfrom, new->hl_from + off, PATH_MAX+1);
-		strlcat(hlto, new->hl_to + off, PATH_MAX+1);
-		
-		if (hl_supported) {
-			if (flags & FSU_ECP_GET)
-				rv = link(hlfrom, hlto);
-			else
-				rv = ukfs_link(fs, hlfrom, hlto);
-			if (rv != 0 && errno == EOPNOTSUPP) {
-				hl_supported = 0;
-				copy_filein(fs, hlfrom, hlto);
+
+		for (curlink = 0;
+		     curlink < new->hl_nlink && new->hl_to[curlink] != NULL;
+		     ++curlink) {
+
+			hlto[len + 1] = '\0';
+			strlcat(hlto, new->hl_to[curlink] + off, PATH_MAX+1);
+
+			if (hl_supported) {
+				if (flags & FSU_ECP_GET)
+					rv = link(hlfrom, hlto);
+				else
+					rv = ukfs_link(fs, hlfrom, hlto);
+				if (rv != 0 && errno == EOPNOTSUPP) {
+					hl_supported = 0;
+					copy_filein(fs, hlfrom, hlto);
+				}
+			} else {
+				if (flags & FSU_ECP_GET)
+					copy_fileout(hlfrom, hlto);
+				else
+					copy_filein(fs, hlfrom, hlto);	
+
 			}
-		} else {
-			if (flags & FSU_ECP_GET)
-				copy_fileout(hlfrom, hlto);
-			else
-				copy_filein(fs, hlfrom, hlto);	
+
+			free(new->hl_to[curlink]);
 		}
 
 		free(new->hl_from);
-		free(new->hl_to);
 		free(new);
 	}
+
 out:
 	fsu_flist_free(root);
 
@@ -509,9 +532,9 @@
 	off = 0;
 	do {
 		if (flags & FSU_ECP_PUT)
-			rd = read(fd, buf, BUFSIZE);
+			rd = read(fd, buf, sizeof(buf));
 		else
-			rd = ukfs_read(fs, from, off, buf, BUFSIZE);
+			rd = ukfs_read(fs, from, off, buf, sizeof(buf));
 		if (rd == -1) {
 			warn("%s", from);
 			rv = -1;
@@ -527,7 +550,7 @@
 			goto out;
 		}
 		off += rd;
-	} while (rd == BUFSIZE);
+	} while (rd > 0);
 
 	rv = 0;
 out:
@@ -693,7 +716,7 @@
 	
 	off = 0;
 	do {
-		rd = ukfs_read(fs, from, off, buf, BUFSIZE);
+		rd = ukfs_read(fs, from, off, buf, sizeof(buf));
 		if (rd == -1) {
 			warn("%s", from);
 			return -1;
@@ -704,7 +727,7 @@
 			return -1;
 		}
 		off += rd;
-	} while (rd == BUFSIZE);
+	} while (rd > 0);
 
 	return 0;
 }
@@ -736,7 +759,7 @@
 	}
 
 	do {
-		rd = read(fdfrom, buf, BUFSIZE);
+		rd = read(fdfrom, buf, sizeof(buf));
 		if (rd == -1) {
 			warn("%s", from);
 			rv = -1;
@@ -748,7 +771,7 @@
 			rv = -1;
 			goto out;
 		}
-	} while (rd == BUFSIZE);
+	} while (rd > 0);
 
 
 out:

Index: othersrc/bin/fsu_ecp/fsu_flist.c
diff -u othersrc/bin/fsu_ecp/fsu_flist.c:1.1 othersrc/bin/fsu_ecp/fsu_flist.c:1.2
--- othersrc/bin/fsu_ecp/fsu_flist.c:1.1	Mon Mar 23 21:03:57 2009
+++ othersrc/bin/fsu_ecp/fsu_flist.c	Fri Apr  3 10:46:36 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: fsu_flist.c,v 1.1 2009/03/23 21:03:57 stacktic Exp $ */
+/* $NetBSD: fsu_flist.c,v 1.2 2009/04/03 10:46:36 stacktic Exp $ */
 
 /*
  * Copyright (c) 2008 Arnaud Ysmal.  All Rights Reserved.
@@ -25,14 +25,15 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/stat.h>
+#include <sys/syslimits.h>
+
 #include <dirent.h>
 #include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <sys/syslimits.h>
-
 #include <rump/ukfs.h>
 
 #include <fsu_utils.h>
Index: othersrc/bin/fsu_ecp/fsu_flist.h
diff -u othersrc/bin/fsu_ecp/fsu_flist.h:1.1 othersrc/bin/fsu_ecp/fsu_flist.h:1.2
--- othersrc/bin/fsu_ecp/fsu_flist.h:1.1	Mon Mar 23 21:03:57 2009
+++ othersrc/bin/fsu_ecp/fsu_flist.h	Fri Apr  3 10:46:36 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: fsu_flist.h,v 1.1 2009/03/23 21:03:57 stacktic Exp $ */
+/* $NetBSD: fsu_flist.h,v 1.2 2009/04/03 10:46:36 stacktic Exp $ */
 
 /*
  * Copyright (c) 2008 Arnaud Ysmal.  All Rights Reserved.
@@ -28,10 +28,7 @@
 #ifndef _FSU_FLIST_H_
 #define _FSU_FLIST_H_
 
-#include <sys/stat.h>
-
-#include <stdbool.h>
-
+struct stat;
 struct ukfs;
 
 #define FSU_FLIST_RECURSIVE (0x01)

Reply via email to