retire 64-bit conversion functions
[minix3.git] / servers / vfs / request.c
blob71ea86ae2858bfaf7fbe7953cdff046628562a28
1 /* This file contains the wrapper functions for issuing a request
2 * and receiving response from FS processes.
3 * Each function builds a request message according to the request
4 * parameter, calls the most low-level fs_sendrec, and copies
5 * back the response.
6 */
8 #include "fs.h"
9 #include <string.h>
10 #include <assert.h>
11 #include <sys/stat.h>
12 #include <sys/statfs.h>
13 #include <sys/statvfs.h>
14 #include <minix/vfsif.h>
15 #include <minix/com.h>
16 #include <minix/const.h>
17 #include <minix/endpoint.h>
18 #include <minix/u64.h>
19 #include <unistd.h>
20 #include <time.h>
21 #include "fproc.h"
22 #include "vmnt.h"
23 #include "vnode.h"
24 #include "path.h"
25 #include "param.h"
28 /*===========================================================================*
29 * req_breadwrite *
30 *===========================================================================*/
31 int req_breadwrite(
32 endpoint_t fs_e,
33 endpoint_t user_e,
34 dev_t dev,
35 u64_t pos,
36 unsigned int num_of_bytes,
37 char *user_addr,
38 int rw_flag,
39 u64_t *new_posp,
40 unsigned int *cum_iop
43 int r;
44 cp_grant_id_t grant_id;
45 message m;
47 grant_id = cpf_grant_magic(fs_e, user_e, (vir_bytes) user_addr, num_of_bytes,
48 (rw_flag == READING ? CPF_WRITE : CPF_READ));
49 if(grant_id == -1)
50 panic("req_breadwrite: cpf_grant_magic failed");
52 /* Fill in request message */
53 m.m_type = rw_flag == READING ? REQ_BREAD : REQ_BWRITE;
54 m.REQ_DEV2 = dev;
55 m.REQ_GRANT = grant_id;
56 m.REQ_SEEK_POS_LO = ex64lo(pos);
57 m.REQ_SEEK_POS_HI = ex64hi(pos);
58 m.REQ_NBYTES = num_of_bytes;
60 /* Send/rec request */
61 r = fs_sendrec(fs_e, &m);
62 cpf_revoke(grant_id);
63 if (r != OK) return(r);
65 /* Fill in response structure */
66 *new_posp = make64(m.RES_SEEK_POS_LO, m.RES_SEEK_POS_HI);
67 *cum_iop = m.RES_NBYTES;
69 return(OK);
72 /*===========================================================================*
73 * req_bpeek *
74 *===========================================================================*/
75 int req_bpeek(endpoint_t fs_e, dev_t dev, u64_t pos, unsigned int num_of_bytes)
77 message m;
79 memset(&m, 0, sizeof(m));
81 /* Fill in request message */
82 m.m_type = REQ_BPEEK;
83 m.REQ_DEV2 = dev;
84 m.REQ_SEEK_POS_LO = ex64lo(pos);
85 m.REQ_SEEK_POS_HI = ex64hi(pos);
86 m.REQ_NBYTES = num_of_bytes;
88 /* Send/rec request */
89 return fs_sendrec(fs_e, &m);
91 return(OK);
94 /*===========================================================================*
95 * req_chmod *
96 *===========================================================================*/
97 int req_chmod(
98 int fs_e,
99 ino_t inode_nr,
100 mode_t rmode,
101 mode_t *new_modep
104 message m;
105 int r;
107 /* Fill in request message */
108 m.m_type = REQ_CHMOD;
109 m.REQ_INODE_NR = inode_nr;
110 m.REQ_MODE = rmode;
112 /* Send/rec request */
113 r = fs_sendrec(fs_e, &m);
115 /* Copy back actual mode. */
116 *new_modep = m.RES_MODE;
118 return(r);
122 /*===========================================================================*
123 * req_chown *
124 *===========================================================================*/
125 int req_chown(
126 endpoint_t fs_e,
127 ino_t inode_nr,
128 uid_t newuid,
129 gid_t newgid,
130 mode_t *new_modep
133 message m;
134 int r;
136 /* Fill in request message */
137 m.m_type = REQ_CHOWN;
138 m.REQ_INODE_NR = inode_nr;
139 m.REQ_UID = newuid;
140 m.REQ_GID = newgid;
142 /* Send/rec request */
143 r = fs_sendrec(fs_e, &m);
145 /* Return new mode to caller. */
146 *new_modep = m.RES_MODE;
148 return(r);
152 /*===========================================================================*
153 * req_create *
154 *===========================================================================*/
155 int req_create(
156 int fs_e,
157 ino_t inode_nr,
158 int omode,
159 uid_t uid,
160 gid_t gid,
161 char *path,
162 node_details_t *res
165 int r;
166 cp_grant_id_t grant_id;
167 size_t len;
168 message m;
170 if (path[0] == '/')
171 panic("req_create: filename starts with '/'");
173 len = strlen(path) + 1;
174 grant_id = cpf_grant_direct(fs_e, (vir_bytes) path, len, CPF_READ);
175 if (grant_id == -1)
176 panic("req_create: cpf_grant_direct failed");
178 /* Fill in request message */
179 m.m_type = REQ_CREATE;
180 m.REQ_INODE_NR = inode_nr;
181 m.REQ_MODE = omode;
182 m.REQ_UID = uid;
183 m.REQ_GID = gid;
184 m.REQ_GRANT = grant_id;
185 m.REQ_PATH_LEN = len;
187 /* Send/rec request */
188 r = fs_sendrec(fs_e, &m);
189 cpf_revoke(grant_id);
190 if (r != OK) return(r);
192 /* Fill in response structure */
193 res->fs_e = m.m_source;
194 res->inode_nr = m.RES_INODE_NR;
195 res->fmode = m.RES_MODE;
196 res->fsize = m.RES_FILE_SIZE_LO;
197 res->uid = m.RES_UID;
198 res->gid = m.RES_GID;
199 res->dev = NO_DEV;
201 return(OK);
205 /*===========================================================================*
206 * req_flush *
207 *===========================================================================*/
208 int req_flush(endpoint_t fs_e, dev_t dev)
210 message m;
212 /* Fill in request message */
213 m.m_type = REQ_FLUSH;
214 m.REQ_DEV = dev;
216 /* Send/rec request */
217 return fs_sendrec(fs_e, &m);
221 /*===========================================================================*
222 * req_fstatfs *
223 *===========================================================================*/
224 int req_fstatfs(endpoint_t fs_e, endpoint_t proc_e, vir_bytes buf)
226 int r;
227 cp_grant_id_t grant_id;
228 message m;
230 grant_id = cpf_grant_magic(fs_e, proc_e, buf, sizeof(struct statfs),
231 CPF_WRITE);
232 if (grant_id == GRANT_INVALID)
233 panic("req_fstatfs: cpf_grant_magic failed");
235 /* Fill in request message */
236 m.m_type = REQ_FSTATFS;
237 m.REQ_GRANT = grant_id;
239 /* Send/rec request */
240 r = fs_sendrec(fs_e, &m);
241 cpf_revoke(grant_id);
243 return(r);
247 /*===========================================================================*
248 * req_statvfs *
249 *===========================================================================*/
250 int req_statvfs(endpoint_t fs_e, endpoint_t proc_e, vir_bytes buf)
252 int r;
253 cp_grant_id_t grant_id;
254 message m;
256 grant_id = cpf_grant_magic(fs_e, proc_e, buf, sizeof(struct statvfs),
257 CPF_WRITE);
258 if(grant_id == GRANT_INVALID)
259 panic("req_statvfs: cpf_grant_magic failed");
261 /* Fill in request message */
262 m.m_type = REQ_STATVFS;
263 m.REQ_GRANT = grant_id;
265 /* Send/rec request */
266 r = fs_sendrec(fs_e, &m);
267 cpf_revoke(grant_id);
269 return(r);
273 /*===========================================================================*
274 * req_ftrunc *
275 *===========================================================================*/
276 int req_ftrunc(endpoint_t fs_e, ino_t inode_nr, off_t start, off_t end)
278 message m;
280 /* Fill in request message */
281 m.m_type = REQ_FTRUNC;
282 m.REQ_INODE_NR = inode_nr;
283 m.REQ_TRC_START_LO = start;
284 m.REQ_TRC_START_HI = 0; /* Not used for now, so clear it. */
285 m.REQ_TRC_END_LO = end;
286 m.REQ_TRC_END_HI = 0; /* Not used for now, so clear it. */
288 /* Send/rec request */
289 return fs_sendrec(fs_e, &m);
293 /*===========================================================================*
294 * req_getdents *
295 *===========================================================================*/
296 int req_getdents(
297 endpoint_t fs_e,
298 ino_t inode_nr,
299 u64_t pos,
300 char *buf,
301 size_t size,
302 u64_t *new_pos,
303 int direct
306 int r;
307 message m;
308 cp_grant_id_t grant_id;
310 if (direct) {
311 grant_id = cpf_grant_direct(fs_e, (vir_bytes) buf, size,
312 CPF_WRITE);
313 } else {
314 grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf, size,
315 CPF_WRITE);
318 if (grant_id < 0)
319 panic("req_getdents: cpf_grant_direct/cpf_grant_magic failed: %d",
320 grant_id);
322 m.m_type = REQ_GETDENTS;
323 m.REQ_INODE_NR = inode_nr;
324 m.REQ_GRANT = grant_id;
325 m.REQ_MEM_SIZE = size;
326 m.REQ_SEEK_POS_LO = ex64lo(pos);
327 m.REQ_SEEK_POS_HI = 0; /* Not used for now, so clear it. */
329 r = fs_sendrec(fs_e, &m);
330 cpf_revoke(grant_id);
332 if (r == OK) {
333 *new_pos = ((u64_t)(m.RES_SEEK_POS_LO));
334 r = m.RES_NBYTES;
337 return(r);
340 /*===========================================================================*
341 * req_inhibread *
342 *===========================================================================*/
343 int req_inhibread(endpoint_t fs_e, ino_t inode_nr)
345 message m;
347 /* Fill in request message */
348 m.m_type = REQ_INHIBREAD;
349 m.REQ_INODE_NR = inode_nr;
351 /* Send/rec request */
352 return fs_sendrec(fs_e, &m);
356 /*===========================================================================*
357 * req_link *
358 *===========================================================================*/
359 int req_link(
360 endpoint_t fs_e,
361 ino_t link_parent,
362 char *lastc,
363 ino_t linked_file
366 int r;
367 cp_grant_id_t grant_id;
368 const size_t len = strlen(lastc) + 1;
369 message m;
371 grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
372 if(grant_id == -1)
373 panic("req_link: cpf_grant_direct failed");
375 /* Fill in request message */
376 m.m_type = REQ_LINK;
377 m.REQ_INODE_NR = linked_file;
378 m.REQ_DIR_INO = link_parent;
379 m.REQ_GRANT = grant_id;
380 m.REQ_PATH_LEN = len;
382 /* Send/rec request */
383 r = fs_sendrec(fs_e, &m);
384 cpf_revoke(grant_id);
386 return(r);
390 /*===========================================================================*
391 * req_lookup *
392 *===========================================================================*/
393 int req_lookup(
394 endpoint_t fs_e,
395 ino_t dir_ino,
396 ino_t root_ino,
397 uid_t uid,
398 gid_t gid,
399 struct lookup *resolve,
400 lookup_res_t *res,
401 struct fproc *rfp
404 int r;
405 size_t len;
406 cp_grant_id_t grant_id=0, grant_id2=0;
407 message m;
408 vfs_ucred_t credentials;
409 int flags;
411 grant_id = cpf_grant_direct(fs_e, (vir_bytes) resolve->l_path, PATH_MAX,
412 CPF_READ | CPF_WRITE);
413 if(grant_id == -1)
414 panic("req_lookup: cpf_grant_direct failed");
416 flags = resolve->l_flags;
417 len = strlen(resolve->l_path) + 1;
419 m.m_type = REQ_LOOKUP;
420 m.REQ_GRANT = grant_id;
421 m.REQ_PATH_LEN = len;
422 m.REQ_PATH_SIZE = PATH_MAX + 1;
423 m.REQ_DIR_INO = dir_ino;
424 m.REQ_ROOT_INO = root_ino;
426 if(rfp->fp_ngroups > 0) { /* Is the process member of multiple groups? */
427 /* In that case the FS has to copy the uid/gid credentials */
428 int i;
430 /* Set credentials */
431 credentials.vu_uid = rfp->fp_effuid;
432 credentials.vu_gid = rfp->fp_effgid;
433 credentials.vu_ngroups = rfp->fp_ngroups;
434 for (i = 0; i < rfp->fp_ngroups; i++)
435 credentials.vu_sgroups[i] = rfp->fp_sgroups[i];
437 grant_id2 = cpf_grant_direct(fs_e, (vir_bytes) &credentials,
438 sizeof(credentials), CPF_READ);
439 if(grant_id2 == -1)
440 panic("req_lookup: cpf_grant_direct failed");
442 m.REQ_GRANT2 = grant_id2;
443 m.REQ_UCRED_SIZE= sizeof(credentials);
444 flags |= PATH_GET_UCRED;
445 } else {
446 /* When there's only one gid, we can send it directly */
447 m.REQ_UID = uid;
448 m.REQ_GID = gid;
449 flags &= ~PATH_GET_UCRED;
452 m.REQ_FLAGS = flags;
454 /* Send/rec request */
455 r = fs_sendrec(fs_e, &m);
456 cpf_revoke(grant_id);
457 if(rfp->fp_ngroups > 0) cpf_revoke(grant_id2);
459 /* Fill in response according to the return value */
460 res->fs_e = m.m_source;
462 switch (r) {
463 case OK:
464 res->inode_nr = m.RES_INODE_NR;
465 res->fmode = m.RES_MODE;
466 res->fsize = m.RES_FILE_SIZE_LO;
467 res->dev = m.RES_DEV;
468 res->uid= m.RES_UID;
469 res->gid= m.RES_GID;
470 break;
471 case EENTERMOUNT:
472 res->inode_nr = m.RES_INODE_NR;
473 res->char_processed = m.RES_OFFSET;
474 res->symloop = m.RES_SYMLOOP;
475 break;
476 case ELEAVEMOUNT:
477 res->char_processed = m.RES_OFFSET;
478 res->symloop = m.RES_SYMLOOP;
479 break;
480 case ESYMLINK:
481 res->char_processed = m.RES_OFFSET;
482 res->symloop = m.RES_SYMLOOP;
483 break;
484 default:
485 break;
488 return(r);
492 /*===========================================================================*
493 * req_mkdir *
494 *===========================================================================*/
495 int req_mkdir(
496 endpoint_t fs_e,
497 ino_t inode_nr,
498 char *lastc,
499 uid_t uid,
500 gid_t gid,
501 mode_t dmode
504 int r;
505 cp_grant_id_t grant_id;
506 size_t len;
507 message m;
509 len = strlen(lastc) + 1;
510 grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
511 if(grant_id == -1)
512 panic("req_mkdir: cpf_grant_direct failed");
514 /* Fill in request message */
515 m.m_type = REQ_MKDIR;
516 m.REQ_INODE_NR = inode_nr;
517 m.REQ_MODE = dmode;
518 m.REQ_UID = uid;
519 m.REQ_GID = gid;
520 m.REQ_GRANT = grant_id;
521 m.REQ_PATH_LEN = len;
523 /* Send/rec request */
524 r = fs_sendrec(fs_e, &m);
525 cpf_revoke(grant_id);
527 return(r);
531 /*===========================================================================*
532 * req_mknod *
533 *===========================================================================*/
534 int req_mknod(
535 endpoint_t fs_e,
536 ino_t inode_nr,
537 char *lastc,
538 uid_t uid,
539 gid_t gid,
540 mode_t dmode,
541 dev_t dev
544 int r;
545 size_t len;
546 cp_grant_id_t grant_id;
547 message m;
549 len = strlen(lastc) + 1;
550 grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
551 if(grant_id == -1)
552 panic("req_mknod: cpf_grant_direct failed");
554 /* Fill in request message */
555 m.m_type = REQ_MKNOD;
556 m.REQ_INODE_NR = inode_nr;
557 m.REQ_MODE = dmode;
558 m.REQ_DEV = dev;
559 m.REQ_UID = uid;
560 m.REQ_GID = gid;
561 m.REQ_GRANT = grant_id;
562 m.REQ_PATH_LEN = len;
564 /* Send/rec request */
565 r = fs_sendrec(fs_e, &m);
566 cpf_revoke(grant_id);
568 return(r);
572 /*===========================================================================*
573 * req_mountpoint *
574 *===========================================================================*/
575 int req_mountpoint(endpoint_t fs_e, ino_t inode_nr)
577 message m;
579 /* Fill in request message */
580 m.m_type = REQ_MOUNTPOINT;
581 m.REQ_INODE_NR = inode_nr;
583 /* Send/rec request */
584 return fs_sendrec(fs_e, &m);
588 /*===========================================================================*
589 * req_newnode *
590 *===========================================================================*/
591 int req_newnode(
592 endpoint_t fs_e,
593 uid_t uid,
594 gid_t gid,
595 mode_t dmode,
596 dev_t dev,
597 struct node_details *res
600 int r;
601 message m;
603 /* Fill in request message */
604 m.m_type = REQ_NEWNODE;
605 m.REQ_MODE = dmode;
606 m.REQ_DEV = dev;
607 m.REQ_UID = uid;
608 m.REQ_GID = gid;
610 /* Send/rec request */
611 r = fs_sendrec(fs_e, &m);
613 res->fs_e = m.m_source;
614 res->inode_nr = m.RES_INODE_NR;
615 res->fmode = m.RES_MODE;
616 res->fsize = m.RES_FILE_SIZE_LO;
617 res->dev = m.RES_DEV;
618 res->uid = m.RES_UID;
619 res->gid = m.RES_GID;
621 return(r);
625 /*===========================================================================*
626 * req_newdriver *
627 *===========================================================================*/
628 int req_newdriver(
629 endpoint_t fs_e,
630 dev_t dev,
631 char *label
634 cp_grant_id_t grant_id;
635 size_t len;
636 message m;
637 int r;
639 /* Grant access to label */
640 len = strlen(label) + 1;
641 grant_id = cpf_grant_direct(fs_e, (vir_bytes) label, len, CPF_READ);
642 if (grant_id == -1)
643 panic("req_newdriver: cpf_grant_direct failed");
645 /* Fill in request message */
646 m.m_type = REQ_NEW_DRIVER;
647 m.REQ_DEV = dev;
648 m.REQ_GRANT = grant_id;
649 m.REQ_PATH_LEN = len;
651 /* Issue request */
652 r = fs_sendrec(fs_e, &m);
654 cpf_revoke(grant_id);
656 return(r);
660 /*===========================================================================*
661 * req_putnode *
662 *===========================================================================*/
663 int req_putnode(fs_e, inode_nr, count)
664 int fs_e;
665 ino_t inode_nr;
666 int count;
668 message m;
670 /* Fill in request message */
671 m.m_type = REQ_PUTNODE;
672 m.REQ_INODE_NR = inode_nr;
673 m.REQ_COUNT = count;
675 /* Send/rec request */
676 return fs_sendrec(fs_e, &m);
680 /*===========================================================================*
681 * req_rdlink *
682 *===========================================================================*/
683 int req_rdlink(fs_e, inode_nr, proc_e, buf, len, direct)
684 endpoint_t fs_e;
685 ino_t inode_nr;
686 endpoint_t proc_e;
687 vir_bytes buf;
688 size_t len;
689 int direct; /* set to 1 to use direct grants instead of magic grants */
691 message m;
692 int r;
693 cp_grant_id_t grant_id;
695 if (direct) {
696 grant_id = cpf_grant_direct(fs_e, buf, len, CPF_WRITE);
697 } else {
698 grant_id = cpf_grant_magic(fs_e, proc_e, buf, len, CPF_WRITE);
700 if (grant_id == -1)
701 panic("req_rdlink: cpf_grant_magic failed");
703 /* Fill in request message */
704 m.m_type = REQ_RDLINK;
705 m.REQ_INODE_NR = inode_nr;
706 m.REQ_GRANT = grant_id;
707 m.REQ_MEM_SIZE = len;
709 /* Send/rec request */
710 r = fs_sendrec(fs_e, &m);
711 cpf_revoke(grant_id);
713 if (r == OK) r = m.RES_NBYTES;
715 return(r);
719 /*===========================================================================*
720 * req_readsuper *
721 *===========================================================================*/
722 int req_readsuper(
723 endpoint_t fs_e,
724 char *label,
725 dev_t dev,
726 int readonly,
727 int isroot,
728 struct node_details *res_nodep,
729 int *con_reqs
732 int r;
733 cp_grant_id_t grant_id;
734 size_t len;
735 message m;
737 len = strlen(label)+1;
738 grant_id = cpf_grant_direct(fs_e, (vir_bytes) label, len, CPF_READ);
739 if (grant_id == -1)
740 panic("req_readsuper: cpf_grant_direct failed");
742 /* Fill in request message */
743 m.m_type = REQ_READSUPER;
744 m.REQ_FLAGS = 0;
745 if(readonly) m.REQ_FLAGS |= REQ_RDONLY;
746 if(isroot) m.REQ_FLAGS |= REQ_ISROOT;
747 m.REQ_GRANT = grant_id;
748 m.REQ_DEV = dev;
749 m.REQ_PATH_LEN = len;
751 /* Send/rec request */
752 r = fs_sendrec(fs_e, &m);
753 cpf_revoke(grant_id);
755 if(r == OK) {
756 /* Fill in response structure */
757 res_nodep->fs_e = m.m_source;
758 res_nodep->inode_nr = m.RES_INODE_NR;
759 res_nodep->fmode = m.RES_MODE;
760 res_nodep->fsize = m.RES_FILE_SIZE_LO;
761 res_nodep->uid = m.RES_UID;
762 res_nodep->gid = m.RES_GID;
763 *con_reqs = m.RES_CONREQS;
766 return(r);
770 /*===========================================================================*
771 * req_readwrite *
772 *===========================================================================*/
773 int req_readwrite(fs_e, inode_nr, pos, rw_flag, user_e,
774 user_addr, num_of_bytes, new_posp, cum_iop)
775 endpoint_t fs_e;
776 ino_t inode_nr;
777 u64_t pos;
778 int rw_flag;
779 endpoint_t user_e;
780 char *user_addr;
781 unsigned int num_of_bytes;
782 u64_t *new_posp;
783 unsigned int *cum_iop;
785 int r;
786 cp_grant_id_t grant_id;
787 message m;
789 if (ex64hi(pos) != 0)
790 panic("req_readwrite: pos too large");
792 grant_id = cpf_grant_magic(fs_e, user_e, (vir_bytes) user_addr, num_of_bytes,
793 (rw_flag==READING ? CPF_WRITE:CPF_READ));
794 if (grant_id == -1)
795 panic("req_readwrite: cpf_grant_magic failed");
797 /* Fill in request message */
798 m.m_type = rw_flag == READING ? REQ_READ : REQ_WRITE;
799 m.REQ_INODE_NR = inode_nr;
800 m.REQ_GRANT = grant_id;
801 m.REQ_SEEK_POS_LO = ex64lo(pos);
802 m.REQ_SEEK_POS_HI = 0; /* Not used for now, so clear it. */
803 m.REQ_NBYTES = num_of_bytes;
805 /* Send/rec request */
806 r = fs_sendrec(fs_e, &m);
807 cpf_revoke(grant_id);
809 if (r == OK) {
810 /* Fill in response structure */
811 *new_posp = ((u64_t)(m.RES_SEEK_POS_LO));
812 *cum_iop = m.RES_NBYTES;
815 return(r);
818 /*===========================================================================*
819 * req_peek *
820 *===========================================================================*/
821 int req_peek(endpoint_t fs_e, ino_t inode_nr, u64_t pos, unsigned int bytes)
823 message m;
825 memset(&m, 0, sizeof(m));
827 if (ex64hi(pos) != 0)
828 panic("req_peek: pos too large");
830 /* Fill in request message */
831 m.m_type = REQ_PEEK;
832 m.REQ_INODE_NR = inode_nr;
833 m.REQ_GRANT = -1;
834 m.REQ_SEEK_POS_LO = ex64lo(pos);
835 m.REQ_SEEK_POS_HI = 0; /* Not used for now, so clear it. */
836 m.REQ_NBYTES = bytes;
838 /* Send/rec request */
839 return fs_sendrec(fs_e, &m);
842 /*===========================================================================*
843 * req_rename *
844 *===========================================================================*/
845 int req_rename(fs_e, old_dir, old_name, new_dir, new_name)
846 endpoint_t fs_e;
847 ino_t old_dir;
848 char *old_name;
849 ino_t new_dir;
850 char *new_name;
852 int r;
853 cp_grant_id_t gid_old, gid_new;
854 size_t len_old, len_new;
855 message m;
857 len_old = strlen(old_name) + 1;
858 gid_old = cpf_grant_direct(fs_e, (vir_bytes) old_name, len_old, CPF_READ);
859 if(gid_old == -1)
860 panic("req_rename: cpf_grant_direct failed");
862 len_new = strlen(new_name) + 1;
863 gid_new = cpf_grant_direct(fs_e, (vir_bytes) new_name, len_new, CPF_READ);
864 if(gid_new == -1)
865 panic("req_rename: cpf_grant_direct failed");
867 /* Fill in request message */
868 m.m_type = REQ_RENAME;
869 m.REQ_REN_OLD_DIR = old_dir;
870 m.REQ_REN_NEW_DIR = new_dir;
871 m.REQ_REN_GRANT_OLD = gid_old;
872 m.REQ_REN_LEN_OLD = len_old;
873 m.REQ_REN_GRANT_NEW = gid_new;
874 m.REQ_REN_LEN_NEW = len_new;
876 /* Send/rec request */
877 r = fs_sendrec(fs_e, &m);
878 cpf_revoke(gid_old);
879 cpf_revoke(gid_new);
881 return(r);
885 /*===========================================================================*
886 * req_rmdir *
887 *===========================================================================*/
888 int req_rmdir(fs_e, inode_nr, lastc)
889 endpoint_t fs_e;
890 ino_t inode_nr;
891 char *lastc;
893 int r;
894 cp_grant_id_t grant_id;
895 size_t len;
896 message m;
898 len = strlen(lastc) + 1;
899 grant_id = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
900 if(grant_id == -1)
901 panic("req_rmdir: cpf_grant_direct failed");
903 /* Fill in request message */
904 m.m_type = REQ_RMDIR;
905 m.REQ_INODE_NR = inode_nr;
906 m.REQ_GRANT = grant_id;
907 m.REQ_PATH_LEN = len;
909 /* Send/rec request */
910 r = fs_sendrec(fs_e, &m);
911 cpf_revoke(grant_id);
913 return(r);
917 /*===========================================================================*
918 * req_slink *
919 *===========================================================================*/
920 int req_slink(
921 endpoint_t fs_e,
922 ino_t inode_nr,
923 char *lastc,
924 endpoint_t proc_e,
925 vir_bytes path_addr,
926 size_t path_length,
927 uid_t uid,
928 gid_t gid
931 int r;
932 size_t len;
933 cp_grant_id_t gid_name, gid_buf;
934 message m;
936 len = strlen(lastc) + 1;
937 gid_name = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
938 if (gid_name == GRANT_INVALID)
939 panic("req_slink: cpf_grant_direct failed");
941 gid_buf = cpf_grant_magic(fs_e, proc_e, path_addr, path_length, CPF_READ);
942 if (gid_buf == GRANT_INVALID) {
943 cpf_revoke(gid_name);
944 panic("req_slink: cpf_grant_magic failed");
947 /* Fill in request message */
948 m.m_type = REQ_SLINK;
949 m.REQ_INODE_NR = inode_nr;
950 m.REQ_UID = uid;
951 m.REQ_GID = gid;
952 m.REQ_GRANT = gid_name;
953 m.REQ_PATH_LEN = len;
954 m.REQ_GRANT3 = gid_buf;
955 m.REQ_MEM_SIZE = path_length;
957 /* Send/rec request */
958 r = fs_sendrec(fs_e, &m);
959 cpf_revoke(gid_name);
960 cpf_revoke(gid_buf);
962 return(r);
966 /*===========================================================================*
967 * req_stat *
968 *===========================================================================*/
969 int req_stat(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e, vir_bytes buf)
971 cp_grant_id_t grant_id;
972 int r;
973 message m;
975 /* Grant FS access to copy straight into user provided buffer */
976 grant_id = cpf_grant_magic(fs_e, proc_e, buf, sizeof(struct stat), CPF_WRITE);
978 if (grant_id < 0)
979 panic("req_stat: cpf_grant_* failed");
981 /* Fill in request message */
982 m.m_type = REQ_STAT;
983 m.REQ_INODE_NR = inode_nr;
984 m.REQ_GRANT = grant_id;
986 /* Send/rec request */
987 r = fs_sendrec(fs_e, &m);
988 cpf_revoke(grant_id);
990 return(r);
994 /*===========================================================================*
995 * req_sync *
996 *===========================================================================*/
997 int req_sync(fs_e)
998 endpoint_t fs_e;
1000 message m;
1002 /* Fill in request message */
1003 m.m_type = REQ_SYNC;
1005 /* Send/rec request */
1006 return fs_sendrec(fs_e, &m);
1010 /*===========================================================================*
1011 * req_unlink *
1012 *===========================================================================*/
1013 int req_unlink(fs_e, inode_nr, lastc)
1014 endpoint_t fs_e;
1015 ino_t inode_nr;
1016 char *lastc;
1018 cp_grant_id_t grant_id;
1019 size_t len;
1020 int r;
1021 message m;
1023 len = strlen(lastc) + 1;
1024 grant_id = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
1025 if(grant_id == -1)
1026 panic("req_unlink: cpf_grant_direct failed");
1028 /* Fill in request message */
1029 m.m_type = REQ_UNLINK;
1030 m.REQ_INODE_NR = inode_nr;
1031 m.REQ_GRANT = grant_id;
1032 m.REQ_PATH_LEN = len;
1034 /* Send/rec request */
1035 r = fs_sendrec(fs_e, &m);
1036 cpf_revoke(grant_id);
1038 return(r);
1042 /*===========================================================================*
1043 * req_unmount *
1044 *===========================================================================*/
1045 int req_unmount(fs_e)
1046 endpoint_t fs_e;
1048 message m;
1050 /* Fill in request message */
1051 m.m_type = REQ_UNMOUNT;
1053 /* Send/rec request */
1054 return fs_sendrec(fs_e, &m);
1058 /*===========================================================================*
1059 * req_utime *
1060 *===========================================================================*/
1061 int req_utime(endpoint_t fs_e, ino_t inode_nr, struct timespec * actimespec,
1062 struct timespec * modtimespec)
1064 message m;
1066 assert(actimespec != NULL);
1067 assert(modtimespec != NULL);
1069 /* Fill in request message */
1070 m.m_type = REQ_UTIME;
1071 m.REQ_INODE_NR = inode_nr;
1072 m.REQ_ACTIME = actimespec->tv_sec;
1073 m.REQ_MODTIME = modtimespec->tv_sec;
1074 m.REQ_ACNSEC = actimespec->tv_nsec;
1075 m.REQ_MODNSEC = modtimespec->tv_nsec;
1077 /* Send/rec request */
1078 return fs_sendrec(fs_e, &m);