diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 547596bb50..c440c53a00 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -37,8 +37,8 @@ LINUXBIOS_COMPONENTS := linuxbios.lar linuxbios.vpd stage0.init $(obj)/linuxbios.rom: $(patsubst %,$(obj)/%,$(LINUXBIOS_COMPONENTS)) $(Q)cat $^ > $@ - $(Q)# qemu wants bios.bin: - $(Q)# run "qemu -L build/ -nographic -hda /dev/zero" + $(Q)# QEMU wants bios.bin: + $(Q)# Run "qemu -L build/ -nographic -hda /dev/zero". $(Q)cp $@ $(obj)/bios.bin # diff --git a/util/lar/create.c b/util/lar/create.c index 078b4374f6..503a3bc1e4 100644 --- a/util/lar/create.c +++ b/util/lar/create.c @@ -52,24 +52,24 @@ int create_lar(const char *archivename, struct file *files) exit(1); } - if(verbose()) + if (verbose()) printf("Opening %s\n", archivename); archive = fopen(archivename, "w"); if (!archive) { - fprintf(stderr, "Could not open archive %s for writing\n", - archivename); + fprintf(stderr, "Could not open archive %s for writing\n", + archivename); exit(1); } while (files) { - char *name=files->name; + char *name = files->name; /* skip ./ if available */ - if (name[0]=='.' && name[1]=='/') + if (name[0] == '.' && name[1] == '/') name += 2; - if(verbose()) + if (verbose()) printf(" Adding %s to archive\n", name); ret = stat(name, &statbuf); @@ -79,17 +79,19 @@ int create_lar(const char *archivename, struct file *files) } 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) { fprintf(stderr, "Out of memory.\n"); return (1); } - memset(tempmem, 0, sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16); + memset(tempmem, 0, sizeof(struct lar_header) + MAX_PATHLEN + + filelen + 16); header = (struct lar_header *)tempmem; pathname = tempmem + sizeof(struct lar_header); - pathlen = snprintf(pathname, MAX_PATHLEN-1, name) + 1; - pathlen = (pathlen + 15) & 0xfffffff0; /* Align it to 16 bytes. */ + pathlen = snprintf(pathname, MAX_PATHLEN - 1, name) + 1; + pathlen = (pathlen + 15) & 0xfffffff0;/* Align to 16 bytes. */ /* Read file into memory. */ filebuf = pathname + pathlen; @@ -110,13 +112,15 @@ int create_lar(const char *archivename, struct file *files) csum = 0; for (walk = (u32 *) tempmem; walk < (u32 *) (tempmem + statbuf.st_size + - sizeof(struct lar_header) + pathlen); walk++) { + sizeof(struct lar_header) + pathlen); + walk++) { csum += ntohl(*walk); } header->checksum = htonl(csum); /* 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); @@ -135,8 +139,9 @@ int create_lar(const char *archivename, struct file *files) diff = get_larsize() - currentsize; if (diff < 0) { - fprintf(stderr, "Error: LAR archive exceeded size (%ld > %ld)\n", - currentsize, get_larsize()); + fprintf(stderr, + "Error: LAR archive exceeded size (%ld > %ld)\n", + currentsize, get_larsize()); /* Open files can not be deleted. */ fclose(archive); @@ -145,10 +150,10 @@ int create_lar(const char *archivename, struct file *files) return -1; } - if ( diff > 0 ) { + if (diff > 0) { char *padding; /* generate padding (0xff is flash friendly) */ - padding=malloc(diff); + padding = malloc(diff); if (!padding) { fprintf(stderr, "Out of memory.\n"); exit(1); @@ -160,7 +165,7 @@ int create_lar(const char *archivename, struct file *files) fclose(archive); - if(verbose()) + if (verbose()) printf("done.\n"); return 0; diff --git a/util/lar/example.c b/util/lar/example.c index a63bb19032..5ea50ee43f 100644 --- a/util/lar/example.c +++ b/util/lar/example.c @@ -89,7 +89,7 @@ int find_file(struct mem_file *archive, char *filename, struct mem_file *result) /* Skip file. */ walk += (ntohl(header->len) + ntohl(header->offset) - - 1) & 0xfffffff0; + 1) & 0xfffffff0; } return 1; diff --git a/util/lar/extract.c b/util/lar/extract.c index 16734bc1f8..b5ed6370d3 100644 --- a/util/lar/extract.c +++ b/util/lar/extract.c @@ -49,7 +49,7 @@ int extract_lar(const char *archivename, struct file *files) exit(1); } - if(verbose()) + if (verbose()) printf("Opening %s\n", archivename); archivefile = open(archivename, O_RDONLY); @@ -76,14 +76,14 @@ int extract_lar(const char *archivename, struct file *files) do_extract = 1; if (files) { - struct file *fwalk=files; + struct file *fwalk = files; do_extract = 0; while (fwalk) { if (strcmp(fullname, fwalk->name) == 0) { do_extract = 1; break; } - fwalk=fwalk->next; + fwalk = fwalk->next; } } @@ -91,7 +91,7 @@ int extract_lar(const char *archivename, struct file *files) if (!do_extract) continue; - if(verbose()) + if (verbose()) printf(" Extracting file %s\n", walk + sizeof(struct lar_header)); @@ -121,14 +121,13 @@ int extract_lar(const char *archivename, struct file *files) fclose(file_to_extract); walk += (ntohl(header->offset) + ntohl(header->len) - -1 ) & 0xfffffff0; + - 1) & 0xfffffff0; } munmap(inmap, statbuf.st_size); close(archivefile); - - if(verbose()) + if (verbose()) printf("done.\n"); return 0; diff --git a/util/lar/lar.c b/util/lar/lar.c index 349f549727..4cd2a7eec4 100644 --- a/util/lar/lar.c +++ b/util/lar/lar.c @@ -38,13 +38,12 @@ static int isverbose = 0; static long larsize = 0; -static char * bootblock = NULL; - +static char *bootblock = NULL; static void usage(char *name) { - printf ("\nLAR - the LinuxBIOS Archiver " VERSION "\n" COPYRIGHT "\n\n" - "Usage: %s [-cxl] archive.lar [[[file1] file2] ...]\n\n", name); + printf("\nLAR - the LinuxBIOS Archiver " VERSION "\n" COPYRIGHT "\n\n" + "Usage: %s [-cxl] archive.lar [[[file1] file2] ...]\n\n", name); } int verbose(void) @@ -62,7 +61,6 @@ char *get_bootblock(void) return bootblock; } - int main(int argc, char *argv[]) { int opt; @@ -70,18 +68,18 @@ int main(int argc, char *argv[]) int larmode = NONE; - char * archivename = NULL; + char *archivename = NULL; - static struct option long_options[]= { - { "create", 0, 0, 'c' }, - { "extract", 0, 0, 'x' }, - { "list", 0, 0, 'l' }, - { "size", 1, 0, 's' }, - { "bootblock", 1, 0, 'b' }, - { "verbose", 0, 0, 'v' }, - { "version", 0, 0, 'V' }, - { "help", 0, 0, 'h' }, - { 0, 0, 0, 0 } + static struct option long_options[] = { + {"create", 0, 0, 'c'}, + {"extract", 0, 0, 'x'}, + {"list", 0, 0, 'l'}, + {"size", 1, 0, 's'}, + {"bootblock", 1, 0, 'b'}, + {"verbose", 0, 0, 'v'}, + {"version", 0, 0, 'V'}, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0} }; if (argc < 3) { @@ -89,9 +87,9 @@ int main(int argc, char *argv[]) exit(1); } - while ((opt = getopt_long(argc, argv, "cxls:b:vVh?", - long_options, &option_index)) != EOF) { - switch(opt) { + while ((opt = getopt_long(argc, argv, "cxls:b:vVh?", + long_options, &option_index)) != EOF) { + switch (opt) { case 'c': larmode = CREATE; break; @@ -105,7 +103,7 @@ int main(int argc, char *argv[]) larsize = strtol(optarg, (char **)NULL, 10); break; case 'b': - printf("Bootblock handling not yet supported. Ignoring\n"); + printf("Bootblock handling not yet supported. Ignoring.\n"); bootblock = strdup(optarg); if (!bootblock) { fprintf(stderr, "Out of memory.\n"); @@ -116,7 +114,7 @@ int main(int argc, char *argv[]) isverbose = 1; break; case 'V': - printf ("LAR - the LinuxBIOS Archiver " VERSION "\n"); + printf("LAR - the LinuxBIOS Archiver " VERSION "\n"); break; default: usage(argv[0]); @@ -129,14 +127,13 @@ int main(int argc, char *argv[]) // Right now, you'd have to write lar x -v instead of // lar xv... but the author of this software was too // lazy to handle all option parameter twice. - if (larmode == NONE) - { + if (larmode == NONE) { if (strncmp(argv[optind], "x", 2) == 0) - larmode=EXTRACT; + larmode = EXTRACT; else if (strncmp(argv[optind], "c", 2) == 0) - larmode=CREATE; + larmode = CREATE; else if (strncmp(argv[optind], "l", 2) == 0) - larmode=LIST; + larmode = LIST; /* If larmode changed in this if branch, * eat a parameter @@ -145,8 +142,7 @@ int main(int argc, char *argv[]) optind++; } - if (larmode == NONE) - { + if (larmode == NONE) { usage(argv[0]); printf("Error: No mode specified.\n\n"); exit(1); @@ -155,11 +151,11 @@ int main(int argc, char *argv[]) /* size only makes sense when creating a lar */ if (larmode != CREATE && larsize) { printf("Warning: size parameter ignored since " - "not creating an archive.\n"); + "not creating an archive.\n"); } if (optind < argc) { - archivename=argv[optind++]; + archivename = argv[optind++]; } else { usage(argv[0]); @@ -178,7 +174,7 @@ int main(int argc, char *argv[]) } else add_file_or_directory(argv[optind++]); } - + switch (larmode) { case EXTRACT: extract_lar(archivename, get_files()); diff --git a/util/lar/lib.c b/util/lar/lib.c index ba9ecbeaea..6c78b4462d 100644 --- a/util/lar/lib.c +++ b/util/lar/lib.c @@ -30,7 +30,7 @@ #define MAX_PATH 1024 -static struct file * files = NULL; +static struct file *files = NULL; int mkdirp(const char *dirpath) { @@ -73,12 +73,13 @@ int mkdirp(const char *dirpath) static int handle_directory(const char *name) { - int ret=-1, n; + int n; + int ret = -1; struct dirent **namelist; n = scandir(name, &namelist, 0, alphasort); - if(n < 0) { + if (n < 0) { fprintf(stderr, "Could not enter directory %s\n", name); } else { while (n--) { @@ -87,15 +88,16 @@ static int handle_directory(const char *name) fullname[0] = '\0'; if (strncmp("..", namelist[n]->d_name, 3) && - strncmp(".", namelist[n]->d_name, 2)) { + strncmp(".", namelist[n]->d_name, 2)) { strncpy(fullname, name, MAX_PATH); - if(name[(strlen(name))-1] != '/') { + if (name[(strlen(name)) - 1] != '/') { strncat(fullname, "/", MAX_PATH); } - strncat(fullname, namelist[n]->d_name, MAX_PATH); + strncat(fullname, namelist[n]->d_name, + MAX_PATH); add_files(fullname); } @@ -103,7 +105,7 @@ static int handle_directory(const char *name) } free(namelist); - ret=0; + ret = 0; } return ret; @@ -124,7 +126,7 @@ int add_files(const char *name) fprintf(stderr, "Error getting file attributes of %s\n", name); return -1; } - + if (S_ISCHR(filestat.st_mode) || S_ISBLK(filestat.st_mode)) { fprintf(stderr, "Device files are not supported: %s\n", name); } @@ -140,12 +142,10 @@ int add_files(const char *name) if (S_ISLNK(filestat.st_mode)) { fprintf(stderr, "Symbolic links are not supported: %s\n", name); } - // Is it a directory? if (S_ISDIR(filestat.st_mode)) { - ret=handle_directory(name); + ret = handle_directory(name); } - // Is it a regular file? if (S_ISREG(filestat.st_mode)) { struct file *tmpfile; @@ -158,7 +158,7 @@ int add_files(const char *name) } tmpfile->name = strdup(name); - if(!tmpfile->name) { + if (!tmpfile->name) { fprintf(stderr, "Out of memory.\n"); exit(1); } @@ -193,7 +193,7 @@ int add_file_or_directory(const char *name) } tmpfile->next = files; - files=tmpfile; + files = tmpfile; return 0; } @@ -205,11 +205,11 @@ struct file *get_files(void) void free_files(void) { - struct file * temp; + struct file *temp; while (files) { - temp=files; - files=files->next; + temp = files; + files = files->next; free(temp->name); free(temp); } @@ -218,14 +218,14 @@ void free_files(void) #ifdef DEBUG int list_files(void) { - struct file * walk = files; + struct file *walk = files; - printf ("File list:\n"); + printf("File list:\n"); while (walk) { printf("- %s\n", walk->name); - walk=walk->next; + walk = walk->next; } - printf ("-----\n"); + printf("-----\n"); return 0; } #endif diff --git a/util/lar/lib.h b/util/lar/lib.h index 4a8bcc4b5f..b65be1a1cd 100644 --- a/util/lar/lib.h +++ b/util/lar/lib.h @@ -24,7 +24,7 @@ /* data types */ struct file { - char * name; + char *name; struct file *next; }; @@ -40,7 +40,6 @@ int verbose(void); long get_larsize(void); char *get_bootblock(void); - /* prototypes for lib.c functions */ int mkdirp(const char *dirpath); diff --git a/util/lar/list.c b/util/lar/list.c index d477cf9303..efea8584b2 100644 --- a/util/lar/list.c +++ b/util/lar/list.c @@ -45,12 +45,12 @@ int list_lar(const char *archivename, struct file *files) int i; if (stat(archivename, &statbuf) != 0) { - fprintf(stderr, "Error opening %s: %s\n", - archivename, strerror(errno)); + fprintf(stderr, "Error opening %s: %s\n", + archivename, strerror(errno)); exit(1); } - if(verbose()) + if (verbose()) printf("Opening %s\n", archivename); archivefile = open(archivename, O_RDONLY); @@ -73,18 +73,17 @@ int list_lar(const char *archivename, struct file *files) do_extract = 1; if (files) { - struct file *fwalk=files; + struct file *fwalk = files; do_extract = 0; while (fwalk) { if (strcmp(fullname, fwalk->name) == 0) { do_extract = 1; break; } - fwalk=fwalk->next; + fwalk = fwalk->next; } } - /* Don't extract this one, skip it. */ if (!do_extract) { continue; @@ -95,14 +94,14 @@ int list_lar(const char *archivename, struct file *files) printf("(%d bytes @0x%lx)\n", ntohl(header->len), (unsigned long)(walk - inmap) + ntohl(header->offset)); - walk += (ntohl(header->len) + ntohl(header->offset) - - 1) & 0xfffffff0; + walk += (ntohl(header->len) + ntohl(header->offset) + - 1) & 0xfffffff0; } munmap(inmap, statbuf.st_size); close(archivefile); - if(verbose()) + if (verbose()) printf("done.\n"); return 0;