/*===========================================================================* * req_flush * *===========================================================================*/ 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; /* Send/rec request */ return fs_sendrec(fs_e, &m); }
/*===========================================================================* * 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); }
/*===========================================================================* * 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); }
/*===========================================================================* * 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); }
/*===========================================================================* * 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); }
/*===========================================================================* * req_bpeek * *===========================================================================*/ int req_bpeek(endpoint_t fs_e, dev_t dev, u64_t pos, unsigned int num_of_bytes) { message m; memset(&m, 0, sizeof(m)); /* Fill in request message */ m.m_type = REQ_BPEEK; m.REQ_DEV2 = dev; m.REQ_SEEK_POS_LO = ex64lo(pos); m.REQ_SEEK_POS_HI = ex64hi(pos); m.REQ_NBYTES = num_of_bytes; /* Send/rec request */ return fs_sendrec(fs_e, &m); return(OK); }
/*===========================================================================* * 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, int direct ) { int r; message m; cp_grant_id_t grant_id; if (direct) { grant_id = cpf_grant_direct(fs_e, (vir_bytes) buf, size, CPF_WRITE); } else { grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf, size, CPF_WRITE); } if (grant_id < 0) panic("req_getdents: cpf_grant_direct/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); }
/*===========================================================================* * 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); }
/*===========================================================================* * req_statvfs * *===========================================================================*/ int req_statvfs(endpoint_t fs_e, endpoint_t proc_e, vir_bytes buf) { int r; cp_grant_id_t grant_id; message m; grant_id = cpf_grant_magic(fs_e, proc_e, buf, sizeof(struct statvfs), CPF_WRITE); if(grant_id == GRANT_INVALID) 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); }
/*===========================================================================* * 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"); /* 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; /* Send/rec request */ r = fs_sendrec(fs_e, &m); cpf_revoke(grant_id); if (r != OK) return(r); /* Fill in response structure */ *new_posp = make64(m.RES_SEEK_POS_LO, m.RES_SEEK_POS_HI); *cum_iop = m.RES_NBYTES; return(OK); }
/*===========================================================================* * 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; /* Send/rec request */ r = fs_sendrec(fs_e, &m); /* Copy back actual mode. */ *new_modep = m.RES_MODE; return(r); }
/*===========================================================================* * 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); }
/*===========================================================================* * 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, struct fproc *rfp ) { 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(rfp->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 = rfp->fp_effuid; credentials.vu_gid = rfp->fp_effgid; credentials.vu_ngroups = rfp->fp_ngroups; for (i = 0; i < rfp->fp_ngroups; i++) credentials.vu_sgroups[i] = rfp->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; /* Send/rec request */ r = fs_sendrec(fs_e, &m); cpf_revoke(grant_id); if(rfp->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); }