Skip to contentSkip to conversation

Don't try to stat() a colon separated list of files in multi or script mode

PATCH New Nye Liu 2 participants 3 messages Nov 19, 2015 – Dec 3, 2015 1 message not in the archive

lore
Share & tools
lore

Nye Liu

author
#0 lore raw

PATCH 1/1 Don't try to stat() a colon separated list of files in multi or script mode

---
 tools/mkimage.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
tools/mkimage.c +19 -13
index 8af9d50..aa739b4 100644
@@ -311,21 +311,27 @@ NXTARG:		;
 		exit (retval);
 	}
 
-	dfd = open(params.datafile, O_RDONLY | O_BINARY);
-	if (dfd < 0) {
-		fprintf(stderr, "%s: Can't open %s: %s\n",
-			params.cmdname, params.datafile, strerror(errno));
-		exit(EXIT_FAILURE);
-	}
+	if (params.skipcpy ||
+		!(params.type == IH_TYPE_MULTI ||
+		params.type == IH_TYPE_SCRIPT)) {
+		dfd = open(params.datafile, O_RDONLY | O_BINARY);
+		if (dfd < 0) {
+			fprintf(stderr, "%s: Can't open %s: %s\n",
+				params.cmdname, params.datafile,
+				strerror(errno));
+			exit(EXIT_FAILURE);
+		}
 
-	if (fstat(dfd, &sbuf) < 0) {
-		fprintf(stderr, "%s: Can't stat %s: %s\n",
-			params.cmdname, params.datafile, strerror(errno));
-		exit(EXIT_FAILURE);
-	}
+		if (fstat(dfd, &sbuf) < 0) {
+			fprintf(stderr, "%s: Can't stat %s: %s\n",
+				params.cmdname, params.datafile,
+				strerror(errno));
+			exit(EXIT_FAILURE);
+		}
 
-	params.file_size = sbuf.st_size + tparams->header_size;
-	close(dfd);
+		params.file_size = sbuf.st_size + tparams->header_size;
+		close(dfd);
+	}
 
 	/*
 	 * In case there an header with a variable
Signature · 1 line
2.6.2
#1 lore raw

PATCH 1/1 Don't try to stat() a colon separated list of files in multi or script mode

Hi,

Quoted 4 lines · Nye Liu
---
 tools/mkimage.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Can you please add a commit message explaining the problem, and what you are trying to do here?

Quoted 48 lines
tools/mkimage.c +19 -14
index 8af9d50..aa739b4 100644
@@ -311,21 +311,27 @@ NXTARG:           ;
                exit (retval);
        }
 
-       dfd = open(params.datafile, O_RDONLY | O_BINARY);
-       if (dfd < 0) {
-               fprintf(stderr, "%s: Can't open %s: %s\n",
-                       params.cmdname, params.datafile, strerror(errno));
-               exit(EXIT_FAILURE);
-       }
+       if (params.skipcpy ||
+               !(params.type == IH_TYPE_MULTI ||
+               params.type == IH_TYPE_SCRIPT)) {
+               dfd = open(params.datafile, O_RDONLY | O_BINARY);
+               if (dfd < 0) {
+                       fprintf(stderr, "%s: Can't open %s: %s\n",
+                               params.cmdname, params.datafile,
+                               strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
 
-       if (fstat(dfd, &sbuf) < 0) {
-               fprintf(stderr, "%s: Can't stat %s: %s\n",
-                       params.cmdname, params.datafile, strerror(errno));
-               exit(EXIT_FAILURE);
-       }
+               if (fstat(dfd, &sbuf) < 0) {
+                       fprintf(stderr, "%s: Can't stat %s: %s\n",
+                               params.cmdname, params.datafile,
+                               strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
 
-       params.file_size = sbuf.st_size + tparams->header_size;
-       close(dfd);
+               params.file_size = sbuf.st_size + tparams->header_size;
+               close(dfd);
+       }
 
        /*
         * In case there an header with a variable
--

2.6.2

Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

PATCH 1/1 Don't try to stat() a colon separated list of files in multi or script mode

Hi,

Quoted 63 lines · Nye Liu
Quoted 54 lines · Simon Glass

Hi,

Quoted 4 lines · Nye Liu
---
 tools/mkimage.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Can you please add a commit message explaining the problem, and what you are trying to do here?

Quoted 43 lines
tools/mkimage.c +19 -13
index 8af9d50..aa739b4 100644
@@ -311,21 +311,27 @@ NXTARG:           ;
                exit (retval);
        }
 
-       dfd = open(params.datafile, O_RDONLY | O_BINARY);
-       if (dfd < 0) {
-               fprintf(stderr, "%s: Can't open %s: %s\n",
-                       params.cmdname, params.datafile, strerror(errno));
-               exit(EXIT_FAILURE);
-       }
+       if (params.skipcpy ||
+               !(params.type == IH_TYPE_MULTI ||
+               params.type == IH_TYPE_SCRIPT)) {
+               dfd = open(params.datafile, O_RDONLY | O_BINARY);
+               if (dfd < 0) {
+                       fprintf(stderr, "%s: Can't open %s: %s\n",
+                               params.cmdname, params.datafile,
+                               strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
 
-       if (fstat(dfd, &sbuf) < 0) {
-               fprintf(stderr, "%s: Can't stat %s: %s\n",
-                       params.cmdname, params.datafile, strerror(errno));
-               exit(EXIT_FAILURE);
-       }
+               if (fstat(dfd, &sbuf) < 0) {
+                       fprintf(stderr, "%s: Can't stat %s: %s\n",
+                               params.cmdname, params.datafile,
+                               strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
 
-       params.file_size = sbuf.st_size + tparams->header_size;
-       close(dfd);
+               params.file_size = sbuf.st_size + tparams->header_size;
+               close(dfd);
+       }
 
Quoted 4 lines
Quoted 4 lines
tools/mkimage.c +0 -1
        /*
         * In case there an header with a variable
--

2.6.2

Meaning, you don't know what it does, or you won't accept the patch w/o it?

Quoted 9 lines

In short,

"mkimage -T multi -d file1:file2:file3"

no longer works.

It stats the file "file1:file2:file3" (and fails) before opening each file separately.

Yes, please put this explanation in version 2 of your patch.

Regards,
Simon