#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/promif.h>
#include <sys/promimpl.h>
int
prom_fopen(ihandle_t fsih, char *path)
{
cell_t ci[10];
size_t len;
#ifdef PROM_32BIT_ADDRS
char *opath = NULL;
if ((uintptr_t)path > (uint32_t)-1) {
opath = path;
len = prom_strlen(opath) + 1;
path = promplat_alloc(len);
if (path == NULL)
return (0);
(void) prom_strcpy(path, opath);
}
#endif
len = prom_strlen(path);
promif_preprom();
ci[0] = p1275_ptr2cell("call-method");
ci[1] = (cell_t)4;
ci[2] = (cell_t)3;
ci[3] = p1275_ptr2cell("open-file");
ci[4] = p1275_ihandle2cell(fsih);
ci[5] = p1275_uint2cell(len);
ci[6] = p1275_ptr2cell(path);
(void) p1275_cif_handler(&ci);
promif_postprom();
#ifdef PROM_32BIT_ADDRS
if (opath != NULL)
promplat_free(path, len + 1);
#endif
if (ci[7] != 0)
return (-1);
if (ci[8] == 0)
return (-1);
return (p1275_cell2int(ci[9]));
}
int
prom_volopen(ihandle_t fsih, char *path)
{
cell_t ci[10];
size_t len;
#ifdef PROM_32BIT_ADDRS
char *opath = NULL;
if ((uintptr_t)path > (uint32_t)-1) {
opath = path;
len = prom_strlen(opath) + 1;
path = promplat_alloc(len);
if (path == NULL)
return (0);
(void) prom_strcpy(path, opath);
}
#endif
len = prom_strlen(path);
promif_preprom();
ci[0] = p1275_ptr2cell("call-method");
ci[1] = (cell_t)4;
ci[2] = (cell_t)3;
ci[3] = p1275_ptr2cell("open-volume");
ci[4] = p1275_ihandle2cell(fsih);
ci[5] = p1275_uint2cell(len);
ci[6] = p1275_ptr2cell(path);
(void) p1275_cif_handler(&ci);
promif_postprom();
#ifdef PROM_32BIT_ADDRS
if (opath != NULL)
promplat_free(path, len + 1);
#endif
if (ci[7] != 0)
return (-1);
if (ci[8] == 0)
return (-1);
return (p1275_cell2int(ci[9]));
}
int
prom_fseek(ihandle_t fsih, int fd, unsigned long long offset)
{
cell_t ci[10];
ci[0] = p1275_ptr2cell("call-method");
ci[1] = (cell_t)4;
ci[2] = (cell_t)3;
ci[3] = p1275_ptr2cell("seek-file");
ci[4] = p1275_ihandle2cell(fsih);
ci[5] = p1275_int2cell(fd);
ci[6] = p1275_ull2cell_low(offset);
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
if (ci[7] != 0)
return (-1);
if (ci[8] == 0)
return (-1);
return (p1275_cell2int(ci[9]));
}
int
prom_fread(ihandle_t fsih, int fd, caddr_t buf, size_t len)
{
cell_t ci[10];
#ifdef PROM_32BIT_ADDRS
caddr_t obuf = NULL;
if ((uintptr_t)buf > (uint32_t)-1) {
obuf = buf;
buf = promplat_alloc(len);
if (buf == NULL)
return (-1);
}
#endif
promif_preprom();
ci[0] = p1275_ptr2cell("call-method");
ci[1] = (cell_t)5;
ci[2] = (cell_t)2;
ci[3] = p1275_ptr2cell("read-file");
ci[4] = p1275_ihandle2cell(fsih);
ci[5] = p1275_int2cell(fd);
ci[6] = p1275_uint2cell(len);
ci[7] = p1275_ptr2cell(buf);
(void) p1275_cif_handler(&ci);
promif_postprom();
#ifdef PROM_32BIT_ADDRS
if (obuf != NULL) {
promplat_bcopy(buf, obuf, len);
promplat_free(buf, len);
}
#endif
if (ci[8] != 0)
return (-1);
return (p1275_cell2int(ci[9]));
}
int
prom_fsize(ihandle_t fsih, int fd, size_t *size)
{
cell_t ci[8];
promif_preprom();
ci[0] = p1275_ptr2cell("call-method");
ci[1] = (cell_t)3;
ci[2] = (cell_t)2;
ci[3] = p1275_ptr2cell("size-file");
ci[4] = p1275_ihandle2cell(fsih);
ci[5] = p1275_int2cell(fd);
(void) p1275_cif_handler(&ci);
promif_postprom();
if (ci[6] != 0)
return (-1);
*size = p1275_cell2uint(ci[7]);
return (0);
}
int
prom_compinfo(ihandle_t fsih, int fd, int *iscmp, size_t *fsize, size_t *bsize)
{
cell_t ci[10];
promif_preprom();
ci[0] = p1275_ptr2cell("call-method");
ci[1] = (cell_t)3;
ci[2] = (cell_t)4;
ci[3] = p1275_ptr2cell("cinfo-file");
ci[4] = p1275_ihandle2cell(fsih);
ci[5] = p1275_int2cell(fd);
(void) p1275_cif_handler(&ci);
promif_postprom();
if (ci[6] != 0)
return (-1);
*iscmp = p1275_cell2int(ci[7]);
*fsize = p1275_cell2uint(ci[8]);
*bsize = p1275_cell2uint(ci[9]);
return (0);
}
void
prom_fclose(ihandle_t fsih, int fd)
{
cell_t ci[7];
ci[0] = p1275_ptr2cell("call-method");
ci[1] = (cell_t)3;
ci[2] = (cell_t)1;
ci[3] = p1275_ptr2cell("close-file");
ci[4] = p1275_ihandle2cell(fsih);
ci[5] = p1275_int2cell(fd);
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
}