Skip to content

Commit

Permalink
Mount and Dismount added niklasekstrom#4
Browse files Browse the repository at this point in the history
  • Loading branch information
dcutugno committed Aug 18, 2024
1 parent fe4a513 commit b6790a8
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 14 deletions.
108 changes: 95 additions & 13 deletions Software/a314fs/a314fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <exec/ports.h>
#include <exec/nodes.h>
#include <exec/libraries.h>
#include <exec/memory.h>

#include <devices/timer.h>

Expand Down Expand Up @@ -70,12 +71,25 @@ BOOL request_buffer_in_a314_memory;
// These are allocated in A314 memory.
ULONG request_buffer_address;
ULONG data_buffer_address;
ULONG data_buffer_size;

void DeletePort(struct MsgPort *port)
{
if (port)
{
if (port->mp_Node.ln_Name)
RemPort(port);
if (port->mp_SigBit < 32)
FreeSignal(port->mp_SigBit);
FreeMem(port, sizeof(struct MsgPort));
}
}

void MyNewList(struct List *l)
{
l->lh_Head = (struct Node *)&(l->lh_Tail);
l->lh_Tail = NULL;
l->lh_TailPred = (struct Node *)&(l->lh_Head);
l->lh_Head = (struct Node *)&(l->lh_Tail);
l->lh_Tail = NULL;
l->lh_TailPred = (struct Node *)&(l->lh_Head);
}

struct MsgPort *MyCreatePort(char *name, long pri)
Expand Down Expand Up @@ -375,7 +389,8 @@ void startup_fs_handler(struct DosPacket *dp)
request_buffer_address = AllocMemA314(REQ_RES_BUF_SIZE);
}

data_buffer_address = AllocMemA314(BUFFER_SIZE);
data_buffer_size = BUFFER_SIZE;
data_buffer_address = AllocMemA314(data_buffer_size);

// Så vi kan anta att vi kommer hit, och då har vi en ström till rasp-sidan, där vi kan skicka data.
create_and_add_volume();
Expand Down Expand Up @@ -1284,6 +1299,72 @@ void action_is_filesystem(struct DosPacket *dp)
reply_packet(dp);
}

void action_die(struct DosPacket *dp)
{
dbg("ACTION_DIE\n");

struct DieRequest *req = (struct DieRequest *)request_buffer;
req->has_response = 0;
req->type = ACTION_DIE;

write_req_and_wait_for_res(sizeof(struct DieRequest));

// Clean up resources here
if (A314Base)
CloseLibrary(A314Base);
if (a314_ior)
CloseDevice((struct IORequest *)a314_ior);
if (a314_mp)
DeletePort(a314_mp);
if (timer_mp)
DeletePort(timer_mp);
if (mp)
DeletePort(mp);
if (request_buffer)
FreeMem(request_buffer, REQ_RES_BUF_SIZE);
if (data_buffer_address)
FreeMemA314(data_buffer_address, data_buffer_size);

dp->dp_Res1 = DOSTRUE;
dp->dp_Res2 = 0;
reply_packet(dp);
}

void action_inhibit(struct DosPacket *dp)
{
LONG inhibit = dp->dp_Arg1;
dbg("ACTION_INHIBIT\n");
dbg(" inhibit = $l\n", inhibit);

struct InhibitRequest *req = (struct InhibitRequest *)request_buffer;
req->has_response = 0;
req->type = ACTION_INHIBIT;
req->inhibit = inhibit;

write_req_and_wait_for_res(sizeof(struct InhibitRequest));

struct InhibitResponse *res = (struct InhibitResponse *)request_buffer;
dp->dp_Res1 = res->success ? DOSTRUE : DOSFALSE;
dp->dp_Res2 = res->error_code;
reply_packet(dp);
}

void action_flush(struct DosPacket *dp)
{
dbg("ACTION_FLUSH\n");

struct FlushRequest *req = (struct FlushRequest *)request_buffer;
req->has_response = 0;
req->type = ACTION_FLUSH;

write_req_and_wait_for_res(sizeof(struct FlushRequest));

struct FlushResponse *res = (struct FlushResponse *)request_buffer;
dp->dp_Res1 = res->success ? DOSTRUE : DOSFALSE;
dp->dp_Res2 = res->error_code;
reply_packet(dp);
}

void action_unsupported(struct DosPacket *dp)
{
dbg("ACTION_UNSUPPORTED\n");
Expand Down Expand Up @@ -1350,16 +1431,17 @@ void start(__reg("a0") struct DosPacket *startup_packet)

case ACTION_IS_FILESYSTEM: action_is_filesystem(dp); break;

/*
case ACTION_CURRENT_VOLUME: action_current_volume(dp); break;
case ACTION_RENAME_DISK: action_rename_disk(dp); break;
case ACTION_DIE: action_die(dp); break;
case ACTION_INHIBIT: action_inhibit(dp); break;
case ACTION_FLUSH: action_flush(dp); break;

/*
case ACTION_CURRENT_VOLUME: action_current_volume(dp); break;
case ACTION_RENAME_DISK: action_rename_disk(dp); break;
case ACTION_DIE: //action_die(dp); break;
case ACTION_MORE_CACHE: //action_more_cache(dp); break;
case ACTION_FLUSH: //action_flush(dp); break;
case ACTION_INHIBIT: //action_inhibit(dp); break;
case ACTION_WRITE_PROTECT: //action_write_protect(dp); break;
*/
case ACTION_MORE_CACHE: //action_more_cache(dp); break;
case ACTION_WRITE_PROTECT: //action_write_protect(dp); break;
*/

default: action_unsupported(dp); break;
}
Expand Down
50 changes: 49 additions & 1 deletion Software/a314fs/a314fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,56 @@ def process_info(key):
block_size = INFO_BLOCK_SIZE
return struct.pack('>HHIII', 1, 0, total_blocks, used_blocks, block_size)

# Add a global variable to track mount state
is_mounted = True

def process_die():
logger.debug('ACTION_DIE')
global is_mounted
is_mounted = False
# Close all open file handles
for fp in list(open_file_handles.keys()):
process_end(fp)
# Clear all locks
locks.clear()
return struct.pack('>HH', 1, 0)

def process_inhibit(inhibit):
logger.debug('ACTION_INHIBIT, inhibit: %s', inhibit)
global is_mounted
if inhibit:
# Inhibit the volume (prepare for unmount)
is_mounted = False
else:
# Uninhibit the volume (remount)
is_mounted = True
return struct.pack('>HH', 1, 0)

def process_flush():
logger.debug('ACTION_FLUSH')
os.sync()
return struct.pack('>HH', 1, 0)


def process_request(req):
#logger.debug('len(req): %s, req: %s', len(req), list(req))
# logger.debug('len(req): %s, req: %s', len(req), list(req))

global is_mounted

(rtype,) = struct.unpack('>H', req[:2])

if rtype == ACTION_DIE:
return process_die()
elif rtype == ACTION_INHIBIT:
(inhibit,) = struct.unpack('>I', req[2:6])
return process_inhibit(inhibit)
elif rtype == ACTION_FLUSH:
return process_flush()

# For all other actions, check if the volume is mounted
if not is_mounted:
return struct.pack('>HH', 0, ERROR_DEVICE_NOT_MOUNTED)

if rtype == ACTION_LOCATE_OBJECT:
key, mode, nlen = struct.unpack('>IHB', req[2:9])
name = req[9:9+nlen].decode('latin-1')
Expand Down Expand Up @@ -825,6 +870,7 @@ def process_request(req):
send_reset(current_stream_id)
current_stream_id = stream_id
send_connect_response(stream_id, 0)
is_mounted = True # Reset the mount state on a new connection
else:
send_connect_response(stream_id, 3)
elif ptype == MSG_DATA:
Expand All @@ -838,7 +884,9 @@ def process_request(req):
logger.debug('Got EOS, stream closed')
send_eos(stream_id)
current_stream_id = None
is_mounted = False # Reset the mount state on stream close
elif ptype == MSG_RESET:
if stream_id == current_stream_id:
logger.debug('Got RESET, stream closed')
current_stream_id = None
is_mounted = False # Reset the mount state on stream close
37 changes: 37 additions & 0 deletions Software/a314fs/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,41 @@ struct UnsupportedResponse
short error_code;
};

struct DieRequest
{
UBYTE has_response;
UBYTE type;
};

struct DieResponse
{
UBYTE success;
ULONG error_code;
};

struct InhibitRequest
{
UBYTE has_response;
UBYTE type;
LONG inhibit;
};

struct InhibitResponse
{
UBYTE success;
ULONG error_code;
};

struct FlushRequest
{
UBYTE has_response;
UBYTE type;
};

struct FlushResponse
{
UBYTE success;
ULONG error_code;
};

#pragma pack(pop)

0 comments on commit b6790a8

Please sign in to comment.