/* NEW CODE implementing a simple system like "drive letters" but longer names, * Copyright (C) 2024 Zak Fenton * NO WARRANTY USE AT YOUR OWN RISK etc. under terms of UNLICENSE or MIT license */ #ifndef _DRIVES_H #define _DRIVES_H // The logic for managing filesystem instances themselves is separate // to the management of the drives structure, but the drives system acts // as a convenience wrapper over the filesystem logic. #include "fsinstance.h" #include "syscdefs.h" #define DRIVES_HANDLER_NONE 0 #define DRIVES_HANDLER_FS 1 /* The maximum number of drives. */ #define DRIVES_MAX 10 /* The maximum length of a drive name. */ #define DRIVES_NAMEMAX 24 /* An entry for a single drive. */ struct drives_entry { int handler; int nusers; void* handlerdata; char name[DRIVES_NAMEMAX]; }; /* The drives structure. */ struct drives { sched_spinlock_t lock; struct drives_entry entries[DRIVES_MAX]; }; /* Allocates and initialises a new drives structure. Note that functions for * dealing with multiple drives structures will be dealt with later! */ struct drives* drives_alloc(); /* Allocates a drive in the drives structure with the given data, returning the * drive number on success or -1 on failure. */ int drives_setup(struct drives* drives, int handlertype, void* handlerdata, const char* name); /* Finds the corresponding drive and retrieves the fields. This should lock the * structure while operating, incrementing nusers before releasing the lock. * * Returns the drive number on success or -1 on failure. */ int drives_open(struct drives* drives, const char* name, int* handlertype, void** handlerdata); /* Safely decrements the user count of the given drive number, returning -1. */ int drives_close(struct drives* drives, int driven); /* Safely increments the user count of the given drive number, returning the number. */ int drives_dup(struct drives* drives, int driven); /* Looks up the (filesystem-specific) inode structure for a given path, storing * the filesystem type in a variable at the given pointer (0 on failure). */ void* drives_fsnode(struct drives* drives, int hint, char* path, int* fstypevar); void* drives_fsparent(struct drives* drives, int hint, char* path, int* fstypevar, char* namevar, int namelen); /* Begin/end a filesystem operation, also returning the appropriate fsinstance for the hint drive and/or path. */ fsinstance_t* drives_fsbegin(struct drives* drives, int hint, char* path); void drives_fsend(struct drives* drives, fsinstance_t* instance); /* Gets information about a drive, filling a structure with information about the drive. */ int drives_getinfo(struct drives* drives, int drivenumber, struct __syscdefs_driveinfo* structure); /* From ifndef at top of file: */ #endif