Skip to content

Commit

Permalink
Initial stab at 32 bit FS operations
Browse files Browse the repository at this point in the history
These have been reverse engineered, so might not be entirely correct,
but they seem stable enough.

These APIs need at least NetFS 6.0, which is floating round the
internet in various places.
  • Loading branch information
mjwoodcock committed Jul 20, 2023
1 parent 7c43f85 commit cb27a36
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 109 deletions.
9 changes: 9 additions & 0 deletions fileserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ fs_func_impl * const fs_dispatch[] = {
[EC_FS_FUNC_CDIRN] = fs_cdirn,
[EC_FS_FUNC_CREATE] = fs_create,
[EC_FS_FUNC_GET_USER_FREE] = fs_get_user_free,
[EC_FS_FUNC_SAVE_32] = fs_save,
[EC_FS_FUNC_CREATE_32] = fs_create,
[EC_FS_FUNC_EXAMINE_32] = fs_examine,
[EC_FS_FUNC_LOAD_32] = fs_load,
[EC_FS_FUNC_OPEN_32] = fs_open,
[EC_FS_FUNC_GETBYTES_32] = fs_getbytes,
[EC_FS_FUNC_PUTBYTES_32] = fs_putbytes,
[EC_FS_FUNC_GET_ARGS_32] = fs_get_args,
[EC_FS_FUNC_SET_ARGS_32] = fs_set_args,
};
#define NFUNC (sizeof(fs_dispatch) / sizeof(fs_dispatch[0]))

Expand Down
51 changes: 49 additions & 2 deletions fs_examine.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
static int fs_examine_read(struct fs_context *, const char *, int);

static int fs_examine_all(FTSENT *, struct ec_fs_reply_examine **, size_t *);
static int fs_examine_all_32(FTSENT *, struct ec_fs_reply_examine_32 **, size_t *);
static int fs_examine_longtxt(struct fs_context *c, FTSENT *,
struct ec_fs_reply_examine **, size_t *);
static int fs_examine_name(FTSENT *, struct ec_fs_reply_examine **, size_t *);
Expand All @@ -62,9 +63,20 @@ fs_examine(struct fs_context *c)
char *upath;
FTSENT *ent;
struct ec_fs_reply_examine *reply;
// Warning: Don't access reply->data in EC_FS_FUNC_EXAMINE_32 mode - it
// is at a different offset!
size_t reply_size;
int i, rc;

if (c->req->function == EC_FS_FUNC_EXAMINE_32)
{
// Examine_32 seems to have "start" and "arg" the wrong way round
u_int8_t tmp;
tmp = request->start;
request->start = request->arg;
request->arg = tmp;
}

request->path[strcspn(request->path, "\r")] = '\0';
if (debug)
printf("examine [%d, %d/%d, {%s}]\n",
Expand All @@ -89,7 +101,11 @@ fs_examine(struct fs_context *c)
if (request->arg == EC_FS_EXAMINE_SHORTTXT ||
request->arg == EC_FS_EXAMINE_LONGTXT)
reply = malloc(reply_size+1);
else
else if (c->req->function == EC_FS_FUNC_EXAMINE_32) {
// 1 byte larger than EC_FS_FUNC_EXAMINE
reply_size += 1;
reply = malloc(reply_size);
} else
reply = malloc(reply_size);
if (fs_examine_read(c, upath, request->start) == -1 || reply == NULL) {
free(reply);
Expand Down Expand Up @@ -120,7 +136,10 @@ fs_examine(struct fs_context *c)
i++;
switch (request->arg) {
case EC_FS_EXAMINE_ALL:
rc = fs_examine_all(ent, &reply, &reply_size);
if (c->req->function == EC_FS_FUNC_EXAMINE)
rc = fs_examine_all(ent, &reply, &reply_size);
else if (c->req->function == EC_FS_FUNC_EXAMINE_32)
rc = fs_examine_all_32(ent, (struct ec_fs_reply_examine_32 **)&reply, &reply_size);
break;
case EC_FS_EXAMINE_LONGTXT:
rc = fs_examine_longtxt(c, ent, &reply, &reply_size);
Expand Down Expand Up @@ -258,6 +277,34 @@ fs_examine_all(FTSENT *ent, struct ec_fs_reply_examine **replyp,
return -1;
}

static int
fs_examine_all_32(FTSENT *ent, struct ec_fs_reply_examine_32 **replyp, size_t *reply_sizep)
{
struct ec_fs_exall_32 *exall;
void *new_reply;

if ((new_reply = realloc(*replyp, *reply_sizep + sizeof(*exall)))
!= NULL)
*replyp = new_reply;
if (new_reply == NULL) {
errno = ENOMEM;
goto burn;
}
exall = (struct ec_fs_exall_32 *)(((void *)*replyp) + *reply_sizep);
fs_get_meta(ent, &(exall->meta)); /* This needs the name unmodified */
fs_acornify_name(ent->fts_name);
strncpy(exall->name, ent->fts_name, sizeof(exall->name));
strpad(exall->name, ' ', sizeof(exall->name));
exall->cr = '\r';
exall->access = fs_mode_to_access(ent->fts_statp->st_mode);
fs_write_val(exall->size, ent->fts_statp->st_size,
sizeof(exall->size));
*reply_sizep += sizeof(*exall);
return 0;
burn:
return -1;
}

static int
fs_examine_name(FTSENT *ent, struct ec_fs_reply_examine **replyp,
size_t *reply_sizep)
Expand Down
Loading

0 comments on commit cb27a36

Please sign in to comment.