coreboot/util/lar/lib.h
Ronald G. Minnich 6b4477c8cb Add a zero-fill command to lar.
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>


Note: the following discussion applies to this patch. 

This patch is basically limited. It is mostly useful for newly-created
LARs. 

On Feb 9, 2008 1:06 PM, Carl-Daniel Hailfinger
<c-d.hailfinger.devel.2006@gmx.net> wrote:

> If I read the code correctly, the command will try to fill the first
> occurrence of free space in the lar, not the biggest one. That means
> we
> might have to call it multiple times.

hmm. I obviously did not think of this.

> And a general problem with the code: If it finds the offset of the
> first
> empty area, it checks whether the area is big enough. If not, it does
> not search for another empty area, but returns instead with an error.

Actually, I think as written it is broken for the general case of lots
of empty spots. It should just look for the room left from start of
empty space to next LAR header. It's just that I have never had a LAR
that has more than one block of empty space, and that empty space is
always at the gap before the bootblock.

How about this. I'd like to commit now, and then fix this later, as I
really need this code in there for speed and it works fine with all
"fresh" images built with v3.

> Should we really call this "zerofill"?

"emptyfill"? I'll let it go for now but you make  good point.


> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>


OK, this is clearly a work in progress but even in this form it is so
useful I'm going to commit it with a note, "This needs more work", and
with luck someone else will improve it once we need it improved -- the
basic structure is there.

Index: util/lar/stream.c
Add hlen (header len) and maxsize (max size left in lar) functions. 

Index: util/lar/lib.h
Add function prototypes and new ZEROFILL enum.

Index: util/lar/lar.c
Add -z option and command support. 



git-svn-id: svn://coreboot.org/repository/coreboot-v3@583 f3766cd6-281f-0410-b1cd-43a5c92072e9
2008-02-09 21:16:42 +00:00

93 lines
2.8 KiB
C

/*
* lar - lightweight archiver
*
* Copyright (C) 2006-2007 coresystems GmbH
* (Written by Stefan Reinauer <stepan@coresystems.de> 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
*/
#ifndef __LAR_LIB_H
#define __LAR_LIB_H
/* data types */
struct file {
char *name;
struct file *next;
};
enum {
NONE,
ADD,
CREATE,
LIST,
EXTRACT,
ZEROFILL,
} larmodes;
/* prototypes for lar.c functions */
int verbose(void);
int elfparse(void);
long get_larsize(void);
char *get_bootblock(void);
/* prototypes for lib.c functions */
int mkdirp_below(const char *parent, const char *dirpath, mode_t mode);
int add_files(const char *name);
int add_file_or_directory(const char *name);
struct file *get_files(void);
void free_files(void);
/* Prototypes for ELF functions */
int iself(char *filebuf);
/* Prototypes for in-memory LAR operations */
int lar_process_name(char *name, char **pfilename, char **ppathname,
enum compalgo *thisalgo);
u32 lar_compress(char *ptr, ssize_t size, char *temp, enum compalgo *thisalgo);
int hlen(char *name);
int maxsize(struct lar *lar, char *name);
int lar_add_entry(struct lar *lar, char *pathname, void *data,
u32 complen, u32 reallen, u32 loadaddress, u32 entry,
enum compalgo thisalgo);
/* Prototypes for the LAR I/O functions */
char *mapfile(char *filename, u32 *size);
struct lar * lar_new_archive(const char *archive, unsigned int size);
struct lar * lar_open_archive(const char *archive);
void lar_close_archive(struct lar *lar);
void lar_list_files(struct lar *lar, struct file *files);
int lar_add_file(struct lar *lar, char *name);
int lar_add_bootblock(struct lar *lar, const char *bootblock);
int lar_extract_files(struct lar *lar, struct file *files);
/* prototypes for extract.c functions */
int extract_lar(const char *archivename, struct file *files);
/* prototypes for list.c functions */
int list_lar(const char *archivename, struct file *files);
/* prototypes for create.c functions */
int create_lar(const char *archivename, struct file *files);
/* prototypes for bootblock.c functions */
extern char *bootblock_code;
extern int bootblock_len;
int load_bootblock(const char *bootblock);
int fixup_bootblock(void);
#endif