1 /*
2 * Copyright 2012, Andreas Henriksson, sausageboy@gmail.com.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include "fssh_stdio.h"
8 #include "syscalls.h"
9
10 #include "bfs.h"
11 #include "bfs_control.h"
12
13
14 namespace FSShell {
15
16
17 fssh_status_t
command_resizefs(int argc,const char * const * argv)18 command_resizefs(int argc, const char* const* argv)
19 {
20 if (argc != 2) {
21 fssh_dprintf("Usage: %s <new size>\n", argv[0]);
22 return B_ERROR;
23 }
24
25 uint64 newSize;
26 if (fssh_sscanf(argv[1], "%" B_SCNu64, &newSize) < 1) {
27 fssh_dprintf("Unknown argument or invalid size\n");
28 return B_ERROR;
29 }
30
31 int rootDir = _kern_open_dir(-1, "/myfs");
32 if (rootDir < 0) {
33 fssh_dprintf("Error: Couldn't open root directory\n");
34 return rootDir;
35 }
36
37 status_t status = _kern_ioctl(rootDir, BFS_IOCTL_RESIZE,
38 &newSize, sizeof(newSize));
39
40 _kern_close(rootDir);
41
42 if (status != B_OK) {
43 fssh_dprintf("Resizing failed, status: %s\n", fssh_strerror(status));
44 return status;
45 }
46
47 fssh_dprintf("File system successfully resized!\n");
48 return B_OK;
49 }
50
51
52 } // namespace FSShell
53