minix/servers/vfs/request.c

1162 lines
28 KiB
C
Raw Normal View History

2007-08-07 14:52:47 +02:00
/* This file contains the wrapper functions for issueing a request
* and receiving response from FS processes.
* Each function builds a request message according to the request
* parameter, calls the most low-level fs_sendrec and copies
* back the response.
* The low-level fs_sendrec handles the recovery mechanism from
* a dead driver and reissues the request.
*/
#include "fs.h"
#include <string.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
#include <minix/vfsif.h>
2007-08-07 14:52:47 +02:00
#include <minix/com.h>
#include <minix/const.h>
#include <minix/endpoint.h>
#include <minix/u64.h>
#include <unistd.h>
#include <minix/vfsif.h>
#include "fproc.h"
#include "vmnt.h"
#include "vnode.h"
#include "param.h"
FORWARD _PROTOTYPE(int fs_sendrec_f, (char *file, int line, endpoint_t fs_e,
message *reqm) );
2007-08-07 14:52:47 +02:00
#define fs_sendrec(e, m) fs_sendrec_f(__FILE__, __LINE__, (e), (m))
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_breadwrite *
*===========================================================================*/
PUBLIC int req_breadwrite(
endpoint_t fs_e,
endpoint_t user_e,
dev_t dev,
u64_t pos,
unsigned int num_of_bytes,
char *user_addr,
int rw_flag,
u64_t *new_posp,
unsigned int *cum_iop
)
{
int r;
cp_grant_id_t grant_id;
message m;
grant_id = cpf_grant_magic(fs_e, user_e, (vir_bytes) user_addr, num_of_bytes,
(rw_flag == READING ? CPF_WRITE : CPF_READ));
if(grant_id == -1)
panic("req_breadwrite: cpf_grant_magic failed");
2007-08-07 14:52:47 +02:00
/* Fill in request message */
m.m_type = rw_flag == READING ? REQ_BREAD : REQ_BWRITE;
m.REQ_DEV2 = dev;
m.REQ_GRANT = grant_id;
m.REQ_SEEK_POS_LO = ex64lo(pos);
m.REQ_SEEK_POS_HI = ex64hi(pos);
m.REQ_NBYTES = num_of_bytes;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r != OK) return(r);
2007-08-07 14:52:47 +02:00
/* Fill in response structure */
*new_posp = make64(m.RES_SEEK_POS_LO, m.RES_SEEK_POS_HI);
*cum_iop = m.RES_NBYTES;
2007-08-07 14:52:47 +02:00
return(OK);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_chmod *
*===========================================================================*/
PUBLIC int req_chmod(
int fs_e,
ino_t inode_nr,
mode_t rmode,
mode_t *new_modep
)
{
message m;
int r;
/* Fill in request message */
m.m_type = REQ_CHMOD;
m.REQ_INODE_NR = inode_nr;
m.REQ_MODE = rmode;
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
/* Copy back actual mode. */
*new_modep = m.RES_MODE;
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
return(r);
}
/*===========================================================================*
* req_chown *
*===========================================================================*/
PUBLIC int req_chown(
endpoint_t fs_e,
ino_t inode_nr,
uid_t newuid,
gid_t newgid,
mode_t *new_modep
)
{
message m;
int r;
/* Fill in request message */
m.m_type = REQ_CHOWN;
m.REQ_INODE_NR = inode_nr;
m.REQ_UID = newuid;
m.REQ_GID = newgid;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
/* Return new mode to caller. */
*new_modep = m.RES_MODE;
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_create *
*===========================================================================*/
PUBLIC int req_create(
int fs_e,
ino_t inode_nr,
int omode,
uid_t uid,
gid_t gid,
char *path,
node_details_t *res
)
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
if (path[0] == '/')
panic("req_create: filename starts with '/'");
len = strlen(path) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) path, len, CPF_READ);
if (grant_id == -1)
panic("req_create: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_CREATE;
m.REQ_INODE_NR = inode_nr;
m.REQ_MODE = omode;
m.REQ_UID = uid;
m.REQ_GID = gid;
m.REQ_GRANT = grant_id;
m.REQ_PATH_LEN = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r != OK) return(r);
/* Fill in response structure */
res->fs_e = m.m_source;
res->inode_nr = m.RES_INODE_NR;
res->fmode = m.RES_MODE;
res->fsize = m.RES_FILE_SIZE_LO;
res->uid = m.RES_UID;
res->gid = m.RES_GID;
res->dev = m.RES_DEV;
return(OK);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_flush *
*===========================================================================*/
PUBLIC int req_flush(endpoint_t fs_e, dev_t dev)
{
message m;
/* Fill in request message */
m.m_type = REQ_FLUSH;
m.REQ_DEV = dev;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_fstatfs *
*===========================================================================*/
PUBLIC int req_fstatfs(int fs_e, int who_e, char *buf)
{
2007-01-05 17:36:55 +01:00
int r;
cp_grant_id_t grant_id;
2007-01-05 17:36:55 +01:00
message m;
grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf, sizeof(struct statfs),
CPF_WRITE);
if(grant_id == -1)
panic("req_fstatfs: cpf_grant_magic failed");
2007-01-05 17:36:55 +01:00
/* Fill in request message */
2007-08-07 14:52:47 +02:00
m.m_type = REQ_FSTATFS;
m.REQ_GRANT = grant_id;
2007-01-05 17:36:55 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
}
/*===========================================================================*
* req_statvfs *
*===========================================================================*/
PUBLIC int req_statvfs(int fs_e, int who_e, char *buf)
{
int r;
cp_grant_id_t grant_id;
message m;
grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf, sizeof(struct statvfs),
CPF_WRITE);
if(grant_id == -1)
panic("req_statvfs: cpf_grant_magic failed");
/* Fill in request message */
m.m_type = REQ_STATVFS;
m.REQ_GRANT = grant_id;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_ftrunc *
*===========================================================================*/
PUBLIC int req_ftrunc(endpoint_t fs_e, ino_t inode_nr, off_t start, off_t end)
{
message m;
/* Fill in request message */
m.m_type = REQ_FTRUNC;
m.REQ_INODE_NR = inode_nr;
m.REQ_TRC_START_LO = start;
m.REQ_TRC_START_HI = 0; /* Not used for now, so clear it. */
m.REQ_TRC_END_LO = end;
m.REQ_TRC_END_HI = 0; /* Not used for now, so clear it. */
/* Send/rec request */
return fs_sendrec(fs_e, &m);
2007-08-07 14:52:47 +02:00
}
2007-01-05 17:36:55 +01:00
2007-08-07 14:52:47 +02:00
/*===========================================================================*
* req_getdents *
*===========================================================================*/
PUBLIC int req_getdents(
endpoint_t fs_e,
ino_t inode_nr,
u64_t pos,
char *buf,
size_t size,
u64_t *new_pos
)
2007-08-07 14:52:47 +02:00
{
int r;
message m;
cp_grant_id_t grant_id;
grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf, size, CPF_WRITE);
if (grant_id < 0)
panic("req_getdents: cpf_grant_magic failed: %d", grant_id);
m.m_type = REQ_GETDENTS;
m.REQ_INODE_NR = inode_nr;
m.REQ_GRANT = grant_id;
m.REQ_MEM_SIZE = size;
m.REQ_SEEK_POS_LO = ex64lo(pos);
m.REQ_SEEK_POS_HI = 0; /* Not used for now, so clear it. */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r == OK) {
*new_pos = cvul64(m.RES_SEEK_POS_LO);
r = m.RES_NBYTES;
}
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_inhibread *
*===========================================================================*/
PUBLIC int req_inhibread(endpoint_t fs_e, ino_t inode_nr)
{
message m;
/* Fill in request message */
m.m_type = REQ_INHIBREAD;
m.REQ_INODE_NR = inode_nr;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_link *
*===========================================================================*/
PUBLIC int req_link(
endpoint_t fs_e,
ino_t link_parent,
char *lastc,
ino_t linked_file
)
{
int r;
cp_grant_id_t grant_id;
const size_t len = strlen(lastc) + 1;
message m;
grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_link: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_LINK;
m.REQ_INODE_NR = linked_file;
m.REQ_DIR_INO = link_parent;
m.REQ_GRANT = grant_id;
m.REQ_PATH_LEN = len;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
2007-08-07 14:52:47 +02:00
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_lookup *
*===========================================================================*/
PUBLIC int req_lookup(
endpoint_t fs_e,
ino_t dir_ino,
ino_t root_ino,
uid_t uid,
gid_t gid,
int flags,
lookup_res_t *res
)
{
int r;
size_t len;
cp_grant_id_t grant_id, grant_id2;
message m;
vfs_ucred_t credentials;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) user_fullpath,
sizeof(user_fullpath), CPF_READ | CPF_WRITE);
if(grant_id == -1)
panic("req_lookup: cpf_grant_direct failed");
len = strlen(user_fullpath) + 1;
m.m_type = REQ_LOOKUP;
m.REQ_GRANT = grant_id;
m.REQ_PATH_LEN = len;
m.REQ_PATH_SIZE = sizeof(user_fullpath);
m.REQ_DIR_INO = dir_ino;
m.REQ_ROOT_INO = root_ino;
if(fp->fp_ngroups > 0) { /* Is the process member of multiple groups? */
/* In that case the FS has to copy the uid/gid credentials */
int i;
/* Set credentials */
credentials.vu_uid = fp->fp_effuid;
credentials.vu_gid = fp->fp_effgid;
credentials.vu_ngroups = fp->fp_ngroups;
for (i = 0; i < fp->fp_ngroups; i++)
credentials.vu_sgroups[i] = fp->fp_sgroups[i];
grant_id2 = cpf_grant_direct(fs_e, (vir_bytes) &credentials,
sizeof(credentials), CPF_READ);
if(grant_id2 == -1)
panic("req_lookup: cpf_grant_direct failed");
m.REQ_GRANT2 = grant_id2;
m.REQ_UCRED_SIZE= sizeof(credentials);
flags |= PATH_GET_UCRED;
} else {
/* When there's only one gid, we can send it directly */
m.REQ_UID = uid;
m.REQ_GID = gid;
flags &= ~PATH_GET_UCRED;
}
m.REQ_FLAGS = flags;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if(fp->fp_ngroups > 0) cpf_revoke(grant_id2);
/* Fill in response according to the return value */
res->fs_e = m.m_source;
switch (r) {
case OK:
res->inode_nr = m.RES_INODE_NR;
res->fmode = m.RES_MODE;
res->fsize = m.RES_FILE_SIZE_LO;
res->dev = m.RES_DEV;
res->uid= m.RES_UID;
res->gid= m.RES_GID;
break;
case EENTERMOUNT:
res->inode_nr = m.RES_INODE_NR;
res->char_processed = m.RES_OFFSET;
res->symloop = m.RES_SYMLOOP;
break;
case ELEAVEMOUNT:
res->char_processed = m.RES_OFFSET;
res->symloop = m.RES_SYMLOOP;
break;
case ESYMLINK:
res->char_processed = m.RES_OFFSET;
res->symloop = m.RES_SYMLOOP;
break;
default:
break;
}
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_mkdir *
*===========================================================================*/
PUBLIC int req_mkdir(
endpoint_t fs_e,
ino_t inode_nr,
char *lastc,
uid_t uid,
gid_t gid,
mode_t dmode
)
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_mkdir: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_MKDIR;
m.REQ_INODE_NR = inode_nr;
m.REQ_MODE = dmode;
m.REQ_UID = uid;
m.REQ_GID = gid;
m.REQ_GRANT = grant_id;
m.REQ_PATH_LEN = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
}
/*===========================================================================*
2007-08-10 15:02:39 +02:00
* req_mknod *
*===========================================================================*/
PUBLIC int req_mknod(
endpoint_t fs_e,
ino_t inode_nr,
char *lastc,
uid_t uid,
gid_t gid,
mode_t dmode,
dev_t dev
)
{
int r;
size_t len;
cp_grant_id_t grant_id;
message m;
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_mknod: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_MKNOD;
m.REQ_INODE_NR = inode_nr;
m.REQ_MODE = dmode;
m.REQ_DEV = dev;
m.REQ_UID = uid;
m.REQ_GID = gid;
m.REQ_GRANT = grant_id;
m.REQ_PATH_LEN = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_mountpoint *
*===========================================================================*/
PUBLIC int req_mountpoint(endpoint_t fs_e, ino_t inode_nr)
{
message m;
/* Fill in request message */
m.m_type = REQ_MOUNTPOINT;
m.REQ_INODE_NR = inode_nr;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
2007-08-07 14:52:47 +02:00
/*===========================================================================*
2007-08-10 15:02:39 +02:00
* req_newnode *
*===========================================================================*/
PUBLIC int req_newnode(
endpoint_t fs_e,
uid_t uid,
gid_t gid,
mode_t dmode,
dev_t dev,
struct node_details *res
)
{
int r;
message m;
/* Fill in request message */
m.m_type = REQ_NEWNODE;
m.REQ_MODE = dmode;
m.REQ_DEV = dev;
m.REQ_UID = uid;
m.REQ_GID = gid;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
res->fs_e = m.m_source;
res->inode_nr = m.RES_INODE_NR;
res->fmode = m.RES_MODE;
res->fsize = m.RES_FILE_SIZE_LO;
res->dev = m.RES_DEV;
res->uid = m.RES_UID;
res->gid = m.RES_GID;
return(r);
}
2007-08-10 15:02:39 +02:00
/*===========================================================================*
* req_newdriver *
*===========================================================================*/
PUBLIC int req_newdriver(
endpoint_t fs_e,
dev_t dev,
endpoint_t driver_e
)
2007-08-10 15:02:39 +02:00
{
/* Note: this is the only request function that doesn't use the
* fs_sendrec internal routine, since we want to avoid the dead
* driver recovery mechanism here. This function is actually called
* during the recovery.
*/
message m;
int r;
/* Fill in request message */
m.m_type = REQ_NEW_DRIVER;
m.REQ_DEV = dev;
m.REQ_DRIVER_E = driver_e;
/* Issue request */
if((r = sendrec(fs_e, &m)) != OK) {
printf("%s:%d VFS req_newdriver: error sending message %d to %d\n",
__FILE__, __LINE__, r, fs_e);
util_stacktrace();
return(r);
}
return(OK);
2007-08-10 15:02:39 +02:00
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_putnode *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_putnode(fs_e, inode_nr, count)
int fs_e;
ino_t inode_nr;
int count;
{
message m;
/* Fill in request message */
m.m_type = REQ_PUTNODE;
m.REQ_INODE_NR = inode_nr;
m.REQ_COUNT = count;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_rdlink *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_rdlink(fs_e, inode_nr, who_e, buf, len)
endpoint_t fs_e;
ino_t inode_nr;
endpoint_t who_e;
char *buf;
2007-08-07 14:52:47 +02:00
size_t len;
{
message m;
int r;
cp_grant_id_t grant_id;
grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf, len, CPF_WRITE);
if(grant_id == -1)
panic("req_rdlink: cpf_grant_magic failed");
/* Fill in request message */
m.m_type = REQ_RDLINK;
m.REQ_INODE_NR = inode_nr;
m.REQ_GRANT = grant_id;
m.REQ_MEM_SIZE = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if(r == OK) r = m.RES_NBYTES;
2007-08-07 14:52:47 +02:00
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_readsuper *
*===========================================================================*/
PUBLIC int req_readsuper(
endpoint_t fs_e,
char *label,
dev_t dev,
int readonly,
int isroot,
struct node_details *res_nodep
)
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
len = strlen(label)+1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) label, len, CPF_READ);
if (grant_id == -1)
panic("req_readsuper: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_READSUPER;
m.REQ_FLAGS = 0;
if(readonly) m.REQ_FLAGS |= REQ_RDONLY;
if(isroot) m.REQ_FLAGS |= REQ_ISROOT;
m.REQ_GRANT = grant_id;
m.REQ_DEV = dev;
m.REQ_PATH_LEN = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if(r == OK) {
/* Fill in response structure */
res_nodep->fs_e = m.m_source;
res_nodep->inode_nr = m.RES_INODE_NR;
res_nodep->fmode = m.RES_MODE;
res_nodep->fsize = m.RES_FILE_SIZE_LO;
res_nodep->uid = m.RES_UID;
res_nodep->gid = m.RES_GID;
}
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_readwrite *
*===========================================================================*/
PUBLIC int req_readwrite(fs_e, inode_nr, pos, rw_flag, user_e,
2007-08-07 14:52:47 +02:00
user_addr, num_of_bytes, new_posp, cum_iop)
endpoint_t fs_e;
ino_t inode_nr;
u64_t pos;
int rw_flag;
endpoint_t user_e;
char *user_addr;
unsigned int num_of_bytes;
u64_t *new_posp;
unsigned int *cum_iop;
{
int r;
cp_grant_id_t grant_id;
message m;
2007-08-07 14:52:47 +02:00
if (ex64hi(pos) != 0)
panic("req_readwrite: pos too large");
2007-08-07 14:52:47 +02:00
grant_id = cpf_grant_magic(fs_e, user_e, (vir_bytes) user_addr, num_of_bytes,
(rw_flag==READING ? CPF_WRITE:CPF_READ));
if (grant_id == -1)
panic("req_readwrite: cpf_grant_magic failed");
/* Fill in request message */
m.m_type = rw_flag == READING ? REQ_READ : REQ_WRITE;
m.REQ_INODE_NR = inode_nr;
m.REQ_GRANT = grant_id;
m.REQ_SEEK_POS_LO = ex64lo(pos);
m.REQ_SEEK_POS_HI = 0; /* Not used for now, so clear it. */
m.REQ_NBYTES = num_of_bytes;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r == OK) {
/* Fill in response structure */
*new_posp = cvul64(m.RES_SEEK_POS_LO);
*cum_iop = m.RES_NBYTES;
}
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_rename *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_rename(fs_e, old_dir, old_name, new_dir, new_name)
endpoint_t fs_e;
ino_t old_dir;
char *old_name;
ino_t new_dir;
char *new_name;
{
int r;
cp_grant_id_t gid_old, gid_new;
size_t len_old, len_new;
message m;
len_old = strlen(old_name) + 1;
gid_old = cpf_grant_direct(fs_e, (vir_bytes) old_name, len_old, CPF_READ);
if(gid_old == -1)
panic("req_rename: cpf_grant_direct failed");
len_new = strlen(new_name) + 1;
gid_new = cpf_grant_direct(fs_e, (vir_bytes) new_name, len_new, CPF_READ);
if(gid_new == -1)
panic("req_rename: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_RENAME;
m.REQ_REN_OLD_DIR = old_dir;
m.REQ_REN_NEW_DIR = new_dir;
m.REQ_REN_GRANT_OLD = gid_old;
m.REQ_REN_LEN_OLD = len_old;
m.REQ_REN_GRANT_NEW = gid_new;
m.REQ_REN_LEN_NEW = len_new;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(gid_old);
cpf_revoke(gid_new);
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_rmdir *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_rmdir(fs_e, inode_nr, lastc)
endpoint_t fs_e;
ino_t inode_nr;
char *lastc;
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_rmdir: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_RMDIR;
m.REQ_INODE_NR = inode_nr;
m.REQ_GRANT = grant_id;
m.REQ_PATH_LEN = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2007-08-07 14:52:47 +02:00
return(r);
2007-08-07 14:52:47 +02:00
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_slink *
*===========================================================================*/
PUBLIC int req_slink(
endpoint_t fs_e,
ino_t inode_nr,
char *lastc,
endpoint_t who_e,
char *path_addr,
unsigned short path_length,
uid_t uid,
gid_t gid
)
{
int r;
size_t len;
cp_grant_id_t gid_name, gid_buf;
message m;
len = strlen(lastc) + 1;
gid_name = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
if(gid_name == -1)
panic("req_slink: cpf_grant_direct failed");
gid_buf = cpf_grant_magic(fs_e, who_e, (vir_bytes) path_addr, path_length,
CPF_READ);
if(gid_buf == -1) {
cpf_revoke(gid_name);
panic("req_slink: cpf_grant_magic failed");
}
/* Fill in request message */
m.m_type = REQ_SLINK;
m.REQ_INODE_NR = inode_nr;
m.REQ_UID = uid;
m.REQ_GID = gid;
m.REQ_GRANT = gid_name;
m.REQ_PATH_LEN = len;
m.REQ_GRANT3 = gid_buf;
m.REQ_MEM_SIZE = path_length;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(gid_name);
cpf_revoke(gid_buf);
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_stat *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_stat(fs_e, inode_nr, who_e, buf, pos)
int fs_e;
ino_t inode_nr;
int who_e;
char *buf;
int pos;
{
cp_grant_id_t grant_id;
2007-08-07 14:52:47 +02:00
int r;
message m;
struct stat sb;
2007-08-07 14:52:47 +02:00
if (pos != 0)
grant_id = cpf_grant_direct(fs_e, (vir_bytes) &sb,
sizeof(struct stat), CPF_WRITE);
2007-08-07 14:52:47 +02:00
else
grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf,
sizeof(struct stat), CPF_WRITE);
if (grant_id < 0)
panic("req_stat: cpf_grant_* failed");
2007-08-07 14:52:47 +02:00
/* Fill in request message */
m.m_type = REQ_STAT;
m.REQ_INODE_NR = inode_nr;
m.REQ_GRANT = grant_id;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2007-08-07 14:52:47 +02:00
if (r == OK && pos != 0) {
sb.st_size -= pos;
r = sys_vircopy(SELF, D, (vir_bytes) &sb, who_e, D, (vir_bytes) buf,
sizeof(struct stat));
2007-08-07 14:52:47 +02:00
}
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_sync *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_sync(fs_e)
endpoint_t fs_e;
{
message m;
/* Fill in request message */
m.m_type = REQ_SYNC;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
2007-08-07 14:52:47 +02:00
}
2007-08-07 14:52:47 +02:00
/*===========================================================================*
* req_unlink *
*===========================================================================*/
PUBLIC int req_unlink(fs_e, inode_nr, lastc)
endpoint_t fs_e;
ino_t inode_nr;
2007-08-07 14:52:47 +02:00
char *lastc;
{
cp_grant_id_t grant_id;
size_t len;
int r;
message m;
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_unlink: cpf_grant_direct failed");
2007-08-07 14:52:47 +02:00
/* Fill in request message */
m.m_type = REQ_UNLINK;
m.REQ_INODE_NR = inode_nr;
m.REQ_GRANT = grant_id;
m.REQ_PATH_LEN = len;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_unmount *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_unmount(fs_e)
endpoint_t fs_e;
{
message m;
/* Fill in request message */
m.m_type = REQ_UNMOUNT;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_utime *
*===========================================================================*/
2007-08-07 14:52:47 +02:00
PUBLIC int req_utime(fs_e, inode_nr, actime, modtime)
endpoint_t fs_e;
ino_t inode_nr;
time_t actime;
time_t modtime;
{
message m;
/* Fill in request message */
m.m_type = REQ_UTIME;
m.REQ_INODE_NR = inode_nr;
m.REQ_ACTIME = actime;
m.REQ_MODTIME = modtime;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
2007-08-07 14:52:47 +02:00
}
/*===========================================================================*
* fs_sendrec *
*===========================================================================*/
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
PRIVATE int fs_sendrec_f(char *file, int line, endpoint_t fs_e, message *reqm)
{
/* This is the low level function that sends requests to FS processes.
* It also handles driver recovery mechanism and reissuing the
* request which failed due to a dead driver.
*/
int r, old_driver_e;
message origm, m;
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
if(fs_e <= 0 || fs_e == NONE)
panic("talking to bogus endpoint: %d", fs_e);
2007-08-07 14:52:47 +02:00
/* Make a copy of the request so that we can load it back in
* case of a dead driver */
origm = *reqm;
/* In response to the request we sent, some file systems may send back their
* own VFS request, instead of a reply. VFS currently offers limited support
* for this. As long as the FS keeps sending requests, we process them and
* send back a reply. We break out of the loop as soon as the FS sends a
* reply to the original request.
*
* There is no form of locking or whatever on global data structures, so it
* is quite easy to mess things up; hence, 'limited' support. A future async
* VFS will solve this problem for good.
*/
for (;;) {
/* Do the actual send, receive */
if (OK != (r = sendrec(fs_e, reqm))) {
printf("VFS:fs_sendrec:%s:%d: error sending message. "
"FS_e: %d req_nr: %d err: %d\n", file, line, fs_e,
reqm->m_type, r);
util_stacktrace();
return(r);
}
/* If the type field is 0 (OK) or negative (E*), this is a reply. If it
* contains a positive nonzero value, this is a request.
*/
if (reqm->m_type <= 0)
break; /* Reply */
if (reqm->m_type == -EENTERMOUNT || reqm->m_type == -ELEAVEMOUNT ||
reqm->m_type == -ESYMLINK) {
reqm->m_type = -reqm->m_type;
break; /* Reply */
}
/* Request */
nested_fs_call(reqm);
}
2009-01-26 14:02:41 +01:00
#if 0
if(r == OK) {
/* Sendrec was okay */
break;
}
/* Dead driver */
if (r == EDEADSRCDST || r == EDSTDIED || r == ESRCDIED) {
old_driver_e = NONE;
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
/* Find old driver by endpoint */
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
if (vmp->m_fs_e == fs_e) { /* found FS */
#if 0
old_driver_e = vmp->m_driver_e;
#endif
dmap_unmap_by_endpt(old_driver_e); /* unmap driver */
break;
}
}
/* No FS ?? */
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
if (old_driver_e == NONE)
panic("VFSdead_driver: couldn't find FS: %d", fs_e);
/* Wait for a new driver. */
for (;;) {
new_driver_e = 0;
printf("VFSdead_driver: waiting for new driver\n");
Basic System Event Framework (SEF) with ping and live update. SYSLIB CHANGES: - SEF must be used by every system process and is thereby part of the system library. - The framework provides a receive() interface (sef_receive) for system processes to automatically catch known system even messages and process them. - SEF provides a default behavior for each type of system event, but allows system processes to register callbacks to override the default behavior. - Custom (local to the process) or predefined (provided by SEF) callback implementations can be registered to SEF. - SEF currently includes support for 2 types of system events: 1. SEF Ping. The event occurs every time RS sends a ping to figure out whether a system process is still alive. The default callback implementation provided by SEF is to notify RS back to let it know the process is alive and kicking. 2. SEF Live update. The event occurs every time RS sends a prepare to update message to let a system process know an update is available and to prepare for it. The live update support is very basic for now. SEF only deals with verifying if the prepare state can be supported by the process, dumping the state for debugging purposes, and providing an event-driven programming model to the process to react to state changes check-in when ready to update. - SEF should be extended in the future to integrate support for more types of system events. Ideally, all the cross-cutting concerns should be integrated into SEF to avoid duplicating code and ease extensibility. Examples include: * PM notify messages primarily used at shutdown. * SYSTEM notify messages primarily used for signals. * CLOCK notify messages used for system alarms. * Debug messages. IS could still be in charge of fkey handling but would forward the debug message to the target process (e.g. PM, if the user requested debug information about PM). SEF would then catch the message and do nothing unless the process has registered an appropriate callback to deal with the event. This simplifies the programming model to print debug information, avoids duplicating code, and reduces the effort to print debug information. SYSTEM PROCESSES CHANGES: - Every system process registers SEF callbacks it needs to override the default system behavior and calls sef_startup() right after being started. - sef_startup() does almost nothing now, but will be extended in the future to support callbacks of its own to let RS control and synchronize with every system process at initialization time. - Every system process calls sef_receive() now rather than receive() directly, to let SEF handle predefined system events. RS CHANGES: - RS supports a basic single-component live update protocol now, as follows: * When an update command is issued (via "service update *"), RS notifies the target system process to prepare for a specific update state. * If the process doesn't respond back in time, the update is aborted. * When the process responds back, RS kills it and marks it for refreshing. * The process is then automatically restarted as for a buggy process and can start running again. * Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
r = sef_receive(RS_PROC_NR, &m);
if (r != OK) {
panic("VFSdead_driver: unable to receive from RS: %d", r);
}
if (m.m_type == DEVCTL) {
/* Map new driver */
r = fs_devctl(m.ctl_req, m.dev_nr, m.driver_nr,
m.dev_style, m.m_force);
if (m.ctl_req == DEV_MAP && r == OK) {
new_driver_e = m.driver_nr;
printf("VFSdead_driver: new driver endpoint: %d\n",
new_driver_e);
}
}
else {
panic("VFSdead_driver: got message from RS type: %d", m.m_type);
}
m.m_type = r;
if ((r = send(RS_PROC_NR, &m)) != OK) {
panic("VFSdead_driver: unable to send to RS: %d", r);
}
/* New driver is ready */
if (new_driver_e) break;
}
/* Copy back original request */
*reqm = origm;
continue;
}
printf("fs_sendrec: unhandled error %d sending to %d\n", r, fs_e);
panic("fs_sendrec: unhandled error");
}
2009-01-26 14:02:41 +01:00
#endif
/* Return message type */
return(reqm->m_type);
}