From 0b3f78e73bcf9d30ad5030b241c771373a4a0a45 Mon Sep 17 00:00:00 2001 From: ahenriksson Date: Fri, 13 Jul 2012 18:17:53 +0200 Subject: [PATCH] fs_shell: 'resizefs' command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie4c18c76cd1a69945739817ecd99409b7611dd7a Reviewed-on: https://review.haiku-os.org/c/haiku/+/939 Reviewed-by: Jérôme Duval --- .../kernel/file_systems/bfs/bfs_control.h | 6 +++ .../file_systems/bfs/kernel_interface.cpp | 12 +++++ src/tools/bfs_shell/Jamfile | 1 + src/tools/bfs_shell/additional_commands.cpp | 3 ++ src/tools/bfs_shell/command_resizefs.cpp | 52 +++++++++++++++++++ src/tools/bfs_shell/command_resizefs.h | 21 ++++++++ 6 files changed, 95 insertions(+) create mode 100644 src/tools/bfs_shell/command_resizefs.cpp create mode 100644 src/tools/bfs_shell/command_resizefs.h diff --git a/src/add-ons/kernel/file_systems/bfs/bfs_control.h b/src/add-ons/kernel/file_systems/bfs/bfs_control.h index 31388f5b8e..2b12e535a6 100644 --- a/src/add-ons/kernel/file_systems/bfs/bfs_control.h +++ b/src/add-ons/kernel/file_systems/bfs/bfs_control.h @@ -98,4 +98,10 @@ struct check_control { #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 */ diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index 98cafcb01c..fd30d20865 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -766,6 +766,18 @@ bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd, 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 case 56741: diff --git a/src/tools/bfs_shell/Jamfile b/src/tools/bfs_shell/Jamfile index 0fa6788d95..901b6a2c02 100644 --- a/src/tools/bfs_shell/Jamfile +++ b/src/tools/bfs_shell/Jamfile @@ -71,6 +71,7 @@ BuildPlatformMain bfs_shell : additional_commands.cpp command_checkfs.cpp + command_resizefs.cpp : bfs.o fs_shell.a $(HOST_LIBSUPC++) $(HOST_LIBSTDC++) diff --git a/src/tools/bfs_shell/additional_commands.cpp b/src/tools/bfs_shell/additional_commands.cpp index be876d1db5..f5dbe8f7a8 100644 --- a/src/tools/bfs_shell/additional_commands.cpp +++ b/src/tools/bfs_shell/additional_commands.cpp @@ -7,6 +7,7 @@ #include "fssh.h" #include "command_checkfs.h" +#include "command_resizefs.h" namespace FSShell { @@ -17,6 +18,8 @@ register_additional_commands() { CommandManager::Default()->AddCommand(command_checkfs, "checkfs", "check file system"); + CommandManager::Default()->AddCommand(command_resizefs, "resizefs", + "resize file system"); } diff --git a/src/tools/bfs_shell/command_resizefs.cpp b/src/tools/bfs_shell/command_resizefs.cpp new file mode 100644 index 0000000000..e2cfe2852d --- /dev/null +++ b/src/tools/bfs_shell/command_resizefs.cpp @@ -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 \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 diff --git a/src/tools/bfs_shell/command_resizefs.h b/src/tools/bfs_shell/command_resizefs.h new file mode 100644 index 0000000000..6bcb6938eb --- /dev/null +++ b/src/tools/bfs_shell/command_resizefs.h @@ -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