fs_shell: 'resizefs' command
Change-Id: Ie4c18c76cd1a69945739817ecd99409b7611dd7a Reviewed-on: https://review.haiku-os.org/c/haiku/+/939 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
003169fbb3
commit
0b3f78e73b
@@ -98,4 +98,10 @@ struct check_control {
|
|||||||
#define BFS_IOCTL_CHECK_MAGIC 'BChk'
|
#define BFS_IOCTL_CHECK_MAGIC 'BChk'
|
||||||
|
|
||||||
|
|
||||||
|
/* A "back door" to side-step the regular resize interface, primarily for
|
||||||
|
* testing with bfs_shell. The parameter is a uint64 with the desired size.
|
||||||
|
*/
|
||||||
|
#define BFS_IOCTL_RESIZE 14205
|
||||||
|
|
||||||
|
|
||||||
#endif /* BFS_CONTROL_H */
|
#endif /* BFS_CONTROL_H */
|
||||||
|
|||||||
@@ -766,6 +766,18 @@ bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd,
|
|||||||
|
|
||||||
return volume->WriteSuperBlock();
|
return volume->WriteSuperBlock();
|
||||||
}
|
}
|
||||||
|
case BFS_IOCTL_RESIZE:
|
||||||
|
{
|
||||||
|
if (bufferLength != sizeof(uint64))
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
uint64 size;
|
||||||
|
if (user_memcpy((uint8*)&size, buffer, sizeof(uint64)) != B_OK)
|
||||||
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
|
ResizeVisitor resizer(volume);
|
||||||
|
return resizer.Resize(size, -1);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_FRAGMENTER
|
#ifdef DEBUG_FRAGMENTER
|
||||||
case 56741:
|
case 56741:
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ BuildPlatformMain <build>bfs_shell
|
|||||||
:
|
:
|
||||||
additional_commands.cpp
|
additional_commands.cpp
|
||||||
command_checkfs.cpp
|
command_checkfs.cpp
|
||||||
|
command_resizefs.cpp
|
||||||
:
|
:
|
||||||
<build>bfs.o
|
<build>bfs.o
|
||||||
<build>fs_shell.a $(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
|
<build>fs_shell.a $(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "fssh.h"
|
#include "fssh.h"
|
||||||
|
|
||||||
#include "command_checkfs.h"
|
#include "command_checkfs.h"
|
||||||
|
#include "command_resizefs.h"
|
||||||
|
|
||||||
|
|
||||||
namespace FSShell {
|
namespace FSShell {
|
||||||
@@ -17,6 +18,8 @@ register_additional_commands()
|
|||||||
{
|
{
|
||||||
CommandManager::Default()->AddCommand(command_checkfs, "checkfs",
|
CommandManager::Default()->AddCommand(command_checkfs, "checkfs",
|
||||||
"check file system");
|
"check file system");
|
||||||
|
CommandManager::Default()->AddCommand(command_resizefs, "resizefs",
|
||||||
|
"resize file system");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Andreas Henriksson, sausageboy@gmail.com.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "fssh_stdio.h"
|
||||||
|
#include "syscalls.h"
|
||||||
|
|
||||||
|
#include "bfs.h"
|
||||||
|
#include "bfs_control.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace FSShell {
|
||||||
|
|
||||||
|
|
||||||
|
fssh_status_t
|
||||||
|
command_resizefs(int argc, const char* const* argv)
|
||||||
|
{
|
||||||
|
if (argc != 2) {
|
||||||
|
fssh_dprintf("Usage: %s <new size>\n", argv[0]);
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 newSize;
|
||||||
|
if (fssh_sscanf(argv[1], "%" B_SCNu64, &newSize) < 1) {
|
||||||
|
fssh_dprintf("Unknown argument or invalid size\n");
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rootDir = _kern_open_dir(-1, "/myfs");
|
||||||
|
if (rootDir < 0) {
|
||||||
|
fssh_dprintf("Error: Couldn't open root directory\n");
|
||||||
|
return rootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t status = _kern_ioctl(rootDir, BFS_IOCTL_RESIZE,
|
||||||
|
&newSize, sizeof(newSize));
|
||||||
|
|
||||||
|
_kern_close(rootDir);
|
||||||
|
|
||||||
|
if (status != B_OK) {
|
||||||
|
fssh_dprintf("Resizing failed, status: %s\n", fssh_strerror(status));
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
fssh_dprintf("File system successfully resized!\n");
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace FSShell
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Andreas Henriksson, sausageboy@gmail.com.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef RESIZEFS_H
|
||||||
|
#define RESIZEFS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "fssh_types.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace FSShell {
|
||||||
|
|
||||||
|
|
||||||
|
fssh_status_t command_resizefs(int argc, const char* const* argv);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace FSShell
|
||||||
|
|
||||||
|
|
||||||
|
#endif // RESIZEFS_H
|
||||||
Reference in New Issue
Block a user