2009-05-11 12:02:28 +02:00
|
|
|
/* This file handles nested counter-request calls to VFS sent by file system
|
|
|
|
* (FS) servers in response to VFS requests.
|
|
|
|
*
|
|
|
|
* The entry points into this file are
|
|
|
|
* nested_fs_call perform a nested call from a file system server
|
2010-08-30 15:44:07 +02:00
|
|
|
* nested_dev_call perform a nested call from a device driver server
|
|
|
|
*
|
2009-05-11 12:02:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include "fproc.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/endpoint.h>
|
2010-08-30 15:44:07 +02:00
|
|
|
#include <minix/vfsif.h>
|
2009-05-11 12:02:28 +02:00
|
|
|
|
|
|
|
/* maximum nested call stack depth */
|
|
|
|
#define MAX_DEPTH 1
|
|
|
|
|
|
|
|
/* global variables stack */
|
2012-03-25 20:25:53 +02:00
|
|
|
static struct {
|
2009-05-11 12:02:28 +02:00
|
|
|
struct fproc *g_fp; /* pointer to caller process */
|
|
|
|
message g_m_in; /* request message */
|
|
|
|
message g_m_out; /* reply message */
|
|
|
|
int g_who_e; /* endpoint of caller process */
|
|
|
|
int g_who_p; /* slot number of caller process */
|
|
|
|
int g_call_nr; /* call number */
|
|
|
|
int g_super_user; /* is the caller root? */
|
2011-09-12 11:00:24 +02:00
|
|
|
char g_user_fullpath[PATH_MAX]; /* path to look up */
|
2009-05-11 12:02:28 +02:00
|
|
|
} globals[MAX_DEPTH];
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int depth = 0; /* current globals stack level */
|
2009-05-11 12:02:28 +02:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int push_globals(void);
|
|
|
|
static void pop_globals(void);
|
|
|
|
static void set_globals(message *m);
|
2009-05-11 12:02:28 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* push_globals *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int push_globals()
|
2009-05-11 12:02:28 +02:00
|
|
|
{
|
|
|
|
/* Save the global variables of the current call onto the globals stack.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (depth == MAX_DEPTH)
|
2012-02-13 16:28:04 +01:00
|
|
|
return(EPERM);
|
2009-05-11 12:02:28 +02:00
|
|
|
|
|
|
|
globals[depth].g_fp = fp;
|
2012-04-13 14:50:38 +02:00
|
|
|
globals[depth].g_m_in = job_m_in;
|
2009-05-11 12:02:28 +02:00
|
|
|
globals[depth].g_m_out = m_out;
|
|
|
|
globals[depth].g_super_user = super_user;
|
|
|
|
|
|
|
|
/* err_code is not used across blocking calls */
|
|
|
|
depth++;
|
2012-02-13 16:28:04 +01:00
|
|
|
return(OK);
|
2009-05-11 12:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* pop_globals *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void pop_globals()
|
2009-05-11 12:02:28 +02:00
|
|
|
{
|
|
|
|
/* Restore the global variables of a call from the globals stack.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (depth == 0)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("Popping from empty globals stack!");
|
2009-05-11 12:02:28 +02:00
|
|
|
|
|
|
|
depth--;
|
|
|
|
|
|
|
|
fp = globals[depth].g_fp;
|
2012-04-13 14:50:38 +02:00
|
|
|
job_m_in = globals[depth].g_m_in;
|
2009-05-11 12:02:28 +02:00
|
|
|
m_out = globals[depth].g_m_out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* set_globals *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void set_globals(m)
|
2009-05-11 12:02:28 +02:00
|
|
|
message *m; /* request message */
|
|
|
|
{
|
|
|
|
/* Initialize global variables based on a request message.
|
|
|
|
*/
|
2012-02-13 16:28:04 +01:00
|
|
|
int proc_p;
|
2009-05-11 12:02:28 +02:00
|
|
|
|
|
|
|
m_in = *m;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
proc_p = _ENDPOINT_P(m_in.m_source);
|
|
|
|
fp = &fproc[proc_p];
|
|
|
|
|
2009-05-11 12:02:28 +02:00
|
|
|
/* the rest need not be initialized */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* nested_fs_call *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void nested_fs_call(m)
|
2009-05-11 12:02:28 +02:00
|
|
|
message *m; /* request/reply message pointer */
|
|
|
|
{
|
|
|
|
/* Handle a nested call from a file system server.
|
|
|
|
*/
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* Save global variables of the current call */
|
|
|
|
if ((r = push_globals()) != OK) {
|
|
|
|
printf("VFS: error saving global variables in call %d from FS %d\n",
|
|
|
|
m->m_type, m->m_source);
|
|
|
|
} else {
|
|
|
|
/* Initialize global variables for the nested call */
|
|
|
|
set_globals(m);
|
|
|
|
|
2010-09-14 23:50:05 +02:00
|
|
|
/* Perform the nested call - only getsysinfo() is allowed right now */
|
2012-04-13 14:50:38 +02:00
|
|
|
if (job_call_nr == COMMON_GETSYSINFO) {
|
2010-09-14 23:50:05 +02:00
|
|
|
r = do_getsysinfo();
|
|
|
|
} else {
|
2012-04-13 14:50:38 +02:00
|
|
|
printf("VFS: invalid nested call %d from FS %d\n", job_call_nr,
|
2009-05-11 12:02:28 +02:00
|
|
|
who_e);
|
|
|
|
|
|
|
|
r = ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the result, and restore original global variables */
|
|
|
|
*m = m_out;
|
|
|
|
|
|
|
|
pop_globals();
|
|
|
|
}
|
|
|
|
|
|
|
|
m->m_type = r;
|
|
|
|
}
|