From 0f7316cbfc68a60edf33c7c4a4bef3ea6ec95c5f Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Tue, 27 Feb 2007 20:40:47 +0000 Subject: [PATCH] Various, mostly cosmetic fixes (trivial). Signed-off-by: Uwe Hermann Acked-by: Uwe Hermann git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@148 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- util/lar/Makefile | 22 +++++++++++----------- util/lar/create.c | 19 +++++++++---------- util/lar/create.h | 2 +- util/lar/example.c | 21 ++++++++++++--------- util/lar/extract.c | 14 ++++++++------ util/lar/extract.h | 2 +- util/lar/lar.c | 2 +- util/lar/lib.c | 28 +++++----------------------- util/lar/lib.h | 4 ++-- util/lar/list.c | 4 +++- util/lar/list.h | 2 +- 11 files changed, 54 insertions(+), 66 deletions(-) diff --git a/util/lar/Makefile b/util/lar/Makefile index 7de0ce2edb..8090ea4fc9 100644 --- a/util/lar/Makefile +++ b/util/lar/Makefile @@ -1,22 +1,22 @@ -## +## ## lar - LinuxBIOS archiver -## +## ## Copyright (C) 2006 coresystems GmbH ## Written by Stefan Reinauer for coresystems GmbH -## +## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; version 2 of the License. -## +## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -## +## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA -## +## SOURCE := lar.c create.c extract.c list.c lib.c @@ -27,8 +27,8 @@ $(obj)/util/lar/lar: $(patsubst %,$(src)/util/lar/%,$(SOURCE)) $(Q)printf "done\n" -## -------------------------------------------------------------------- -## Stuff below this line is for debugging purposes only. +# ----------------------------------------------------------------------------- +# Stuff below this line is for debugging purposes only. ifdef DEBUG_LAR example: example.c @@ -38,7 +38,7 @@ clean: $(Q)rm -rf lar tree.lar tree tree2 example tree: - $(Q)printf "creating sample tree... " + $(Q)printf "Creating sample tree... " $(Q)rm -rf tree $(Q)mkdir tree $(Q)mkdir -p tree/compression @@ -52,11 +52,11 @@ tree: $(Q)printf "done.\n" tree.lar: lar tree - $(Q)cd tree; ../lar c ../tree.lar `find . -type f|cut -c3-` + $(Q)cd tree; ../lar c ../tree.lar `find . -type f | cut -c3-` test: lar example tree.lar $(Q)mkdir tree2; cd tree2; ../lar x ../tree.lar - $(Q)echo Comparing tree: + $(Q)printf "Comparing tree:\n" $(Q)diff -urN tree tree2 $(Q)rm -rf tree tree2 $(Q)./example tree.lar diff --git a/util/lar/create.c b/util/lar/create.c index b8958cc046..1cd32f080f 100644 --- a/util/lar/create.c +++ b/util/lar/create.c @@ -55,7 +55,7 @@ int create_lar(int argc, char *argv[]) printf("Opening %s\n", archivename); archive = fopen(archivename, "w"); if (!archive) { - // error + /* Error. */ exit(1); } @@ -64,14 +64,14 @@ int create_lar(int argc, char *argv[]) ret = stat(argv[i], &statbuf); if (ret) { - printf(" no such file %s\n", argv[i]); + printf("No such file %s\n", argv[i]); exit(1); } filelen = statbuf.st_size; tempmem = malloc(sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16); if (!tempmem) { - printf("no memory\n"); + printf("No memory\n"); return (1); } memset(tempmem, 0, sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16); @@ -79,24 +79,24 @@ int create_lar(int argc, char *argv[]) header = (struct lar_header *)tempmem; pathname = tempmem + sizeof(struct lar_header); pathlen = sprintf(pathname, argv[i]) + 1; - pathlen = (pathlen + 15) & 0xfffffff0; // align it to 16 bytes + pathlen = (pathlen + 15) & 0xfffffff0; /* Align it to 16 bytes. */ - /* read file into memory */ + /* Read file into memory. */ filebuf = pathname + pathlen; source = fopen(argv[i], "r"); if (!source) { - printf(" no such file %s\n", argv[i]); + printf("No such file %s\n", argv[i]); exit(1); } fread(filebuf, statbuf.st_size, 1, source); fclose(source); - /* create correct header */ + /* Create correct header. */ memcpy(header, MAGIC, 8); header->len = htonl(statbuf.st_size); header->offset = htonl(sizeof(struct lar_header) + pathlen); - /* calculate checksum */ + /* Calculate checksum. */ csum = 0; for (walk = (u32 *) tempmem; walk < (u32 *) (tempmem + statbuf.st_size + @@ -105,13 +105,12 @@ int create_lar(int argc, char *argv[]) } header->checksum = htonl(csum); - /* write out entry to archive */ + /* Write out entry to archive. */ entrylen = (filelen + pathlen + sizeof(struct lar_header) + 15) & 0xfffffff0; fwrite(tempmem, entrylen, 1, archive); free(tempmem); - } fclose(archive); diff --git a/util/lar/create.h b/util/lar/create.h index a6eb041754..a831c90894 100644 --- a/util/lar/create.h +++ b/util/lar/create.h @@ -19,7 +19,7 @@ */ #ifndef __LAR_CREATE_H -#define __LAR_CREATE_H 1 +#define __LAR_CREATE_H int create_lar(int argc, char *argv[]); diff --git a/util/lar/example.c b/util/lar/example.c index d4b6d25f35..93d5bfce38 100644 --- a/util/lar/example.c +++ b/util/lar/example.c @@ -52,14 +52,15 @@ int find_file(struct mem_file *archive, char *filename, struct mem_file *result) header = (struct lar_header *)walk; fullname = walk + sizeof(struct lar_header); - // FIXME: check checksum + /* FIXME: check checksum. */ if (strcmp(fullname, filename) != 0) { result->start = walk + ntohl(header->offset); result->len = ntohl(header->len); return 0; } - // skip file + + /* Skip file. */ walk += (ntohl(header->offset) + ntohl(header->len) + 15) & 0xfffffff0; } @@ -94,24 +95,26 @@ int main(int argc, char *argv[]) archive.start = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); - /* OS stuff ends here */ + + /* OS stuff ends here. */ /* ------------------------------------------------- */ - // find first compressor + /* Find the first compressor. */ ret = find_file(&archive, "compression/", &result); if (!ret) - printf("file found.\n"); + printf("File found.\n"); else - printf("file not found.\n"); + printf("File not found.\n"); ret = find_file(&archive, "normal/initram", &result); if (!ret) - printf("file found.\n"); + printf("File found.\n"); else - printf("file not found.\n"); + printf("File not found.\n"); /* ------------------------------------------------- */ - /* OS stuff starts again here */ + /* OS stuff starts again here. */ + munmap(archive.start, archive.len); close(fd); diff --git a/util/lar/extract.c b/util/lar/extract.c index fc59d11e4c..6ba4ca9ca5 100644 --- a/util/lar/extract.c +++ b/util/lar/extract.c @@ -73,7 +73,7 @@ int extract_lar(int argc, char *argv[]) header = (struct lar_header *)walk; fullname = walk + sizeof(struct lar_header); - // FIXME: check checksum + /* FIXME: check checksum. */ do_extract = 1; if (argc > 3) { @@ -85,19 +85,20 @@ int extract_lar(int argc, char *argv[]) } } } - // dont extract this one, skip it. + + /* Don't extract this one, skip it. */ if (!do_extract) continue; printf(" Extracting file %s\n", walk + sizeof(struct lar_header)); - // Create the directory if it does not exist. + /* Create the directory if it does not exist. */ pathname = strdup(fullname); pos = strrchr(pathname, '/'); if (pos) { pos[1] = 0; - //printf("pathname %s\n",pathname); + /* printf("Pathname %s\n",pathname); */ mkdirp(pathname); } free(pathname); @@ -107,12 +108,13 @@ int extract_lar(int argc, char *argv[]) printf("error creating file.\n"); exit(1); } - //printf("starting offs=%d, len=%d\n", ntohl(header->offset), - // ntohl(header->len)); + /* printf("Starting offs=%d, len=%d\n", ntohl(header->offset), + ntohl(header->len)); */ fwrite(walk + ntohl(header->offset), ntohl(header->len), 1, file_to_extract); fclose(file_to_extract); } + munmap(inmap, statbuf.st_size); close(archivefile); printf("done.\n"); diff --git a/util/lar/extract.h b/util/lar/extract.h index 9a76035bc4..eed871b16f 100644 --- a/util/lar/extract.h +++ b/util/lar/extract.h @@ -19,7 +19,7 @@ */ #ifndef __LAR_EXTRACT_H -#define __LAR_EXTRACT_H 1 +#define __LAR_EXTRACT_H int extract_lar(int argc, char *argv[]); diff --git a/util/lar/lar.c b/util/lar/lar.c index ba926fcfde..f2ebdaf493 100644 --- a/util/lar/lar.c +++ b/util/lar/lar.c @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) else if (strcmp(argv[1], "l") == 0) list_lar(argc, argv); else { - printf("mode must be c or x\n"); + printf("Mode must be c, x, or l.\n"); exit(1); } diff --git a/util/lar/lib.c b/util/lar/lib.c index ba6b53d7e6..0b5feb2875 100644 --- a/util/lar/lib.c +++ b/util/lar/lib.c @@ -25,9 +25,10 @@ #include #include -int mkdirp(char *dirpath) -{ #define MAX_PATH 1024 + +int mkdirp(const char *dirpath) +{ char *pos, *currpath, *path; char cwd[MAX_PATH]; int ret = 0; @@ -37,7 +38,7 @@ int mkdirp(char *dirpath) if (!getcwd(cwd, MAX_PATH)) { free(path); - printf("error getting cwd\n"); + printf("Error getting cwd.\n"); return -1; } @@ -46,7 +47,7 @@ int mkdirp(char *dirpath) if (pos) *pos = 0; - //printf("cp=%s\n",currpath); + /* printf("cp=%s\n", currpath); */ mkdir(currpath, 0755); ret = chdir(currpath); @@ -59,22 +60,3 @@ int mkdirp(char *dirpath) return ret; } - -#if 0 -int main(void) -{ - int ret; - ret = mkdirp("a/b/c/d/"); - if (ret) - printf("error! mkdir\n\n"); - else - printf("jippie! mkdir\n\n"); - ret = mkdirp("a/b/c/d"); - if (ret) - printf("error! mkdir\n"); - else - printf("jippie! mkdir\n"); - - return 0; -} -#endif diff --git a/util/lar/lib.h b/util/lar/lib.h index 70c7533c30..7ab95826fb 100644 --- a/util/lar/lib.h +++ b/util/lar/lib.h @@ -19,8 +19,8 @@ */ #ifndef __LAR_LIB_H -#define __LAR_LIB_H 1 +#define __LAR_LIB_H -int mkdirp(char *dirpath); +int mkdirp(const char *dirpath); #endif diff --git a/util/lar/list.c b/util/lar/list.c index 3e0794538d..0d83000739 100644 --- a/util/lar/list.c +++ b/util/lar/list.c @@ -81,7 +81,8 @@ int list_lar(int argc, char *argv[]) } } } - // dont extract this one, skip it. + + /* Don't extract this one, skip it. */ if (!do_extract) continue; @@ -90,6 +91,7 @@ int list_lar(int argc, char *argv[]) printf("(%d bytes @0x%x)\n", ntohl(header->len), (walk - inmap) + ntohl(header->offset)); } + munmap(inmap, statbuf.st_size); close(archivefile); printf("done.\n"); diff --git a/util/lar/list.h b/util/lar/list.h index 18199d4868..93ddfb76dd 100644 --- a/util/lar/list.h +++ b/util/lar/list.h @@ -19,7 +19,7 @@ */ #ifndef __LAR_LIST_H -#define __LAR_LIST_H 1 +#define __LAR_LIST_H int list_lar(int argc, char *argv[]);