Various, mostly cosmetic fixes (trivial).

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>



git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@148 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Uwe Hermann 2007-02-27 20:40:47 +00:00
parent 02598fb2de
commit 0f7316cbfc
11 changed files with 54 additions and 66 deletions

View file

@ -1,22 +1,22 @@
## ##
## lar - LinuxBIOS archiver ## lar - LinuxBIOS archiver
## ##
## Copyright (C) 2006 coresystems GmbH ## Copyright (C) 2006 coresystems GmbH
## Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH ## Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH
## ##
## This program is free software; you can redistribute it and/or modify ## 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 ## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; version 2 of the License. ## the Free Software Foundation; version 2 of the License.
## ##
## This program is distributed in the hope that it will be useful, ## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of ## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software ## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
## ##
SOURCE := lar.c create.c extract.c list.c lib.c 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" $(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 ifdef DEBUG_LAR
example: example.c example: example.c
@ -38,7 +38,7 @@ clean:
$(Q)rm -rf lar tree.lar tree tree2 example $(Q)rm -rf lar tree.lar tree tree2 example
tree: tree:
$(Q)printf "creating sample tree... " $(Q)printf "Creating sample tree... "
$(Q)rm -rf tree $(Q)rm -rf tree
$(Q)mkdir tree $(Q)mkdir tree
$(Q)mkdir -p tree/compression $(Q)mkdir -p tree/compression
@ -52,11 +52,11 @@ tree:
$(Q)printf "done.\n" $(Q)printf "done.\n"
tree.lar: lar tree 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 test: lar example tree.lar
$(Q)mkdir tree2; cd tree2; ../lar x ../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)diff -urN tree tree2
$(Q)rm -rf tree tree2 $(Q)rm -rf tree tree2
$(Q)./example tree.lar $(Q)./example tree.lar

View file

@ -55,7 +55,7 @@ int create_lar(int argc, char *argv[])
printf("Opening %s\n", archivename); printf("Opening %s\n", archivename);
archive = fopen(archivename, "w"); archive = fopen(archivename, "w");
if (!archive) { if (!archive) {
// error /* Error. */
exit(1); exit(1);
} }
@ -64,14 +64,14 @@ int create_lar(int argc, char *argv[])
ret = stat(argv[i], &statbuf); ret = stat(argv[i], &statbuf);
if (ret) { if (ret) {
printf(" no such file %s\n", argv[i]); printf("No such file %s\n", argv[i]);
exit(1); exit(1);
} }
filelen = statbuf.st_size; filelen = statbuf.st_size;
tempmem = malloc(sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16); tempmem = malloc(sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16);
if (!tempmem) { if (!tempmem) {
printf("no memory\n"); printf("No memory\n");
return (1); return (1);
} }
memset(tempmem, 0, sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16); 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; header = (struct lar_header *)tempmem;
pathname = tempmem + sizeof(struct lar_header); pathname = tempmem + sizeof(struct lar_header);
pathlen = sprintf(pathname, argv[i]) + 1; 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; filebuf = pathname + pathlen;
source = fopen(argv[i], "r"); source = fopen(argv[i], "r");
if (!source) { if (!source) {
printf(" no such file %s\n", argv[i]); printf("No such file %s\n", argv[i]);
exit(1); exit(1);
} }
fread(filebuf, statbuf.st_size, 1, source); fread(filebuf, statbuf.st_size, 1, source);
fclose(source); fclose(source);
/* create correct header */ /* Create correct header. */
memcpy(header, MAGIC, 8); memcpy(header, MAGIC, 8);
header->len = htonl(statbuf.st_size); header->len = htonl(statbuf.st_size);
header->offset = htonl(sizeof(struct lar_header) + pathlen); header->offset = htonl(sizeof(struct lar_header) + pathlen);
/* calculate checksum */ /* Calculate checksum. */
csum = 0; csum = 0;
for (walk = (u32 *) tempmem; for (walk = (u32 *) tempmem;
walk < (u32 *) (tempmem + statbuf.st_size + walk < (u32 *) (tempmem + statbuf.st_size +
@ -105,13 +105,12 @@ int create_lar(int argc, char *argv[])
} }
header->checksum = htonl(csum); header->checksum = htonl(csum);
/* write out entry to archive */ /* Write out entry to archive. */
entrylen = (filelen + pathlen + sizeof(struct lar_header) + 15) & 0xfffffff0; entrylen = (filelen + pathlen + sizeof(struct lar_header) + 15) & 0xfffffff0;
fwrite(tempmem, entrylen, 1, archive); fwrite(tempmem, entrylen, 1, archive);
free(tempmem); free(tempmem);
} }
fclose(archive); fclose(archive);

View file

@ -19,7 +19,7 @@
*/ */
#ifndef __LAR_CREATE_H #ifndef __LAR_CREATE_H
#define __LAR_CREATE_H 1 #define __LAR_CREATE_H
int create_lar(int argc, char *argv[]); int create_lar(int argc, char *argv[]);

View file

@ -52,14 +52,15 @@ int find_file(struct mem_file *archive, char *filename, struct mem_file *result)
header = (struct lar_header *)walk; header = (struct lar_header *)walk;
fullname = walk + sizeof(struct lar_header); fullname = walk + sizeof(struct lar_header);
// FIXME: check checksum /* FIXME: check checksum. */
if (strcmp(fullname, filename) != 0) { if (strcmp(fullname, filename) != 0) {
result->start = walk + ntohl(header->offset); result->start = walk + ntohl(header->offset);
result->len = ntohl(header->len); result->len = ntohl(header->len);
return 0; return 0;
} }
// skip file
/* Skip file. */
walk += (ntohl(header->offset) + ntohl(header->len) walk += (ntohl(header->offset) + ntohl(header->len)
+ 15) & 0xfffffff0; + 15) & 0xfffffff0;
} }
@ -94,24 +95,26 @@ int main(int argc, char *argv[])
archive.start = mmap(NULL, statbuf.st_size, PROT_READ, archive.start = mmap(NULL, statbuf.st_size, PROT_READ,
MAP_SHARED, fd, 0); 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); ret = find_file(&archive, "compression/", &result);
if (!ret) if (!ret)
printf("file found.\n"); printf("File found.\n");
else else
printf("file not found.\n"); printf("File not found.\n");
ret = find_file(&archive, "normal/initram", &result); ret = find_file(&archive, "normal/initram", &result);
if (!ret) if (!ret)
printf("file found.\n"); printf("File found.\n");
else 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); munmap(archive.start, archive.len);
close(fd); close(fd);

View file

@ -73,7 +73,7 @@ int extract_lar(int argc, char *argv[])
header = (struct lar_header *)walk; header = (struct lar_header *)walk;
fullname = walk + sizeof(struct lar_header); fullname = walk + sizeof(struct lar_header);
// FIXME: check checksum /* FIXME: check checksum. */
do_extract = 1; do_extract = 1;
if (argc > 3) { 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) if (!do_extract)
continue; continue;
printf(" Extracting file %s\n", printf(" Extracting file %s\n",
walk + sizeof(struct lar_header)); walk + sizeof(struct lar_header));
// Create the directory if it does not exist. /* Create the directory if it does not exist. */
pathname = strdup(fullname); pathname = strdup(fullname);
pos = strrchr(pathname, '/'); pos = strrchr(pathname, '/');
if (pos) { if (pos) {
pos[1] = 0; pos[1] = 0;
//printf("pathname %s\n",pathname); /* printf("Pathname %s\n",pathname); */
mkdirp(pathname); mkdirp(pathname);
} }
free(pathname); free(pathname);
@ -107,12 +108,13 @@ int extract_lar(int argc, char *argv[])
printf("error creating file.\n"); printf("error creating file.\n");
exit(1); exit(1);
} }
//printf("starting offs=%d, len=%d\n", ntohl(header->offset), /* printf("Starting offs=%d, len=%d\n", ntohl(header->offset),
// ntohl(header->len)); ntohl(header->len)); */
fwrite(walk + ntohl(header->offset), ntohl(header->len), fwrite(walk + ntohl(header->offset), ntohl(header->len),
1, file_to_extract); 1, file_to_extract);
fclose(file_to_extract); fclose(file_to_extract);
} }
munmap(inmap, statbuf.st_size); munmap(inmap, statbuf.st_size);
close(archivefile); close(archivefile);
printf("done.\n"); printf("done.\n");

View file

@ -19,7 +19,7 @@
*/ */
#ifndef __LAR_EXTRACT_H #ifndef __LAR_EXTRACT_H
#define __LAR_EXTRACT_H 1 #define __LAR_EXTRACT_H
int extract_lar(int argc, char *argv[]); int extract_lar(int argc, char *argv[]);

View file

@ -48,7 +48,7 @@ int main(int argc, char *argv[])
else if (strcmp(argv[1], "l") == 0) else if (strcmp(argv[1], "l") == 0)
list_lar(argc, argv); list_lar(argc, argv);
else { else {
printf("mode must be c or x\n"); printf("Mode must be c, x, or l.\n");
exit(1); exit(1);
} }

View file

@ -25,9 +25,10 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
int mkdirp(char *dirpath)
{
#define MAX_PATH 1024 #define MAX_PATH 1024
int mkdirp(const char *dirpath)
{
char *pos, *currpath, *path; char *pos, *currpath, *path;
char cwd[MAX_PATH]; char cwd[MAX_PATH];
int ret = 0; int ret = 0;
@ -37,7 +38,7 @@ int mkdirp(char *dirpath)
if (!getcwd(cwd, MAX_PATH)) { if (!getcwd(cwd, MAX_PATH)) {
free(path); free(path);
printf("error getting cwd\n"); printf("Error getting cwd.\n");
return -1; return -1;
} }
@ -46,7 +47,7 @@ int mkdirp(char *dirpath)
if (pos) if (pos)
*pos = 0; *pos = 0;
//printf("cp=%s\n",currpath); /* printf("cp=%s\n", currpath); */
mkdir(currpath, 0755); mkdir(currpath, 0755);
ret = chdir(currpath); ret = chdir(currpath);
@ -59,22 +60,3 @@ int mkdirp(char *dirpath)
return ret; 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

View file

@ -19,8 +19,8 @@
*/ */
#ifndef __LAR_LIB_H #ifndef __LAR_LIB_H
#define __LAR_LIB_H 1 #define __LAR_LIB_H
int mkdirp(char *dirpath); int mkdirp(const char *dirpath);
#endif #endif

View file

@ -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) if (!do_extract)
continue; continue;
@ -90,6 +91,7 @@ int list_lar(int argc, char *argv[])
printf("(%d bytes @0x%x)\n", ntohl(header->len), printf("(%d bytes @0x%x)\n", ntohl(header->len),
(walk - inmap) + ntohl(header->offset)); (walk - inmap) + ntohl(header->offset));
} }
munmap(inmap, statbuf.st_size); munmap(inmap, statbuf.st_size);
close(archivefile); close(archivefile);
printf("done.\n"); printf("done.\n");

View file

@ -19,7 +19,7 @@
*/ */
#ifndef __LAR_LIST_H #ifndef __LAR_LIST_H
#define __LAR_LIST_H 1 #define __LAR_LIST_H
int list_lar(int argc, char *argv[]); int list_lar(int argc, char *argv[]);