Remove building with NOCRYPTO option
[minix.git] / minix / lib / libfsdriver / utility.c
blobd0553df92a8b5ad921bbf89f7974cdfd4c10c3b3
2 #include "fsdriver.h"
4 /*
5 * Copy data from the caller into the local address space.
6 */
7 int
8 fsdriver_copyin(const struct fsdriver_data * data, size_t off, void * ptr,
9 size_t len)
12 /* Do nothing for peek requests. */
13 if (data == NULL)
14 return OK;
16 /* The data size field is used only for this integrity check. */
17 if (off + len > data->size)
18 panic("fsdriver: copy-in buffer overflow");
20 if (data->endpt == SELF) {
21 memcpy(ptr, &data->ptr[off], len);
23 return OK;
26 return sys_safecopyfrom(data->endpt, data->grant, off, (vir_bytes)ptr,
27 (phys_bytes)len);
31 * Copy data from the local address space to the caller.
33 int
34 fsdriver_copyout(const struct fsdriver_data * data, size_t off,
35 const void * ptr, size_t len)
38 /* Do nothing for peek requests. */
39 if (data == NULL)
40 return OK;
42 /* The data size field is used only for this integrity check. */
43 if (off + len > data->size)
44 panic("fsdriver: copy-out buffer overflow");
46 if (data->endpt == SELF) {
47 memcpy(&data->ptr[off], ptr, len);
49 return OK;
52 return sys_safecopyto(data->endpt, data->grant, off, (vir_bytes)ptr,
53 (phys_bytes)len);
57 * Zero out a data region in the caller.
59 int
60 fsdriver_zero(const struct fsdriver_data * data, size_t off, size_t len)
63 /* Do nothing for peek requests. */
64 if (data == NULL)
65 return OK;
67 /* The data size field is used only for this integrity check. */
68 if (off + len > data->size)
69 panic("fsdriver: copy-out buffer overflow");
71 if (data->endpt == SELF) {
72 memset(&data->ptr[off], 0, len);
74 return OK;
77 return sys_safememset(data->endpt, data->grant, off, 0, len);
81 * Copy in a null-terminated name, and perform sanity checks.
83 int
84 fsdriver_getname(endpoint_t endpt, cp_grant_id_t grant, size_t len,
85 char * name, size_t size, int not_empty)
87 int r;
89 /* The given length includes the null terminator. */
90 if (len == 0 || (not_empty && len == 1))
91 return EINVAL;
92 if (len > size)
93 return ENAMETOOLONG;
95 if ((r = sys_safecopyfrom(endpt, grant, 0, (vir_bytes)name,
96 (phys_bytes)len)) != OK)
97 return r;
99 if (name[len - 1] != 0) {
100 printf("fsdriver: name not null-terminated\n");
101 return EINVAL;
104 return OK;