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

[dm-devel] [PATCH] dmsetup: Remove limitation on table file line length


The dmsetup tool currently has a limit of 1024 characters for the length of a 
line in a table file when running the 'create' or 'load' command. When have 
run into scenarios where we've exceeded this length, usually due to creating 
large striped devices with unusually long names for the underlying disks.

To get around this limitation, I wrote a patch that simply changes from using 
fgets() to getline() in the _parse_file() routine. The getline() routine will 
automatically allocate (or reallocate) space as needed to read in an entire 
line from a file.

I have tested this patch successfully with table lines of at least 1300 

Kevin Corry
kevcorry us ibm com

Use getline() instead of fgets() to remove the line-size limitation when
parsing the input file in dmsetup. 

Signed-Off-By: Kevin Corry <kevcorry us ibm com>

Index: device-mapper.1.02.05/dmsetup/dmsetup.c
--- device-mapper.1.02.05.orig/dmsetup/dmsetup.c
+++ device-mapper.1.02.05/dmsetup/dmsetup.c
@@ -117,7 +117,8 @@ static struct dm_tree *_dtree;
 static int _parse_file(struct dm_task *dmt, const char *file)
-	char buffer[LINE_SIZE], ttype[LINE_SIZE], *ptr, *comment;
+	char *buffer = NULL, ttype[LINE_SIZE], *ptr, *comment;
+	size_t buffer_size = 0;
 	FILE *fp;
 	unsigned long long start, size;
 	int r = 0, n, line = 0;
@@ -132,7 +133,7 @@ static int _parse_file(struct dm_task *d
 	} else
 		fp = stdin;
-	while (fgets(buffer, sizeof(buffer), fp)) {
+	while (getline(&buffer, &buffer_size, fp) > 0) {
 		/* trim trailing space */
@@ -166,6 +167,7 @@ static int _parse_file(struct dm_task *d
 	if (file)
+	free(buffer);
 	return r;

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