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
10 #include <minix/const.h>
11 #include <minix/endpoint.h>
12 #include <minix/u64.h>
13 #include <minix/vfsif.h>
14 #include <sys/dirent.h>
16 #include <sys/statvfs.h>
27 /*===========================================================================*
28 * req_breadwrite_actual *
29 *===========================================================================*/
30 static int req_breadwrite_actual(endpoint_t fs_e
, endpoint_t user_e
, dev_t dev
, off_t pos
,
31 unsigned int num_of_bytes
, vir_bytes user_addr
, int rw_flag
,
32 off_t
*new_pos
, unsigned int *cum_iop
, int cpflag
)
35 cp_grant_id_t grant_id
;
38 grant_id
= cpf_grant_magic(fs_e
, user_e
, user_addr
, num_of_bytes
,
39 (rw_flag
== READING
? CPF_WRITE
: CPF_READ
) | cpflag
);
41 panic("req_breadwrite: cpf_grant_magic failed");
43 /* Fill in request message */
44 m
.m_type
= rw_flag
== READING
? REQ_BREAD
: REQ_BWRITE
;
46 m
.REQ_GRANT
= grant_id
;
48 m
.REQ_NBYTES
= num_of_bytes
;
50 /* Send/rec request */
51 r
= fs_sendrec(fs_e
, &m
);
53 if (r
!= OK
) return(r
);
55 /* Fill in response structure */
56 *new_pos
= m
.RES_SEEK_POS
;
57 *cum_iop
= m
.RES_NBYTES
;
62 int req_breadwrite(endpoint_t fs_e
, endpoint_t user_e
, dev_t dev
, off_t pos
,
63 unsigned int num_of_bytes
, vir_bytes user_addr
, int rw_flag
,
64 off_t
*new_pos
, unsigned int *cum_iop
)
68 r
= req_breadwrite_actual(fs_e
, user_e
, dev
, pos
, num_of_bytes
,
69 user_addr
, rw_flag
, new_pos
, cum_iop
, CPF_TRY
);
72 if((r
=vm_vfs_procctl_handlemem(user_e
, user_addr
, num_of_bytes
,
73 rw_flag
== READING
)) != OK
) {
77 r
= req_breadwrite_actual(fs_e
, user_e
, dev
, pos
, num_of_bytes
,
78 user_addr
, rw_flag
, new_pos
, cum_iop
, 0);
84 /*===========================================================================*
86 *===========================================================================*/
87 int req_bpeek(endpoint_t fs_e
, dev_t dev
, off_t pos
, unsigned int num_of_bytes
)
91 memset(&m
, 0, sizeof(m
));
93 /* Fill in request message */
97 m
.REQ_NBYTES
= num_of_bytes
;
99 /* Send/rec request */
100 return fs_sendrec(fs_e
, &m
);
103 /*===========================================================================*
105 *===========================================================================*/
116 /* Fill in request message */
117 m
.m_type
= REQ_CHMOD
;
118 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
119 m
.REQ_MODE
= (pmode_t
) rmode
;
121 /* Send/rec request */
122 r
= fs_sendrec(fs_e
, &m
);
124 /* Copy back actual mode. */
125 *new_modep
= (mode_t
) m
.RES_MODE
;
131 /*===========================================================================*
133 *===========================================================================*/
145 /* Fill in request message */
146 m
.m_type
= REQ_CHOWN
;
147 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
148 m
.REQ_UID
= (puid_t
) newuid
;
149 m
.REQ_GID
= (pgid_t
) newgid
;
151 /* Send/rec request */
152 r
= fs_sendrec(fs_e
, &m
);
154 /* Return new mode to caller. */
155 *new_modep
= (mode_t
) m
.RES_MODE
;
161 /*===========================================================================*
163 *===========================================================================*/
175 cp_grant_id_t grant_id
;
180 vmp
= find_vmnt(fs_e
);
182 len
= strlen(path
) + 1;
183 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) path
, len
, CPF_READ
);
185 panic("req_create: cpf_grant_direct failed");
187 /* Fill in request message */
188 m
.m_type
= REQ_CREATE
;
189 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
190 m
.REQ_MODE
= (pmode_t
) omode
;
191 m
.REQ_UID
= (puid_t
) uid
;
192 m
.REQ_GID
= (pgid_t
) gid
;
193 m
.REQ_GRANT
= grant_id
;
194 m
.REQ_PATH_LEN
= len
;
196 /* Send/rec request */
197 r
= fs_sendrec(fs_e
, &m
);
198 cpf_revoke(grant_id
);
199 if (r
!= OK
) return(r
);
201 /* Fill in response structure */
202 res
->fs_e
= m
.m_source
;
203 res
->inode_nr
= (ino_t
) m
.RES_INODE_NR
;
204 res
->fmode
= (mode_t
) m
.RES_MODE
;
205 res
->fsize
= m
.RES_FILE_SIZE
;
206 res
->uid
= (uid_t
) m
.RES_UID
;
207 res
->gid
= (gid_t
) m
.RES_GID
;
214 /*===========================================================================*
216 *===========================================================================*/
217 int req_flush(endpoint_t fs_e
, dev_t dev
)
221 /* Fill in request message */
222 m
.m_type
= REQ_FLUSH
;
225 /* Send/rec request */
226 return fs_sendrec(fs_e
, &m
);
230 /*===========================================================================*
232 *===========================================================================*/
233 int req_statvfs(endpoint_t fs_e
, struct statvfs
*buf
)
236 cp_grant_id_t grant_id
;
239 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) buf
, sizeof(struct statvfs
),
241 if(grant_id
== GRANT_INVALID
)
242 panic("req_statvfs: cpf_grant_direct failed");
244 /* Fill in request message */
245 m
.m_type
= REQ_STATVFS
;
246 m
.REQ_GRANT
= grant_id
;
248 /* Send/rec request */
249 r
= fs_sendrec(fs_e
, &m
);
250 cpf_revoke(grant_id
);
256 /*===========================================================================*
258 *===========================================================================*/
259 int req_ftrunc(endpoint_t fs_e
, ino_t inode_nr
, off_t start
, off_t end
)
264 vmp
= find_vmnt(fs_e
);
266 /* Fill in request message */
267 m
.m_type
= REQ_FTRUNC
;
268 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
269 m
.REQ_TRC_START
= start
;
272 if (!(vmp
->m_fs_flags
& RES_64BIT
) &&
273 ((start
> INT_MAX
) || (end
> INT_MAX
))) {
274 /* FS does not support 64-bit off_t and 32 bits is not enough */
278 /* Send/rec request */
279 return fs_sendrec(fs_e
, &m
);
283 /*===========================================================================*
284 * req_getdents_actual *
285 *===========================================================================*/
286 static int req_getdents_actual(
299 cp_grant_id_t grant_id
;
302 vmp
= find_vmnt(fs_e
);
306 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) buf
, size
, CPF_WRITE
);
308 grant_id
= cpf_grant_magic(fs_e
, who_e
, (vir_bytes
) buf
, size
,
313 panic("req_getdents: cpf_grant_direct/cpf_grant_magic failed: %d",
316 m
.m_type
= REQ_GETDENTS
;
317 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
318 m
.REQ_GRANT
= grant_id
;
319 m
.REQ_MEM_SIZE
= size
;
320 m
.REQ_SEEK_POS
= pos
;
321 if (!(vmp
->m_fs_flags
& RES_64BIT
) && (pos
> INT_MAX
)) {
322 /* FS does not support 64-bit off_t and 32 bits is not enough */
326 r
= fs_sendrec(fs_e
, &m
);
327 cpf_revoke(grant_id
);
330 *new_pos
= m
.RES_SEEK_POS
;
337 /*===========================================================================*
339 *===========================================================================*/
351 r
= req_getdents_actual(fs_e
, inode_nr
, pos
, buf
, size
, new_pos
,
354 if(r
== EFAULT
&& !direct
) {
355 if((r
=vm_vfs_procctl_handlemem(who_e
, (vir_bytes
) buf
,
360 r
= req_getdents_actual(fs_e
, inode_nr
, pos
, buf
, size
,
367 /*===========================================================================*
369 *===========================================================================*/
370 int req_inhibread(endpoint_t fs_e
, ino_t inode_nr
)
374 /* Fill in request message */
375 m
.m_type
= REQ_INHIBREAD
;
376 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
378 /* Send/rec request */
379 return fs_sendrec(fs_e
, &m
);
383 /*===========================================================================*
385 *===========================================================================*/
394 cp_grant_id_t grant_id
;
395 const size_t len
= strlen(lastc
) + 1;
398 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
)lastc
, len
, CPF_READ
);
400 panic("req_link: cpf_grant_direct failed");
402 /* Fill in request message */
404 m
.REQ_INODE_NR
= (pino_t
) linked_file
;
405 m
.REQ_DIR_INO
= (pino_t
) link_parent
;
406 m
.REQ_GRANT
= grant_id
;
407 m
.REQ_PATH_LEN
= len
;
409 /* Send/rec request */
410 r
= fs_sendrec(fs_e
, &m
);
411 cpf_revoke(grant_id
);
417 /*===========================================================================*
419 *===========================================================================*/
426 struct lookup
*resolve
,
432 vfs_ucred_t credentials
;
436 cp_grant_id_t grant_id
=0, grant_id2
=0;
438 vmp
= find_vmnt(fs_e
);
440 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) resolve
->l_path
, PATH_MAX
,
441 CPF_READ
| CPF_WRITE
);
443 panic("req_lookup: cpf_grant_direct failed");
445 flags
= resolve
->l_flags
;
446 len
= strlen(resolve
->l_path
) + 1;
448 m
.m_type
= REQ_LOOKUP
;
449 m
.REQ_GRANT
= grant_id
;
450 m
.REQ_PATH_LEN
= len
;
451 m
.REQ_PATH_SIZE
= PATH_MAX
+ 1;
452 m
.REQ_DIR_INO
= (pino_t
) dir_ino
;
453 m
.REQ_ROOT_INO
= (pino_t
) root_ino
;
455 if(rfp
->fp_ngroups
> 0) { /* Is the process member of multiple groups? */
456 /* In that case the FS has to copy the uid/gid credentials */
459 /* Set credentials */
460 credentials
.vu_uid
= rfp
->fp_effuid
;
461 credentials
.vu_gid
= rfp
->fp_effgid
;
462 credentials
.vu_ngroups
= rfp
->fp_ngroups
;
463 for (i
= 0; i
< rfp
->fp_ngroups
; i
++)
464 credentials
.vu_sgroups
[i
] = rfp
->fp_sgroups
[i
];
466 grant_id2
= cpf_grant_direct(fs_e
, (vir_bytes
) &credentials
,
467 sizeof(credentials
), CPF_READ
);
469 panic("req_lookup: cpf_grant_direct failed");
471 m
.REQ_GRANT2
= grant_id2
;
472 m
.REQ_UCRED_SIZE
= sizeof(credentials
);
473 flags
|= PATH_GET_UCRED
;
475 /* When there's only one gid, we can send it directly */
476 m
.REQ_UID
= (pgid_t
) uid
;
477 m
.REQ_GID
= (pgid_t
) gid
;
478 flags
&= ~PATH_GET_UCRED
;
483 /* Send/rec request */
484 r
= fs_sendrec(fs_e
, &m
);
485 cpf_revoke(grant_id
);
486 if(rfp
->fp_ngroups
> 0) cpf_revoke(grant_id2
);
488 /* Fill in response according to the return value */
489 res
->fs_e
= m
.m_source
;
493 res
->inode_nr
= (ino_t
) m
.RES_INODE_NR
;
494 res
->fmode
= (mode_t
) m
.RES_MODE
;
495 res
->fsize
= m
.RES_FILE_SIZE
;
496 res
->dev
= m
.RES_DEV
;
497 res
->uid
= (uid_t
) m
.RES_UID
;
498 res
->gid
= (gid_t
) m
.RES_GID
;
501 res
->inode_nr
= (ino_t
) m
.RES_INODE_NR
;
502 res
->char_processed
= m
.RES_OFFSET
;
503 res
->symloop
= m
.RES_SYMLOOP
;
506 res
->char_processed
= m
.RES_OFFSET
;
507 res
->symloop
= m
.RES_SYMLOOP
;
510 res
->char_processed
= m
.RES_OFFSET
;
511 res
->symloop
= m
.RES_SYMLOOP
;
521 /*===========================================================================*
523 *===========================================================================*/
534 cp_grant_id_t grant_id
;
538 len
= strlen(lastc
) + 1;
539 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
)lastc
, len
, CPF_READ
);
541 panic("req_mkdir: cpf_grant_direct failed");
543 /* Fill in request message */
544 m
.m_type
= REQ_MKDIR
;
545 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
546 m
.REQ_MODE
= (pmode_t
) dmode
;
547 m
.REQ_UID
= (puid_t
) uid
;
548 m
.REQ_GID
= (pgid_t
) gid
;
549 m
.REQ_GRANT
= grant_id
;
550 m
.REQ_PATH_LEN
= len
;
552 /* Send/rec request */
553 r
= fs_sendrec(fs_e
, &m
);
554 cpf_revoke(grant_id
);
560 /*===========================================================================*
562 *===========================================================================*/
575 cp_grant_id_t grant_id
;
578 len
= strlen(lastc
) + 1;
579 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
)lastc
, len
, CPF_READ
);
581 panic("req_mknod: cpf_grant_direct failed");
583 /* Fill in request message */
584 m
.m_type
= REQ_MKNOD
;
585 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
586 m
.REQ_MODE
= (pmode_t
) dmode
;
588 m
.REQ_UID
= (puid_t
) uid
;
589 m
.REQ_GID
= (pgid_t
) gid
;
590 m
.REQ_GRANT
= grant_id
;
591 m
.REQ_PATH_LEN
= len
;
593 /* Send/rec request */
594 r
= fs_sendrec(fs_e
, &m
);
595 cpf_revoke(grant_id
);
601 /*===========================================================================*
603 *===========================================================================*/
604 int req_mountpoint(endpoint_t fs_e
, ino_t inode_nr
)
608 /* Fill in request message */
609 m
.m_type
= REQ_MOUNTPOINT
;
610 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
612 /* Send/rec request */
613 return fs_sendrec(fs_e
, &m
);
617 /*===========================================================================*
619 *===========================================================================*/
626 struct node_details
*res
633 vmp
= find_vmnt(fs_e
);
635 /* Fill in request message */
636 m
.m_type
= REQ_NEWNODE
;
637 m
.REQ_MODE
= (pmode_t
) dmode
;
639 m
.REQ_UID
= (puid_t
) uid
;
640 m
.REQ_GID
= (pgid_t
) gid
;
642 /* Send/rec request */
643 r
= fs_sendrec(fs_e
, &m
);
645 res
->fs_e
= m
.m_source
;
646 res
->inode_nr
= (ino_t
) m
.RES_INODE_NR
;
647 res
->fmode
= (mode_t
) m
.RES_MODE
;
648 res
->fsize
= m
.RES_FILE_SIZE
;
649 res
->dev
= m
.RES_DEV
;
650 res
->uid
= (uid_t
) m
.RES_UID
;
651 res
->gid
= (gid_t
) m
.RES_GID
;
657 /*===========================================================================*
659 *===========================================================================*/
666 cp_grant_id_t grant_id
;
671 /* Grant access to label */
672 len
= strlen(label
) + 1;
673 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) label
, len
, CPF_READ
);
675 panic("req_newdriver: cpf_grant_direct failed");
677 /* Fill in request message */
678 m
.m_type
= REQ_NEW_DRIVER
;
680 m
.REQ_GRANT
= grant_id
;
681 m
.REQ_PATH_LEN
= len
;
684 r
= fs_sendrec(fs_e
, &m
);
686 cpf_revoke(grant_id
);
692 /*===========================================================================*
694 *===========================================================================*/
695 int req_putnode(fs_e
, inode_nr
, count
)
702 /* Fill in request message */
703 m
.m_type
= REQ_PUTNODE
;
704 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
707 /* Send/rec request */
708 return fs_sendrec(fs_e
, &m
);
712 /*===========================================================================*
713 * req_rdlink_actual *
714 *===========================================================================*/
715 static int req_rdlink_actual(endpoint_t fs_e
, ino_t inode_nr
,
716 endpoint_t proc_e
, vir_bytes buf
, size_t len
,
717 int direct
, /* set to 1 to use direct grants instead of magic grants */
722 cp_grant_id_t grant_id
;
725 grant_id
= cpf_grant_direct(fs_e
, buf
, len
, CPF_WRITE
);
727 grant_id
= cpf_grant_magic(fs_e
, proc_e
, buf
, len
, CPF_WRITE
| cpflag
);
730 panic("req_rdlink: cpf_grant_magic failed");
732 /* Fill in request message */
733 m
.m_type
= REQ_RDLINK
;
734 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
735 m
.REQ_GRANT
= grant_id
;
736 m
.REQ_MEM_SIZE
= len
;
738 /* Send/rec request */
739 r
= fs_sendrec(fs_e
, &m
);
740 cpf_revoke(grant_id
);
742 if (r
== OK
) r
= m
.RES_NBYTES
;
747 /*===========================================================================*
749 *===========================================================================*/
750 int req_rdlink(endpoint_t fs_e
, ino_t inode_nr
, endpoint_t proc_e
,
751 vir_bytes buf
, size_t len
,
752 int direct
/* set to 1 to use direct grants instead of magic grants */
757 r
= req_rdlink_actual(fs_e
, inode_nr
, proc_e
, buf
, len
, direct
,
760 if(r
== EFAULT
&& !direct
) {
761 if((r
=vm_vfs_procctl_handlemem(proc_e
, buf
, len
, 1)) != OK
) {
765 r
= req_rdlink_actual(fs_e
, inode_nr
, proc_e
, buf
, len
,
772 /*===========================================================================*
774 *===========================================================================*/
781 struct node_details
*res
,
782 unsigned int *fs_flags
786 cp_grant_id_t grant_id
;
793 len
= strlen(label
)+1;
794 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) label
, len
, CPF_READ
);
796 panic("req_readsuper: cpf_grant_direct failed");
798 /* Fill in request message */
799 m
.m_type
= REQ_READSUPER
;
801 if(readonly
) m
.REQ_FLAGS
|= REQ_RDONLY
;
802 if(isroot
) m
.REQ_FLAGS
|= REQ_ISROOT
;
803 m
.REQ_GRANT
= grant_id
;
805 m
.REQ_PATH_LEN
= len
;
807 /* Send/rec request */
808 r
= fs_sendrec(fs_e
, &m
);
809 cpf_revoke(grant_id
);
812 /* Fill in response structure */
813 res
->fs_e
= m
.m_source
;
814 res
->inode_nr
= (ino_t
) m
.RES_INODE_NR
;
815 res
->fmode
= (mode_t
) m
.RES_MODE
;
816 res
->fsize
= m
.RES_FILE_SIZE
;
817 res
->uid
= (uid_t
) m
.RES_UID
;
818 res
->gid
= (gid_t
) m
.RES_GID
;
819 *fs_flags
= m
.RES_FLAGS
;
826 /*===========================================================================*
827 * req_readwrite_actual *
828 *===========================================================================*/
829 static int req_readwrite_actual(endpoint_t fs_e
, ino_t inode_nr
, off_t pos
,
830 int rw_flag
, endpoint_t user_e
, vir_bytes user_addr
,
831 unsigned int num_of_bytes
, off_t
*new_posp
, unsigned int *cum_iop
,
836 cp_grant_id_t grant_id
;
839 vmp
= find_vmnt(fs_e
);
841 grant_id
= cpf_grant_magic(fs_e
, user_e
, user_addr
, num_of_bytes
,
842 (rw_flag
==READING
? CPF_WRITE
:CPF_READ
) | cpflag
);
844 panic("req_readwrite: cpf_grant_magic failed");
846 /* Fill in request message */
847 m
.m_type
= rw_flag
== READING
? REQ_READ
: REQ_WRITE
;
848 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
849 m
.REQ_GRANT
= grant_id
;
850 m
.REQ_SEEK_POS
= pos
;
851 if ((!(vmp
->m_fs_flags
& RES_64BIT
)) && (pos
> INT_MAX
)) {
854 m
.REQ_NBYTES
= num_of_bytes
;
856 /* Send/rec request */
857 r
= fs_sendrec(fs_e
, &m
);
858 cpf_revoke(grant_id
);
861 /* Fill in response structure */
862 *new_posp
= m
.RES_SEEK_POS
;
863 *cum_iop
= m
.RES_NBYTES
;
869 /*===========================================================================*
871 *===========================================================================*/
872 int req_readwrite(endpoint_t fs_e
, ino_t inode_nr
, off_t pos
,
873 int rw_flag
, endpoint_t user_e
, vir_bytes user_addr
,
874 unsigned int num_of_bytes
, off_t
*new_posp
, unsigned int *cum_iop
)
878 r
= req_readwrite_actual(fs_e
, inode_nr
, pos
, rw_flag
, user_e
,
879 user_addr
, num_of_bytes
, new_posp
, cum_iop
, CPF_TRY
);
882 if((r
=vm_vfs_procctl_handlemem(user_e
, (vir_bytes
) user_addr
, num_of_bytes
,
883 rw_flag
== READING
)) != OK
) {
887 r
= req_readwrite_actual(fs_e
, inode_nr
, pos
, rw_flag
, user_e
,
888 user_addr
, num_of_bytes
, new_posp
, cum_iop
, 0);
894 /*===========================================================================*
896 *===========================================================================*/
897 int req_peek(endpoint_t fs_e
, ino_t inode_nr
, off_t pos
, unsigned int bytes
)
901 memset(&m
, 0, sizeof(m
));
903 if (ex64hi(pos
) != 0)
904 panic("req_peek: pos too large");
906 /* Fill in request message */
908 m
.REQ_INODE_NR
= inode_nr
;
910 m
.REQ_SEEK_POS
= pos
;
911 m
.REQ_NBYTES
= bytes
;
913 /* Send/rec request */
914 return fs_sendrec(fs_e
, &m
);
917 /*===========================================================================*
919 *===========================================================================*/
920 int req_rename(fs_e
, old_dir
, old_name
, new_dir
, new_name
)
928 cp_grant_id_t gid_old
, gid_new
;
929 size_t len_old
, len_new
;
932 len_old
= strlen(old_name
) + 1;
933 gid_old
= cpf_grant_direct(fs_e
, (vir_bytes
) old_name
, len_old
, CPF_READ
);
935 panic("req_rename: cpf_grant_direct failed");
937 len_new
= strlen(new_name
) + 1;
938 gid_new
= cpf_grant_direct(fs_e
, (vir_bytes
) new_name
, len_new
, CPF_READ
);
940 panic("req_rename: cpf_grant_direct failed");
942 /* Fill in request message */
943 m
.m_type
= REQ_RENAME
;
944 m
.REQ_REN_OLD_DIR
= (pino_t
) old_dir
;
945 m
.REQ_REN_NEW_DIR
= (pino_t
) new_dir
;
946 m
.REQ_REN_GRANT_OLD
= gid_old
;
947 m
.REQ_REN_LEN_OLD
= len_old
;
948 m
.REQ_REN_GRANT_NEW
= gid_new
;
949 m
.REQ_REN_LEN_NEW
= len_new
;
951 /* Send/rec request */
952 r
= fs_sendrec(fs_e
, &m
);
960 /*===========================================================================*
962 *===========================================================================*/
963 int req_rmdir(fs_e
, inode_nr
, lastc
)
969 cp_grant_id_t grant_id
;
973 len
= strlen(lastc
) + 1;
974 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) lastc
, len
, CPF_READ
);
976 panic("req_rmdir: cpf_grant_direct failed");
978 /* Fill in request message */
979 m
.m_type
= REQ_RMDIR
;
980 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
981 m
.REQ_GRANT
= grant_id
;
982 m
.REQ_PATH_LEN
= len
;
984 /* Send/rec request */
985 r
= fs_sendrec(fs_e
, &m
);
986 cpf_revoke(grant_id
);
992 /*===========================================================================*
994 *===========================================================================*/
995 static int req_slink_actual(
1000 vir_bytes path_addr
,
1009 cp_grant_id_t gid_name
, gid_buf
;
1012 len
= strlen(lastc
) + 1;
1013 gid_name
= cpf_grant_direct(fs_e
, (vir_bytes
) lastc
, len
, CPF_READ
);
1014 if (gid_name
== GRANT_INVALID
)
1015 panic("req_slink: cpf_grant_direct failed");
1017 gid_buf
= cpf_grant_magic(fs_e
, proc_e
, path_addr
, path_length
,
1020 if (gid_buf
== GRANT_INVALID
) {
1021 cpf_revoke(gid_name
);
1022 panic("req_slink: cpf_grant_magic failed");
1025 /* Fill in request message */
1026 m
.m_type
= REQ_SLINK
;
1027 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
1028 m
.REQ_UID
= (puid_t
) uid
;
1029 m
.REQ_GID
= (pgid_t
) gid
;
1030 m
.REQ_GRANT
= gid_name
;
1031 m
.REQ_PATH_LEN
= len
;
1032 m
.REQ_GRANT3
= gid_buf
;
1033 m
.REQ_MEM_SIZE
= path_length
;
1035 /* Send/rec request */
1036 r
= fs_sendrec(fs_e
, &m
);
1037 cpf_revoke(gid_name
);
1038 cpf_revoke(gid_buf
);
1043 /*===========================================================================*
1045 *===========================================================================*/
1051 vir_bytes path_addr
,
1059 r
= req_slink_actual(fs_e
, inode_nr
, lastc
, proc_e
, path_addr
,
1060 path_length
, uid
, gid
, CPF_TRY
);
1063 if((r
=vm_vfs_procctl_handlemem(proc_e
, (vir_bytes
) path_addr
,
1064 path_length
, 0)) != OK
) {
1068 r
= req_slink_actual(fs_e
, inode_nr
, lastc
, proc_e
, path_addr
,
1069 path_length
, uid
, gid
, 0);
1075 /*===========================================================================*
1077 *===========================================================================*/
1078 int req_stat_actual(endpoint_t fs_e
, ino_t inode_nr
, endpoint_t proc_e
,
1079 vir_bytes buf
, int cpflag
)
1081 cp_grant_id_t grant_id
;
1085 /* Grant FS access to copy straight into user provided buffer */
1086 grant_id
= cpf_grant_magic(fs_e
, proc_e
, buf
, sizeof(struct stat
),
1087 CPF_WRITE
| cpflag
);
1090 panic("req_stat: cpf_grant_* failed");
1092 /* Fill in request message */
1093 m
.m_type
= REQ_STAT
;
1094 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
1095 m
.REQ_GRANT
= grant_id
;
1097 /* Send/rec request */
1098 r
= fs_sendrec(fs_e
, &m
);
1099 cpf_revoke(grant_id
);
1105 /*===========================================================================*
1107 *===========================================================================*/
1108 int req_stat(endpoint_t fs_e
, ino_t inode_nr
, endpoint_t proc_e
,
1113 r
= req_stat_actual(fs_e
, inode_nr
, proc_e
, buf
, CPF_TRY
);
1116 if((r
=vm_vfs_procctl_handlemem(proc_e
, (vir_bytes
) buf
,
1117 sizeof(struct stat
), 1)) != OK
) {
1121 r
= req_stat_actual(fs_e
, inode_nr
, proc_e
, buf
, 0);
1127 /*===========================================================================*
1129 *===========================================================================*/
1135 /* Fill in request message */
1136 m
.m_type
= REQ_SYNC
;
1138 /* Send/rec request */
1139 return fs_sendrec(fs_e
, &m
);
1143 /*===========================================================================*
1145 *===========================================================================*/
1146 int req_unlink(fs_e
, inode_nr
, lastc
)
1151 cp_grant_id_t grant_id
;
1156 len
= strlen(lastc
) + 1;
1157 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) lastc
, len
, CPF_READ
);
1159 panic("req_unlink: cpf_grant_direct failed");
1161 /* Fill in request message */
1162 m
.m_type
= REQ_UNLINK
;
1163 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
1164 m
.REQ_GRANT
= grant_id
;
1165 m
.REQ_PATH_LEN
= len
;
1167 /* Send/rec request */
1168 r
= fs_sendrec(fs_e
, &m
);
1169 cpf_revoke(grant_id
);
1175 /*===========================================================================*
1177 *===========================================================================*/
1178 int req_unmount(fs_e
)
1183 /* Fill in request message */
1184 m
.m_type
= REQ_UNMOUNT
;
1186 /* Send/rec request */
1187 return fs_sendrec(fs_e
, &m
);
1191 /*===========================================================================*
1193 *===========================================================================*/
1194 int req_utime(endpoint_t fs_e
, ino_t inode_nr
, struct timespec
* actimespec
,
1195 struct timespec
* modtimespec
)
1199 assert(actimespec
!= NULL
);
1200 assert(modtimespec
!= NULL
);
1202 /* Fill in request message */
1203 m
.m_type
= REQ_UTIME
;
1204 m
.REQ_INODE_NR
= (pino_t
) inode_nr
;
1205 m
.REQ_INODE_NR
= inode_nr
;
1206 m
.REQ_ACTIME
= actimespec
->tv_sec
;
1207 m
.REQ_MODTIME
= modtimespec
->tv_sec
;
1208 m
.REQ_ACNSEC
= actimespec
->tv_nsec
;
1209 m
.REQ_MODNSEC
= modtimespec
->tv_nsec
;
1211 /* Send/rec request */
1212 return fs_sendrec(fs_e
, &m
);