aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Lohoff <flo@rfc822.org>2008-10-04 15:45:55 +0000
committerGuido G√ľnther <agx@sigxcpu.org>2009-04-26 15:26:26 +0200
commitae4dcabd39938e93afa1fb095ed5421e92c10d7d (patch)
tree7bf99aee7c2504512782978067692f051874907a
parent7ef5cc75cfd3cf93f7edaf2b1b02e557ae16bf7f (diff)
Seperate ARC prom calls from ext2io.c
-rw-r--r--arclib/prom.c27
-rw-r--r--common/prom.h25
-rw-r--r--ext2load/ext2io.c46
3 files changed, 65 insertions, 33 deletions
diff --git a/arclib/prom.c b/arclib/prom.c
index 7048e11..ab3b49a 100644
--- a/arclib/prom.c
+++ b/arclib/prom.c
@@ -3,6 +3,33 @@
#include "arc.h"
#include "prom.h"
+int prom_open(char *name, int mode, FILE *stream) {
+ /* Translate mode to Arc variant */
+ int amode=OpenReadOnly;
+ if (mode == O_RDWR)
+ amode=OpenReadWrite;
+ return ArcOpen(name, amode, stream);
+}
+
+int prom_close(FILE stream) {
+ return ArcClose(stream);
+}
+
+int prom_seek(FILE stream, long long position, int whence) {
+ LARGEINTEGER apos;
+ SEEKMODE amode=SeekAbsolute;
+
+ /* Translate generic positioning to ARC positioning */
+ if (whence == SEEK_CUR)
+ amode=SeekRelative;
+
+ /* Translate 64 bit long long to Arc representation */
+ apos.HighPart=position>>32;
+ apos.LowPart=position&0xffffffff;
+
+ return ArcSeek(stream, &apos, amode);
+}
+
int prom_write(FILE stream, char *string, unsigned long len, unsigned long *rlen) {
return ArcWrite(stream, string, len, rlen);
}
diff --git a/common/prom.h b/common/prom.h
index 31852e9..b347d36 100644
--- a/common/prom.h
+++ b/common/prom.h
@@ -1,4 +1,29 @@
+
+/*
+ * Open may be used to open "partitions" passed in by name from the prom. It is the
+ * proms abstraction layers responsibility to associate a file which associates to the
+ * block device
+ *
+ */
+int prom_open(char *name, int mode, FILE *stream);
+int prom_close(FILE stream);
+/*
+ * Seek on the e.g. partition to a specific block indicated by a byte offset.
+ *
+ */
+int prom_seek(FILE stream, long long position, int whence);
+
+enum {
+ O_RDONLY,
+ O_RDWR,
+};
+
+enum {
+ SEEK_SET,
+ SEEK_CUR,
+};
+
int prom_write(FILE stream, char *buf, unsigned long len, unsigned long *rlen);
int prom_read(FILE stream, char *buf, unsigned long len, unsigned long *rlen);
diff --git a/ext2load/ext2io.c b/ext2load/ext2io.c
index 6f12b60..8776630 100644
--- a/ext2load/ext2io.c
+++ b/ext2load/ext2io.c
@@ -16,7 +16,7 @@
#include <sys/types.h>
#include <ext2_fs.h>
#include <ext2fs.h>
-#include <arc.h>
+#include <prom.h>
/*
* All About the Cache
@@ -99,8 +99,8 @@ static unsigned long virtual_time;
struct arc_private_data {
int magic;
- OPENMODE mode;
- ULONG fileID;
+ int mode;
+ unsigned long fileID;
struct arc_cache cache[CACHE_SIZE];
char *arc_sg_buf;
unsigned long total_read;
@@ -122,7 +122,6 @@ static errcode_t fill_sg_blocks(io_channel, struct arc_private_data *, int);
static errcode_t raw_read_blk(io_channel, struct arc_private_data *,
unsigned long, int, char *);
-static void mul64(unsigned long, int, LARGEINTEGER *);
static errcode_t arc_seek(io_channel, unsigned long);
static errcode_t arc_open(const char *name, int flags, io_channel * channel);
@@ -273,9 +272,9 @@ raw_read_blk(io_channel channel, struct arc_private_data *priv,
priv->seek_pos_valid = 0;
if (status == 0) {
length = (count < 0) ? -count : count * channel->block_size;
- ULONG nread = 0;
+ unsigned long nread = 0;
- status = ArcRead(priv->fileID, buf, length, &nread);
+ status = prom_read(priv->fileID, buf, length, &nread);
if ((nread > 0) && (nread < length)) {
status = EXT2_ET_SHORT_READ;
memset(((char *) buf) + nread, 0, length - nread);
@@ -479,10 +478,10 @@ arc_open(const char *name, int flags, io_channel * pchannel)
channel->private_data = priv;
priv->magic = EXT2_ET_BAD_MAGIC;
priv->mode =
- (flags & IO_FLAG_RW) ? OpenReadWrite :
- OpenReadOnly;
+ (flags & IO_FLAG_RW) ? O_RDWR :
+ O_RDONLY;
status =
- ArcOpen((char *) name, priv->mode,
+ prom_open((char *) name, priv->mode,
&priv->fileID);
if( status ) {
status = EXT2_ET_BAD_DEVICE_NAME;
@@ -517,7 +516,7 @@ static errcode_t arc_close(io_channel channel)
EXT2_CHECK_MAGIC(priv, EXT2_ET_BAD_MAGIC);
if (--channel->refcount == 0) {
- status = ArcClose(priv->fileID);
+ status = prom_close(priv->fileID);
free_cache(priv);
if (channel->name != NULL)
ext2fs_free_mem((void **) &channel->name);
@@ -548,31 +547,12 @@ static errcode_t arc_set_blksize(io_channel channel, int blksize)
return 0;
}
-static void
-mul64(unsigned long block, int blocksize, LARGEINTEGER *result)
-{
- ULONG m1l = block & 0x0FFFF, m1h = (block >> 16) & 0x0FFFF;
- ULONG m2l = blocksize & 0x0FFFF, m2h = (blocksize >> 16) & 0x0FFFF;
- ULONG i1 = m1l * m2h, i2 = m1h * m2l;
-
- result->HighPart =
- (m1h * m2h) + ((i1 >> 16) & 0x0FFFF) + ((i2 >> 16) & 0x0FFFF);
- i1 =
- (i1 & 0x0FFFF) + (i2 & 0x0FFFF) +
- (((m1l * m2l) >> 16) & 0x0FFFF);
- result->LowPart = ((i1 & 0x0FFFF) << 16) + ((m1l * m2l) & 0x0FFFF);
- result->HighPart += (i1 >> 16) & 0x0FFFF;
-}
-
static errcode_t
arc_seek(io_channel channel, unsigned long block)
{
struct arc_private_data *priv;
- LARGEINTEGER position;
-
priv = (struct arc_private_data *) channel->private_data;
- mul64(block, channel->block_size, &position);
- return ArcSeek(priv->fileID, &position, SeekAbsolute);
+ return prom_seek(priv->fileID, block*channel->block_size, SEEK_SET);
}
/*
@@ -686,14 +666,14 @@ arc_write_blk (io_channel channel, unsigned long block, int count,
if (status == 0) {
size_t length =
(count < 0) ? -count : count * channel->block_size;
- ULONG nwritten = 0;
+ unsigned long nwritten = 0;
status =
- ArcWrite(priv->fileID, (void *) buf, length,
+ prom_write(priv->fileID, (void *) buf, length,
&nwritten);
if ((nwritten > 0) && (nwritten < length))
status = EXT2_ET_SHORT_WRITE;
- if ((status != ESUCCESS) && (channel->write_error != NULL)) {
+ if ((status != 0) && (channel->write_error != NULL)) {
status = (channel->write_error)
(channel, block, count, buf, length, nwritten, status);
}