Skip to content

Commit 0ef5ba8

Browse files
committed
write rootfs
1 parent 21d73ff commit 0ef5ba8

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

init/nitro/main.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ rootfs_rcv(int sock_fd)
203203
{
204204
uint8_t len_b[8], *rootfs_archive;
205205
ssize_t read_len;
206-
uint64_t len;
206+
uint64_t len, idx = 0;
207207
int ret;
208208

209209
read_len = read(sock_fd, len_b, 8);
@@ -215,6 +215,24 @@ rootfs_rcv(int sock_fd)
215215

216216
memcpy(&len, len_b, sizeof(uint64_t));
217217

218+
rootfs_archive = (uint8_t *) malloc(len);
219+
if (rootfs_archive == NULL) {
220+
close(sock_fd);
221+
perror("rootfs archive malloc");
222+
return -1;
223+
}
224+
225+
while (len) {
226+
read_len = read(sock_fd, &rootfs_archive[idx], len);
227+
if (read_len <= 0) {
228+
close(sock_fd);
229+
perror("vsock rootfs archive read");
230+
return -1;
231+
}
232+
idx += read_len;
233+
len -= read_len;
234+
}
235+
218236
return 0;
219237
}
220238

src/nitro/src/enclaves.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ impl NitroEnclave {
137137
.write_all(&len.to_ne_bytes())
138138
.map_err(NitroError::RootFsLenWrite)?;
139139

140+
stream
141+
.write_all(&archive)
142+
.map_err(NitroError::RootFsWrite)?;
143+
140144
Ok(())
141145
}
142146
}

src/nitro/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum NitroError {
2424
VsockConnect,
2525
IpcWrite(io::Error),
2626
RootFsLenWrite(io::Error),
27+
RootFsWrite(io::Error),
2728
RootFsTooLarge,
2829
}
2930

@@ -69,6 +70,9 @@ impl fmt::Display for NitroError {
6970
NitroError::RootFsLenWrite(e) => {
7071
format!("unable to write rootfs archive length to enclave: {e}")
7172
}
73+
NitroError::RootFsWrite(e) => {
74+
format!("unable to write rootfs archive to enclave: {e}")
75+
}
7276
NitroError::RootFsTooLarge => "rootfs size is larger than 64 bytes".to_string(),
7377
};
7478

0 commit comments

Comments
 (0)