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
, size_t *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
;
45 m
.m_vfs_fs_breadwrite
.device
= dev
;
46 m
.m_vfs_fs_breadwrite
.grant
= grant_id
;
47 m
.m_vfs_fs_breadwrite
.seek_pos
= pos
;
48 m
.m_vfs_fs_breadwrite
.nbytes
= num_of_bytes
;
50 /* Send/rec request */
51 r
= fs_sendrec(fs_e
, &m
);
53 if (cpf_revoke(grant_id
) == GRANT_FAULTED
) return(ERESTART
);
55 if (r
!= OK
) return(r
);
57 /* Fill in response structure */
58 *new_pos
= m
.m_fs_vfs_breadwrite
.seek_pos
;
59 *cum_iop
= m
.m_fs_vfs_breadwrite
.nbytes
;
64 int req_breadwrite(endpoint_t fs_e
, endpoint_t user_e
, dev_t dev
, off_t pos
,
65 unsigned int num_of_bytes
, vir_bytes user_addr
, int rw_flag
,
66 off_t
*new_pos
, size_t *cum_iop
)
70 r
= req_breadwrite_actual(fs_e
, user_e
, dev
, pos
, num_of_bytes
,
71 user_addr
, rw_flag
, new_pos
, cum_iop
, CPF_TRY
);
74 if((r
=vm_vfs_procctl_handlemem(user_e
, user_addr
, num_of_bytes
,
75 rw_flag
== READING
)) != OK
) {
79 r
= req_breadwrite_actual(fs_e
, user_e
, dev
, pos
, num_of_bytes
,
80 user_addr
, rw_flag
, new_pos
, cum_iop
, 0);
86 /*===========================================================================*
88 *===========================================================================*/
89 int req_bpeek(endpoint_t fs_e
, dev_t dev
, off_t pos
, unsigned int num_of_bytes
)
93 memset(&m
, 0, sizeof(m
));
95 /* Fill in request message */
97 m
.m_vfs_fs_breadwrite
.device
= dev
;
98 m
.m_vfs_fs_breadwrite
.seek_pos
= pos
;
99 m
.m_vfs_fs_breadwrite
.nbytes
= num_of_bytes
;
101 /* Send/rec request */
102 return fs_sendrec(fs_e
, &m
);
105 /*===========================================================================*
107 *===========================================================================*/
118 /* Fill in request message */
119 m
.m_type
= REQ_CHMOD
;
120 m
.m_vfs_fs_chmod
.inode
= inode_nr
;
121 m
.m_vfs_fs_chmod
.mode
= rmode
;
123 /* Send/rec request */
124 r
= fs_sendrec(fs_e
, &m
);
126 /* Copy back actual mode. */
127 *new_modep
= m
.m_fs_vfs_chmod
.mode
;
133 /*===========================================================================*
135 *===========================================================================*/
147 /* Fill in request message */
148 m
.m_type
= REQ_CHOWN
;
149 m
.m_vfs_fs_chown
.inode
= inode_nr
;
150 m
.m_vfs_fs_chown
.uid
= newuid
;
151 m
.m_vfs_fs_chown
.gid
= newgid
;
153 /* Send/rec request */
154 r
= fs_sendrec(fs_e
, &m
);
156 /* Return new mode to caller. */
157 *new_modep
= m
.m_fs_vfs_chown
.mode
;
163 /*===========================================================================*
165 *===========================================================================*/
177 cp_grant_id_t grant_id
;
182 // vmp = find_vmnt(fs_e);
184 len
= strlen(path
) + 1;
185 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) path
, len
, CPF_READ
);
187 panic("req_create: cpf_grant_direct failed");
189 /* Fill in request message */
190 m
.m_type
= REQ_CREATE
;
191 m
.m_vfs_fs_create
.inode
= inode_nr
;
192 m
.m_vfs_fs_create
.mode
= omode
;
193 m
.m_vfs_fs_create
.uid
= uid
;
194 m
.m_vfs_fs_create
.gid
= gid
;
195 m
.m_vfs_fs_create
.grant
= grant_id
;
196 m
.m_vfs_fs_create
.path_len
= len
;
198 /* Send/rec request */
199 r
= fs_sendrec(fs_e
, &m
);
200 cpf_revoke(grant_id
);
201 if (r
!= OK
) return(r
);
203 /* Fill in response structure */
204 res
->fs_e
= m
.m_source
;
205 res
->inode_nr
= m
.m_fs_vfs_create
.inode
;
206 res
->fmode
= m
.m_fs_vfs_create
.mode
;
207 res
->fsize
= m
.m_fs_vfs_create
.file_size
;
208 res
->uid
= m
.m_fs_vfs_create
.uid
;
209 res
->gid
= m
.m_fs_vfs_create
.gid
;
216 /*===========================================================================*
218 *===========================================================================*/
219 int req_flush(endpoint_t fs_e
, dev_t dev
)
223 /* Fill in request message */
224 m
.m_type
= REQ_FLUSH
;
225 m
.m_vfs_fs_flush
.device
= dev
;
227 /* Send/rec request */
228 return fs_sendrec(fs_e
, &m
);
232 /*===========================================================================*
234 *===========================================================================*/
235 int req_statvfs(endpoint_t fs_e
, struct statvfs
*buf
)
238 cp_grant_id_t grant_id
;
241 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) buf
, sizeof(struct statvfs
),
243 if(grant_id
== GRANT_INVALID
)
244 panic("req_statvfs: cpf_grant_direct failed");
246 /* Fill in request message */
247 m
.m_type
= REQ_STATVFS
;
248 m
.m_vfs_fs_statvfs
.grant
= grant_id
;
250 /* Send/rec request */
251 r
= fs_sendrec(fs_e
, &m
);
252 cpf_revoke(grant_id
);
258 /*===========================================================================*
260 *===========================================================================*/
261 int req_ftrunc(endpoint_t fs_e
, ino_t inode_nr
, off_t start
, off_t end
)
266 vmp
= find_vmnt(fs_e
);
268 /* Fill in request message */
269 m
.m_type
= REQ_FTRUNC
;
270 m
.m_vfs_fs_ftrunc
.inode
= inode_nr
;
271 m
.m_vfs_fs_ftrunc
.trc_start
= start
;
272 m
.m_vfs_fs_ftrunc
.trc_end
= end
;
274 if (!(vmp
->m_fs_flags
& RES_64BIT
) &&
275 ((start
> INT_MAX
) || (end
> INT_MAX
))) {
276 /* FS does not support 64-bit off_t and 32 bits is not enough */
280 /* Send/rec request */
281 return fs_sendrec(fs_e
, &m
);
285 /*===========================================================================*
286 * req_getdents_actual *
287 *===========================================================================*/
288 static int req_getdents_actual(
301 cp_grant_id_t grant_id
;
304 vmp
= find_vmnt(fs_e
);
308 grant_id
= cpf_grant_direct(fs_e
, buf
, size
, CPF_WRITE
);
310 grant_id
= cpf_grant_magic(fs_e
, who_e
, buf
, size
,
315 panic("req_getdents: cpf_grant_direct/cpf_grant_magic failed: %d",
318 m
.m_type
= REQ_GETDENTS
;
319 m
.m_vfs_fs_getdents
.inode
= inode_nr
;
320 m
.m_vfs_fs_getdents
.grant
= grant_id
;
321 m
.m_vfs_fs_getdents
.mem_size
= size
;
322 m
.m_vfs_fs_getdents
.seek_pos
= pos
;
323 if (!(vmp
->m_fs_flags
& RES_64BIT
) && (pos
> INT_MAX
)) {
324 /* FS does not support 64-bit off_t and 32 bits is not enough */
328 r
= fs_sendrec(fs_e
, &m
);
330 if (cpf_revoke(grant_id
) == GRANT_FAULTED
) return(ERESTART
);
333 *new_pos
= m
.m_fs_vfs_getdents
.seek_pos
;
334 r
= m
.m_fs_vfs_getdents
.nbytes
;
340 /*===========================================================================*
342 *===========================================================================*/
354 r
= req_getdents_actual(fs_e
, inode_nr
, pos
, buf
, size
, new_pos
,
360 if((r
=vm_vfs_procctl_handlemem(who_e
, buf
, size
, 1)) != OK
) {
364 r
= req_getdents_actual(fs_e
, inode_nr
, pos
, buf
, size
,
371 /*===========================================================================*
373 *===========================================================================*/
374 int req_inhibread(endpoint_t fs_e
, ino_t inode_nr
)
378 /* Fill in request message */
379 m
.m_type
= REQ_INHIBREAD
;
380 m
.m_vfs_fs_inhibread
.inode
= inode_nr
;
382 /* Send/rec request */
383 return fs_sendrec(fs_e
, &m
);
387 /*===========================================================================*
389 *===========================================================================*/
398 cp_grant_id_t grant_id
;
399 const size_t len
= strlen(lastc
) + 1;
402 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
)lastc
, len
, CPF_READ
);
404 panic("req_link: cpf_grant_direct failed");
406 /* Fill in request message */
408 m
.m_vfs_fs_link
.inode
= linked_file
;
409 m
.m_vfs_fs_link
.dir_ino
= link_parent
;
410 m
.m_vfs_fs_link
.grant
= grant_id
;
411 m
.m_vfs_fs_link
.path_len
= len
;
413 /* Send/rec request */
414 r
= fs_sendrec(fs_e
, &m
);
415 cpf_revoke(grant_id
);
421 /*===========================================================================*
423 *===========================================================================*/
430 struct lookup
*resolve
,
436 vfs_ucred_t credentials
;
440 cp_grant_id_t grant_id
=0, grant_id2
=0;
442 // vmp = find_vmnt(fs_e);
444 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) resolve
->l_path
, PATH_MAX
,
445 CPF_READ
| CPF_WRITE
);
447 panic("req_lookup: cpf_grant_direct failed");
449 flags
= resolve
->l_flags
;
450 len
= strlen(resolve
->l_path
) + 1;
452 m
.m_type
= REQ_LOOKUP
;
453 m
.m_vfs_fs_lookup
.grant_path
= grant_id
;
454 m
.m_vfs_fs_lookup
.path_len
= len
;
455 m
.m_vfs_fs_lookup
.path_size
= PATH_MAX
+ 1;
456 m
.m_vfs_fs_lookup
.dir_ino
= dir_ino
;
457 m
.m_vfs_fs_lookup
.root_ino
= root_ino
;
459 if(rfp
->fp_ngroups
> 0) { /* Is the process member of multiple groups? */
460 /* In that case the FS has to copy the uid/gid credentials */
463 /* Set credentials */
464 credentials
.vu_uid
= rfp
->fp_effuid
;
465 credentials
.vu_gid
= rfp
->fp_effgid
;
466 credentials
.vu_ngroups
= rfp
->fp_ngroups
;
467 for (i
= 0; i
< rfp
->fp_ngroups
; i
++)
468 credentials
.vu_sgroups
[i
] = rfp
->fp_sgroups
[i
];
470 grant_id2
= cpf_grant_direct(fs_e
, (vir_bytes
) &credentials
,
471 sizeof(credentials
), CPF_READ
);
473 panic("req_lookup: cpf_grant_direct failed");
475 m
.m_vfs_fs_lookup
.grant_ucred
= grant_id2
;
476 m
.m_vfs_fs_lookup
.ucred_size
= sizeof(credentials
);
477 flags
|= PATH_GET_UCRED
;
479 /* When there's only one gid, we can send it directly */
480 m
.m_vfs_fs_lookup
.uid
= uid
;
481 m
.m_vfs_fs_lookup
.gid
= gid
;
482 flags
&= ~PATH_GET_UCRED
;
485 m
.m_vfs_fs_lookup
.flags
= flags
;
487 /* Send/rec request */
488 r
= fs_sendrec(fs_e
, &m
);
489 cpf_revoke(grant_id
);
490 if(rfp
->fp_ngroups
> 0) cpf_revoke(grant_id2
);
492 /* Fill in response according to the return value */
493 res
->fs_e
= m
.m_source
;
497 res
->inode_nr
= m
.m_fs_vfs_lookup
.inode
;
498 res
->fmode
= m
.m_fs_vfs_lookup
.mode
;
499 res
->fsize
= m
.m_fs_vfs_lookup
.file_size
;
500 res
->dev
= m
.m_fs_vfs_lookup
.device
;
501 res
->uid
= m
.m_fs_vfs_lookup
.uid
;
502 res
->gid
= m
.m_fs_vfs_lookup
.gid
;
505 res
->inode_nr
= m
.m_fs_vfs_lookup
.inode
;
506 res
->char_processed
= m
.m_fs_vfs_lookup
.offset
;
507 res
->symloop
= m
.m_fs_vfs_lookup
.symloop
;
510 res
->char_processed
= m
.m_fs_vfs_lookup
.offset
;
511 res
->symloop
= m
.m_fs_vfs_lookup
.symloop
;
514 res
->char_processed
= m
.m_fs_vfs_lookup
.offset
;
515 res
->symloop
= m
.m_fs_vfs_lookup
.symloop
;
525 /*===========================================================================*
527 *===========================================================================*/
538 cp_grant_id_t grant_id
;
542 len
= strlen(lastc
) + 1;
543 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
)lastc
, len
, CPF_READ
);
545 panic("req_mkdir: cpf_grant_direct failed");
547 /* Fill in request message */
548 m
.m_type
= REQ_MKDIR
;
549 m
.m_vfs_fs_mkdir
.inode
= inode_nr
;
550 m
.m_vfs_fs_mkdir
.mode
= dmode
;
551 m
.m_vfs_fs_mkdir
.uid
= uid
;
552 m
.m_vfs_fs_mkdir
.gid
= gid
;
553 m
.m_vfs_fs_mkdir
.grant
= grant_id
;
554 m
.m_vfs_fs_mkdir
.path_len
= len
;
556 /* Send/rec request */
557 r
= fs_sendrec(fs_e
, &m
);
558 cpf_revoke(grant_id
);
564 /*===========================================================================*
566 *===========================================================================*/
579 cp_grant_id_t grant_id
;
582 len
= strlen(lastc
) + 1;
583 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
)lastc
, len
, CPF_READ
);
585 panic("req_mknod: cpf_grant_direct failed");
587 /* Fill in request message */
588 m
.m_type
= REQ_MKNOD
;
589 m
.m_vfs_fs_mknod
.inode
= inode_nr
;
590 m
.m_vfs_fs_mknod
.mode
= dmode
;
591 m
.m_vfs_fs_mknod
.device
= dev
;
592 m
.m_vfs_fs_mknod
.uid
= uid
;
593 m
.m_vfs_fs_mknod
.gid
= gid
;
594 m
.m_vfs_fs_mknod
.grant
= grant_id
;
595 m
.m_vfs_fs_mknod
.path_len
= len
;
597 /* Send/rec request */
598 r
= fs_sendrec(fs_e
, &m
);
599 cpf_revoke(grant_id
);
605 /*===========================================================================*
607 *===========================================================================*/
608 int req_mountpoint(endpoint_t fs_e
, ino_t inode_nr
)
612 /* Fill in request message */
613 m
.m_type
= REQ_MOUNTPOINT
;
614 m
.m_vfs_fs_mountpoint
.inode
= inode_nr
;
616 /* Send/rec request */
617 return fs_sendrec(fs_e
, &m
);
621 /*===========================================================================*
623 *===========================================================================*/
630 struct node_details
*res
637 // vmp = find_vmnt(fs_e);
639 /* Fill in request message */
640 m
.m_type
= REQ_NEWNODE
;
641 m
.m_vfs_fs_newnode
.mode
= dmode
;
642 m
.m_vfs_fs_newnode
.device
= dev
;
643 m
.m_vfs_fs_newnode
.uid
= uid
;
644 m
.m_vfs_fs_newnode
.gid
= gid
;
646 /* Send/rec request */
647 r
= fs_sendrec(fs_e
, &m
);
649 res
->fs_e
= m
.m_source
;
650 res
->inode_nr
= m
.m_fs_vfs_newnode
.inode
;
651 res
->fmode
= m
.m_fs_vfs_newnode
.mode
;
652 res
->fsize
= m
.m_fs_vfs_newnode
.file_size
;
653 res
->dev
= m
.m_fs_vfs_newnode
.device
;
654 res
->uid
= m
.m_fs_vfs_newnode
.uid
;
655 res
->gid
= m
.m_fs_vfs_newnode
.gid
;
661 /*===========================================================================*
663 *===========================================================================*/
670 cp_grant_id_t grant_id
;
675 /* Grant access to label */
676 len
= strlen(label
) + 1;
677 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) label
, len
, CPF_READ
);
679 panic("req_newdriver: cpf_grant_direct failed");
681 /* Fill in request message */
682 m
.m_type
= REQ_NEW_DRIVER
;
683 m
.m_vfs_fs_new_driver
.device
= dev
;
684 m
.m_vfs_fs_new_driver
.grant
= grant_id
;
685 m
.m_vfs_fs_new_driver
.path_len
= len
;
688 r
= fs_sendrec(fs_e
, &m
);
690 cpf_revoke(grant_id
);
696 /*===========================================================================*
698 *===========================================================================*/
700 req_putnode(int fs_e
, ino_t inode_nr
, int count
)
704 /* Fill in request message */
705 m
.m_type
= REQ_PUTNODE
;
706 m
.m_vfs_fs_putnode
.inode
= inode_nr
;
707 m
.m_vfs_fs_putnode
.count
= count
;
709 /* Send/rec request */
710 return fs_sendrec(fs_e
, &m
);
714 /*===========================================================================*
715 * req_rdlink_actual *
716 *===========================================================================*/
717 static int req_rdlink_actual(endpoint_t fs_e
, ino_t inode_nr
,
718 endpoint_t proc_e
, vir_bytes buf
, size_t len
,
719 int direct
, /* set to 1 to use direct grants instead of magic grants */
724 cp_grant_id_t grant_id
;
727 grant_id
= cpf_grant_direct(fs_e
, buf
, len
, CPF_WRITE
);
729 grant_id
= cpf_grant_magic(fs_e
, proc_e
, buf
, len
, CPF_WRITE
| cpflag
);
732 panic("req_rdlink: cpf_grant_magic failed");
734 /* Fill in request message */
735 m
.m_type
= REQ_RDLINK
;
736 m
.m_vfs_fs_rdlink
.inode
= inode_nr
;
737 m
.m_vfs_fs_rdlink
.grant
= grant_id
;
738 m
.m_vfs_fs_rdlink
.mem_size
= len
;
740 /* Send/rec request */
741 r
= fs_sendrec(fs_e
, &m
);
743 if (cpf_revoke(grant_id
) == GRANT_FAULTED
) return(ERESTART
);
745 if (r
== OK
) r
= m
.m_fs_vfs_rdlink
.nbytes
;
750 /*===========================================================================*
752 *===========================================================================*/
753 int req_rdlink(endpoint_t fs_e
, ino_t inode_nr
, endpoint_t proc_e
,
754 vir_bytes buf
, size_t len
,
755 int direct
/* set to 1 to use direct grants instead of magic grants */
760 r
= req_rdlink_actual(fs_e
, inode_nr
, proc_e
, buf
, len
, direct
,
766 if((r
=vm_vfs_procctl_handlemem(proc_e
, buf
, len
, 1)) != OK
) {
770 r
= req_rdlink_actual(fs_e
, inode_nr
, proc_e
, buf
, len
,
777 /*===========================================================================*
779 *===========================================================================*/
786 struct node_details
*res
,
787 unsigned int *fs_flags
791 cp_grant_id_t grant_id
;
798 len
= strlen(label
)+1;
799 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) label
, len
, CPF_READ
);
801 panic("req_readsuper: cpf_grant_direct failed");
803 /* Fill in request message */
804 m
.m_type
= REQ_READSUPER
;
805 m
.m_vfs_fs_readsuper
.flags
= 0;
806 if(readonly
) m
.m_vfs_fs_readsuper
.flags
|= REQ_RDONLY
;
807 if(isroot
) m
.m_vfs_fs_readsuper
.flags
|= REQ_ISROOT
;
808 m
.m_vfs_fs_readsuper
.grant
= grant_id
;
809 m
.m_vfs_fs_readsuper
.device
= dev
;
810 m
.m_vfs_fs_readsuper
.path_len
= len
;
812 /* Send/rec request */
813 r
= fs_sendrec(fs_e
, &m
);
814 cpf_revoke(grant_id
);
817 /* Fill in response structure */
818 res
->fs_e
= m
.m_source
;
819 res
->inode_nr
= m
.m_fs_vfs_readsuper
.inode
;
820 res
->fmode
= m
.m_fs_vfs_readsuper
.mode
;
821 res
->fsize
= m
.m_fs_vfs_readsuper
.file_size
;
822 res
->uid
= m
.m_fs_vfs_readsuper
.uid
;
823 res
->gid
= m
.m_fs_vfs_readsuper
.gid
;
824 *fs_flags
= m
.m_fs_vfs_readsuper
.flags
;
831 /*===========================================================================*
832 * req_readwrite_actual *
833 *===========================================================================*/
834 static int req_readwrite_actual(endpoint_t fs_e
, ino_t inode_nr
, off_t pos
,
835 int rw_flag
, endpoint_t user_e
, vir_bytes user_addr
,
836 unsigned int num_of_bytes
, off_t
*new_posp
, size_t *cum_iop
,
841 cp_grant_id_t grant_id
;
844 vmp
= find_vmnt(fs_e
);
846 grant_id
= cpf_grant_magic(fs_e
, user_e
, user_addr
, num_of_bytes
,
847 (rw_flag
==READING
? CPF_WRITE
:CPF_READ
) | cpflag
);
849 panic("req_readwrite: cpf_grant_magic failed");
851 /* Fill in request message */
852 m
.m_type
= rw_flag
== READING
? REQ_READ
: REQ_WRITE
;
853 m
.m_vfs_fs_readwrite
.inode
= inode_nr
;
854 m
.m_vfs_fs_readwrite
.grant
= grant_id
;
855 m
.m_vfs_fs_readwrite
.seek_pos
= pos
;
856 if ((!(vmp
->m_fs_flags
& RES_64BIT
)) && (pos
> INT_MAX
)) {
859 m
.m_vfs_fs_readwrite
.nbytes
= num_of_bytes
;
861 /* Send/rec request */
862 r
= fs_sendrec(fs_e
, &m
);
864 if (cpf_revoke(grant_id
) == GRANT_FAULTED
) return(ERESTART
);
867 /* Fill in response structure */
868 *new_posp
= m
.m_fs_vfs_readwrite
.seek_pos
;
869 *cum_iop
= m
.m_fs_vfs_readwrite
.nbytes
;
875 /*===========================================================================*
877 *===========================================================================*/
878 int req_readwrite(endpoint_t fs_e
, ino_t inode_nr
, off_t pos
,
879 int rw_flag
, endpoint_t user_e
, vir_bytes user_addr
,
880 unsigned int num_of_bytes
, off_t
*new_posp
, size_t *cum_iop
)
884 r
= req_readwrite_actual(fs_e
, inode_nr
, pos
, rw_flag
, user_e
,
885 user_addr
, num_of_bytes
, new_posp
, cum_iop
, CPF_TRY
);
888 if ((r
=vm_vfs_procctl_handlemem(user_e
, (vir_bytes
) user_addr
,
889 num_of_bytes
, rw_flag
== READING
)) != OK
) {
893 r
= req_readwrite_actual(fs_e
, inode_nr
, pos
, rw_flag
, user_e
,
894 user_addr
, num_of_bytes
, new_posp
, cum_iop
, 0);
900 /*===========================================================================*
902 *===========================================================================*/
903 int req_peek(endpoint_t fs_e
, ino_t inode_nr
, off_t pos
, unsigned int bytes
)
907 memset(&m
, 0, sizeof(m
));
909 if (ex64hi(pos
) != 0)
910 panic("req_peek: pos too large");
912 /* Fill in request message */
914 m
.m_vfs_fs_readwrite
.inode
= inode_nr
;
915 m
.m_vfs_fs_readwrite
.grant
= -1;
916 m
.m_vfs_fs_readwrite
.seek_pos
= pos
;
917 m
.m_vfs_fs_readwrite
.nbytes
= bytes
;
919 /* Send/rec request */
920 return fs_sendrec(fs_e
, &m
);
923 /*===========================================================================*
925 *===========================================================================*/
927 req_rename(endpoint_t fs_e
, ino_t old_dir
, char *old_name
, ino_t new_dir
, char *new_name
)
930 cp_grant_id_t gid_old
, gid_new
;
931 size_t len_old
, len_new
;
934 len_old
= strlen(old_name
) + 1;
935 gid_old
= cpf_grant_direct(fs_e
, (vir_bytes
) old_name
, len_old
, CPF_READ
);
937 panic("req_rename: cpf_grant_direct failed");
939 len_new
= strlen(new_name
) + 1;
940 gid_new
= cpf_grant_direct(fs_e
, (vir_bytes
) new_name
, len_new
, CPF_READ
);
942 panic("req_rename: cpf_grant_direct failed");
944 /* Fill in request message */
945 m
.m_type
= REQ_RENAME
;
946 m
.m_vfs_fs_rename
.dir_old
= old_dir
;
947 m
.m_vfs_fs_rename
.grant_old
= gid_old
;
948 m
.m_vfs_fs_rename
.len_old
= len_old
;
950 m
.m_vfs_fs_rename
.dir_new
= new_dir
;
951 m
.m_vfs_fs_rename
.grant_new
= gid_new
;
952 m
.m_vfs_fs_rename
.len_new
= len_new
;
954 /* Send/rec request */
955 r
= fs_sendrec(fs_e
, &m
);
963 /*===========================================================================*
965 *===========================================================================*/
967 req_rmdir(endpoint_t fs_e
, ino_t inode_nr
, char *lastc
)
970 cp_grant_id_t grant_id
;
974 len
= strlen(lastc
) + 1;
975 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) lastc
, len
, CPF_READ
);
977 panic("req_rmdir: cpf_grant_direct failed");
979 /* Fill in request message */
980 m
.m_type
= REQ_RMDIR
;
981 m
.m_vfs_fs_unlink
.inode
= inode_nr
;
982 m
.m_vfs_fs_unlink
.grant
= grant_id
;
983 m
.m_vfs_fs_unlink
.path_len
= len
;
985 /* Send/rec request */
986 r
= fs_sendrec(fs_e
, &m
);
987 cpf_revoke(grant_id
);
993 /*===========================================================================*
995 *===========================================================================*/
996 static int req_slink_actual(
1001 vir_bytes path_addr
,
1010 cp_grant_id_t gid_name
, gid_buf
;
1013 len
= strlen(lastc
) + 1;
1014 gid_name
= cpf_grant_direct(fs_e
, (vir_bytes
) lastc
, len
, CPF_READ
);
1015 if (gid_name
== GRANT_INVALID
)
1016 panic("req_slink: cpf_grant_direct failed");
1018 gid_buf
= cpf_grant_magic(fs_e
, proc_e
, path_addr
, path_length
,
1021 if (gid_buf
== GRANT_INVALID
) {
1022 cpf_revoke(gid_name
);
1023 panic("req_slink: cpf_grant_magic failed");
1026 /* Fill in request message */
1027 m
.m_type
= REQ_SLINK
;
1028 m
.m_vfs_fs_slink
.inode
= inode_nr
;
1029 m
.m_vfs_fs_slink
.uid
= uid
;
1030 m
.m_vfs_fs_slink
.gid
= gid
;
1031 m
.m_vfs_fs_slink
.grant_path
= gid_name
;
1032 m
.m_vfs_fs_slink
.path_len
= len
;
1033 m
.m_vfs_fs_slink
.grant_target
= gid_buf
;
1034 m
.m_vfs_fs_slink
.mem_size
= path_length
;
1036 /* Send/rec request */
1037 r
= fs_sendrec(fs_e
, &m
);
1039 cpf_revoke(gid_name
);
1040 if (cpf_revoke(gid_buf
) == GRANT_FAULTED
) return(ERESTART
);
1045 /*===========================================================================*
1047 *===========================================================================*/
1053 vir_bytes path_addr
,
1061 r
= req_slink_actual(fs_e
, inode_nr
, lastc
, proc_e
, path_addr
,
1062 path_length
, uid
, gid
, CPF_TRY
);
1064 if (r
== ERESTART
) {
1065 if((r
=vm_vfs_procctl_handlemem(proc_e
, (vir_bytes
) path_addr
,
1066 path_length
, 0)) != OK
) {
1070 r
= req_slink_actual(fs_e
, inode_nr
, lastc
, proc_e
, path_addr
,
1071 path_length
, uid
, gid
, 0);
1077 /*===========================================================================*
1079 *===========================================================================*/
1080 int req_stat_actual(endpoint_t fs_e
, ino_t inode_nr
, endpoint_t proc_e
,
1081 vir_bytes buf
, int cpflag
)
1083 cp_grant_id_t grant_id
;
1087 /* Grant FS access to copy straight into user provided buffer */
1088 grant_id
= cpf_grant_magic(fs_e
, proc_e
, buf
, sizeof(struct stat
),
1089 CPF_WRITE
| cpflag
);
1092 panic("req_stat: cpf_grant_* failed");
1094 /* Fill in request message */
1095 m
.m_type
= REQ_STAT
;
1096 m
.m_vfs_fs_stat
.inode
= inode_nr
;
1097 m
.m_vfs_fs_stat
.grant
= grant_id
;
1099 /* Send/rec request */
1100 r
= fs_sendrec(fs_e
, &m
);
1102 if (cpf_revoke(grant_id
) == GRANT_FAULTED
) return(ERESTART
);
1108 /*===========================================================================*
1110 *===========================================================================*/
1111 int req_stat(endpoint_t fs_e
, ino_t inode_nr
, endpoint_t proc_e
,
1116 r
= req_stat_actual(fs_e
, inode_nr
, proc_e
, buf
, CPF_TRY
);
1118 if (r
== ERESTART
) {
1119 if((r
=vm_vfs_procctl_handlemem(proc_e
, (vir_bytes
) buf
,
1120 sizeof(struct stat
), 1)) != OK
) {
1124 r
= req_stat_actual(fs_e
, inode_nr
, proc_e
, buf
, 0);
1130 /*===========================================================================*
1132 *===========================================================================*/
1134 req_sync(endpoint_t fs_e
)
1138 /* Fill in request message */
1139 m
.m_type
= REQ_SYNC
;
1141 /* Send/rec request */
1142 return fs_sendrec(fs_e
, &m
);
1146 /*===========================================================================*
1148 *===========================================================================*/
1150 req_unlink(endpoint_t fs_e
, ino_t inode_nr
, char *lastc
)
1152 cp_grant_id_t grant_id
;
1157 len
= strlen(lastc
) + 1;
1158 grant_id
= cpf_grant_direct(fs_e
, (vir_bytes
) lastc
, len
, CPF_READ
);
1160 panic("req_unlink: cpf_grant_direct failed");
1162 /* Fill in request message */
1163 m
.m_type
= REQ_UNLINK
;
1164 m
.m_vfs_fs_unlink
.inode
= inode_nr
;
1165 m
.m_vfs_fs_unlink
.grant
= grant_id
;
1166 m
.m_vfs_fs_unlink
.path_len
= len
;
1168 /* Send/rec request */
1169 r
= fs_sendrec(fs_e
, &m
);
1170 cpf_revoke(grant_id
);
1176 /*===========================================================================*
1178 *===========================================================================*/
1180 req_unmount(endpoint_t fs_e
)
1184 /* Fill in request message */
1185 m
.m_type
= REQ_UNMOUNT
;
1187 /* Send/rec request */
1188 return fs_sendrec(fs_e
, &m
);
1192 /*===========================================================================*
1194 *===========================================================================*/
1195 int req_utime(endpoint_t fs_e
, ino_t inode_nr
, struct timespec
* actimespec
,
1196 struct timespec
* modtimespec
)
1200 assert(actimespec
!= NULL
);
1201 assert(modtimespec
!= NULL
);
1203 /* Fill in request message */
1204 m
.m_type
= REQ_UTIME
;
1205 m
.m_vfs_fs_utime
.inode
= inode_nr
;
1206 m
.m_vfs_fs_utime
.actime
= actimespec
->tv_sec
;
1207 m
.m_vfs_fs_utime
.modtime
= modtimespec
->tv_sec
;
1208 m
.m_vfs_fs_utime
.acnsec
= actimespec
->tv_nsec
;
1209 m
.m_vfs_fs_utime
.modnsec
= modtimespec
->tv_nsec
;
1211 /* Send/rec request */
1212 return fs_sendrec(fs_e
, &m
);