1 2 #include "fsdriver.h" 3 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) 10 { 11 12 /* Do nothing for peek requests. */ 13 if (data == NULL) 14 return OK; 15 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"); 19 20 if (data->endpt == SELF) { 21 memcpy(ptr, &data->ptr[off], len); 22 23 return OK; 24 } 25 26 return sys_safecopyfrom(data->endpt, data->grant, off, (vir_bytes)ptr, 27 (phys_bytes)len); 28 } 29 30 /* 31 * Copy data from the local address space to the caller. 32 */ 33 int 34 fsdriver_copyout(const struct fsdriver_data * data, size_t off, 35 const void * ptr, size_t len) 36 { 37 38 /* Do nothing for peek requests. */ 39 if (data == NULL) 40 return OK; 41 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"); 45 46 if (data->endpt == SELF) { 47 memcpy(&data->ptr[off], ptr, len); 48 49 return OK; 50 } 51 52 return sys_safecopyto(data->endpt, data->grant, off, (vir_bytes)ptr, 53 (phys_bytes)len); 54 } 55 56 /* 57 * Zero out a data region in the caller. 58 */ 59 int 60 fsdriver_zero(const struct fsdriver_data * data, size_t off, size_t len) 61 { 62 63 /* Do nothing for peek requests. */ 64 if (data == NULL) 65 return OK; 66 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"); 70 71 if (data->endpt == SELF) { 72 memset(&data->ptr[off], 0, len); 73 74 return OK; 75 } 76 77 return sys_safememset(data->endpt, data->grant, off, 0, len); 78 } 79 80 /* 81 * Copy in a null-terminated name, and perform sanity checks. 82 */ 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) 86 { 87 int r; 88 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; 94 95 if ((r = sys_safecopyfrom(endpt, grant, 0, (vir_bytes)name, 96 (phys_bytes)len)) != OK) 97 return r; 98 99 if (name[len - 1] != 0) { 100 printf("fsdriver: name not null-terminated\n"); 101 return EINVAL; 102 } 103 104 return OK; 105 } 106