From a722407264d1a7dfc114fcb896ae039038132dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 27 Mar 2006 07:38:53 +0000 Subject: [PATCH] Added "relabel" command to rename volumes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16888 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/fs_shell/fsh.cpp | 26 +++++++++++++++++ .../kernel/file_systems/fs_shell/kernel.c | 29 +++++++++++++++++++ .../kernel/file_systems/fs_shell/kprotos.h | 1 + 3 files changed, 56 insertions(+) diff --git a/src/tests/add-ons/kernel/file_systems/fs_shell/fsh.cpp b/src/tests/add-ons/kernel/file_systems/fs_shell/fsh.cpp index b9d5769c25..8d565865bf 100644 --- a/src/tests/add-ons/kernel/file_systems/fs_shell/fsh.cpp +++ b/src/tests/add-ons/kernel/file_systems/fs_shell/fsh.cpp @@ -1669,6 +1669,31 @@ do_sync(int argc, char **argv) } +static int +do_relabel(int argc, char **argv) +{ + if (argc < 2) { + printf("usage: relabel \n"); + return FS_EINVAL; + } + + struct my_stat st; + status_t error = sys_rstat(true, -1, "/myfs", &st, true); + if (error == FS_OK) { + fs_info info; + strncpy(info.volume_name, argv[1], sizeof(info.volume_name)); + info.volume_name[sizeof(info.volume_name) - 1] = '\0'; + + error = sys_write_fs_info(true, st.dev, &info, WFSSTAT_NAME); + } + + if (error != FS_OK) + printf("Could not create index: %s\n", fs_strerror(error)); + + return error; +} + + static int do_mkindex(int argc, char **argv) { @@ -2038,6 +2063,7 @@ static cmd_entry builtin_commands[] = { "seek", do_seek, "seek to the position specified" }, { "mv", do_rename, "rename a file or directory" }, { "sync", do_sync, "call sync" }, + { "relabel", do_relabel, "rename the volume" }, { "wrattr", do_write_attr, "write attribute \"name\" to the current file (N bytes [256])." }, { "rdattr", do_read_attr, "read attribute \"name\" from the current file (N bytes [256])." }, { "rmattr", do_remove_attr, "remove attribute \"name\" from the current file." }, diff --git a/src/tests/add-ons/kernel/file_systems/fs_shell/kernel.c b/src/tests/add-ons/kernel/file_systems/fs_shell/kernel.c index 1eb3925d4e..1ca4780eaf 100644 --- a/src/tests/add-ons/kernel/file_systems/fs_shell/kernel.c +++ b/src/tests/add-ons/kernel/file_systems/fs_shell/kernel.c @@ -2084,6 +2084,35 @@ error1: } +int +sys_write_fs_info(int kernel, dev_t device, struct fs_info *info, int mask) +{ + int status = FS_EINVAL; + fsystem *fs = NULL; + vnode *root = NULL; + nspace *ns; + + LOCK(vnlock); + ns = nsidtons(device); + if (ns != NULL) { + fs = ns->fs; + if (fs->ops.wfsstat != NULL) { + status = FS_OK; + root = ns->root; + root->rcnt++; + } + } + UNLOCK(vnlock); + + if (status == FS_OK) { + status = (*fs->ops.wfsstat)(ns->data, info, mask); + dec_vnode(root, FALSE); + } + + return status; +} + + int sys_mkindex(int kernel, dev_t device, const char *index, int type, int flags) { diff --git a/src/tests/add-ons/kernel/file_systems/fs_shell/kprotos.h b/src/tests/add-ons/kernel/file_systems/fs_shell/kprotos.h index f0523daecd..1575d87a5a 100644 --- a/src/tests/add-ons/kernel/file_systems/fs_shell/kprotos.h +++ b/src/tests/add-ons/kernel/file_systems/fs_shell/kprotos.h @@ -31,6 +31,7 @@ void *sys_mount(int kernel, const char *filesystem, int fd, const char *where, const char *device, ulong flags, void *parms, size_t len); int sys_unmount(int kernel, int fd, const char *where); +int sys_write_fs_info(int kernel, dev_t device, struct fs_info *info, int mask); int sys_rstat(int kernel, int fd, const char *path, struct my_stat *st, int eatlink); int sys_wstat(int kernel, int fd, const char *path, struct my_stat *st,