From aef6ece9e60e092d2815d894e04b4e0f244929fa Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Thu, 6 Jun 2024 09:29:54 -0600 Subject: [PATCH] Meta: Remove shred utility --- Base/usr/share/man/man1/shred.md | 39 ---------------- Userland/Utilities/CMakeLists.txt | 1 - Userland/Utilities/shred.cpp | 75 ------------------------------- 3 files changed, 115 deletions(-) delete mode 100644 Base/usr/share/man/man1/shred.md delete mode 100644 Userland/Utilities/shred.cpp diff --git a/Base/usr/share/man/man1/shred.md b/Base/usr/share/man/man1/shred.md deleted file mode 100644 index 8c1def0ac42..00000000000 --- a/Base/usr/share/man/man1/shred.md +++ /dev/null @@ -1,39 +0,0 @@ -## Name - -shred - destroy a file with its content on disk - -## Synopsis - -```**sh -$ shred [options...] [path...] -``` - -## Description - -`shred` destroys files' content on disk. - -## Options - -* `--help`: Display this message -* `-v`, `--verbose`: Show progress during the shred operation -* `-n`, `--iterations`: Iterations count of shred operation -* `-u`: Deallocate and remove file after overwriting -* `--random-source`: Get random bytes from a file other than /dev/random - -## Arguments - -* `path`: Files to shred - -## Examples - -```sh -# shred a file and remove it aftewards -$ shred -u /tmp/FILE_TO_BE_SHREDDED_AND_REMOVED -# shred a file with 10 iterations -$ shred --iterations 10 /tmp/FILE_TO_BE_SHREDDED -# shred a file with verbose progress and 10 iterations -$ shred -v --iterations 10 /tmp/FILE_TO_BE_SHREDDED -``` - -## See also -* [`rm`(1)](help://man/1/rm) to delete a file or directory without overwriting the content first diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 56ac9b6337a..c64aefbb26e 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -9,7 +9,6 @@ set(CMD_SOURCES isobmff.cpp js.cpp lzcat.cpp - shred.cpp tar.cpp test-jpeg-roundtrip.cpp ttfdisasm.cpp diff --git a/Userland/Utilities/shred.cpp b/Userland/Utilities/shred.cpp deleted file mode 100644 index b4cb826a6d7..00000000000 --- a/Userland/Utilities/shred.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2024, Romain Chardiny - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include - -ErrorOr serenity_main(Main::Arguments arguments) -{ - TRY(Core::System::pledge("stdio unix rpath wpath cpath")); - - Vector paths; - bool remove_file = false; - bool verbose = false; - u32 iterations = 3; - Optional random_source; - - Core::ArgsParser args_parser; - args_parser.add_option(remove_file, "Deallocate and remove file after overwriting", nullptr, 'u'); - args_parser.add_option(verbose, "Show progress", "verbose", 'v'); - args_parser.add_option(iterations, "Overwrite N times instead of the default (3)", "iterations", 'n', "N"); - args_parser.add_option(random_source, "Get random bytes from FILE", "random-source", 0, "FILE"); - args_parser.add_positional_argument(paths, "Path(s) to overwrite", "FILE", Core::ArgsParser::Required::Yes); - args_parser.parse(arguments); - - auto rng_file = TRY(Core::File::open(random_source.value_or("/dev/random"sv), Core::File::OpenMode::Read)); - - for (auto& path : paths) { - auto file = TRY(Core::File::open(path, Core::File::OpenMode::ReadWrite | Core::File::OpenMode::DontCreate)); - - off_t output_file_length = TRY(FileSystem::size_from_fstat(file->fd())); - - for (u32 iter = 0; iter < iterations; iter++) { - if (verbose) - outln("shred: {}: pass {}/{} (random)", path, iter + 1, iterations); - - Array buffer; - off_t total_written = 0; - ssize_t nread = 0; - ssize_t nwritten = 0; - - while (total_written < output_file_length) { - auto buffer_span = buffer.span().trim(output_file_length - total_written); - - nread = TRY(Core::System::read(rng_file->fd(), buffer_span)); - - if (nread == 0) - break; - - nwritten = TRY(Core::System::write(file->fd(), buffer_span)); - - if (nwritten == 0) - break; - - total_written += nwritten; - } - - TRY(Core::System::fsync(file->fd())); - TRY(file->seek(0, SeekMode::SetPosition)); - } - - if (remove_file) { - TRY(Core::System::ftruncate(file->fd(), 0)); - TRY(Core::System::unlink(path)); - } - } - - return 0; -}