Make it usable from userland.

This commit is contained in:
christos 2016-03-09 15:45:37 +00:00
parent 00a072ac83
commit 635b4dc047

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd9660_util.c,v 1.12 2014/11/10 18:46:33 maxv Exp $ */
/* $NetBSD: cd9660_util.c,v 1.13 2016/03/09 15:45:37 christos Exp $ */
/*-
* Copyright (c) 1994
@ -37,9 +37,17 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cd9660_util.c,v 1.12 2014/11/10 18:46:33 maxv Exp $");
#ifdef _KERNEL
__KERNEL_RCSID(0, "$NetBSD: cd9660_util.c,v 1.13 2016/03/09 15:45:37 christos Exp $");
#else
/* used by macppc_installboot */
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#endif
#include <sys/param.h>
#ifdef _KERNEL
#include <sys/systm.h>
#include <sys/namei.h>
#include <sys/resourcevar.h>
@ -51,14 +59,24 @@ __KERNEL_RCSID(0, "$NetBSD: cd9660_util.c,v 1.12 2014/11/10 18:46:33 maxv Exp $"
#include <sys/mount.h>
#include <sys/vnode.h>
#include <sys/dirent.h>
#else
#include <assert.h>
#include <dirent.h>
#define KASSERT(x) assert(x) /* XXX for <fs/unicode.h> */
#endif
#include <fs/cd9660/iso.h>
#ifdef _KERNEL
#include <fs/cd9660/cd9660_extern.h>
#else
#include "installboot.h"
static int isochar(const u_char *, const u_char *, int, uint16_t *);
#endif
#include <fs/unicode.h>
static u_int16_t wget(const u_char **, size_t *, int);
static int wput(u_char *, size_t, u_int16_t, int);
static uint16_t wget(const u_char **, size_t *, int);
static int wput(u_char *, size_t, uint16_t, int);
int cd9660_utf8_joliet = 1;
@ -68,8 +86,9 @@ int cd9660_utf8_joliet = 1;
*/
int
isochar(const u_char *isofn, const u_char *isoend, int joliet_level,
u_int16_t *c)
uint16_t *c)
{
*c = isofn[0];
if (joliet_level == 0 || isofn + 1 == isoend) {
/* (00) and (01) are one byte in Joliet, too */
@ -95,12 +114,17 @@ isochar(const u_char *isofn, const u_char *isoend, int joliet_level,
*/
int
isofncmp(const u_char *fn, size_t fnlen, const u_char *isofn, size_t isolen,
int joliet_level)
int joliet_level)
{
int i, j;
u_int16_t fc, ic;
uint16_t fc, ic;
const u_char *isoend = isofn + isolen;
#ifdef ISOFNCMPDEBUG
printf("fn = %s, fnlen = %zu, isofn = %s, isolen = %zu\n",
fn, fnlen, isofn, isolen);
#endif
while (fnlen > 0) {
fc = wget(&fn, &fnlen, joliet_level);
@ -132,10 +156,10 @@ isofncmp(const u_char *fn, size_t fnlen, const u_char *isofn, size_t isolen,
if (fc >= 'a' && fc <= 'z')
fc -= 'a' - 'A';
return (int) fc - (int) ic;
return (int)fc - (int)ic;
}
} else
return (int) fc - (int) ic;
return (int)fc - (int)ic;
}
}
if (isofn != isoend) {
@ -162,11 +186,11 @@ isofncmp(const u_char *fn, size_t fnlen, const u_char *isofn, size_t isolen,
*/
void
isofntrans(const u_char *infn, int infnlen, u_char *outfn, u_short *outfnlen,
int original, int casetrans, int assoc, int joliet_level)
int original, int casetrans, int assoc, int joliet_level)
{
int fnidx = 0;
const u_char *infnend = infn + infnlen;
u_int16_t c;
uint16_t c;
int sz;
if (assoc) {
@ -199,7 +223,7 @@ isofntrans(const u_char *infn, int infnlen, u_char *outfn, u_short *outfnlen,
*outfnlen = fnidx;
}
static u_int16_t
static uint16_t
wget(const u_char **str, size_t *sz, int joliet_level)
{
if (joliet_level > 0 && cd9660_utf8_joliet) {
@ -211,7 +235,7 @@ wget(const u_char **str, size_t *sz, int joliet_level)
* this effectively assumes provided file name is using
* ISO-8859-1 subset.
*/
u_int16_t c = *str[0];
uint16_t c = *str[0];
(*str)++;
(*sz)--;
@ -220,7 +244,7 @@ wget(const u_char **str, size_t *sz, int joliet_level)
}
static int
wput(u_char *s, size_t n, u_int16_t c, int joliet_level)
wput(u_char *s, size_t n, uint16_t c, int joliet_level)
{
if (joliet_level > 0 && cd9660_utf8_joliet) {
/* Store Joliet file name encoded into UTF-8 */