VFS
David Laur
david at rainsound.com
Wed Mar 17 18:18:18 GMT 1999
At the risk of being a bit object-oriented, it seems to me that
maintaining a context, an "object" if you like, for each virtual
share makes things a lot more manageable.
So, I think that Tim's connection_struct is on the right track.
The "obvious" alternative to specifying it as an argument in every
routine would be a C++ object which would implement the various
open(), close(), etc, methods.
However, given that plain-old-C is in use, you can still simplify
everything via a struct typedef which maintains the appropriate
pointers for a given share type.
For example:
---------- cut here ------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
/* --------------------------------------------------------- */
typedef struct VFS_Context_s {
struct connection_struct *conn; /* or it's elements directly */
int (*open) (const char *path, int oflag, ... /* mode_t mode */);
int (*read) (int fildes, void *buf, size_t nbyte);
int (*close) (int fd);
/* ... */
} VFS_Context;
/* --------------------------------------------------------- */
VFS_Context *
new_VFS_CRunTimeFile (void)
{
VFS_Context *ctx = (VFS_Context*) malloc( sizeof(VFS_Context) );
/* ctx->conn = xyz; ... whatever is req'd */
ctx->open = open;
ctx->read = read;
ctx->close = close;
/* ... */
return( ctx );
}
/* --------------------------------------------------------- */
void
delete_VFS_context (VFS_Context *ctx)
{
if (ctx) {
/* do sensible clean-ups, etc */
free(ctx);
}
}
/* --------------------------------------------------------- */
int main ()
{
VFS_Context *vfs;
int fd;
char buf[128];
vfs = new_VFS_CRunTimeFile();
fd = vfs->open("/etc/hosts", O_RDONLY);
vfs->read(fd, buf, 100);
buf[100] = 0;
vfs->close(fd);
delete_VFS_context(vfs);
printf("buf = '%s'\n", buf);
return 0;
}
/* --------------------------------------------------------- */
More information about the samba-technical
mailing list