⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util-linux-2.12r.diff

📁 Fast and transparent file system and swap encryption package for linux. No source code changes to li
💻 DIFF
📖 第 1 页 / 共 5 页
字号:
+	if(run_mkfs_command && fstype && *fstype && **fstype && (getuid() == 0)) {+		if(!loop_fork_mkfs_command((char *)device, (char *)(*fstype))) {+			/* !strncasecmp(passHashFuncName, "random", 6) test matched */+			/* This reads octal mode for newly created file system root */+			/* directory node from '-o phash=random/1777' mount option. */+			/*                          octal mode--^^^^                */+			sscanf(passHashFuncName + 6, "/%o", AutoChmodPtr);+		} else {+			if((fd = open(device, mode)) >= 0) {+				ioctl(fd, LOOP_CLR_FD, 0);+				close(fd);+				return 1;+			}+		}+	}+#endif -char *-find_unused_loop_device (void) {-	mutter();+	if (verbose > 1)+		printf(_("set_loop(%s,%s): success\n"), device, file); 	return 0; } -#endif- #ifdef MAIN -#ifdef LOOP_SET_FD- #include <getopt.h> #include <stdarg.h>  int verbose = 0;-char *progname;+static char *progname;  static void usage(void) { 	fprintf(stderr, _("usage:\n\-  %s loop_device                                       # give info\n\-  %s -d loop_device                                    # delete\n\-  %s -f                                                # find unused\n\-  %s [-e encryption] [-o offset] {-f|loop_device} file # setup\n"),-		progname, progname, progname, progname);+  %s [options] loop_device file        # setup\n\+  %s -F [options] loop_device [file]   # setup, read /etc/fstab\n\+  %s loop_device                       # give info\n\+  %s -a                                # give info of all loops\n\+  %s -d loop_device                    # delete\n\+  %s -R loop_device                    # resize\n\+options:  -e encryption  -o offset  -s sizelimit  -p passwdfd  -T  -S pseed\n\+          -H phash  -I loinit  -K gpgkey  -G gpghome  -C itercountk  -v  -r\n\+          -P cleartextkey\n"),+		progname, progname, progname, progname, progname, progname); 	exit(1); } @@ -439,107 +1104,252 @@ 	fprintf (stderr, "\n"); } +void+show_all_loops(void)+{+	char dev[20];+	char *lfmt[] = { "/dev/loop%d", "/dev/loop/%d" };+	int i, j, fd, x;+	struct stat statbuf;++	for(i = 0; i < 256; i++) {+		for(j = (sizeof(lfmt) / sizeof(lfmt[0])) - 1; j >= 0; j--) {+			sprintf(dev, lfmt[j], i);+			if(stat(dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {+				fd = open(dev, O_RDONLY);+				if(fd >= 0) {+					x = is_unused_loop_device(fd);+					close(fd);+					if(x == 0) {+						show_loop(dev);+						j = 0;+					}+				}+			}+		}+	}+}++int+read_options_from_fstab(char *loopToFind, char **partitionPtr)+{+	FILE *f;+	struct mntent *m;+	int y, foundMatch = 0;+	char *opt, *fr1, *fr2;+	struct options {+		char *name;	/* name of /etc/fstab option */+		char **dest;	/* destination where it is written to */+		char *line;	/* temp */+	};+	struct options tbl[] = {+		{ "device/file name ",	partitionPtr },	/* must be index 0 */+		{ "loop=",		&loopToFind },	/* must be index 1 */+		{ "offset=",		&loopOffsetBytes },+		{ "sizelimit=",		&loopSizeBytes },+		{ "encryption=",	&loopEncryptionType },+		{ "pseed=",		&passSeedString },+		{ "phash=",		&passHashFuncName },+		{ "loinit=",		&loInitValue },+		{ "gpgkey=",		&gpgKeyFile },+		{ "gpghome=",		&gpgHomeDir },+		{ "cleartextkey=",	&clearTextKeyFile },+		{ "itercountk=",	&passIterThousands },+	};+	struct options *p;++	if (!(f = setmntent("/etc/fstab", "r"))) {+		fprintf(stderr, _("Error: unable to open /etc/fstab for reading\n"));+		return 0;+	}+	while ((m = getmntent(f)) != NULL) {+		tbl[0].line = fr1 = xstrdup(m->mnt_fsname);+		p = &tbl[1];+		do {+			p->line = NULL;+		} while (++p < &tbl[sizeof(tbl) / sizeof(struct options)]);+		opt = fr2 = xstrdup(m->mnt_opts);+		for (opt = strtok(opt, ","); opt != NULL; opt = strtok(NULL, ",")) {+			p = &tbl[1];+			do {+				y = strlen(p->name);+				if (!strncmp(opt, p->name, y))+					p->line = opt + y;+			} while (++p < &tbl[sizeof(tbl) / sizeof(struct options)]);+		}+		if (tbl[1].line && !strcmp(loopToFind, tbl[1].line)) {+			if (++foundMatch > 1) {+				fprintf(stderr, _("Error: multiple loop=%s options found in /etc/fstab\n"), loopToFind);+				endmntent(f);+				return 0;+			}+			p = &tbl[0];+			do {+				if (!*p->dest && p->line) {+					*p->dest = p->line;+					if (verbose)+						printf(_("using %s%s from /etc/fstab\n"), p->name, p->line);+				}+			} while (++p < &tbl[sizeof(tbl) / sizeof(struct options)]);+			fr1 = fr2 = NULL;+		}+		if(fr1) free(fr1);+		if(fr2) free(fr2);+	}+	endmntent(f);+	if (foundMatch == 0) {+		fprintf(stderr, _("Error: loop=%s option not found in /etc/fstab\n"), loopToFind);+	}+	return foundMatch;+}++int+recompute_loop_dev_size(char *device)+{+	int fd, err1 = 0, err2, err3;+	long long oldBytes = -1, newBytes = -1;++	fd = open(device, O_RDONLY);+	if(fd < 0) {+		perror(device);+		return 1;+	}+	if(verbose) {+		err1 = ioctl(fd, BLKGETSIZE64, &oldBytes);+	}+	err2 = ioctl(fd, LOOP_RECOMPUTE_DEV_SIZE, 0);+	if(err2) {+		perror(device);+		goto done1;+	}+	if(verbose) {+		err3 = ioctl(fd, BLKGETSIZE64, &newBytes);+		if(!err1 && (oldBytes >= 0)) {+			printf("%s: old size %lld bytes\n", device, oldBytes);+		}+		if(!err3 && (newBytes >= 0)) {+			printf("%s: new size %lld bytes\n", device, newBytes);+		}+	}+done1:+	close(fd);+	return err2;+}+ int main(int argc, char **argv) {-	char *p, *offset, *encryption, *passfd, *device, *file;-	int delete, find, c;+	char *partitionName = NULL;+	int delete,c,option_a=0,option_F=0,option_R=0,setup_o=0; 	int res = 0; 	int ro = 0;-	int pfd = -1;-	unsigned long long off;  	setlocale(LC_ALL, ""); 	bindtextdomain(PACKAGE, LOCALEDIR); 	textdomain(PACKAGE); -	delete = find = 0;-	off = 0;-	offset = encryption = passfd = NULL;-+	delete = 0; 	progname = argv[0];-	if ((p = strrchr(progname, '/')) != NULL)-		progname = p+1;--	while ((c = getopt(argc, argv, "de:E:fo:p:v")) != -1) {+	while ((c = getopt(argc,argv,"aC:de:FG:H:I:K:o:p:P:rRs:S:Tv")) != -1) { 		switch (c) {+		case 'a':		/* show status of all loops */+			option_a = 1;+			break;+		case 'C':+			passIterThousands = optarg;+			setup_o = 1;+			break; 		case 'd': 			delete = 1; 			break;-		case 'E': 		case 'e':-			encryption = optarg;+			loopEncryptionType = optarg;+			setup_o = 1;+			break;+		case 'F':		/* read loop related options from /etc/fstab */+			option_F = 1;+			setup_o = 1;+			break;+		case 'G':               /* GnuPG home dir */+			gpgHomeDir = optarg;+			setup_o = 1; 			break;-		case 'f':-			find = 1;+		case 'H':               /* passphrase hash function name */+			passHashFuncName = optarg;+			setup_o = 1;+			break;+		case 'I':               /* lo_init[0] value (in string form)  */+			loInitValue = optarg;+			setup_o = 1;+			break;+		case 'K':               /* GnuPG key file name */+			gpgKeyFile = optarg;+			setup_o = 1; 			break; 		case 'o':-			offset = optarg;+			loopOffsetBytes = optarg;+			setup_o = 1;+			break;+		case 'p':               /* read passphrase from given fd */+			passFDnumber = optarg;+			setup_o = 1;+			break;+		case 'P':               /* read passphrase from given file */+			clearTextKeyFile = optarg;+			setup_o = 1;+			break;+		case 'r':               /* read-only */+			ro = 1;+			setup_o = 1; 			break;-		case 'p':-			passfd = optarg;+		case 'R':               /* recompute loop dev size */+			option_R = 1;+			break;+		case 's':+			loopSizeBytes = optarg;+			setup_o = 1;+			break;+		case 'S':               /* optional seed for passphrase */+			passSeedString = optarg;+			setup_o = 1;+			break;+		case 'T':               /* ask passphrase _twice_ */+			passAskTwice = "T";+			setup_o = 1; 			break; 		case 'v':-			verbose = 1;+			verbose++; 			break; 		default: 			usage(); 		} 	}--	if (argc == 1) {-		usage();+	if (option_a + delete + option_R + setup_o > 1) usage();+	if (option_a) {+		/* show all loops */+		if (argc != optind) usage();+		show_all_loops();+		res = 0; 	} else if (delete) {-		if (argc != optind+1 || encryption || offset || find)-			usage();-	} else if (find) {-		if (argc < optind || argc > optind+1)-			usage();+		/* delete loop */+		if (argc != optind+1) usage();+		res = del_loop(argv[optind]);+	} else if (option_R) {+		/* resize existing loop */+		if (argc != optind+1) usage();+		res = recompute_loop_dev_size(argv[optind]);+	} else if ((argc == optind+1) && !setup_o) {+		/* show one loop */+		res = show_loop(argv[optind]); 	} else {-		if (argc < optind+1 || argc > optind+2)+		/* set up new loop */+		if ((argc < optind+1) || ((argc == optind+1) && !option_F) || (argc > optind+2)) 			usage();-	}--	if (find) {-		device = find_unused_loop_device();-		if (device == NULL)-			return -1;-		if (verbose)-			printf("Loop device is %s\n", device);-		if (argc == optind) {-			printf("%s\n", device);-			return 0;-		}-		file = argv[optind];-	} else {-		device = argv[optind];-		if (argc == optind+1)-			file = NULL;-		else-			file = argv[optind+1];-	}--	if (delete)-		res = del_loop(device);-	else if (file == NULL)-		res = show_loop(device);-	else {-		if (offset && sscanf(offset, "%llu", &off) != 1)-			usage();-		if (passfd && sscanf(passfd, "%d", &pfd) != 1)-			usage();-		res = set_loop(device, file, off, encryption, pfd, &ro);+		if (argc > optind+1)+			partitionName = argv[optind+1];+		if (option_F && (read_options_from_fstab(argv[optind], &partitionName) != 1))+			exit(1);+		res = set_loop(argv[optind],partitionName,&ro,(const char**)0,(unsigned int *)0, 1); 	} 	return res; }--#else /* LOOP_SET_FD not defined */--int-main(int argc, char **argv) {-	fprintf(stderr,-		_("No loop support was available at compile time. "-		  "Please recompile.\n"));-	return -1;-}-#endif #endifdiff -urN util-linux-2.12r/mount/lomount.h util-linux-2.12r-AES/mount/lomount.h--- util-linux-2.12r/mount/lomount.h	2004-07-11 20:23:46.000000000 +0300+++ util-linux-2.12r-AES/mount/lomount.h	2007-09-03 12:13:49.000000000 +0300@@ -1,6 +1,19 @@ extern int verbose;-extern int set_loop(const char *, const char *, unsigned long long,-		    const char *, int, int *);+extern int set_loop(const char *, const char *, int *, const char **, unsigned int *, int); extern int del_loop(const char *); extern int is_loop_device(const char *);+extern int is_loop_active(const char *, const char *); extern char * find_unused_loop_device(void);++extern char *passFDnumber;+extern char *passAskTwice;+extern char *passSeedString;+extern char *passHashFuncName;+extern char *passIterThousands;+extern char *loInitValue;+extern char *gpgKeyFile;+extern char *gpgHomeDir;+extern char *clearTextKeyFile;+extern char *loopOffsetBytes;+extern char *loopSizeBytes;+extern char *loopEncryptionType;diff -urN util-linux-2.12r/mount/loop.c util-linux-2.12r-AES/mount/loop.c--- util-linux-2.12r/mount/loop.c	1970-01-01 02:00:00.000000000 +0200+++ util-linux-2.12r-AES/mount/loop.c	2005-09-24 14:48:53.000000000 +0300@@ -0,0 +1,221 @@+/*+ *  loop.c+ *+ *  Copyright 2003 by Jari Ruusu.+ *  Redistribution of this file is permitted under the GNU GPL+ */++/* collection of loop helper functions used by losetup, mount and swapon */++#include <stdio.h>+#include <string.h>+#include <ctype.h>+#include <sys/ioctl.h>+#include <sys/types.h>+#include <errno.h>+#include "loop.h"++static void convert_info_to_info64(struct loop_info *info, struct loop_info64 *info64)+{+	memset(info64, 0, sizeof(*info64));+	info64->lo_number = info->lo_number;+	info64->lo_device = inf

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -