commit bbd10e0d3036a40260f41eae445488baf7bf27a1
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Mar 13 13:47:59 2024 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Mar 13 13:47:59 2024 +0100
Move more things around
diff --git a/ubase/ctrlaltdel.8 b/linux/ctrlaltdel.8
similarity index 100%
rename from ubase/ctrlaltdel.8
rename to linux/ctrlaltdel.8
diff --git a/ubase/ctrlaltdel.c b/linux/ctrlaltdel.c
similarity index 100%
rename from ubase/ctrlaltdel.c
rename to linux/ctrlaltdel.c
diff --git a/ubase/insmod.8 b/linux/insmod.8
similarity index 100%
rename from ubase/insmod.8
rename to linux/insmod.8
diff --git a/ubase/insmod.c b/linux/insmod.c
similarity index 100%
rename from ubase/insmod.c
rename to linux/insmod.c
diff --git a/ubase/df.1 b/posix/df.1
similarity index 100%
rename from ubase/df.1
rename to posix/df.1
diff --git a/ubase/df.c b/posix/df.c
similarity index 100%
rename from ubase/df.c
rename to posix/df.c
diff --git a/ubase/id.1 b/posix/id.1
similarity index 100%
rename from ubase/id.1
rename to posix/id.1
diff --git a/ubase/id.c b/posix/id.c
similarity index 100%
rename from ubase/id.c
rename to posix/id.c
diff --git a/ubase/ps.1 b/posix/ps.1
similarity index 100%
rename from ubase/ps.1
rename to posix/ps.1
diff --git a/ubase/ps.c b/posix/ps.c
similarity index 100%
rename from ubase/ps.c
rename to posix/ps.c
diff --git a/ubase/who.1 b/posix/who.1
similarity index 100%
rename from ubase/who.1
rename to posix/who.1
diff --git a/ubase/who.c b/posix/who.c
similarity index 100%
rename from ubase/who.c
rename to posix/who.c
diff --git a/ubase/dd.1 b/ubase/dd.1
deleted file mode 100644
index 477e99f..0000000
--- a/ubase/dd.1
+++ /dev/null
_AT_@ -1,66 +0,0 @@
-.Dd February 2, 2015
-.Dt DD 1
-.Os ubase
-.Sh NAME
-.Nm dd
-.Nd convert and copy a file
-.Sh SYNOPSIS
-.Nm
-.Op Ar operand...
-.Sh DESCRIPTION
-.Nm
-copies the standard input to the standard output. By default input data is
-read and written in 64kB blocks. When finished,
-.Nm
-displays the number of records read and written as well as the total number
-of bytes copied.
-.Nm
-syncs the filesystem once it is done copying. If you want to disable that use
-the
-.Ar nosync
-option.
-.Sh OPTIONS
-.Bl -tag -width Ds
-.It Ar bs Ns Op Ar =N
-If
-.Ar bs
-is not specified, the default blocksize is 64kB. If
-.Ar bs
-is specified
-without setting it to a specific value then an optimal value between the
-source and target filesystem will be selected. If this process fails it will
-fallback to the system's pagesize. Adjust
-.Ar N
-to set the block size of the transfers in bytes.
-.It Ar count=N
-Copy only
-.Ar N
-input blocks.
-.It Ar direct
-Use direct I/O for data.
-.It Ar if=file
-Read input from
-.Ar file
-instead of the standard input.
-.It Ar nosync
-Do not sync the filesystem once we are done copying.
-.It Ar quiet
-Enable quiet output.
-.It Ar of=file
-Write output to
-.Ar file
-instead of the standard output. If an initial portion of the output
-.Ar file
-is skipped using the seek operand, the output file is truncated at that
-point.
-.It Ar seek=N
-Seek
-.Ar N
-blocks from the beginning of the output before copying.
-.It Ar skip=N
-Skip
-.Ar N
-blocks from the beginning of the input before copying.
-.It Ar conv=notrunc
-Do not truncate the output file.
-.El
diff --git a/ubase/dd.c b/ubase/dd.c
deleted file mode 100644
index 2dce98e..0000000
--- a/ubase/dd.c
+++ /dev/null
_AT_@ -1,301 +0,0 @@
-/* (C) 2011-2012 Sebastian Krahmer all rights reserved.
- *
- * Optimized dd, to speed up backups etc.
- *
- * Permission has been granted to release this code under MIT/X.
- * The original code is at
https://github.com/stealth/odd. This
- * version of the code has been modified by sin_AT_2f30.org.
- */
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/vfs.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "util.h"
-
-struct dd_config {
- const char *in, *out;
- uint64_t skip, seek, count, b_in, b_out, rec_in, rec_out;
- off_t fsize;
- blksize_t bs;
- char quiet, nosync, notrunc, direct;
- time_t t_start, t_end;
-};
-
-static int sigint = 0;
-
-static void
-sig_int(int unused_1, siginfo_t *unused_2, void *unused_3)
-{
- (void) unused_1;
- (void) unused_2;
- (void) unused_3;
- sigint = 1;
-}
-
-static int
-prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
-{
- struct stat st;
- int fli = O_RDONLY|O_LARGEFILE|O_NOCTTY, flo = O_WRONLY|O_LARGEFILE|O_CREAT|O_NOATIME|O_NOCTTY;
- long pagesize;
-
- if (ddc->direct) {
- fli |= O_DIRECT;
- flo |= O_DIRECT;
- }
-
- if (!ddc->in) *ifd = 0;
- else if ((*ifd = open(ddc->in, fli)) < 0)
- return -1;
-
- if (fstat(*ifd, &st) < 0)
- return -1;
-
- ddc->fsize = st.st_size;
-
- /* If "bsize" is not given, use optimum of both FS' */
- if (!ddc->bs) {
- struct statfs fst;
- memset(&fst, 0, sizeof(fst));
- pagesize = sysconf(_SC_PAGESIZE);
- if (pagesize <= 0)
- pagesize = 0x1000;
- if (statfs(ddc->out, &fst) < 0 || fst.f_bsize == 0)
- fst.f_bsize = pagesize;
- if ((unsigned long)fst.f_bsize > (unsigned long)st.st_blksize)
- ddc->bs = fst.f_bsize;
- else
- ddc->bs = st.st_blksize;
- if (ddc->bs == 0)
- ddc->bs = pagesize;
- }
-
- /* check if device or regular file */
- if (!S_ISREG(st.st_mode)) {
- if (S_ISBLK(st.st_mode)) {
- if (ioctl(*ifd, BLKGETSIZE64, &ddc->fsize) < 0) {
- close(*ifd);
- return -1;
- }
- } else {
- ddc->fsize = (off_t)-1;
- }
- }
-
- /* skip and seek are in block items */
- ddc->skip *= ddc->bs;
- ddc->seek *= ddc->bs;
-
- /* skip more bytes than are inside source file? */
- if (ddc->fsize != (off_t)-1 && ddc->skip >= (uint64_t)ddc->fsize) {
- errno = EINVAL;
- close(*ifd);
- return -1;
- }
-
- if (!ddc->seek && !ddc->notrunc)
- flo |= O_TRUNC;
-
- if (!ddc->out) *ofd = 1;
- else if ((*ofd = open(ddc->out, flo, st.st_mode)) < 0) {
- close(*ifd);
- return -1;
- }
-
- if (ddc->seek && !ddc->notrunc) {
- if (fstat(*ofd, &st) < 0)
- return -1;
- if (!S_ISREG(st.st_mode))
- ;
- else if (ftruncate(*ofd, ddc->seek) < 0)
- return -1;
- }
-
- if (lseek(*ifd, ddc->skip, SEEK_CUR) < 0) {
- char buffer[ddc->bs];
- for (uint64_t i = 0; i < ddc->skip; i += ddc->bs) {
- if (read(*ifd, &buffer, ddc->bs) < 0) {
- errno = EINVAL;
- close(*ifd);
- return -1;
- }
- }
- }
- lseek(*ofd, ddc->seek, SEEK_CUR);
- posix_fadvise(*ifd, ddc->skip, 0, POSIX_FADV_SEQUENTIAL);
- posix_fadvise(*ofd, 0, 0, POSIX_FADV_DONTNEED);
-
- /* count is in block items too */
- ddc->count *= ddc->bs;
-
- /* If no count is given, its the filesize minus skip offset */
- if (ddc->count == (uint64_t) -1)
- ddc->count = ddc->fsize - ddc->skip;
-
- return 0;
-}
-
-static int
-copy_splice(struct dd_config *ddc)
-{
- int ifd, ofd, p[2] = {-1, -1};
- ssize_t r = 0;
- size_t n = 0;
-
- if (prepare_copy(ddc, &ifd, &ofd) < 0)
- return -1;
- if (pipe(p) < 0) {
- close(ifd); close(ofd);
- close(p[0]); close(p[1]);
- return -1;
- }
-#ifdef F_SETPIPE_SZ
- for (n = 29; n >= 20; --n) {
- if (fcntl(p[0], F_SETPIPE_SZ, 1<<n) != -1)
- break;
- }
- errno = 0;
-#endif
- n = ddc->bs;
- for (;ddc->b_out != ddc->count && !sigint;) {
- if (r < 0)
- break;
- if (n > ddc->count - ddc->b_out)
- n = ddc->count - ddc->b_out;
- r = splice(ifd, NULL, p[1], NULL, n, SPLICE_F_MORE);
- if (r <= 0)
- break;
- ++ddc->rec_in;
- r = splice(p[0], NULL, ofd, NULL, r, SPLICE_F_MORE);
- if (r <= 0)
- break;
- ddc->b_out += r;
- ++ddc->rec_out;
- }
-
- if (sigint)
- fprintf(stderr, "SIGINT! Aborting ...\n");
-
- close(ifd);
- close(ofd);
- close(p[0]);
- close(p[1]);
- if (r < 0)
- return -1;
- return 0;
-}
-
-static int
-copy(struct dd_config *ddc)
-{
- int r = 0;
-
- ddc->t_start = time(NULL);
-
- r = copy_splice(ddc);
- ddc->t_end = time(NULL);
-
- /* avoid div by zero */
- if (ddc->t_start == ddc->t_end)
- ++ddc->t_end;
- return r;
-}
-
-static void
-print_stat(const struct dd_config *ddc)
-{
- if (ddc->quiet)
- return;
-
- fprintf(stderr, "%"PRIu64" records in\n", ddc->rec_in);
- fprintf(stderr, "%"PRIu64" records out\n", ddc->rec_out);
- fprintf(stderr, "%"PRIu64" bytes (%"PRIu64" MB) copied", ddc->b_out,
- ddc->b_out/(1<<20));
- fprintf(stderr, ", %lu s, %f MB/s\n",
- (unsigned long)ddc->t_end - ddc->t_start,
- ((double)(ddc->b_out/(1<<20)))/(ddc->t_end - ddc->t_start));
-}
-
-static void
-usage(void)
-{
- eprintf("usage: %s [-h] [if=infile] [of=outfile] [bs[=N]] [seek=N] "
- "[skip=N] [count=N] [direct] [quiet] [nosync]"
- "[conv=notrunc]\n", argv0);
-}
-
-int
-main(int argc, char *argv[])
-{
- int i = 0;
- char buf[1024];
- struct dd_config config;
- struct sigaction sa;
-
- argv0 = argv[0];
- memset(&config, 0, sizeof(config));
- config.bs = 1<<16;
- config.in = NULL;
- config.out = NULL;
- config.count = (uint64_t) -1;
-
- /* emulate 'dd' argument parsing */
- for (i = 1; i < argc; ++i) {
- memset(buf, 0, sizeof(buf));
- if (strncmp(argv[i], "if=", 3) == 0)
- config.in = argv[i]+3;
- else if (strncmp(argv[i], "of=", 3) == 0)
- config.out = argv[i]+3;
- else if (sscanf(argv[i], "skip=%1023s", buf) == 1)
- config.skip = estrtoul(buf, 0);
- else if (sscanf(argv[i], "seek=%1023s", buf) == 1)
- config.seek = estrtoul(buf, 0);
- else if (sscanf(argv[i], "count=%1023s", buf) == 1)
- config.count = estrtoul(buf, 0);
- else if (strcmp(argv[i], "direct") == 0)
- config.direct = 1;
- else if (sscanf(argv[i], "bs=%1023s", buf) == 1)
- config.bs = estrtoul(buf, 0);
- else if (strcmp(argv[i], "bs") == 0)
- config.bs = 0;
- else if (strcmp(argv[i], "quiet") == 0)
- config.quiet = 1;
- else if (strcmp(argv[i], "nosync") == 0)
- config.nosync = 1;
- else if (strcmp(argv[i], "conv=notrunc") == 0)
- config.notrunc = 1;
- else if (strcmp(argv[i], "-h") == 0)
- usage();
- }
-
- signal(SIGPIPE, SIG_IGN);
-
- sa.sa_flags = SA_SIGINFO;
- sigemptyset(&sa.sa_mask);
- sa.sa_sigaction = sig_int;
-
- if (sigaction(SIGINT, &sa, NULL) == -1)
- weprintf("sigaction");
-
- if (copy(&config) < 0)
- weprintf("copy:");
- print_stat(&config);
-
- if (config.nosync == 0)
- sync();
- return errno;
-}
diff --git a/ubase/dmesg.1 b/unix/dmesg.1
similarity index 100%
rename from ubase/dmesg.1
rename to unix/dmesg.1
diff --git a/ubase/dmesg.c b/unix/dmesg.c
similarity index 100%
rename from ubase/dmesg.c
rename to unix/dmesg.c
diff --git a/ubase/getty.8 b/unix/getty.8
similarity index 100%
rename from ubase/getty.8
rename to unix/getty.8
diff --git a/ubase/getty.c b/unix/getty.c
similarity index 100%
rename from ubase/getty.c
rename to unix/getty.c
diff --git a/ubase/last.c b/unix/last.c
similarity index 100%
rename from ubase/last.c
rename to unix/last.c
diff --git a/ubase/lastlog.8 b/unix/lastlog.8
similarity index 100%
rename from ubase/lastlog.8
rename to unix/lastlog.8
diff --git a/ubase/lastlog.c b/unix/lastlog.c
similarity index 100%
rename from ubase/lastlog.c
rename to unix/lastlog.c
diff --git a/ubase/login.1 b/unix/login.1
similarity index 100%
rename from ubase/login.1
rename to unix/login.1
diff --git a/ubase/login.c b/unix/login.c
similarity index 100%
rename from ubase/login.c
rename to unix/login.c
diff --git a/ubase/mknod.1 b/unix/mknod.1
similarity index 100%
rename from ubase/mknod.1
rename to unix/mknod.1
diff --git a/ubase/mknod.c b/unix/mknod.c
similarity index 100%
rename from ubase/mknod.c
rename to unix/mknod.c
diff --git a/ubase/mount.8 b/unix/mount.8
similarity index 100%
rename from ubase/mount.8
rename to unix/mount.8
diff --git a/ubase/mount.c b/unix/mount.c
similarity index 100%
rename from ubase/mount.c
rename to unix/mount.c
diff --git a/ubase/passwd.1 b/unix/passwd.1
similarity index 100%
rename from ubase/passwd.1
rename to unix/passwd.1
diff --git a/ubase/passwd.c b/unix/passwd.c
similarity index 100%
rename from ubase/passwd.c
rename to unix/passwd.c
diff --git a/ubase/passwd.h b/unix/passwd.h
similarity index 100%
rename from ubase/passwd.h
rename to unix/passwd.h
diff --git a/ubase/stat.1 b/unix/stat.1
similarity index 100%
rename from ubase/stat.1
rename to unix/stat.1
diff --git a/ubase/stat.c b/unix/stat.c
similarity index 100%
rename from ubase/stat.c
rename to unix/stat.c
diff --git a/ubase/su.1 b/unix/su.1
similarity index 100%
rename from ubase/su.1
rename to unix/su.1
diff --git a/ubase/su.c b/unix/su.c
similarity index 100%
rename from ubase/su.c
rename to unix/su.c
diff --git a/ubase/umount.8 b/unix/umount.8
similarity index 100%
rename from ubase/umount.8
rename to unix/umount.8
diff --git a/ubase/umount.c b/unix/umount.c
similarity index 100%
rename from ubase/umount.c
rename to unix/umount.c
Received on Wed Mar 13 2024 - 13:48:33 CET