* Copyright (c) 1990 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)kvm_mkdb.c 5.6 (Berkeley) %G%";
#define basename(cp) ((tmp=rindex((cp), '/')) ? tmp+1 : (cp))
char *nlistpath
, *nlistname
;
while ((ch
= getopt(argc
, argv
, "")) != EOF
)
fprintf(stderr
, "usage: %s", progname
, USAGE
);
nlistpath
= argc
> 1 ? argv
[0] : _PATH_UNIX
;
nlistname
= basename(nlistpath
);
sprintf(dbtemp
, "%s/kvm_tmp%s", KVMDBDIR
, nlistname
);
sprintf(dbname
, "%s/kvm_%s", KVMDBDIR
, nlistname
);
if ((db
= dbm_open(dbtemp
, O_CREAT
|O_WRONLY
|O_EXCL
, 0644)) == NULL
)
syserrexit("error opening dbmfile");
if (create_knlist(nlistpath
, db
) == -1)
errexit("error creating kernel namelist");
if (create_devnames(db
) == -1)
errexit("error creating devnames");
if (len
> (MAXPATHLEN
- 5))
errexit("pathname too long: %s", file
);
strcpy(file
+len
, ".dir");
if (unlink(file
) < 0 && errno
!= ENOENT
)
syserrexit("can't unlink %s", file
);
strcpy(file
+len
, ".pag");
if (unlink(file
) < 0 && errno
!= ENOENT
)
syserrexit("can't unlink %s", file
);
if (flen
> (MAXPATHLEN
- 5) || tlen
> (MAXPATHLEN
- 5))
errexit("pathname too long: %s or %s", from
, to
);
strcpy(from
+flen
, ".dir");
if (rename(from
, to
) == -1)
syserrexit("rename %s to %s", from
, to
);
strcpy(from
+flen
, ".pag");
if (rename(from
, to
) == -1)
syserrexit("rename %s to %s", from
, to
);
*(from
+flen
) = *(to
+tlen
) = '\0';
typedef struct nlist NLIST
;
#define _strx n_un.n_strx
#define _name n_un.n_name
#define ISVALID(p) (p->_name && p->_name[0])
off_t strings_offset
, symbol_offset
, symbol_size
, lseek();
if (!(fsym
= fopen(name
, "r")))
syserrexit("can't open %s", name
);
if (fread((char *)&ebuf
, sizeof(struct exec
), 1, fsym
) != 1 ||
syserrexit("can't read exec");
symbol_offset
= N_SYMOFF(ebuf
);
symbol_size
= ebuf
.a_syms
;
strings_offset
= symbol_offset
+ symbol_size
;
if (fseek(fsym
, symbol_offset
, SEEK_SET
) == -1)
syserrexit("can't seek symbol table: %x", symbol_offset
);
if ((fstr
= fopen(name
, "r")) == NULL
)
syserrexit("can't open %s", name
);
data
.dptr
= (char *)&nbuf
;
data
.dsize
= sizeof (NLIST
);
for (s
= &nbuf
; symbol_size
; symbol_size
-= sizeof (NLIST
)) {
if (fread((char *)s
, sizeof (NLIST
), 1, fsym
) != 1)
syserrexit("can't read nlist entry");
if (!s
->_strx
|| s
->n_type
&N_STAB
)
if (fseek(fstr
, strings_offset
+ s
->_strx
, SEEK_SET
) == -1)
syserrexit("can't seek string: %x",
strings_offset
+ s
->_strx
);
while ((c
= fgetc(fstr
)) != EOF
&& c
!= '\0') {
errexit("string too long");
if (dbm_store(db
, key
, data
, DBM_INSERT
) < 0)
if (strcmp(sbuf
+1, "_version") == 0) {
* store the value of version in VERSION
char versbuf
[_POSIX2_LINE_MAX
];
/* offset relative to start of text image in VM. */
* on tahoe, first 0x800 is reserved for communication
* with the console processor.
reloffset
= ((s
->n_value
& ~KERNBASE
) - 0x800);
reloffset
= (s
->n_value
& ~KERNBASE
);
* When loaded, data is rounded
* to next page cluster after text, but not in file.
reloffset
-= CLBYTES
- (ebuf
.a_text
% CLBYTES
);
versoff
= N_TXTOFF(ebuf
) + reloffset
;
if (fseek(fstr
, versoff
, SEEK_SET
) == -1)
syserrexit("seek (version): %x", s
->n_value
);
* Just read version string up to, and
if (fgets(versbuf
, _POSIX2_LINE_MAX
, fstr
) == NULL
)
syserrexit("can't read version");
strcpy(sbuf
+1, "VERSION");
key
.dsize
= (sizeof ("VERSION") - 1) + 1;
vers
.dsize
= strlen(versbuf
);
if (dbm_store(db
, key
, vers
, DBM_INSERT
) < 0)
syserrexit("dbm_store: can't store VERSION");
fprintf(stderr
, "%s: warning: ", progname
);
fmt
= va_arg(ap
, char *);
(void) vfprintf(stderr
, fmt
, ap
);
fprintf(stderr
, "%s: ", progname
);
fmt
= va_arg(ap
, char *);
(void) vfprintf(stderr
, fmt
, ap
);
fprintf(stderr
, "%s: ", progname
);
fmt
= va_arg(ap
, char *);
(void) vfprintf(stderr
, fmt
, ap
);
fprintf(stderr
, ": %s\n", strerror(errno
));