├── .clang-format ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── Makefile.in ├── NEWS ├── README.md ├── TODO ├── acinclude.m4 ├── aclocal.m4 ├── configure ├── configure.ac ├── doc ├── README.fsremap ├── design.txt ├── notes.txt └── torture-test.sh ├── examples └── fsremap.job.1 │ └── fsremap.log ├── fsattr ├── .cproject ├── .project ├── .settings │ └── language.settings.xml ├── build │ ├── Makefile.am │ └── Makefile.in └── src │ ├── autoconf.hh │ ├── check.hh │ ├── e4attr.cc │ ├── e4attr.hh │ ├── features.hh │ ├── first.hh │ ├── ft_config.hh │ ├── log.cc │ ├── log.hh │ ├── main.cc │ ├── misc.cc │ ├── misc.hh │ ├── mstring.cc │ ├── mstring.hh │ ├── traits.hh │ └── types.hh ├── fsmount_kernel ├── .cproject ├── .project ├── .settings │ └── language.settings.xml ├── build │ ├── Makefile.am │ └── Makefile.in └── src │ ├── autoconf.hh │ ├── check.hh │ ├── features.hh │ ├── first.hh │ ├── ft_config.hh │ ├── log.cc │ ├── log.hh │ ├── main.cc │ ├── misc.cc │ ├── misc.hh │ ├── mstring.cc │ ├── mstring.hh │ ├── traits.hh │ └── types.hh ├── fsmove ├── .cproject ├── .project ├── .settings │ └── language.settings.xml ├── build │ ├── Makefile.am │ └── Makefile.in └── src │ ├── args.cc │ ├── args.hh │ ├── assert.cc │ ├── assert.hh │ ├── autoconf.hh │ ├── cache │ ├── cache.hh │ ├── cache_adaptor.hh │ ├── cache_mem.hh │ ├── cache_symlink.cc │ └── cache_symlink.hh │ ├── check.hh │ ├── copy.cc │ ├── copy.hh │ ├── eta.cc │ ├── eta.hh │ ├── features.hh │ ├── first.hh │ ├── ft_config.hh │ ├── fwd.hh │ ├── io │ ├── disk_stat.cc │ ├── disk_stat.hh │ ├── io.cc │ ├── io.hh │ ├── io_posix.cc │ ├── io_posix.hh │ ├── io_posix_dir.cc │ ├── io_posix_dir.hh │ ├── io_posix_xattr.cc │ ├── io_posix_xattr.hh │ ├── io_prealloc.cc │ ├── io_prealloc.hh │ ├── util_dir.cc │ ├── util_dir.hh │ ├── util_posix.cc │ └── util_posix.hh │ ├── log.cc │ ├── log.hh │ ├── main.cc │ ├── misc.cc │ ├── misc.hh │ ├── move.cc │ ├── move.hh │ ├── mstring.cc │ ├── mstring.hh │ ├── rope │ ├── rope.cc │ ├── rope.hh │ ├── rope_impl.cc │ ├── rope_impl.hh │ ├── rope_list.cc │ ├── rope_list.hh │ ├── rope_pool.cc │ ├── rope_pool.hh │ ├── rope_test.cc │ └── rope_test.hh │ ├── traits.hh │ ├── types.hh │ ├── unsorted_map.cc │ ├── unsorted_map.hh │ ├── zstring.cc │ └── zstring.hh ├── fsremap ├── .cproject ├── .project ├── .settings │ └── language.settings.xml ├── build │ ├── Makefile.am │ └── Makefile.in └── src │ ├── arch │ ├── mem.cc │ ├── mem.hh │ ├── mem_linux.cc │ ├── mem_linux.hh │ ├── mem_posix.cc │ └── mem_posix.hh │ ├── args.cc │ ├── args.hh │ ├── assert.cc │ ├── assert.hh │ ├── autoconf.hh │ ├── cache │ ├── cache.hh │ ├── cache_adaptor.hh │ ├── cache_mem.hh │ ├── cache_symlink.cc │ └── cache_symlink.hh │ ├── check.hh │ ├── config.hh.in │ ├── copy.cc │ ├── copy.hh │ ├── dispatch.cc │ ├── dispatch.hh │ ├── eta.cc │ ├── eta.hh │ ├── extent.hh │ ├── features.hh │ ├── first.hh │ ├── fwd.hh │ ├── io │ ├── extent_file.cc │ ├── extent_file.hh │ ├── extent_posix.cc │ ├── extent_posix.hh │ ├── io.cc │ ├── io.hh │ ├── io_null.cc │ ├── io_null.hh │ ├── io_posix.cc │ ├── io_posix.hh │ ├── io_posix_dir.cc │ ├── io_posix_dir.hh │ ├── io_prealloc.cc │ ├── io_prealloc.hh │ ├── io_self_test.cc │ ├── io_self_test.hh │ ├── io_test.cc │ ├── io_test.hh │ ├── persist.cc │ ├── persist.hh │ ├── request.hh │ ├── util_dir.cc │ ├── util_dir.hh │ ├── util_posix.cc │ └── util_posix.hh │ ├── job.cc │ ├── job.hh │ ├── log.cc │ ├── log.hh │ ├── main.cc │ ├── map.cc │ ├── map.hh │ ├── map.t.hh │ ├── map_stat.cc │ ├── map_stat.hh │ ├── map_stat.t.hh │ ├── misc.cc │ ├── misc.hh │ ├── mstring.cc │ ├── mstring.hh │ ├── pool.cc │ ├── pool.hh │ ├── pool.t.hh │ ├── remap.cc │ ├── remap.hh │ ├── tmp_zero.cc │ ├── traits.hh │ ├── types.hh │ ├── ui │ ├── ui.cc │ ├── ui.hh │ ├── ui_tty.cc │ └── ui_tty.hh │ ├── unsorted_map.cc │ ├── unsorted_map.hh │ ├── vector.cc │ ├── vector.hh │ ├── vector.t.hh │ ├── work.cc │ ├── work.hh │ └── work.t.hh ├── fstransform ├── .cproject ├── .project ├── .settings │ └── language.settings.xml ├── build │ ├── Makefile.am │ ├── Makefile.am.work │ └── Makefile.in ├── fstransform-sh └── src │ ├── features.hh │ ├── first.hh │ ├── log.cc │ ├── log.hh │ ├── main.cc │ ├── mstring.cc │ ├── mstring.hh │ ├── transform.cc │ ├── transform.hh │ └── types.hh └── tools ├── config.guess ├── config.sub ├── depcomp ├── ft_cxx_features.m4 ├── ft_cxx_flags.m4 ├── ft_cxx_unordered_map.m4 ├── ft_need_funcs.m4 ├── ft_need_libs.m4 ├── ft_output.m4 ├── install-sh └── missing /.clang-format: -------------------------------------------------------------------------------- 1 | Language: Cpp 2 | # BasedOnStyle: Google 3 | AllowShortFunctionsOnASingleLine: false 4 | AllowShortIfStatementsOnASingleLine: false 5 | AllowShortLoopsOnASingleLine: false 6 | ColumnLimit: 100 7 | IndentWidth: 4 8 | Standard: Cpp11 9 | SortIncludes: false 10 | UseTab: Never 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *~ 3 | Debug/ 4 | .deps/ 5 | .dirstamp 6 | /autom4te.cache/ 7 | /config.cache 8 | /config.log 9 | /config.status 10 | /Makefile 11 | /fsattr/build/Makefile 12 | /fsattr/build/fsattr 13 | /fsmount_kernel/build/Makefile 14 | /fsmount_kernel/build/fsmount_kernel 15 | /fsmove/build/Makefile 16 | /fsmove/build/fsmove 17 | /fsremap/build/Makefile 18 | /fsremap/build/fsremap 19 | /fsremap/src/config.hh 20 | /fsremap/src/ft_config.hh 21 | /fsremap/src/stamp-h1 22 | /fstransform/build/Makefile 23 | /fstransform/build/fstransform 24 | /fstransform/fstransform 25 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Author: Massimiliano Ghilardi 2 | 3 | Contributors: none yet... 4 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | 3 | fstransform is currently tested only on Linux. 4 | Building and installing it is usually quite simple. 5 | Just run the following commands: 6 | 7 | ./configure 8 | make 9 | 10 | to actually install it, run as root the command 11 | 12 | make install 13 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = fsattr/build fsmove/build fsmount_kernel/build fsremap/build fstransform/build 2 | 3 | mrproper-distclean: distclean 4 | rm -fr autom4te.cache configure fsremap/src/ft_config.hh 5 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cosmos72/fstransform/efc519736069b6808f1c0fe74e810626732d5799/NEWS -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO 2 | 3 | * fstransform: preserve filesystem LABEL and UUID. To collect them, 4 | run "lsblk -r -o maj:min,label,uuid" warning: special 5 | characters in label and uuid will be escaped as \xAB 6 | 7 | * all: test on more file systems 8 | 9 | nilfs: ok as target. 10 | as source it gets practically full very quickly, free space fluctuates 11 | between zero and 1GB while the GC works to avoid "disk full" errors. 12 | But it works :) 13 | 14 | ntfs: ntfs-3g is VERY slow both as source and target because it's userspace. 15 | it supports only UTF-8 filenames, not arbitrary bytes in the range 128-255. 16 | fsmove must check beforehand! 17 | use mount.ntfs option big_writes... enough or still too slow? 18 | 19 | logfs: as target: "mkfs -t logfs" does NOT accept option -q, 20 | fsmove and umount crash with kernel bugs (see tests/) 21 | 22 | others: btrfs, gfs, gfs2, hfs, jffs2, ocfs2, qnx4, qnx6, ubifs... 23 | 24 | not yet: tux3 25 | 26 | * fstransform, fsmove: add fsremap-like persistence, i.e. the ability to resume 27 | a transformation after CTRL-C, power failure or similar interruptions 28 | 29 | * fsmove: use a larger buffer (1MB) to speed up backward copy. 30 | Worth it? beware of low free space... 31 | 32 | * fsremap: add a graphical interface ? probably not so worth it... 33 | 34 | * all: port to FreeBSD. see this: 35 | Procedure to mount file system images under FreeBSD 36 | First you have to create virtual device, using this command: 37 | # mdconfig -a -t vnode -f /path/to/image.iso -u 1 38 | The "mdconfig" command creates a device and prints the name. Just 39 | append that to "/dev/" and use it for whatever you need: 40 | # newfs /dev/md1 41 | # mount /dev/md1 /mnt 42 | To unmount the image use command: 43 | # umount /mnt 44 | Once unmounted, you can unconfigure the device with 45 | # mdconfig -d -u 1 46 | 47 | Also, many system files, as /lib/libc.so.7 are set as 48 | 'simmutable' (cannot open O_RDWR) and 'sunlink' (cannot unlink) 49 | so fsmove fails 50 | 51 | Furthermore, fsmove df-like stats do not work on FreeBSD: 52 | they seem to report usage of root file system 53 | 54 | Additionally, fsremap wraps calls to ff_posix_mkdir() with 55 | #ifdef __USE_POSIX, which is undefined by default on FreeBSD, 56 | causing ff_mkdir() to fail with ENOSYS. 57 | 58 | Finally, 'umount' wants mount-point instead of device. 59 | And how to 'mount -o remount,ro ' ? 60 | 61 | WONTDO 62 | * fsmove: if file system free space is critically low, launch 'xfs_fsr' 63 | to try and free some space before giving up. 64 | why not: 65 | LIMITED USEFULNESS: only for 'xfs' file system 66 | DANGEROUS: at least on linux with an almost-full source device 67 | xfs_fsr can WORSEN the problem by triggering 'loop write error' kernel errors, 68 | which mean the source device has not enough space to accommodate the loop file contents. 69 | typically this CORRUPTS the file system inside target (loop) device! 70 | 71 | 72 | DONE in 0.9.3 73 | * all: check FHS (Filesystem Hierarchy Standard) and decide where to 74 | put persistence data. decision: /var/tmp/fstransform/ 75 | 76 | * fsremap: add persistence, i.e. the ability to resume a transformation 77 | after CTRL-C, power failure or similar interruptions 78 | 79 | * fstransform: also allow device to be UNMOUNTED instead of MOUNTED. 80 | gives easier integration with gparted, and guarantees 81 | that nobody is accessing the file-system inside device 82 | 83 | DONE in 0.9.2 84 | * fsremap: preemptively check that last device block is writable. 85 | avoids troubles on linux with file-systems significantly smaller than device 86 | -------------------------------------------------------------------------------- /acinclude.m4: -------------------------------------------------------------------------------- 1 | m4_include([tools/ft_cxx_flags.m4]) 2 | m4_include([tools/ft_cxx_features.m4]) 3 | m4_include([tools/ft_cxx_unordered_map.m4]) 4 | m4_include([tools/ft_need_funcs.m4]) 5 | m4_include([tools/ft_need_libs.m4]) 6 | m4_include([tools/ft_output.m4]) 7 | -------------------------------------------------------------------------------- /doc/notes.txt: -------------------------------------------------------------------------------- 1 | ############################################### 2 | ################### NOTES ##################### 3 | ############################################### 4 | 5 | 1) logging 6 | 7 | 1.1) ff_log() and ff_vlog() must check if log subsystem is not initialized, and in case initialize it. 8 | removes the need to manually call ff_log_init() 9 | 10 | 1.2) ff_log(err) must distinguish between unreported (not yet logged) and reported (already logged) errors. 11 | the former have normal sign (EINVAL, ENOMEM...) and are reported normally, 12 | the latter have opposite sign (-EINVAL, -ENOMEM...) and are reported as " (caused by previous error: %s)" 13 | 14 | 1.2.1) ff_log() and ff_vlog() always return errors as reported (-EINVAL, -ENOMEM...) 15 | 16 | 1.2.2) ft_remap.main() and other high-level *.main() methods 17 | must check for unreported errors and log them them with message 18 | "failed with unreported error" 19 | 20 | 1.3) configurable log format: 21 | FC_FMT_MSG, // message only 22 | FC_FMT_LEVEL_MSG, // level + message 23 | FC_FMT_DATETIME_LEVEL_MSG, // datetime + level + message 24 | FC_FMT_DATETIME_LEVEL_CALLER_MSG, // datetime + level + [file.func(line)] + message 25 | 26 | 1.4.1) -v enables FC_FMT_LEVEL_MSG also for stdout/stderr 27 | 1.4.2) -vv enables FC_FMT_DATETIME_LEVEL_MSG also for stdout/stderr 28 | 1.4.3) instead fsremap.log always uses FC_FMT_DATETIME_LEVEL_CALLER_MSG 29 | 30 | 1.5) more log(DEBUG) in io_posix.read_extents() 31 | 32 | 2) io.copy() and io.flush() queueing is managed by io, not its subclasses, 33 | Overflow checks must be performed by the queueing methods in io. 34 | 35 | 3) -n, --dry-run options to run everything normally (including which I/O to use), 36 | except that extents relocation does not read/write on disk 37 | problem: still create secondary storage? yes, but create it sparse 38 | 39 | 4) mlock(primary_storage). without it we get a lot of disk thrashing, 40 | but even with it disk I/O is not fully sequential. 41 | An alternative would be not to mmap() at all primary_storage, 42 | and maybe neither secondary_storage 43 | 44 | 5) fsremap must correctly handle the case where device_len and/or loop_file_len 45 | are not multiples of effective block size 46 | and file-system in loop_file uses a smaller block size than file-system in device 47 | 48 | PARTIALLY implemented: fstransform creates a loop_file that is always multiple 49 | of device block size. In this way, fsremap will not have problems. 50 | 51 | 6) some ioctl(FIEMAP) implementations are strange (buggy?) and refuse 52 | to return more than a certain number of extents (approx. 1300) 53 | in a single call. 54 | 55 | if this case happens, fsremap MUST detect that the returned extents 56 | are incomplete, log the problem, and work around it 57 | - currently, fsremap switches to ioctl(FIBMAP) if it happens. 58 | 59 | 7) fsmove MUST preemptively check for DISK ALMOST FULL conditions 60 | on {source-device} and {target-device} 61 | 62 | Checking for I/O errors during the copy is NOT enough: Linux loop devices 63 | created on top of sparse files (the case we exploit) do NOT report ANY error 64 | when writing to the backing sparse file fails because of disk full, 65 | but only write the I/O error to kernel messages (dmesg). 66 | 67 | 68 | ############################################### 69 | ################### TO DO ##################### 70 | ############################################### 71 | 72 | * bug? primary storage sometimes too small 73 | 74 | 75 | -------------------------------------------------------------------------------- /doc/torture-test.sh: -------------------------------------------------------------------------------- 1 | # 2 | # This simple script is a helper to run torture tests on 'fstransform.sh' 3 | # 4 | # It is designed assuming the availability of certain files and commands 5 | # in certain hard-coded paths, 6 | # and it will NOT be useful for the general public until customized. 7 | # 8 | 9 | DEVICE_FILE_SAVE=0.device 10 | DEVICE_FILE=1.device 11 | LOOP_FILE=random 12 | DEVICE_MOUNT_POINT=device 13 | ZERO_FILE=zero 14 | 15 | FSREMAP=fsremap 16 | CAT_RANDOM=cat-random 17 | 18 | set -e 19 | set -x 20 | 21 | if [ "$1" = "" ]; then 22 | TESTDIR=torture-test.dir.0 23 | else 24 | TESTDIR="$1" 25 | shift 26 | fi 27 | 28 | if [ "$1" = "" ]; then 29 | # this is a race condition if multiple torture-test.sh are executed simultaneously: 30 | # in such case you must specify explicitly which loop device to use 31 | DEVICE=`losetup -f` 32 | else 33 | DEVICE="$1" 34 | shift 35 | fi 36 | 37 | if [ "$1" = "" ]; then 38 | FILE_SIZE=16777216 39 | else 40 | FILE_SIZE=`expr $1 / 4096 \* 4096` 41 | shift 42 | fi 43 | 44 | if [ "$#" = 0 ]; then 45 | MKFS="mkfs -t ext2" 46 | else 47 | MKFS="$@" 48 | fi 49 | 50 | DEVICE_SIZE=`expr $FILE_SIZE \* 11 / 10 / 4096 \* 4096` 51 | 52 | mkdir "$TESTDIR" || true 53 | mount -t tmpfs tmpfs "$TESTDIR" 54 | mkdir "$TESTDIR"/device 55 | pushd "$TESTDIR" 56 | exec >& log.txt 57 | 58 | cleanup() { 59 | set +e 60 | exec >& /dev/tty 61 | trap - EXIT SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGABRT SIGBUS SIGFPE SIGSEGV SIGALRM SIGTERM SIGSTKFLT 62 | echo 'press ENTER to delete test files and quit.' 63 | read dummy 64 | popd 65 | umount "$TESTDIR"/$DEVICE_MOUNT_POINT 66 | losetup -d "$DEVICE" 67 | umount "$TESTDIR" 68 | rmdir "$TESTDIR" 69 | exit 1 70 | } 71 | 72 | trap cleanup EXIT SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGABRT SIGBUS SIGFPE SIGSEGV SIGALRM SIGTERM SIGSTKFLT 73 | 74 | $CAT_RANDOM $FILE_SIZE > $LOOP_FILE 75 | truncate -s $DEVICE_SIZE $LOOP_FILE 76 | 77 | while true; do 78 | rm -f $DEVICE_FILE 79 | 80 | truncate -s $DEVICE_SIZE $DEVICE_FILE 81 | 82 | losetup -d "$DEVICE" 2>/dev/null || true 83 | losetup "$DEVICE" $DEVICE_FILE 84 | $MKFS "$DEVICE" 85 | mount "$DEVICE" $DEVICE_MOUNT_POINT 86 | cp -avf --sparse=always $LOOP_FILE $DEVICE_MOUNT_POINT/ 87 | dd bs=512 if=/dev/zero of=$DEVICE_MOUNT_POINT/$ZERO_FILE 2>/dev/null || true 88 | # show $ZERO_FILE length 89 | stat --format=%s $DEVICE_MOUNT_POINT/$ZERO_FILE 90 | 91 | mount -o remount,ro "$DEVICE" 92 | sync 93 | cp -vf --sparse=always "$DEVICE" $DEVICE_FILE_SAVE 94 | 95 | $FSREMAP -t . -q "$DEVICE" $DEVICE_MOUNT_POINT/$LOOP_FILE $DEVICE_MOUNT_POINT/$ZERO_FILE < /dev/null 96 | umount "$DEVICE" || true 97 | 98 | if false; then 99 | if ! cmp "$DEVICE" $DEVICE_FILE; then 100 | echo "$DEVICE and $DEVICE_FILE differ!!! bug in Linux loop devices?" 101 | cmp -l "$DEVICE" $DEVICE_FILE | less 102 | break 103 | fi 104 | fi || true 105 | sync 106 | if ! losetup -d "$DEVICE"; then 107 | fuser -vm "$DEVICE" || true 108 | losetup -d "$DEVICE" 109 | fi 110 | if ! cmp $LOOP_FILE $DEVICE_FILE; then 111 | echo "$LOOP_FILE and $DEVICE_FILE differ!!! bug in fsremap?" 112 | cmp -l $LOOP_FILE $DEVICE_FILE | less 113 | break 114 | fi 115 | done 116 | 117 | exit 1 118 | 119 | -------------------------------------------------------------------------------- /fsattr/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fsattr 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /fsattr/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /fsattr/build/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | 3 | sbin_PROGRAMS = fsattr 4 | 5 | fsattr_LDADD = @LD_LIBEXT2FS@ @LD_LIBCOM_ERR@ 6 | 7 | fsattr_SOURCES = \ 8 | ../src/e4attr.cc \ 9 | ../src/log.cc \ 10 | ../src/main.cc \ 11 | ../src/misc.cc \ 12 | ../src/mstring.cc 13 | -------------------------------------------------------------------------------- /fsattr/src/autoconf.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/autoconf.hh -------------------------------------------------------------------------------- /fsattr/src/check.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/check.hh -------------------------------------------------------------------------------- /fsattr/src/e4attr.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fsattr - modify file-system internal data structures 3 | * 4 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * e4attr.hh 20 | * 21 | * Created on: Apr 14, 2012 22 | * Author: max 23 | */ 24 | 25 | #ifndef FSATTR_E4ATTR_HH 26 | #define FSATTR_E4ATTR_HH 27 | 28 | #include "types.hh" 29 | 30 | FT_NAMESPACE_BEGIN 31 | 32 | int e4attr_main(int argc, char **argv); 33 | 34 | FT_NAMESPACE_END 35 | 36 | #endif /* FSTRANSFORM_LOG_HH */ 37 | -------------------------------------------------------------------------------- /fsattr/src/features.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/features.hh -------------------------------------------------------------------------------- /fsattr/src/first.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/first.hh -------------------------------------------------------------------------------- /fsattr/src/ft_config.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/ft_config.hh -------------------------------------------------------------------------------- /fsattr/src/log.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.cc -------------------------------------------------------------------------------- /fsattr/src/log.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.hh -------------------------------------------------------------------------------- /fsattr/src/main.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fsattr - modify file-system internal data structures 3 | * 4 | * Copyright (C) 2012 Massimiliano Ghilardi 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * main.cc 20 | * Created on: Apr 15, 2012 21 | * Author: max 22 | */ 23 | #include "first.hh" 24 | 25 | # include "e4attr.hh" // for e4attr_main() 26 | # define FA_MAIN(argc, argv) FT_NS e4attr_main(argc, argv) 27 | 28 | int main(int argc, char ** argv) { 29 | return FA_MAIN(argc, argv); 30 | } 31 | -------------------------------------------------------------------------------- /fsattr/src/misc.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/misc.cc -------------------------------------------------------------------------------- /fsattr/src/misc.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/misc.hh -------------------------------------------------------------------------------- /fsattr/src/mstring.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.cc -------------------------------------------------------------------------------- /fsattr/src/mstring.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.hh -------------------------------------------------------------------------------- /fsattr/src/traits.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/traits.hh -------------------------------------------------------------------------------- /fsattr/src/types.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/types.hh -------------------------------------------------------------------------------- /fsmount_kernel/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fsmount_kernel 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /fsmount_kernel/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /fsmount_kernel/build/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | 3 | sbin_PROGRAMS = fsmount_kernel 4 | 5 | fsmount_kernel_SOURCES = \ 6 | ../src/log.cc \ 7 | ../src/main.cc \ 8 | ../src/misc.cc \ 9 | ../src/mstring.cc 10 | -------------------------------------------------------------------------------- /fsmount_kernel/src/autoconf.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/autoconf.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/check.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/check.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/features.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/features.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/first.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/first.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/ft_config.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/ft_config.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/log.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.cc -------------------------------------------------------------------------------- /fsmount_kernel/src/log.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/misc.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/misc.cc -------------------------------------------------------------------------------- /fsmount_kernel/src/misc.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/misc.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/mstring.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.cc -------------------------------------------------------------------------------- /fsmount_kernel/src/mstring.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/traits.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/traits.hh -------------------------------------------------------------------------------- /fsmount_kernel/src/types.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/types.hh -------------------------------------------------------------------------------- /fsmove/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fsmove 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /fsmove/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /fsmove/build/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | 3 | sbin_PROGRAMS = fsmove 4 | 5 | fsmove_SOURCES = \ 6 | ../src/args.cc \ 7 | ../src/assert.cc \ 8 | ../src/copy.cc \ 9 | ../src/eta.cc \ 10 | ../src/cache/cache_symlink.cc \ 11 | ../src/io/disk_stat.cc \ 12 | ../src/io/io.cc \ 13 | ../src/io/io_posix.cc \ 14 | ../src/io/io_posix_dir.cc \ 15 | ../src/io/io_posix_xattr.cc \ 16 | ../src/io/io_prealloc.cc \ 17 | ../src/io/util_dir.cc \ 18 | ../src/io/util_posix.cc \ 19 | ../src/log.cc \ 20 | ../src/main.cc \ 21 | ../src/misc.cc \ 22 | ../src/move.cc \ 23 | ../src/mstring.cc \ 24 | ../src/rope/rope.cc \ 25 | ../src/rope/rope_impl.cc \ 26 | ../src/rope/rope_list.cc \ 27 | ../src/rope/rope_pool.cc \ 28 | ../src/rope/rope_test.cc \ 29 | ../src/zstring.cc 30 | 31 | # ../src/io/util.cc 32 | 33 | # fsmove_LDADD = $(LD_LIBZ) 34 | -------------------------------------------------------------------------------- /fsmove/src/args.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * args.cc 21 | * 22 | * Created on: Mar 21, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #include "args.hh" // for fm_args 29 | 30 | FT_NAMESPACE_BEGIN 31 | 32 | 33 | /** default constructor */ 34 | fm_args::fm_args() 35 | : program_name("fsmove"), 36 | io_args(), exclude_list(NULL), inode_cache_path(NULL), 37 | io_kind(FC_IO_AUTODETECT), ui_kind(FC_UI_NONE), 38 | force_run(false), simulate_run(false) 39 | { } 40 | 41 | FT_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /fsmove/src/args.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * main.hh 21 | * 22 | * Created on: Mar 20, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSMOVE_ARGS_HH 27 | #define FSMOVE_ARGS_HH 28 | 29 | #include "types.hh" // for ft_uint, ft_size 30 | #include "io/io.hh" // for FC_ARGS_COUNT 31 | 32 | FT_NAMESPACE_BEGIN 33 | 34 | enum fm_io_kind { FC_IO_AUTODETECT, FC_IO_POSIX, FC_IO_PREALLOC }; 35 | enum fm_ui_kind { FC_UI_NONE }; 36 | 37 | class fm_args 38 | { 39 | public: 40 | const char * program_name; // detected from command line. default: "fsmove" 41 | const char * io_args[FT_IO_NS fm_io::FC_ARGS_COUNT]; 42 | char const * const * exclude_list; // NULL-terminated array of files _not_ to move 43 | const char * inode_cache_path; 44 | fm_io_kind io_kind; // if FC_IO_AUTODETECT, will autodetect 45 | fm_ui_kind ui_kind; // default is FC_UI_NONE 46 | bool force_run; // if true, some sanity checks will be WARNINGS instead of ERRORS 47 | bool simulate_run; // if true, move algorithm runs WITHOUT actually moving/preallocating any file/directory/special-device 48 | 49 | fm_args(); 50 | }; 51 | 52 | 53 | FT_NAMESPACE_END 54 | 55 | #endif /* FSMOVE_ARGS_HH */ 56 | -------------------------------------------------------------------------------- /fsmove/src/assert.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/assert.cc -------------------------------------------------------------------------------- /fsmove/src/assert.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/assert.hh -------------------------------------------------------------------------------- /fsmove/src/autoconf.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/autoconf.hh -------------------------------------------------------------------------------- /fsmove/src/cache/cache.hh: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/cache/cache.hh -------------------------------------------------------------------------------- /fsmove/src/cache/cache_adaptor.hh: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/cache/cache_adaptor.hh -------------------------------------------------------------------------------- /fsmove/src/cache/cache_mem.hh: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/cache/cache_mem.hh -------------------------------------------------------------------------------- /fsmove/src/cache/cache_symlink.cc: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/cache/cache_symlink.cc -------------------------------------------------------------------------------- /fsmove/src/cache/cache_symlink.hh: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/cache/cache_symlink.hh -------------------------------------------------------------------------------- /fsmove/src/check.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/check.hh -------------------------------------------------------------------------------- /fsmove/src/copy.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/copy.cc -------------------------------------------------------------------------------- /fsmove/src/copy.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/copy.hh -------------------------------------------------------------------------------- /fsmove/src/eta.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/eta.cc -------------------------------------------------------------------------------- /fsmove/src/eta.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/eta.hh -------------------------------------------------------------------------------- /fsmove/src/features.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/features.hh -------------------------------------------------------------------------------- /fsmove/src/first.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/first.hh -------------------------------------------------------------------------------- /fsmove/src/ft_config.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/ft_config.hh -------------------------------------------------------------------------------- /fsmove/src/fwd.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * fwd.hh 21 | * 22 | * Created on: Sep 21, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSMOVE_FWD_HH 27 | #define FSMOVE_FWD_HH 28 | 29 | #include "check.hh" 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | class fm_args; 34 | class fm_move; 35 | 36 | FT_NAMESPACE_END 37 | 38 | 39 | FT_IO_NAMESPACE_BEGIN 40 | class fm_io; 41 | class fm_io_posix; 42 | FT_IO_NAMESPACE_END 43 | 44 | #endif /* FSMOVE_FWD_HH */ 45 | -------------------------------------------------------------------------------- /fsmove/src/io/disk_stat.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/disk_stat.cc 21 | * 22 | * Created on: Oct 05, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "../first.hh" 27 | 28 | #include "disk_stat.hh" // for fm_disk_stat 29 | #include "../log.hh" // for ff_log() 30 | #include "../misc.hh" // for ff_pretty_size() 31 | 32 | FT_IO_NAMESPACE_BEGIN 33 | 34 | /** constructor */ 35 | fm_disk_stat::fm_disk_stat() : this_name(), this_total(0), this_free(0) { 36 | } 37 | 38 | /** clear all data stored in this object */ 39 | void fm_disk_stat::clear() { 40 | this_name.clear(); 41 | this_total = this_free = 0; 42 | } 43 | 44 | /** 45 | * set the free disk space. 46 | * returns 0, or error if free disk space becomes critically low 47 | */ 48 | int fm_disk_stat::set_free(ft_uoff free) { 49 | this_free = free; 50 | int err = 0; 51 | if (is_too_low_free_space(free)) { 52 | double pretty_size = 0.0; 53 | const char *pretty_label = ff_pretty_size(free, &pretty_size); 54 | ff_log(FC_ERROR, 0, 55 | "free space on %s device is critically low: only %.2f %sbytes left, " 56 | "ABORTING!!!", 57 | this_name.c_str(), pretty_size, pretty_label); 58 | err = -ENOSPC; 59 | } 60 | return err; 61 | } 62 | 63 | /** 64 | * return true if 'free' amount of free space would trigger a 'critically low 65 | * free space' error 66 | */ 67 | bool fm_disk_stat::is_too_low_free_space(ft_uoff free) const { 68 | /** 69 | * if file system is smaller than 6GB, critically low free space is 96kbytes. 70 | * if file system is between 6GB and 64TB, critically low free space is total 71 | * disk space divided 65536 (i.e. 0.0015%). if file system is larger than 72 | * 64TB, critically low free space is 1Gbyte. 73 | */ 74 | return free <= THRESHOLD_MIN || (free <= THRESHOLD_MAX && free <= (this_total >> 16)); 75 | } 76 | 77 | FT_IO_NAMESPACE_END 78 | -------------------------------------------------------------------------------- /fsmove/src/io/disk_stat.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/disk_stat.hh 21 | * 22 | * Created on: Oct 05, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSMOVE_IO_DISK_STAT_HH 27 | #define FSMOVE_IO_DISK_STAT_HH 28 | 29 | #include "../check.hh" 30 | #include "../types.hh" // for ft_uoff, ft_string 31 | 32 | FT_IO_NAMESPACE_BEGIN 33 | 34 | /** 35 | * class to keep track of disk total and free space 36 | */ 37 | class fm_disk_stat { 38 | private: 39 | enum { _96kbytes = (ft_uoff)96 << 10, _1Gbyte = (ft_uoff)1 << 30 }; 40 | 41 | ft_string this_name; 42 | ft_uoff this_total, this_free; 43 | 44 | public: 45 | /** 46 | * if file systems is smaller than 6GB, critically low free space is 96kbytes. 47 | * if file systems is between 6GB and 64TB, critically low free space is total 48 | * disk space divided 65536 (i.e. 0.0015%). if file systems is larger than 49 | * 64TB, critically low free space is 1Gbyte. 50 | */ 51 | enum { 52 | // THRESHOLD_MIN must be somewhat larger than fm_io_posix::FT_BUFSIZE 53 | // (currently 64k) 54 | THRESHOLD_MIN = _96kbytes, 55 | THRESHOLD_MAX = _1Gbyte, 56 | }; 57 | /** constructor */ 58 | fm_disk_stat(); 59 | 60 | /** compiler-generated copy constructor is fine */ 61 | // const fm_disk_stat & fm_disk_stat(const fm_disk_stat &); 62 | 63 | /** compiler-generated destructor is fine */ 64 | // ~fm_disk_stat(); 65 | 66 | /** compiler-generated assignment operator is fine */ 67 | // const fm_disk_stat & operator=(const fm_disk_stat &); 68 | 69 | /** clear all data stored in this object */ 70 | void clear(); 71 | 72 | /** get the disk name */ 73 | FT_INLINE const ft_string &get_name() const { 74 | return this_name; 75 | } 76 | /** set the disk name */ 77 | FT_INLINE void set_name(const ft_string &name) { 78 | this_name = name; 79 | } 80 | 81 | /** return the total disk space */ 82 | FT_INLINE ft_uoff get_total() const { 83 | return this_total; 84 | } 85 | /** set the total disk space */ 86 | FT_INLINE void set_total(ft_uoff total) { 87 | this_total = total; 88 | } 89 | 90 | /** return the free disk space */ 91 | FT_INLINE ft_uoff get_free() const { 92 | return this_free; 93 | } 94 | 95 | /** 96 | * set the free disk space. 97 | * returns 0, or error if free disk space becomes critically low 98 | */ 99 | int set_free(ft_uoff free); 100 | 101 | /** 102 | * return true if 'free' amount of free space would trigger a 'critically low 103 | * free space' error 104 | */ 105 | bool is_too_low_free_space(ft_uoff free) const; 106 | 107 | /** return the used disk space */ 108 | FT_INLINE ft_uoff get_used() const { 109 | return this_free < this_total ? this_total - this_free : 0; 110 | } 111 | }; 112 | 113 | FT_IO_NAMESPACE_END 114 | 115 | #endif /* FSMOVE_IO_IO_HH */ 116 | -------------------------------------------------------------------------------- /fsmove/src/io/io_posix_dir.cc: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/io/io_posix_dir.cc -------------------------------------------------------------------------------- /fsmove/src/io/io_posix_dir.hh: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/io/io_posix_dir.hh -------------------------------------------------------------------------------- /fsmove/src/io/io_posix_xattr.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/io_posix_xattr.hh 21 | * 22 | * Created on: Apr 17, 2021 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSMOVE_IO_IO_POSIX_XATTR_HH 27 | #define FSMOVE_IO_IO_POSIX_XATTR_HH 28 | 29 | #include "../types.hh" // for ft_u64, ft_string */ 30 | 31 | FT_IO_NAMESPACE_BEGIN 32 | 33 | /** 34 | * class dealing with extended attributes on POSIX systems 35 | */ 36 | class fm_io_posix_xattr { 37 | public: 38 | fm_io_posix_xattr(); 39 | ~fm_io_posix_xattr(); // calls close() 40 | 41 | int openfile(const ft_string &path); // return file descriptor, or < 0 42 | int opendir(const ft_string &path); // return file descriptor, or < 0 43 | int close(); 44 | 45 | // copy current flags and projid to specified file descriptor, 46 | // assuming it *will* be modified afterwards 47 | int copy_xattr_before(const ft_string &path, int fd) const; 48 | 49 | // copy current flags and projid to specified file descriptor, 50 | // assuming it will *not* be modified afterwards 51 | int copy_xattr_after(const ft_string &path, int fd) const; 52 | 53 | private: 54 | int open(const ft_string &path, bool isdir); 55 | 56 | int copy_xattr_to(const ft_string &path, int fd, ft_u64 clearmask, ft_u64 copymask) const; 57 | 58 | int this_fd; // file descriptor 59 | ft_u32 this_flags; 60 | ft_u32 this_projid; 61 | }; 62 | 63 | FT_IO_NAMESPACE_END 64 | 65 | #endif /* FSMOVE_IO_IO_POSIX_XATTR_HH */ 66 | -------------------------------------------------------------------------------- /fsmove/src/io/io_prealloc.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/io_prealloc.hh 21 | * 22 | * Created on: Apr 15, 2012 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSMOVE_IO_IO_PREALLOC_HH 27 | #define FSMOVE_IO_IO_PREALLOC_HH 28 | 29 | #include "../types.hh" // for ft_string, FT_HAVE_FALLOCATE 30 | #include "io_posix.hh" // for fm_io_posix 31 | 32 | // io_prealloc requires fallocate() 33 | #ifdef FT_HAVE_FALLOCATE 34 | # define FT_HAVE_FM_IO_IO_PREALLOC 35 | 36 | FT_IO_NAMESPACE_BEGIN 37 | 38 | /** 39 | * class performing I/O on POSIX systems with preallocation. 40 | * performs target files preallocation WITHOUT modifying the source file directory 41 | */ 42 | class fm_io_prealloc: public fm_io_posix 43 | { 44 | private: 45 | typedef fm_io_posix super_type; 46 | 47 | protected: 48 | /** 49 | * does nothing: fr_io_prealloc never needs to ::sync(). 50 | */ 51 | virtual void sync(); 52 | 53 | /** 54 | * copy the contents of single regular file 'source_path' to 'target_path'. 55 | * Since we are preallocating, we just preallocate enough blocks inside 'target_path' 56 | */ 57 | virtual int copy_file_contents(const ft_string & source_path, const ft_stat & source_stat, const ft_string & target_path); 58 | 59 | /** 60 | * remove a regular file inside source directory 61 | * Since we are preallocating, we can (and will) avoid any modification 62 | * to the source file system. Thus this method does nothing. 63 | */ 64 | virtual int remove_file(const char * source_path); 65 | 66 | /** 67 | * remove a special file inside source directory 68 | * Since we are preallocating, we can (and will) avoid any modification 69 | * to the source file system. Thus this method does nothing. 70 | */ 71 | virtual int remove_special(const char * source_path); 72 | 73 | /** 74 | * remove a source directory, which must be empty 75 | * exception: will not remove '/lost+found' directory inside source_root() 76 | * Since we are preallocating, we can (and will) avoid any modification 77 | * to the source file system. Thus this method does nothing. 78 | */ 79 | virtual int remove_dir(const ft_string & path); 80 | 81 | public: 82 | /** default constructor. */ 83 | fm_io_prealloc(); 84 | 85 | /** check for consistency and open SOURCE_ROOT, TARGET_ROOT */ 86 | virtual int open(const fm_args & args); 87 | 88 | /** destructor. */ 89 | virtual ~fm_io_prealloc(); 90 | }; 91 | 92 | FT_IO_NAMESPACE_END 93 | 94 | #endif /* FT_HAVE_FM_IO_IO_PREALLOC */ 95 | 96 | #endif /* FSMOVE_IO_IO_PREALLOC_HH */ 97 | -------------------------------------------------------------------------------- /fsmove/src/io/util_dir.cc: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/io/util_dir.cc -------------------------------------------------------------------------------- /fsmove/src/io/util_dir.hh: -------------------------------------------------------------------------------- 1 | ../../../fsremap/src/io/util_dir.hh -------------------------------------------------------------------------------- /fsmove/src/io/util_posix.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/util_posix.hh 21 | * 22 | * Created on: Mar 27, 2012 23 | * Author: max 24 | */ 25 | #ifndef FSMOVE_IO_POSIX_UTIL_HH 26 | #define FSMOVE_IO_POSIX_UTIL_HH 27 | 28 | #include "../types.hh" 29 | 30 | FT_IO_NAMESPACE_BEGIN 31 | 32 | /** 33 | * spawn a system command, wait for it to complete and return its exit status. 34 | * argv[0] is conventionally the program name. 35 | * argv[1...] are program arguments and must be terminated with a NULL pointer. 36 | */ 37 | int ff_posix_exec_silent(const char * path, const char * const argv[]); 38 | 39 | FT_IO_NAMESPACE_END 40 | 41 | 42 | #endif /* FSREMAP_IO_POSIX_UTIL_HH */ 43 | -------------------------------------------------------------------------------- /fsmove/src/log.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.cc -------------------------------------------------------------------------------- /fsmove/src/log.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.hh -------------------------------------------------------------------------------- /fsmove/src/main.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * main.cc 21 | * Created on: Aug 18, 2011 22 | * Author: max 23 | */ 24 | #include "first.hh" 25 | 26 | #undef FM_TEST_ROPE 27 | #undef FM_TEST_ZSTRING 28 | 29 | #if defined(FM_TEST_ROPE) 30 | # include "rope/rope_test.hh" // rope self-test 31 | #define FM_MAIN(argc, argv) FT_NS rope_test(argc, argv) 32 | 33 | #elif defined(FM_TEST_ZSTRING) 34 | # include "zstring.hh" // zstring self-test 35 | #define FM_MAIN(argc, argv) FT_NS ztest() 36 | 37 | #else 38 | # include "move.hh" // actual fsmove program 39 | # define FM_MAIN(argc, argv) FT_NS fm_move::main(argc, argv) 40 | 41 | #endif // defined(FT_TEST_*) 42 | 43 | 44 | 45 | int main(int argc, char ** argv) { 46 | return FM_MAIN(argc, argv); 47 | } 48 | -------------------------------------------------------------------------------- /fsmove/src/misc.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/misc.cc -------------------------------------------------------------------------------- /fsmove/src/misc.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/misc.hh -------------------------------------------------------------------------------- /fsmove/src/move.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * move.hh 21 | * 22 | * Created on: Aug 18, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSMOVE_MOVE_HH 27 | #define FSMOVE_MOVE_HH 28 | 29 | #include "args.hh" // for fm_args 30 | #include "fwd.hh" // for fm_io forward declaration 31 | #include "log.hh" // for FC_TRACE 32 | 33 | 34 | FT_NAMESPACE_BEGIN 35 | 36 | /** 37 | * class doing the core of recursive move work. 38 | */ 39 | class fm_move 40 | { 41 | private: 42 | FT_IO_NS fm_io * this_io; 43 | 44 | /** true if usage() or version() was called. */ 45 | bool quit_immediately; 46 | 47 | /** cannot call copy constructor */ 48 | fm_move(const fm_move &); 49 | 50 | /** cannot call assignment operator */ 51 | const fm_move & operator=(const fm_move &); 52 | 53 | /** display command-line usage to stdout and return 0 */ 54 | int usage(const char * program_name); 55 | 56 | /** output version information and return 0 */ 57 | int version(); 58 | 59 | static int invalid_cmdline(const char * program_name, int err, const char * fmt, ...); 60 | 61 | /** return EISCONN if remapper is initialized, else call quit_io() and return 0 */ 62 | int check_is_closed(); 63 | 64 | /** return 0 if remapper is initialized, else call quit_io() and return ENOTCONN */ 65 | int check_is_open(); 66 | 67 | /** 68 | * checks that I/O is open. 69 | * if success, stores a reference to I/O object. 70 | */ 71 | int init(FT_IO_NS fm_io & io); 72 | 73 | /** core of recursive move algorithm, actually moves the whole source tree into target */ 74 | int move(); 75 | 76 | /** show progress status and E.T.A. */ 77 | void show_progress(); 78 | 79 | public: 80 | /** default constructor */ 81 | fm_move(); 82 | 83 | /** destructor. calls quit() */ 84 | ~fm_move(); 85 | 86 | /** 87 | * high-level do-everything method. calls in sequence init(), run() and cleanup(). 88 | * return 0 if success, else error. 89 | */ 90 | static int main(int argc, char ** argv); 91 | 92 | bool is_initialized() const; 93 | 94 | /** 95 | * parse command line and initialize all subsystems (job, I/O, log...) 96 | * return 0 if success, else error. 97 | * 98 | * implementation: parse command line, fill a fr_args and call init(const fr_args &) 99 | */ 100 | int init(int argc, char const* const* argv); 101 | 102 | /** 103 | * initialize all subsystems (job, I/O, log...) using specified arguments 104 | * return 0 if success, else error. 105 | */ 106 | int init(const fm_args & args); 107 | 108 | /** 109 | * main recursive move algorithm. 110 | * calls in sequence analyze() and move() 111 | */ 112 | int run(); 113 | 114 | /** 115 | * performs cleanup. called by destructor, you can also call it explicitly after (or instead of) run(). 116 | * closes configured I/O and delete it 117 | */ 118 | void quit(); 119 | }; 120 | 121 | 122 | FT_NAMESPACE_END 123 | 124 | 125 | #endif /* FSMOVE_MOVE_HH */ 126 | -------------------------------------------------------------------------------- /fsmove/src/mstring.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.cc -------------------------------------------------------------------------------- /fsmove/src/mstring.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.hh -------------------------------------------------------------------------------- /fsmove/src/rope/rope.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * rope.cc 21 | * 22 | * Created on: Mar 3, 2018 23 | * Author: max 24 | */ 25 | 26 | #include "../first.hh" 27 | 28 | #include // for std::invalid_argument 29 | 30 | #include "rope.hh" // for ft_rope 31 | #include "rope_impl.hh" // for ft_rope_impl 32 | 33 | FT_NAMESPACE_BEGIN 34 | 35 | /** copy constructor. */ 36 | ft_rope::ft_rope(const ft_rope & other) : p(NULL) 37 | { 38 | other.validate(); 39 | if (other.p != NULL) { 40 | other.p->ref(); 41 | p = other.p; 42 | } 43 | } 44 | 45 | /** constructor from ft_string */ 46 | ft_rope::ft_rope(const ft_string & other) : p(NULL) 47 | { 48 | if (other.size() != 0) 49 | p = ft_rope_impl::make(NULL, other.c_str(), other.size()); 50 | } 51 | 52 | /** constructor with prefix and suffix. makes a private copy of 'suffix' */ 53 | ft_rope::ft_rope(const ft_rope * prefix, const char * suffix, ft_size suffix_length) : p(NULL) 54 | { 55 | if (prefix) 56 | prefix->validate(); 57 | ft_rope_impl * prefix_p = prefix ? prefix->p : NULL; 58 | if (prefix_p != NULL || suffix_length != 0) 59 | p = ft_rope_impl::make(prefix_p, suffix, suffix_length); 60 | } 61 | 62 | /** assignment operator */ 63 | const ft_rope & ft_rope::operator=(const ft_rope & other) 64 | { 65 | validate(); 66 | other.validate(); 67 | if (this->p != other.p) { 68 | if (p != NULL) { 69 | p->unref(); 70 | p = NULL; 71 | } 72 | if ((other.p != NULL)) { 73 | other.p->ref(); 74 | p = other.p; 75 | } 76 | } 77 | return *this; 78 | } 79 | 80 | /* destructor */ 81 | ft_rope::~ft_rope() 82 | { 83 | validate(); 84 | if (p != NULL) { 85 | p->unref(); 86 | p = NULL; 87 | } 88 | } 89 | 90 | bool ft_rope::empty() const 91 | { 92 | return p == NULL || p->empty(); 93 | } 94 | 95 | /* validate ft_rope_impl pointer */ 96 | void ft_rope::validate() const 97 | { 98 | if (p == NULL) 99 | return; 100 | ft_size n = (ft_size)p; 101 | if ((n & 7) || n <= 0xffff) 102 | throw std::invalid_argument("invalid ft_rope_impl pointer"); 103 | } 104 | 105 | 106 | 107 | /** convert to ft_string */ 108 | void ft_rope::to_string(ft_string & append_dst) const 109 | { 110 | validate(); 111 | if (p != NULL) 112 | p->to_string(append_dst); 113 | } 114 | 115 | /** compare against char[] */ 116 | bool ft_rope::equals(const char other[], ft_size other_len) const 117 | { 118 | validate(); 119 | if (p == NULL) 120 | return other_len == 0; 121 | return p->equals(other, other_len); 122 | } 123 | 124 | /** return this hash */ 125 | ft_size ft_rope::hash() const 126 | { 127 | validate(); 128 | return p ? p->hash() : ft_rope_impl::hash(NULL, 0); 129 | } 130 | 131 | /** return other's hash */ 132 | ft_size ft_rope::hash(const char other[], ft_size other_len) 133 | { 134 | return ft_rope_impl::hash(other, other_len); 135 | } 136 | 137 | 138 | FT_NAMESPACE_END 139 | -------------------------------------------------------------------------------- /fsmove/src/rope/rope.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * rope.hh 21 | * 22 | * Created on: Mar 3, 2018 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_ROPE_HH 27 | #define FSTRANSFORM_ROPE_HH 28 | 29 | #include "../types.hh" // for ft_string, ft_size 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | class ft_rope_impl; 34 | 35 | // ----------------------------------------------------------------------------- 36 | /** 37 | * short immutable string, with a prefix shared with other rope:s 38 | */ 39 | class ft_rope 40 | { 41 | private: 42 | ft_rope_impl * p; 43 | 44 | public: 45 | /** default constructor. */ 46 | FT_INLINE ft_rope() : p(NULL) 47 | { } 48 | 49 | /** copy constructor. */ 50 | ft_rope(const ft_rope & other); 51 | 52 | /** constructor from ft_string */ 53 | explicit ft_rope(const ft_string & other); 54 | 55 | /** constructor with prefix and suffix. makes a private copy of 'suffix' */ 56 | ft_rope(const ft_rope * prefix, const char * suffix, ft_size suffix_length); 57 | 58 | /** assignment operator */ 59 | const ft_rope & operator=(const ft_rope & other); 60 | 61 | /** destructor */ 62 | ~ft_rope(); 63 | 64 | /** 65 | * identity comparison: returns true ONLY if pointing to the same ft_rope_impl. 66 | * enough for the comparison against empty ft_rope() made by ft_cache_mem. 67 | * does NOT compare the char[] array! 68 | */ 69 | FT_INLINE bool operator==(const ft_rope & other) const { 70 | return p == other.p; 71 | } 72 | FT_INLINE bool operator!=(const ft_rope & other) const { 73 | return p != other.p; 74 | } 75 | 76 | bool empty() const; 77 | 78 | /* validate ft_rope_impl pointer */ 79 | void validate() const; 80 | 81 | /** convert to ft_string */ 82 | void to_string(ft_string & append_dst) const; 83 | 84 | /** compare against char[] */ 85 | bool equals(const char other[], ft_size other_len) const; 86 | 87 | /** compare against ft_string */ 88 | FT_INLINE bool equals(const ft_string & other) const { 89 | return equals(other.c_str(), other.size()); 90 | } 91 | 92 | /** return this hash */ 93 | ft_size hash() const; 94 | 95 | /** return other's hash */ 96 | static ft_size hash(const char other[], ft_size other_len); 97 | 98 | /** return other's hash */ 99 | static FT_INLINE ft_size hash(const ft_string & other) { 100 | return hash(other.c_str(), other.size()); 101 | } 102 | }; 103 | 104 | FT_NAMESPACE_END 105 | 106 | #endif /* FSTRANSFORM_ROPE_HH */ 107 | -------------------------------------------------------------------------------- /fsmove/src/rope/rope_impl.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * rope_impl.hh 21 | * 22 | * Created on: Mar 3, 2018 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_ROPE_IMPL_HH 27 | #define FSTRANSFORM_ROPE_IMPL_HH 28 | 29 | #include "../types.hh" // for ft_string, ft_size 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | /** 34 | * short immutable string, with a prefix shared with other rope:s 35 | */ 36 | class ft_rope_impl 37 | { 38 | private: 39 | enum { PREFIX_SCALE = sizeof(void *) }; 40 | 41 | ft_i32 prefix_delta; 42 | ft_u32 refcount, suffix_len; 43 | 44 | /** default constructor. private use only, call make() instead */ 45 | FT_INLINE ft_rope_impl() : prefix_delta(0), refcount(0), suffix_len(0) 46 | { } 47 | 48 | /** copy constructor. forbidden. call make() instead */ 49 | ft_rope_impl(const ft_rope_impl & other); 50 | 51 | /** assignment operator. forbidden */ 52 | const ft_rope_impl & operator=(const ft_rope_impl & other); 53 | 54 | /** 55 | * constructor. private use only. call make() instead. 56 | * makes a copy of 'suffix' 57 | */ 58 | FT_INLINE ft_rope_impl(ft_rope_impl * prefix_ptr, ft_size suffix_length); 59 | 60 | /** destructor. private use only. call unref() instead */ 61 | ~ft_rope_impl(); 62 | 63 | FT_INLINE char * suffix() { 64 | return reinterpret_cast(this) + sizeof(ft_rope_impl); 65 | } 66 | 67 | FT_INLINE const char * suffix() const { 68 | return reinterpret_cast(this) + sizeof(ft_rope_impl); 69 | } 70 | 71 | FT_INLINE ft_rope_impl * prefix() const { 72 | if (!prefix_delta) 73 | return NULL; 74 | ft_size self = (ft_size)(this); 75 | return reinterpret_cast(self + (ft_size)prefix_delta * PREFIX_SCALE); 76 | } 77 | 78 | FT_INLINE ft_size prefix_len() const { 79 | ft_rope_impl * ptr = prefix(); 80 | return ptr ? ptr->len() : 0; 81 | } 82 | 83 | public: 84 | /** create an empty rope */ 85 | static ft_rope_impl * make(); 86 | 87 | /** create a rope with given prefix and suffix. makes a private copy of 'suffix' */ 88 | static ft_rope_impl * make(ft_rope_impl * prefix, const char * suffix, ft_size suffix_length); 89 | 90 | /** increment reference count */ 91 | void ref(); 92 | 93 | /** decrement reference count */ 94 | void unref(); 95 | 96 | bool empty() const; 97 | 98 | ft_size len() const; 99 | 100 | /** convert to ft_string */ 101 | void to_string(ft_string & append_dst) const; 102 | 103 | /** compare against char[] */ 104 | bool equals(const char other[], ft_size other_len) const; 105 | 106 | /** return this hash */ 107 | ft_size hash() const; 108 | 109 | /** return other's hash */ 110 | static ft_size hash(const char other[], ft_size other_len); 111 | }; 112 | FT_NAMESPACE_END 113 | 114 | #endif /* FSTRANSFORM_ROPE_IMPL_HH */ 115 | -------------------------------------------------------------------------------- /fsmove/src/rope/rope_list.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * rope_list.cc 21 | * 22 | * Created on: Mar 3, 2018 23 | * Author: max 24 | */ 25 | 26 | #include "../first.hh" 27 | 28 | #include // for std::out_of_range 29 | 30 | 31 | #include "rope_list.hh" // for ft_rope_list 32 | 33 | FT_NAMESPACE_BEGIN 34 | 35 | /** copy constructor. */ 36 | ft_rope_list::ft_rope_list(const ft_rope_list & other) : head(NULL) 37 | { 38 | init(other.head); 39 | } 40 | 41 | /** assignment operator */ 42 | const ft_rope_list & ft_rope_list::operator=(const ft_rope_list & other) 43 | { 44 | if (head != other.head) { 45 | clear(); 46 | init(other.head); 47 | } 48 | return *this; 49 | } 50 | 51 | void ft_rope_list::clear() 52 | { 53 | ft_rope_node * next; 54 | while (head != NULL) { 55 | next = head->next; 56 | delete head; 57 | head = next; 58 | } 59 | } 60 | 61 | void ft_rope_list::init(const ft_rope_node * list) 62 | { 63 | head = NULL; 64 | ft_rope_node ** dst = &head; 65 | while (list != NULL) { 66 | *dst = new ft_rope_node(list->e); 67 | dst = & (*dst)->next; 68 | list = list->next; 69 | } 70 | } 71 | 72 | ft_rope & ft_rope_list::front() 73 | { 74 | ft_rope_node * node = head; 75 | if (node == NULL) 76 | throw std::out_of_range("ft_rope_list::front(): list is empty"); 77 | return node->e; 78 | } 79 | 80 | void ft_rope_list::pop_front() 81 | { 82 | ft_rope_node * node = head; 83 | if (node == NULL) 84 | throw std::out_of_range("ft_rope_list::pop_front(): list is empty"); 85 | head = node->next; 86 | delete node; 87 | } 88 | 89 | void ft_rope_list::push_front(const ft_rope & e) 90 | { 91 | ft_rope_node * node = new ft_rope_node(e, head); 92 | head = node; 93 | } 94 | 95 | FT_NAMESPACE_END 96 | -------------------------------------------------------------------------------- /fsmove/src/rope/rope_pool.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * rope_pool.cc 21 | * 22 | * Created on: Mar 3, 2018 23 | * Author: max 24 | */ 25 | 26 | #include "../first.hh" 27 | 28 | #include "rope_impl.hh" 29 | #include "rope_pool.hh" 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | /** default constructor. */ 34 | ft_rope_pool::ft_rope_pool() : count(0), table() 35 | { } 36 | 37 | /** copy constructor. */ 38 | ft_rope_pool::ft_rope_pool(const ft_rope_pool & other) 39 | : count(other.count), table(other.table) 40 | { } 41 | 42 | /** assignment operator. */ 43 | const ft_rope_pool & ft_rope_pool::operator=(const ft_rope_pool & other) 44 | { 45 | if (this != & other) { 46 | count = other.count; 47 | table = other.table; 48 | } 49 | return *this; 50 | } 51 | 52 | /** destructor. */ 53 | ft_rope_pool::~ft_rope_pool() 54 | { } 55 | 56 | void ft_rope_pool::rehash(ft_size new_len) 57 | { 58 | // assert((new_len & new_lenn-1)) == 0); // must be power-of-two 59 | ft_table tmp(new_len); 60 | tmp.swap(table); 61 | ft_bucket::const_iterator iter, end; 62 | for (ft_size i = 0, n = tmp.size(); i < n; i++) { 63 | const ft_bucket & bucket = tmp[i]; 64 | iter = bucket.begin(); 65 | end = bucket.end(); 66 | for (; iter != end; ++iter) { 67 | const ft_rope & r = *iter; 68 | ft_size index = r.hash() & (new_len - 1); 69 | table[index].push_front(r); 70 | } 71 | } 72 | } 73 | 74 | // returned pointer is valid only while pool is not modified 75 | const ft_rope * ft_rope_pool::find(const char s[], ft_size len) const 76 | { 77 | ft_size n = table.size(); 78 | if (n == 0) 79 | return NULL; 80 | // assert((n & (n-1)) == 0); // must be power-of-two 81 | ft_size index = ft_rope::hash(s, len) & (n - 1); 82 | const ft_bucket & bucket = table[index]; 83 | ft_bucket::const_iterator iter = bucket.begin(), end = bucket.end(); 84 | for (; iter != end; ++iter) { 85 | const ft_rope & r = *iter; 86 | if (r.equals(s, len)) 87 | return & r; 88 | } 89 | return NULL; 90 | } 91 | 92 | ft_rope ft_rope_pool::make(const char s[], ft_size len) 93 | { 94 | if (len == 0) 95 | return ft_rope(); 96 | const ft_rope * r = find(s, len); 97 | if (r != NULL) 98 | return *r; 99 | 100 | enum { SPLIT_LO = sizeof(ft_rope_impl), SPLIT_HI = SPLIT_LO / 3 }; 101 | 102 | // rehash() invalidates all pooled (ft_rope *), so prefix cannot be a pointer 103 | ft_rope prefix; 104 | const char * suffix = s; 105 | ft_size suffix_len = len; 106 | if (len >= SPLIT_LO + SPLIT_HI) { 107 | ft_size split = len - SPLIT_HI; 108 | for (; split >= SPLIT_LO; split--) { 109 | if (s[split] == '/') { 110 | prefix = make(s, ++split); 111 | prefix.validate(); 112 | suffix += split; 113 | suffix_len -= split; 114 | break; 115 | } 116 | } 117 | } 118 | ft_rope result(& prefix, suffix, suffix_len); 119 | if (suffix[suffix_len - 1] == '/') { 120 | // only cache directory names 121 | ft_size n = table.size(); 122 | if (count / 2 >= n) 123 | rehash(n = (n ? n * 2 : 64)); 124 | 125 | ft_size index = ft_rope::hash(s, len) & (n - 1); 126 | ft_bucket & bucket = table[index]; 127 | bucket.push_front(result); 128 | count++; 129 | } 130 | return result; 131 | } 132 | 133 | FT_NAMESPACE_END 134 | -------------------------------------------------------------------------------- /fsmove/src/rope/rope_pool.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * rope_pool.hh 21 | * 22 | * Created on: Mar 3, 2018 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_ROPE_POOL_HH 27 | #define FSTRANSFORM_ROPE_POOL_HH 28 | 29 | #include 30 | #include 31 | 32 | #include "../types.hh" // for ft_string 33 | #include "rope.hh" // for ft_rope 34 | #include "rope_list.hh" // for ft_rope_list 35 | 36 | FT_NAMESPACE_BEGIN 37 | 38 | // ----------------------------------------------------------------------------- 39 | /** 40 | * pool of ropes. useful to compress large sets of repetitive strings, 41 | * in particular for the strings in the inode cache ft_cache 42 | */ 43 | class ft_rope_pool 44 | { 45 | private: 46 | typedef ft_rope_list ft_bucket; 47 | typedef std::vector ft_table; 48 | 49 | ft_size count; 50 | ft_table table; 51 | 52 | void rehash(ft_size new_len); 53 | 54 | public: 55 | /** default constructor. */ 56 | ft_rope_pool(); 57 | 58 | /** copy constructor. */ 59 | ft_rope_pool(const ft_rope_pool & other); 60 | 61 | /** assignment operator. */ 62 | const ft_rope_pool & operator=(const ft_rope_pool & other); 63 | 64 | /* destructor. */ 65 | ~ft_rope_pool(); 66 | 67 | /** returned pointer is valid only until pool is rehashed. 68 | * copy returned ft_rope if you need it further */ 69 | const ft_rope * find(const char s[], ft_size len) const; 70 | 71 | FT_INLINE const ft_rope * find(const ft_string & s) const { 72 | return find(s.c_str(), s.size()); 73 | } 74 | 75 | ft_rope make(const char s[], ft_size len); 76 | 77 | FT_INLINE ft_rope make(const ft_string & s) { 78 | return make(s.c_str(), s.size()); 79 | } 80 | void erase(const ft_string & s); 81 | }; 82 | 83 | FT_NAMESPACE_END 84 | 85 | #endif /* FSTRANSFORM_ROPE_POOL_HH */ 86 | -------------------------------------------------------------------------------- /fsmove/src/rope/rope_test.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * rope_test.hh 21 | * 22 | * Created on: Mar 3, 2018 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_ROPE_TEST_HH 27 | #define FSTRANSFORM_ROPE_TEST_HH 28 | 29 | FT_NAMESPACE_BEGIN 30 | 31 | int rope_test(int argc, char ** argv); 32 | 33 | FT_NAMESPACE_END 34 | 35 | #endif /* FSTRANSFORM_ROPE_TEST_HH */ 36 | -------------------------------------------------------------------------------- /fsmove/src/traits.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/traits.hh -------------------------------------------------------------------------------- /fsmove/src/types.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/types.hh -------------------------------------------------------------------------------- /fsmove/src/unsorted_map.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/unsorted_map.cc -------------------------------------------------------------------------------- /fsmove/src/unsorted_map.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/unsorted_map.hh -------------------------------------------------------------------------------- /fsmove/src/zstring.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * xstring.hh 21 | * 22 | * Created on: Mar 5, 2018 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_ZSTRING_HH 27 | #define FSTRANSFORM_ZSTRING_HH 28 | 29 | #include "types.hh" // for ft_string 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | int ztest(); 34 | 35 | void zinit(); 36 | 37 | /** compress src into dst */ 38 | void z(ft_string & dst, const ft_string & src, bool force = false); 39 | /** decompress src into dst */ 40 | void unz(ft_string & dst, const ft_string & src); 41 | 42 | FT_NAMESPACE_END 43 | 44 | #endif /* FSTRANSFORM_ZSTRING_HH */ 45 | -------------------------------------------------------------------------------- /fsremap/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fsremap 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /fsremap/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /fsremap/build/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | 3 | sbin_PROGRAMS = fsremap 4 | 5 | fsremap_SOURCES = \ 6 | ../src/arch/mem.cc \ 7 | ../src/arch/mem_linux.cc \ 8 | ../src/arch/mem_posix.cc \ 9 | ../src/args.cc \ 10 | ../src/assert.cc \ 11 | ../src/dispatch.cc \ 12 | ../src/eta.cc \ 13 | ../src/io/extent_file.cc \ 14 | ../src/io/extent_posix.cc \ 15 | ../src/io/io.cc \ 16 | ../src/io/io_null.cc \ 17 | ../src/io/io_posix.cc \ 18 | ../src/io/io_posix_dir.cc \ 19 | ../src/io/io_prealloc.cc \ 20 | ../src/io/io_self_test.cc \ 21 | ../src/io/io_test.cc \ 22 | ../src/io/persist.cc \ 23 | ../src/io/util_dir.cc \ 24 | ../src/io/util_posix.cc \ 25 | ../src/job.cc \ 26 | ../src/log.cc \ 27 | ../src/main.cc \ 28 | ../src/map.cc \ 29 | ../src/map_stat.cc \ 30 | ../src/misc.cc \ 31 | ../src/mstring.cc \ 32 | ../src/pool.cc \ 33 | ../src/remap.cc \ 34 | ../src/tmp_zero.cc \ 35 | ../src/ui/ui.cc \ 36 | ../src/ui/ui_tty.cc \ 37 | ../src/vector.cc \ 38 | ../src/work.cc 39 | -------------------------------------------------------------------------------- /fsremap/src/arch/mem.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * arch/mem.cc 21 | * 22 | * Created on: Mar 10, 2011 23 | * Author: max 24 | */ 25 | #include "../first.hh" 26 | 27 | #include "mem.hh" // for ff_arch_mem_system_free(), ff_arch_mem_page_size() 28 | #include "mem_posix.hh" // for ff_arch_posix_mem_page_size() 29 | #include "mem_linux.hh" // for ff_arch_linux_mem_system_free() 30 | 31 | 32 | FT_ARCH_NAMESPACE_BEGIN 33 | 34 | /** 35 | * return an approximation of free system memory in bytes, 36 | * or 0 if cannot be determined 37 | */ 38 | ft_uoff ff_arch_mem_system_free() { 39 | #if defined(__linux__) 40 | return ff_arch_linux_mem_system_free(); 41 | #else 42 | return 0; 43 | #endif 44 | } 45 | 46 | /** 47 | * return RAM page size, or 0 if cannot be determined 48 | */ 49 | ft_size ff_arch_mem_page_size() { 50 | #if defined(__unix__) 51 | return ff_arch_posix_mem_page_size(); 52 | #else 53 | return 0; 54 | #endif 55 | } 56 | 57 | FT_ARCH_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /fsremap/src/arch/mem.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * arch/mem.hh 21 | * 22 | * Created on: Mar 10, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_ARCH_MEM_HH 27 | #define FSREMAP_ARCH_MEM_HH 28 | 29 | #include "../types.hh" 30 | 31 | FT_ARCH_NAMESPACE_BEGIN 32 | 33 | /** 34 | * return an approximation of free system memory in bytes, 35 | * or 0 if cannot be determined 36 | */ 37 | ft_uoff ff_arch_mem_system_free(); 38 | 39 | /** 40 | * return RAM page size, or 0 if cannot be determined 41 | */ 42 | ft_size ff_arch_mem_page_size(); 43 | 44 | FT_ARCH_NAMESPACE_END 45 | 46 | #endif /* FSREMAP_ARCH_MEM_HH */ 47 | -------------------------------------------------------------------------------- /fsremap/src/arch/mem_linux.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * arch/mem_linux.hh 21 | * 22 | * Created on: Mar 10, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_ARCH_MEM_LINUX_HH 27 | #define FSREMAP_ARCH_MEM_LINUX_HH 28 | 29 | #include "../types.hh" 30 | 31 | #ifdef __linux__ 32 | 33 | FT_ARCH_NAMESPACE_BEGIN 34 | 35 | /** 36 | * return an approximation of free system memory in bytes, 37 | * or 0 if cannot be determined 38 | */ 39 | ft_uoff ff_arch_linux_mem_system_free(); 40 | 41 | FT_ARCH_NAMESPACE_END 42 | 43 | #endif /* __linux__ */ 44 | 45 | #endif /* FSREMAP_ARCH_MEM_LINUX_HH */ 46 | -------------------------------------------------------------------------------- /fsremap/src/arch/mem_posix.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * arch/mem_posix.cc 21 | * 22 | * Created on: Mar 11, 2011 23 | * Author: max 24 | */ 25 | #include "../first.hh" 26 | 27 | #ifdef __unix__ 28 | 29 | #ifdef FT_HAVE_UNISTD_H 30 | # include // for sysconf(), _SC_PAGESIZE 31 | #endif 32 | 33 | #include "mem_posix.hh" 34 | 35 | 36 | FT_ARCH_NAMESPACE_BEGIN 37 | 38 | /** 39 | * return RAM page size, or 0 if cannot be determined 40 | */ 41 | ft_size ff_arch_posix_mem_page_size() { 42 | 43 | // first attempt: sysconf(_SC_PAGESIZE) 44 | #if defined(FT_HAVE_SYSCONF) && defined(_SC_PAGESIZE) 45 | long n = sysconf(_SC_PAGESIZE); 46 | if (n > 0 && n == (long)(ft_size) n) 47 | return (ft_size) n; 48 | #endif 49 | 50 | // second attempt: getpagesize() 51 | #if defined(FT_HAVE_GETPAGESIZE) 52 | int n2 = getpagesize(); 53 | if (n2 > 0 && n2 == (int)(ft_size) n2) 54 | return (ft_size) n2; 55 | #endif 56 | 57 | // third attempt: PAGE_SIZE and PAGESIZE 58 | #if defined(PAGE_SIZE) 59 | return PAGE_SIZE; 60 | #elif defined(PAGESIZE) 61 | return PAGESIZE; 62 | #else 63 | return 0; 64 | #endif 65 | } 66 | 67 | FT_ARCH_NAMESPACE_END 68 | 69 | 70 | #endif /* __unix__ */ 71 | -------------------------------------------------------------------------------- /fsremap/src/arch/mem_posix.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * arch/mem_posix.hh 21 | * 22 | * Created on: Mar 11, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_ARCH_MEM_POSIX_HH 27 | #define FSREMAP_ARCH_MEM_POSIX_HH 28 | 29 | #include "../types.hh" 30 | 31 | #ifdef __unix__ 32 | 33 | FT_ARCH_NAMESPACE_BEGIN 34 | 35 | /** 36 | * return RAM page size, or 0 if cannot be determined 37 | */ 38 | ft_size ff_arch_posix_mem_page_size(); 39 | 40 | FT_ARCH_NAMESPACE_END 41 | 42 | #endif /* __unix__ */ 43 | 44 | 45 | #endif /* FSREMAP_ARCH_MEM_POSIX_HH */ 46 | -------------------------------------------------------------------------------- /fsremap/src/args.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * args.cc 21 | * 22 | * Created on: Mar 21, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #include "args.hh" // for fr_args 29 | 30 | FT_NAMESPACE_BEGIN 31 | 32 | 33 | /** default constructor */ 34 | fr_args::fr_args() 35 | : program_name("fsremap"), root_dir(NULL), 36 | io_args(), mount_points(), loop_dev(NULL), 37 | ui_arg(NULL), cmd_losetup(NULL), cmd_umount(NULL), 38 | storage_size(), job_id(FC_JOB_ID_AUTODETECT), job_clear(FC_CLEAR_AUTODETECT), 39 | io_kind(FC_IO_AUTODETECT), ui_kind(FC_UI_NONE), 40 | force_run(false), simulate_run(false), ask_questions(false) 41 | { 42 | ft_size i, n; 43 | for (i = 0, n = sizeof(io_args)/sizeof(io_args[0]); i < n; i++) 44 | io_args[i] = NULL; 45 | for (i = 0, n = sizeof(mount_points)/sizeof(mount_points[0]); i < n; i++) 46 | mount_points[i] = NULL; 47 | for (i = 0, n = sizeof(storage_size)/sizeof(storage_size[0]); i < n; i++) 48 | storage_size[i] = 0; 49 | } 50 | 51 | FT_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /fsremap/src/args.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * main.hh 21 | * 22 | * Created on: Mar 20, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_ARGS_HH 27 | #define FSREMAP_ARGS_HH 28 | 29 | #include "types.hh" // for ft_uint, ft_size 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | enum fr_storage_size { FC_MEM_BUFFER_SIZE, FC_SECONDARY_STORAGE_SIZE, FC_PRIMARY_STORAGE_EXACT_SIZE, FC_SECONDARY_STORAGE_EXACT_SIZE, FC_STORAGE_SIZE_N, }; 34 | 35 | enum fr_clear_free_space { FC_CLEAR_AUTODETECT, FC_CLEAR_ALL, FC_CLEAR_MINIMAL, FC_CLEAR_NONE, }; 36 | enum fr_job_id_kind { FC_JOB_ID_AUTODETECT = 0 }; 37 | enum fr_io_kind { FC_IO_AUTODETECT, FC_IO_TEST, FC_IO_SELF_TEST, FC_IO_POSIX, FC_IO_PREALLOC }; 38 | enum fr_mount_points { FC_MOUNT_POINT_DEVICE = 0, FC_MOUNT_POINT_LOOP_FILE, FC_MOUNT_POINTS_N }; 39 | enum fr_ui_kind { FC_UI_NONE, FC_UI_TTY }; 40 | 41 | class fr_args 42 | { 43 | public: 44 | const char * program_name; // detected from command line. default: "fsremap" 45 | const char * root_dir; // write logs and persistence files inside this folder. if NULL, will autodetect 46 | const char * io_args[3]; // some I/O will need less than 3 arguments 47 | const char * mount_points[FC_MOUNT_POINTS_N]; // device and loop file mount points. currently only needed by fr_io_prealloc 48 | const char * loop_dev; // loop device. currently only needed by fr_io_prealloc 49 | const char * ui_arg; 50 | const char * cmd_losetup; // 'losetup' command. currently only needed by fr_io_prealloc 51 | const char * cmd_umount; 52 | ft_size storage_size[FC_STORAGE_SIZE_N]; // if 0, will autodetect 53 | ft_uint job_id; // if FC_JOB_ID_AUTODETECT, will autodetect 54 | fr_clear_free_space job_clear; 55 | fr_io_kind io_kind; // if FC_IO_AUTODETECT, will autodetect 56 | fr_ui_kind ui_kind; 57 | bool force_run; // if true, some sanity checks will be WARNINGS instead of ERRORS 58 | bool simulate_run; // if true, remapping algorithm runs WITHOUT reading or writing device blocks 59 | bool ask_questions; // if true, remapping algorithm will ask confirmation and read answer from stdin before actually starting 60 | 61 | fr_args(); 62 | }; 63 | 64 | 65 | FT_NAMESPACE_END 66 | 67 | #endif /* FSREMAP_ARGS_HH */ 68 | -------------------------------------------------------------------------------- /fsremap/src/assert.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * assert.cc 21 | * 22 | * Created on: Mar 13, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #if defined(FT_HAVE_STDLIB_H) 29 | # include // for exit() 30 | #elif defined(FT_HAVE_CSTDLIB) 31 | # include // for exit() 32 | #endif 33 | 34 | #include "assert.hh" // for ff_assert() 35 | #include "log.hh" // for ff_log() 36 | 37 | FT_NAMESPACE_BEGIN 38 | 39 | void ff_assert_fail0(const char * caller_file, int caller_file_len, const char * caller_func, int caller_line, const char * assertion) 40 | { 41 | ff_logl(caller_file, caller_file_len, caller_func, caller_line, FC_FATAL, 0, "internal error! assertion failed: %s", assertion); 42 | ft_log_appender::flush_all(FC_FATAL); 43 | exit(1); 44 | } 45 | 46 | FT_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /fsremap/src/assert.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * assert.h 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_ASSERT_HH 27 | #define FSTRANSFORM_ASSERT_HH 28 | 29 | #include "check.hh" 30 | 31 | FT_EXTERN_C_BEGIN 32 | FT_NAMESPACE_BEGIN 33 | 34 | void ff_assert_fail0(const char * caller_file, int caller_file_len, const char * caller_func, int caller_line, const char * assertion); 35 | 36 | FT_NAMESPACE_END 37 | FT_EXTERN_C_END 38 | 39 | #define ff_assert(expr) do { if (!(expr)) ff_assert_fail0(FT_THIS_FILE, sizeof(FT_THIS_FILE)-1, FT_THIS_FUNCTION, FT_THIS_LINE, #expr ); } while (0) 40 | 41 | #define ff_assert_fail(msg) ff_assert_fail0(FT_THIS_FILE, sizeof(FT_THIS_FILE)-1, FT_THIS_FUNCTION, FT_THIS_LINE, (msg)) 42 | 43 | 44 | #endif /* FSTRANSFORM_ASSERT_HH */ 45 | -------------------------------------------------------------------------------- /fsremap/src/autoconf.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * autoconf.hh 21 | * 22 | * defines compiler, headers and library features. 23 | * 24 | * Created on: Feb 27, 2011 25 | * Author: max 26 | */ 27 | 28 | #ifndef FSTRANSFORM_AUTOCONF_HH 29 | #define FSTRANSFORM_AUTOCONF_HH 30 | 31 | #include "check.hh" 32 | #include "ft_config.hh" 33 | 34 | // clang-format off 35 | 36 | /** 37 | * define if C++ library implements something usable for ft_unsorted_map 38 | * possibilities include: std::unordered_map and std::tr1::unordered_map 39 | */ 40 | #if !defined(FT_HAVE_FT_UNSORTED_MAP) && (defined(FT_HAVE_STD_UNORDERED_MAP) || defined(FT_HAVE_STD_TR1_UNORDERED_MAP)) 41 | # define FT_HAVE_FT_UNSORTED_MAP 42 | #endif 43 | 44 | 45 | 46 | /** define if compiler supports the types (long long) and (unsigned long long) */ 47 | #if !defined(FT_HAVE_LONG_LONG) || !defined(FT_HAVE_UNSIGNED_LONG_LONG) 48 | # if defined(__GNUC__) 49 | # define FT_HAVE_LONG_LONG 50 | # define FT_HAVE_UNSIGNED_LONG_LONG 51 | # endif 52 | #endif /* FT_HAVE_LONG_LONG */ 53 | 54 | /* (long long) and (unsigned long long) are useful only if they are BOTH supported */ 55 | #ifndef FT_HAVE_LONG_LONG 56 | # undef FT_HAVE_UNSIGNED_LONG_LONG 57 | #endif 58 | #ifndef FT_HAVE_UNSIGNED_LONG_LONG 59 | # undef FT_HAVE_LONG_LONG 60 | #endif 61 | 62 | 63 | 64 | /** define if va_copy() macro is supported (copies va_list variadic arguments) */ 65 | #ifndef FT_HAVE_VA_COPY 66 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 67 | # define FT_HAVE_VA_COPY 68 | # endif 69 | #endif 70 | 71 | 72 | /** define to compiler's own version of 'inline' keyword */ 73 | #ifndef FT_INLINE 74 | # if defined(__cplusplus) 75 | /* inline is standard keyword in C++ */ 76 | # define FT_INLINE inline 77 | # elif defined(__GNUC__) 78 | /* prefer __inline__ to inline, the former works even in gcc strict-ansi mode */ 79 | # define FT_INLINE __inline__ 80 | # else 81 | # define FT_INLINE 82 | # endif 83 | #endif /* FT_INLINE */ 84 | 85 | 86 | /** 87 | * define if extern "C" { ... } is understood by the compiler and needed to get C linkage. 88 | * should be defined in C++, and undefined in C. 89 | */ 90 | #ifndef FT_HAVE_EXTERN_C 91 | # if defined(__cplusplus) 92 | # define FT_HAVE_EXTERN_C 93 | # endif 94 | #endif /* FT_HAVE_EXTERN_C */ 95 | 96 | 97 | /** 98 | * define if namespace Foo { ... } is understood by the compiler. 99 | * should be defined in C++, and undefined in C. 100 | */ 101 | #ifndef FT_HAVE_NAMESPACE 102 | # if defined(__cplusplus) 103 | # define FT_HAVE_NAMESPACE 104 | # endif 105 | #endif /* FT_HAVE_NAMESPACE */ 106 | 107 | 108 | /** define to compiler's own version of __FILE__ or equivalent */ 109 | #ifndef FT_THIS_FILE 110 | # define FT_THIS_FILE __FILE__ 111 | #endif 112 | 113 | /** define to compiler's own version of __LINE__ or equivalent */ 114 | #ifndef FT_THIS_LINE 115 | # define FT_THIS_LINE __LINE__ 116 | #endif 117 | 118 | /** define to compiler's own version of __func__, __FUNCTION__ or equivalent (don't use __PRETTY_FUNCTION__) */ 119 | #ifndef FT_THIS_FUNCTION 120 | # define FT_THIS_FUNCTION __FUNCTION__ 121 | #endif 122 | 123 | 124 | #endif /* FSTRANSFORM_AUTOCONF_HH */ 125 | -------------------------------------------------------------------------------- /fsremap/src/cache/cache.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * cache.hh 21 | * 22 | * Created on: Aug 18, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_CACHE_HH 27 | #define FSTRANSFORM_CACHE_HH 28 | 29 | FT_NAMESPACE_BEGIN 30 | 31 | /* 32 | * Base class for generic key->value caches. 33 | * 34 | * Used to implement inode cache, needed to detect multiple files 35 | * hard-linked together (i.e. having the same inode) and let fsmove 36 | * create an accurate replica of them. 37 | */ 38 | template 39 | class ft_cache 40 | { 41 | protected: 42 | V zero_payload; 43 | 44 | public: 45 | /** default constructor */ 46 | ft_cache(const V & init_zero_payload = V()) : zero_payload(init_zero_payload) 47 | { } 48 | 49 | /** copy constructor */ 50 | ft_cache(const ft_cache & other) : zero_payload(other.zero_payload) 51 | { } 52 | 53 | /** assignment operator */ 54 | virtual const ft_cache & operator=(const ft_cache & other) 55 | { 56 | if (this != &other) 57 | zero_payload = other.zero_payload; 58 | return *this; 59 | } 60 | 61 | /** destructor */ 62 | virtual ~ft_cache() 63 | { } 64 | 65 | /** 66 | * if cached inode found, set payload and return 1. 67 | * Otherwise add it to cache and return 0. 68 | * On error, return < 0. 69 | * if returns 0, find_and_delete() must be called on the same inode when done with payload! 70 | */ 71 | virtual int find_or_add(const K key, V & inout_payload) = 0; 72 | 73 | /** 74 | * if cached inode found, set result_payload, remove inode from cache and return 1. 75 | * Otherwise return 0. On error, return < 0. 76 | */ 77 | virtual int find_and_delete(const K key, V & result_payload) = 0; 78 | 79 | /** 80 | * if cached inode found, change its payload and return 1. 81 | * Otherwise return 0. On error, return < 0. 82 | */ 83 | virtual int find_and_update(const K key, const V & new_payload) = 0; 84 | 85 | virtual void clear() = 0; 86 | }; 87 | 88 | FT_NAMESPACE_END 89 | 90 | #endif /* FSTRANSFORM_CACHE_HH */ 91 | -------------------------------------------------------------------------------- /fsremap/src/cache/cache_adaptor.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * inode_cache.hh 21 | * 22 | * Created on: Aug 18, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_CACHE_ADAPTOR_HH 27 | #define FSTRANSFORM_CACHE_ADAPTOR_HH 28 | 29 | #include "cache.hh" // for ft_cache 30 | #include "../copy.hh" // for ff_set() 31 | 32 | FT_NAMESPACE_BEGIN 33 | 34 | /** 35 | * adaptor from string->string caches to K->V caches. 36 | * 37 | * Used to wrap ft_cache_symlink and tranform it into ft_cache_symlink_kv 38 | * - see cache_symlink.hh for details. 39 | */ 40 | template 41 | class ft_cache_adaptor : public ft_cache, public Cache 42 | { 43 | private: 44 | typedef ft_cache super_type; 45 | typedef ft_cache_adaptor this_type; 46 | 47 | typedef Cache mixin_type; 48 | typedef typename Cache::key_type mixin_key_type; 49 | typedef typename Cache::payload_type mixin_payload_type; 50 | 51 | public: 52 | /** default constructor */ 53 | ft_cache_adaptor(const V & init_zero_payload = V()) : super_type(init_zero_payload), mixin_type() 54 | { } 55 | 56 | /** copy constructor */ 57 | ft_cache_adaptor(const this_type & other) : super_type(other), mixin_type(other) 58 | { } 59 | 60 | /** assignment operator */ 61 | virtual const super_type & operator=(const this_type & other) 62 | { 63 | mixin_type::operator=(other); 64 | return super_type::operator=(other); 65 | } 66 | 67 | /** destructor */ 68 | virtual ~ft_cache_adaptor() 69 | { } 70 | 71 | /** 72 | * if cached inode found, set payload and return 1. 73 | * Otherwise add it to cache and return 0. 74 | * On error, return < 0. 75 | * if returns 0, erase() must be called on the same inode when done with payload! 76 | */ 77 | virtual int find_or_add(const K key, V & inout_payload) 78 | { 79 | mixin_key_type m_key; 80 | ff_set(m_key, key); 81 | 82 | mixin_payload_type m_payload; 83 | ff_set(m_payload, inout_payload); 84 | 85 | int err = mixin_type::find_or_add(m_key, m_payload); 86 | ff_set(inout_payload, m_payload); 87 | 88 | return err; 89 | } 90 | 91 | /** 92 | * if cached key found, set payload, remove cached key and return 1. 93 | * Otherwise return 0. On error, return < 0. 94 | */ 95 | virtual int find_and_delete(const K key, V & result_payload) 96 | { 97 | mixin_key_type m_key; 98 | ff_set(m_key, key); 99 | 100 | mixin_payload_type m_payload; 101 | int err = mixin_type::find_and_delete(m_key, m_payload); 102 | ff_set(result_payload, m_payload); 103 | 104 | return err; 105 | } 106 | 107 | /** 108 | * if cached inode found, change its payload and return 1. 109 | * Otherwise return 0. On error, return < 0. 110 | */ 111 | virtual int find_and_update(const K key, const V & new_payload) 112 | { 113 | mixin_key_type m_key; 114 | ff_set(m_key, key); 115 | 116 | mixin_payload_type m_payload; 117 | ff_set(m_payload, new_payload); 118 | 119 | return mixin_type::find_and_update(m_key, m_payload); 120 | } 121 | 122 | virtual void clear() 123 | { 124 | mixin_type::clear(); 125 | } 126 | }; 127 | 128 | FT_NAMESPACE_END 129 | 130 | #endif /* FSTRANSFORM_CACHE_ADAPTOR_HH */ 131 | -------------------------------------------------------------------------------- /fsremap/src/check.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | #ifndef FSTRANSFORM_FIRST_HH 21 | # error "first.hh" must be included before any other #include 22 | #endif 23 | -------------------------------------------------------------------------------- /fsremap/src/copy.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * copy.cc 21 | * 22 | * Created on: Aug 18, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #include "copy.hh" 29 | 30 | #if defined(FT_HAVE_STDIO_H) 31 | #include /* for snprintf() */ 32 | #elif defined(FT_HAVE_CSTDIO) 33 | #include /* for snprintf() */ 34 | #endif 35 | 36 | FT_NAMESPACE_BEGIN 37 | 38 | void ff_set(ft_string &dst, const ft_string &src) { 39 | dst = src; 40 | } 41 | 42 | void ff_set(ft_string &dst, ft_ull src) { 43 | enum { maxlen = sizeof(ft_ull) * 3 + 1 }; 44 | dst.resize(maxlen); 45 | char *buf = &dst[0]; 46 | 47 | int delta = snprintf(buf, maxlen, "%" FT_XLL, src); 48 | dst.resize(delta > 0 ? delta : 0); 49 | } 50 | 51 | void ff_set(ft_ull &dst, const ft_string &src) { 52 | dst = 0; 53 | sscanf(src.c_str(), "%" FT_XLL, &dst); 54 | } 55 | 56 | void ff_cat(ft_string &dst, const ft_string &src) { 57 | dst += src; 58 | } 59 | 60 | void ff_cat(ft_string &dst, ft_ull src) { 61 | enum { maxlen = sizeof(ft_ull) * 3 + 1 }; 62 | size_t oldlen = dst.length(); 63 | dst.resize(oldlen + maxlen); 64 | char *buf = &dst[oldlen]; 65 | 66 | int delta = snprintf(buf, maxlen, "%" FT_XLL, src); 67 | dst.resize(oldlen + (delta > 0 ? delta : 0)); 68 | } 69 | 70 | FT_NAMESPACE_END 71 | -------------------------------------------------------------------------------- /fsremap/src/copy.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * copy.hh 21 | * 22 | * Created on: Aug 18, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_COPY_HH 27 | #define FSTRANSFORM_COPY_HH 28 | 29 | #include "types.hh" // for ft_string 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | void ff_set(ft_string &dst, const ft_string &src); 34 | void ff_set(ft_string &dst, ft_ull src); 35 | 36 | void ff_set(ft_ull &dst, const ft_string &src); 37 | 38 | void ff_cat(ft_string &dst, const ft_string &src); 39 | void ff_cat(ft_string &dst, ft_ull src); 40 | 41 | FT_NAMESPACE_END 42 | 43 | #endif /* FSTRANSFORM_COPY_HH */ 44 | -------------------------------------------------------------------------------- /fsremap/src/dispatch.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * dispatch.cc 21 | * 22 | * Created on: Mar 3, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #include "dispatch.hh" // for fr_dispatch 29 | #include "work.hh" // for fr_work 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | 34 | /** 35 | * instantiate and run fr_work 36 | * with the smallest T that can represent device blocks count. 37 | * return 0 if success, else error. 38 | * 39 | * implementation: iterates on all known configured T and, 40 | * if both fr_work::check() and fr_work::init() succeed, 41 | * calls fr_work::run(), then fr_work::cleanup() 42 | */ 43 | int fr_dispatch::main(fr_vector & loop_file_extents, 44 | fr_vector & free_space_extents, 45 | fr_vector & to_zero_extents, 46 | FT_IO_NS fr_io & io) 47 | { 48 | if (fr_work::check(io) == 0) { 49 | ff_log(FC_INFO, 0, "using reduced (%" FT_ULL " bit) remapping algorithm", (ft_ull)8*sizeof(ft_uint)); 50 | return fr_work::main(loop_file_extents, free_space_extents, to_zero_extents, io); 51 | } 52 | ff_log(FC_INFO, 0, "using full (%" FT_ULL " bit) remapping algorithm", (ft_ull)8*sizeof(ft_uoff)); 53 | return fr_work::main(loop_file_extents, free_space_extents, to_zero_extents, io); 54 | } 55 | 56 | FT_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /fsremap/src/dispatch.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * dispatch.hh 21 | * 22 | * Created on: Mar 3, 2011 23 | * Author: max 24 | */ 25 | #ifndef FSREMAP_WORK_BASE_HH 26 | #define FSREMAP_WORK_BASE_HH 27 | 28 | #include "types.hh" // for ft_uoff 29 | #include "fwd.hh" // for fr_io, fr_vector forward declarations 30 | 31 | 32 | FT_NAMESPACE_BEGIN 33 | 34 | 35 | class fr_dispatch 36 | { 37 | public: 38 | /** 39 | * instantiate and run fr_work::main(...) 40 | * with the smallest T that can represent device blocks count. 41 | * return 0 if success, else error. 42 | * 43 | * implementation: iterates on all configured T and, 44 | * if both fr_work::check(..) and fr_work::init(..) succeed, 45 | * calls ff_work::run(), then ff_work::cleanup() 46 | */ 47 | static int main(fr_vector & loop_file_extents, 48 | fr_vector & free_space_extents, 49 | fr_vector & to_zero_extents, 50 | FT_IO_NS fr_io & io); 51 | 52 | }; 53 | 54 | FT_NAMESPACE_END 55 | 56 | #endif /* FSREMAP_WORK_BASE_HH */ 57 | -------------------------------------------------------------------------------- /fsremap/src/eta.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * eta.hh 21 | * 22 | * Created on: Mar 22, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_ETA_HH 27 | #define FSTRANSFORM_ETA_HH 28 | 29 | #include "types.hh" // for ft_size 30 | 31 | #include // for std::vector 32 | 33 | FT_NAMESPACE_BEGIN 34 | 35 | /** estimates time-of-arrival from a sliding window extrapolation of last 3 progress percentages */ 36 | class ft_eta 37 | { 38 | private: 39 | std::vector this_x; 40 | std::vector this_y; 41 | ft_size this_max_n; 42 | 43 | public: 44 | enum { DEFAULT_MAX_N = 12 }; 45 | 46 | ft_eta(ft_size max_n = DEFAULT_MAX_N); 47 | 48 | /** 49 | * add percentage and {current timestamp} to the sliding window E.T.A. extrapolation. 50 | * return number of seconds to E.T.A., or < 0 if not enough data available yet. 51 | */ 52 | double add(double percentage); 53 | 54 | /* reset this E.T.A. to empty */ 55 | void clear(ft_size max_n = DEFAULT_MAX_N); 56 | }; 57 | 58 | 59 | FT_NAMESPACE_END 60 | 61 | #endif /* FSTRANSFORM_ETA_HH */ 62 | -------------------------------------------------------------------------------- /fsremap/src/features.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * common header for fsattr, fsmove, fsremap 3 | * 4 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * features.hh 20 | * 21 | * Created on: Feb 27, 2011 22 | * Author: max 23 | */ 24 | 25 | #ifndef FSTRANSFORM_FEATURES_HH 26 | #define FSTRANSFORM_FEATURES_HH 27 | 28 | #ifdef FT_HAVE_EXTERN_C 29 | /** in C++, define to extern "C" { ... }. in C, define as empty */ 30 | # define FT_EXTERN_C_BEGIN extern "C" { 31 | # define FT_EXTERN_C_END } 32 | #else 33 | # define FT_EXTERN_C_BEGIN 34 | # define FT_EXTERN_C_END 35 | #endif /* FT_HAVE_EXTERN_C */ 36 | 37 | 38 | /* suppress warning about unused function argument */ 39 | #ifndef FT_ARG_UNUSED 40 | # define FT_ARG_UNUSED(arg) 41 | #endif 42 | 43 | 44 | #ifdef FT_HAVE_NAMESPACE 45 | /** in C++, define to namespace ft { ... }. in C, define as empty */ 46 | # define FT_NAMESPACE_BEGIN namespace ft { 47 | # define FT_NAMESPACE_END } 48 | 49 | # define FT_ARCH_NAMESPACE_BEGIN FT_NAMESPACE_BEGIN namespace arch { 50 | # define FT_ARCH_NAMESPACE_END } FT_NAMESPACE_END 51 | 52 | # define FT_IO_NAMESPACE_BEGIN FT_NAMESPACE_BEGIN namespace io { 53 | # define FT_IO_NAMESPACE_END } FT_NAMESPACE_END 54 | 55 | # define FT_UI_NAMESPACE_BEGIN FT_NAMESPACE_BEGIN namespace ui { 56 | # define FT_UI_NAMESPACE_END } FT_NAMESPACE_END 57 | 58 | 59 | # define FT_NS ft:: 60 | # define FT_ARCH_NS FT_NS arch:: 61 | # define FT_IO_NS FT_NS io:: 62 | # define FT_UI_NS FT_NS ui:: 63 | 64 | #else 65 | 66 | # define FT_NAMESPACE_BEGIN 67 | # define FT_NAMESPACE_END 68 | 69 | # define FT_ARCH_NAMESPACE_BEGIN 70 | # define FT_ARCH_NAMESPACE_END 71 | 72 | # define FT_IO_NAMESPACE_BEGIN 73 | # define FT_IO_NAMESPACE_END 74 | 75 | # define FT_UI_NAMESPACE_BEGIN 76 | # define FT_UI_NAMESPACE_END 77 | 78 | 79 | 80 | # define FT_NS 81 | # define FT_ARCH_NS 82 | # define FT_IO_NS 83 | # define FT_UI_NS 84 | 85 | #endif /* FT_HAVE_NAMESPACE */ 86 | 87 | // list of types we want to instantiate fr_work with 88 | #define FT_TYPE_LIST(ft_prefix, ft_macro) \ 89 | ft_macro(ft_prefix, ft_uint) \ 90 | ft_macro(ft_prefix, ft_uoff) 91 | 92 | /* 93 | * does compiler supports 94 | * extern template class Foo; 95 | * extern template int foo(T bar); 96 | * and 97 | * template class Foo; 98 | * template int foo(T bar); 99 | * to explicitly control template instantiation? 100 | */ 101 | #ifdef FT_HAVE_EXTERN_TEMPLATE 102 | 103 | # define FT_TEMPLATE_DECLARE(ft_macro) FT_TYPE_LIST(extern template, ft_macro) 104 | # define FT_TEMPLATE_INSTANTIATE(ft_macro) FT_TYPE_LIST( template, ft_macro) 105 | 106 | #else /* !defined(FT_HAVE_EXTERN_TEMPLATE) */ 107 | 108 | # define FT_TEMPLATE_DECLARE(ft_macro) 109 | # define FT_TEMPLATE_INSTANTIATE(ft_macro) 110 | 111 | #endif /* FT_HAVE_EXTERN_TEMPLATE */ 112 | 113 | #endif /* FSTRANSFORM_FEATURES_HH */ 114 | -------------------------------------------------------------------------------- /fsremap/src/first.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * common header for fsattr, fsmove, fsremap 3 | * 4 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * first.hh 20 | * 21 | * Created on: Feb 24, 2011 22 | * Author: max 23 | */ 24 | 25 | #ifndef FSTRANSFORM_FIRST_HH 26 | #define FSTRANSFORM_FIRST_HH 27 | 28 | #if defined(__USE_ANSI) || defined(_FEATURES_H) || defined(FSTRANSFORM_FEATURES_HH) || defined(FSTRANSFORM_AUTOCONF_HH) 29 | # error "first.hh" must be included before any other #include 30 | #endif 31 | 32 | /* put here any option/define/... affecting system-wide includes */ 33 | 34 | /* 35 | * _GNU_SOURCE implies _LARGEFILE_SOURCE. 36 | * together with _FILE_OFFSET_BITS=64 they should set off_t to be at least 64 bits wide 37 | */ 38 | #ifndef _GNU_SOURCE 39 | # define _GNU_SOURCE 40 | #endif 41 | #ifndef _LARGEFILE_SOURCE 42 | # define _LARGEFILE_SOURCE 43 | #endif 44 | #ifndef _FILE_OFFSET_BITS 45 | # define _FILE_OFFSET_BITS 64 46 | #endif 47 | 48 | 49 | /* put here any option/define/... affecting the whole program (headers and source files) */ 50 | 51 | #include "autoconf.hh" 52 | 53 | #ifdef FT_HAVE_FEATURES_H 54 | # include 55 | #endif 56 | 57 | #include "features.hh" 58 | 59 | 60 | 61 | #endif /* FSTRANSFORM_FIRST_HH */ 62 | -------------------------------------------------------------------------------- /fsremap/src/fwd.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * fwd.hh 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_FWD_HH 27 | #define FSREMAP_FWD_HH 28 | 29 | #include "check.hh" 30 | 31 | FT_NAMESPACE_BEGIN 32 | class fr_args; 33 | class fr_remap; 34 | class fr_dispatch; 35 | class fr_job; 36 | 37 | template struct fr_extent_key; 38 | template struct fr_extent_payload; 39 | template class fr_extent; 40 | template class fr_vector; 41 | template class fr_map; 42 | template class fr_pool_entry; 43 | template class fr_pool; 44 | template class fr_work; 45 | FT_NAMESPACE_END 46 | 47 | 48 | FT_IO_NAMESPACE_BEGIN 49 | class fr_io; 50 | class fr_io_posix; 51 | class fr_io_test; 52 | class fr_io_self_test; 53 | FT_IO_NAMESPACE_END 54 | 55 | FT_UI_NAMESPACE_BEGIN 56 | class fr_ui; 57 | class fr_ui_tty; 58 | FT_UI_NAMESPACE_END 59 | 60 | #endif /* FSREMAP_FWD_HH */ 61 | -------------------------------------------------------------------------------- /fsremap/src/io/extent_file.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/extent_posix.hh 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_IO_POSIX_EXTENT_HH 27 | #define FSREMAP_IO_POSIX_EXTENT_HH 28 | 29 | #include "../check.hh" 30 | 31 | #if defined(FT_HAVE_STDIO_H) 32 | # include // for FILE 33 | #elif defined(FT_HAVE_CSTDIO) 34 | # include // for FILE 35 | #endif 36 | 37 | #include "../fwd.hh" // for fr_vector forward declaration */ 38 | #include "../types.hh" // for ft_uoff 39 | 40 | FT_IO_NAMESPACE_BEGIN 41 | 42 | /** 43 | * load file blocks allocation map (extents) previously saved into specified file 44 | * and appends them to ret_container (retrieves also user_data) 45 | * in case of failure returns errno-compatible error code, and ret_list contents will be UNDEFINED. 46 | * 47 | * implementation: simply reads the list of triplets (physical, logical, length) 48 | * stored in the stream as decimal numbers 49 | */ 50 | int ff_load_extents_file(FILE * f, fr_vector & ret_list, ft_uoff & ret_block_size_bitmask); 51 | 52 | /** 53 | * writes file blocks allocation map (extents) to specified FILE (stores also user_data) 54 | * in case of failure returns errno-compatible error code. 55 | * 56 | * implementation: simply writes the list of triplets (physical, logical, length) 57 | * into the FILE as decimal numbers 58 | */ 59 | int ff_save_extents_file(FILE * f, const fr_vector & extent_list); 60 | 61 | /** 62 | * write 'length' bytes of zeros '\0' into file descriptor and return 0. 63 | * in case of failure returns errno-compatible error code. 64 | */ 65 | int ff_write_zero_fd(int fd, ft_uoff length); 66 | 67 | FT_IO_NAMESPACE_END 68 | 69 | 70 | #endif /* FSREMAP_FILEMAP_HH */ 71 | -------------------------------------------------------------------------------- /fsremap/src/io/extent_posix.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/extent_posix.hh 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_IO_POSIX_EXTENT_HH 27 | #define FSREMAP_IO_POSIX_EXTENT_HH 28 | 29 | #include "../fwd.hh" // for fr_vector forward declaration */ 30 | #include "../types.hh" // for ft_uoff 31 | 32 | 33 | FT_IO_NAMESPACE_BEGIN 34 | 35 | /** 36 | * retrieves file blocks allocation map (extents) for specified file descriptor 37 | * and appends them to ret_vector (with user_data = FC_DEFAULT_USER_DATA) sorted by ->logical 38 | * in case of failure returns errno-compatible error code, and ret_vector contents will be UNDEFINED. 39 | * 40 | * implementation: calls ioctl(FS_IOC_FIEMAP) and if it fails, tries with ioctl(FIBMAP) 41 | */ 42 | int ff_read_extents_posix(int fd, ft_uoff dev_length, fr_vector & ret_list, ft_uoff & ret_block_size_bitmask); 43 | 44 | 45 | FT_IO_NAMESPACE_END 46 | 47 | 48 | #endif /* FSREMAP_FILEMAP_HH */ 49 | -------------------------------------------------------------------------------- /fsremap/src/io/io_posix_dir.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/io_posix_dir.cc 21 | * 22 | * Created on: Sep 22, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "../first.hh" 27 | 28 | #if defined(FT_HAVE_CERRNO) 29 | #include // for errno and error codes 30 | #elif defined(FT_HAVE_ERRNO_H) 31 | #include 32 | #endif 33 | 34 | #ifdef FT_HAVE_SYS_TYPES_H 35 | #include // for DIR, opendir() 36 | #endif 37 | #ifdef FT_HAVE_DIRENT_H 38 | #include // " " " , readdir(), closedir() 39 | #endif 40 | 41 | #include "../log.hh" // for ff_log() 42 | #include "io_posix_dir.hh" // for ft_io_posix_dir 43 | 44 | FT_IO_NAMESPACE_BEGIN 45 | 46 | /** default constructor */ 47 | ft_io_posix_dir::ft_io_posix_dir() : this_path(), this_dir(NULL) { 48 | } 49 | 50 | /** destructor. calls close() */ 51 | ft_io_posix_dir::~ft_io_posix_dir() { 52 | close(); 53 | } 54 | 55 | /** open a directory */ 56 | int ft_io_posix_dir::open(const ft_string &path) { 57 | int err = 0; 58 | if (this_dir != NULL) 59 | err = EISCONN; 60 | else if ((this_dir = ::opendir(path.c_str())) == NULL) 61 | err = errno; 62 | else { 63 | this_path = path; 64 | return err; 65 | } 66 | return ff_log(FC_ERROR, err, "failed to open directory `%s'", path.c_str()); 67 | } 68 | 69 | /** close the currently open directory */ 70 | int ft_io_posix_dir::close() { 71 | if (this_dir != NULL) { 72 | if (closedir(this_dir) != 0) 73 | return ff_log(FC_ERROR, errno, "failed to close directory `%s'", this_path.c_str()); 74 | this_dir = NULL; 75 | } 76 | this_path.clear(); 77 | return 0; 78 | } 79 | 80 | /** 81 | * get next directory entry. 82 | * returns 0 if success (NULL result indicates EOF), 83 | * else returns error code 84 | */ 85 | int ft_io_posix_dir::next(ft_io_posix_dirent *&result) { 86 | int err; 87 | if (this_dir == NULL) 88 | err = ENOTCONN; 89 | else { 90 | errno = 0; 91 | result = readdir(this_dir); 92 | if ((err = errno) == 0) // 0 for success or end-of-dir 93 | return err; 94 | } 95 | return ff_log(FC_ERROR, err, "failed to read directory `%s'", this_path.c_str()); 96 | } 97 | 98 | FT_IO_NAMESPACE_END 99 | -------------------------------------------------------------------------------- /fsremap/src/io/io_posix_dir.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/io_posix_dir.hh 21 | * 22 | * Created on: Sep 22, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_IO_IO_POSIX_DIR_HH 27 | #define FSTRANSFORM_IO_IO_POSIX_DIR_HH 28 | 29 | #include "../types.hh" // for ft_string, ft_inode 30 | 31 | #ifdef FT_HAVE_DIRENT_H 32 | #include // for DIR, DT_UNKNOWN 33 | #endif 34 | 35 | FT_IO_NAMESPACE_BEGIN 36 | 37 | typedef struct dirent ft_io_posix_dirent; 38 | 39 | class ft_io_posix_dir { 40 | private: 41 | ft_string this_path; 42 | DIR *this_dir; 43 | 44 | /** cannot call copy constructor */ 45 | ft_io_posix_dir(const ft_io_posix_dir &); 46 | 47 | /** cannot call assignment operator */ 48 | const ft_io_posix_dir &operator=(const ft_io_posix_dir &); 49 | 50 | public: 51 | /** default constructor */ 52 | ft_io_posix_dir(); 53 | 54 | /** destructor, calls close() */ 55 | ~ft_io_posix_dir(); 56 | 57 | /** open a directory */ 58 | int open(const ft_string &path); 59 | 60 | FT_INLINE bool is_open() const { 61 | return this_dir != NULL; 62 | }; 63 | 64 | FT_INLINE DIR *dir() { 65 | return this_dir; 66 | } 67 | FT_INLINE const ft_string &path() const { 68 | return this_path; 69 | } 70 | 71 | /** 72 | * get next directory entry. 73 | * returns 0 if success (NULL result indicates EOF), 74 | * else returns error code 75 | */ 76 | int next(ft_io_posix_dirent *&result); 77 | 78 | /** close the currently open directory */ 79 | int close(); 80 | }; 81 | 82 | FT_IO_NAMESPACE_END 83 | 84 | #endif /* FSTRANSFORM_IO_IO_POSIX_DIR_HH */ 85 | -------------------------------------------------------------------------------- /fsremap/src/io/io_self_test.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/io_self_test.hh 21 | * 22 | * Created on: Feb 23, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_IO_IO_SELF_TEST_HH 27 | #define FSREMAP_IO_IO_SELF_TEST_HH 28 | 29 | #include "../types.hh" // for ft_uoff, ft_ull 30 | 31 | #include "io_null.hh" // for ft_io_null 32 | 33 | 34 | FT_IO_NAMESPACE_BEGIN 35 | 36 | /** 37 | * self-test class: 38 | * reports random LOOP-FILE and ZERO-FILE extents and emulates I/O 39 | */ 40 | class fr_io_self_test: public ft_io_null 41 | { 42 | private: 43 | typedef ft_io_null super_type; 44 | 45 | ft_ull this_block_size_log2; 46 | 47 | /** fill ret_extents with random (but consistent) extents. extents will stop at 'length' bytes */ 48 | void invent_extents(fr_map & ret_extents, ft_uoff length, ft_uoff & ret_block_size_bitmask) const; 49 | 50 | protected: 51 | 52 | /** 53 | * retrieve LOOP-FILE extents and FREE-SPACE extents and insert them into 54 | * the vectors loop_file_extents and free_space_extents. 55 | * the vectors will be ordered by extent ->logical. 56 | * 57 | * return 0 for success, else error (and vectors contents will be UNDEFINED). 58 | * 59 | * if success, also returns in ret_effective_block_size_log2 the log2() 60 | * of device effective block size. 61 | * 62 | * implementation: fill loop_file_extents and free_space_extents 63 | * with random (but consistent) data. 64 | */ 65 | virtual int read_extents(fr_vector & loop_file_extents, 66 | fr_vector & free_space_extents, 67 | fr_vector & to_zero_extents, 68 | ft_uoff & ret_block_size_bitmask); 69 | 70 | public: 71 | /** constructor */ 72 | fr_io_self_test(fr_persist & persist); 73 | 74 | /** destructor. calls close() */ 75 | virtual ~fr_io_self_test(); 76 | 77 | /** check for consistency and prepare for read_extents() */ 78 | virtual int open(const fr_args & args); 79 | 80 | /** return true if this fr_io_posix is currently (and correctly) open */ 81 | virtual bool is_open() const; 82 | 83 | /** close this I/O, including file descriptors to DEVICE, LOOP-FILE and ZERO-FILE */ 84 | virtual void close(); 85 | 86 | /** close any resource associated to LOOP-FILE and ZERO-FILE extents */ 87 | virtual void close_extents(); 88 | }; 89 | 90 | FT_IO_NAMESPACE_END 91 | 92 | #endif /* FSREMAP_IO_IO_SELF_TEST_HH */ 93 | -------------------------------------------------------------------------------- /fsremap/src/io/io_test.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/io_test.hh 21 | * 22 | * Created on: Feb 28, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_IO_IO_TEST_HH 27 | #define FSREMAP_IO_IO_TEST_HH 28 | 29 | #include "../types.hh" // for ft_uoff, ft_size 30 | 31 | #if defined(FT_HAVE_STDIO_H) 32 | # include // for FILE. also for fopen(), fclose() used in io_test.cc 33 | #elif defined(FT_HAVE_CSTDIO) 34 | # include // for FILE. also for fopen(), fclose() used in io_test.cc 35 | #endif 36 | 37 | #include "io_null.hh" // for ft_io_null 38 | 39 | 40 | FT_IO_NAMESPACE_BEGIN 41 | 42 | /** 43 | * "test" class emulating I/O. 44 | * actually loads extents definition from persistence files 45 | */ 46 | class fr_io_test: public ft_io_null 47 | { 48 | private: 49 | typedef ft_io_null super_type; 50 | 51 | FILE * this_f[FC_EXTENTS_FILE_COUNT]; 52 | 53 | protected: 54 | 55 | /** return true if this I/O has open descriptors/streams to LOOP-FILE and FREE-SPACE */ 56 | bool is_open_extents() const; 57 | 58 | /** close a single descriptor/stream */ 59 | void close0(ft_size which); 60 | 61 | /** 62 | * retrieve LOOP-FILE extents, FREE-SPACE extents and any additional extents to be ZEROED 63 | * and insert them into the vectors loop_file_extents, free_space_extents and to_zero_extents 64 | * the vectors will be ordered by extent ->logical (for to_zero_extents, ->physical and ->logical will be the same). 65 | * 66 | * return 0 for success, else error (and vectors contents will be UNDEFINED). 67 | * 68 | * if success, also returns in ret_effective_block_size_log2 the log2() 69 | * of device effective block size. 70 | * the device effective block size is defined as follows: 71 | * it is the largest power of 2 that exactly divides all physical, 72 | * logical and lengths in all returned extents (both for LOOP-FILE 73 | * and for FREE-SPACE) and that also exactly exactly divides device length. 74 | * 75 | * this implementation simply reads extents from persistence files. 76 | */ 77 | virtual int read_extents(fr_vector & loop_file_extents, 78 | fr_vector & free_space_extents, 79 | fr_vector & to_zero_extents, 80 | ft_uoff & ret_block_size_bitmask); 81 | 82 | public: 83 | /** constructor */ 84 | fr_io_test(fr_persist & persist); 85 | 86 | /** destructor. calls close() */ 87 | virtual ~fr_io_test(); 88 | 89 | /** check for consistency and load LOOP-FILE and ZERO-FILE extents list from files */ 90 | virtual int open(const fr_args & args); 91 | 92 | /** return true if this fr_io_posix is currently (and correctly) open */ 93 | virtual bool is_open() const; 94 | 95 | /** close this I/O, including file descriptors to DEVICE, LOOP-FILE and ZERO-FILE */ 96 | virtual void close(); 97 | 98 | /** 99 | * close the file descriptors for LOOP-FILE and ZERO-FILE 100 | */ 101 | virtual void close_extents(); 102 | }; 103 | 104 | FT_IO_NAMESPACE_END 105 | 106 | #endif /* FSREMAP_IO_IO_TEST_HH */ 107 | -------------------------------------------------------------------------------- /fsremap/src/io/persist.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/persist.hh 21 | * 22 | * Created on: Mar 6, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_PERSIST_HH 27 | #define FSREMAP_PERSIST_HH 28 | 29 | #include "../job.hh" // for fr_job 30 | 31 | #if defined(FT_HAVE_STDIO_H) 32 | # include // for FILE. also for fopen(), fclose(), fprintf() and fscanf() used in persist.cc 33 | #elif defined(FT_HAVE_CSTDIO) 34 | # include // for FILE. also for fopen(), fclose(), fprintf() and fscanf() used in persist.cc 35 | #endif 36 | 37 | FT_IO_NAMESPACE_BEGIN 38 | 39 | class fr_persist 40 | { 41 | private: 42 | ft_ull this_progress1, this_progress2; 43 | ft_string this_persist_path; 44 | 45 | FILE * this_persist_file; 46 | 47 | fr_job & this_job; 48 | 49 | /** true while replaying persistence */ 50 | bool this_replaying; 51 | 52 | /** cannot call copy constructor */ 53 | fr_persist(const fr_persist &); 54 | 55 | /** cannot call assignment operator */ 56 | const fr_persist & operator=(const fr_persist &); 57 | 58 | /** try to read data from persistence fle */ 59 | int do_read(ft_ull & progress1, ft_ull & progress2); 60 | 61 | /** try to write data into persistence fle */ 62 | int do_write(ft_ull progress1, ft_ull progress2); 63 | 64 | /** flush this_persist_file to disk: calls fflush() then fdatasync() or fsync() */ 65 | int do_flush(); 66 | 67 | public: 68 | /** constructor */ 69 | fr_persist(fr_job & job); 70 | 71 | /** return job */ 72 | FT_INLINE fr_job & job() { return this_job; } 73 | 74 | /** create and open persistence file job.job_dir() + "/fsremap.persist" */ 75 | int open(); 76 | 77 | /** return true if replaying persistence file */ 78 | FT_INLINE bool is_replaying() const { return this_replaying; } 79 | 80 | /** 81 | * get exact primary/secondary storage sizes. 82 | * also verify that sizes in persistence file (if present) match ones from command line (if specified). 83 | * if no exact sizes are available, sets them to 0. 84 | */ 85 | int get_storage_sizes_exact(ft_size & primary_size_exact, ft_size & secondary_size_exact); 86 | 87 | /** set exact primary/secondary storage sizes. */ 88 | int set_storage_sizes_exact(ft_size primary_size_exact, ft_size secondary_size_exact); 89 | 90 | /** read a step from persistence fle */ 91 | int read(ft_ull & progress1, ft_ull & progress2); 92 | 93 | /** read or write a step in persistence file */ 94 | int next(ft_ull progress1, ft_ull progress2); 95 | 96 | /** close persistence file */ 97 | int close(); 98 | 99 | /** destructor */ 100 | ~fr_persist(); 101 | }; 102 | 103 | 104 | FT_IO_NAMESPACE_END 105 | 106 | #endif /* FSREMAP_PERSIST_HH */ 107 | -------------------------------------------------------------------------------- /fsremap/src/io/request.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/request.hh 21 | * 22 | * Created on: Mar 15, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_IO_REQUEST_HH 27 | #define FSREMAP_IO_REQUEST_HH 28 | 29 | #include "../types.hh" // for ft_uoff 30 | #include "../extent.hh" // for fr_dir 31 | 32 | 33 | FT_IO_NAMESPACE_BEGIN 34 | 35 | /** 36 | * simple class containing details of an I/O request. 37 | * 38 | * class invariant: ff_can_sum(ff_max2(this_from, this_to), this_length) 39 | */ 40 | class ft_request { 41 | private: 42 | ft_uoff this_from; 43 | ft_uoff this_to; 44 | ft_uoff this_length; 45 | fr_dir this_dir; 46 | 47 | public: 48 | /** construct a request with no pending copies */ 49 | ft_request(); 50 | 51 | /** construct a request with specified values */ 52 | ft_request(ft_uoff from, ft_uoff to, ft_uoff length, fr_dir dir); 53 | 54 | /** compiler-generated copy constructor is ok */ 55 | // ft_request(const ft_request &); 56 | 57 | /** compiler-generated assignment operator is ok */ 58 | // const ft_request & operator=(const ft_request &); 59 | 60 | /** compiler-generated destructor is ok */ 61 | // ~ft_request(); 62 | 63 | 64 | /** forget and discard any requested copy */ 65 | void clear(); 66 | 67 | FT_INLINE ft_uoff from() const { return this_from; } 68 | FT_INLINE ft_uoff to() const { return this_to; } 69 | FT_INLINE ft_uoff length() const { return this_length; } 70 | FT_INLINE fr_dir dir() const { return this_dir; } 71 | FT_INLINE bool empty() const { return this_length == 0; } 72 | 73 | FT_INLINE bool is_from_dev() const { return ff_is_from_dev(this_dir); } 74 | FT_INLINE bool is_to_dev() const { return ff_is_to_dev(this_dir); } 75 | 76 | const char * label_from() const; 77 | const char * label_to() const; 78 | 79 | /** 80 | * forget any requested copy and set this request to specified values. 81 | * returns EOVERFLOW if max(from,to)+length overflows ft_uoff 82 | */ 83 | int assign(ft_uoff from, ft_uoff to, ft_uoff length, fr_dir dir); 84 | 85 | /** 86 | * coalesce this request with specified values, or return error if they cannot be coalesced. 87 | * possible errors: 88 | * ENOTDIR the two requests are not in the same direction 89 | * EINVAL the two requests are not consecutive, or coalescing them would overflow 90 | */ 91 | int coalesce(ft_uoff from, ft_uoff to, ft_uoff length, fr_dir dir); 92 | 93 | /** 94 | * remove 'length' bytes from the beginning of this request 95 | */ 96 | int remove_front(ft_uoff length); 97 | }; 98 | 99 | FT_IO_NAMESPACE_END 100 | 101 | #endif /* FSREMAP_IO_REQUEST_HH */ 102 | -------------------------------------------------------------------------------- /fsremap/src/io/util_dir.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/util.cc 21 | * 22 | * Created on: Mar 6, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "../first.hh" 27 | 28 | #include "../types.hh" // for ft_mode 29 | #include "../log.hh" // for ff_log 30 | 31 | #if defined(FT_HAVE_STRING_H) 32 | # include // for memchr() 33 | #elif defined(FT_HAVE_CSTRING) 34 | # include // for memchr() 35 | #endif 36 | 37 | #if defined(FT_HAVE_ERRNO_H) 38 | # include // for errno 39 | #elif defined(FT_HAVE_CERRNO) 40 | # include // for errno 41 | #endif 42 | 43 | #ifdef FT_HAVE_SYS_STAT_H 44 | # include // for mkdir() 45 | #endif 46 | #ifdef FT_HAVE_SYS_TYPES_H 47 | # include // for mkdir() 48 | #endif 49 | 50 | 51 | 52 | 53 | FT_IO_NAMESPACE_BEGIN 54 | 55 | 56 | /** 57 | * create a directory, return 0 (success) or error. 58 | * note: path MUST NOT end with '/' 59 | */ 60 | int ff_mkdir(const char * path, ft_mode mode) 61 | { 62 | #ifdef __USE_POSIX 63 | int err = mkdir(path, mode); 64 | return err != 0 ? errno : 0; 65 | #else 66 | return ENOSYS; 67 | #endif 68 | } 69 | 70 | int ff_mkdir_or_warn(const char * path, ft_mode mode) 71 | { 72 | int err = ff_mkdir(path, mode); 73 | if (err != 0 && err != EEXIST) 74 | err = ff_log(FC_WARN, err, "failed to create directory `%s'", path); 75 | return err; 76 | } 77 | 78 | int ff_mkdir_recursive(const ft_string & path) 79 | { 80 | ft_string partial; 81 | size_t len = path.length(); 82 | const char * start = path.c_str(), * slash, * prev = start, * end = start + len; 83 | int err = 0; 84 | partial.reserve(len); 85 | while ((slash = (const char *)memchr(prev, '/', end - prev)) != NULL) 86 | { 87 | // if path starts with "/", try to create "/", NOT the unnamed directory "" 88 | partial.assign(start, slash == start ? 1 : slash - start); 89 | err = ff_mkdir_or_warn(partial.c_str(), 0700); 90 | if (err != 0 && err != EEXIST) 91 | return err; 92 | 93 | prev = slash + 1; 94 | } 95 | // if path does not end with "/", create the last segment 96 | if (len != 0 && prev != end) 97 | err = ff_mkdir_or_warn(path.c_str(), 0700); 98 | return err; 99 | } 100 | 101 | int ff_remove_recursive(const ft_string & FT_ARG_UNUSED(path)) 102 | { 103 | return ENOSYS; 104 | } 105 | 106 | 107 | FT_IO_NAMESPACE_END 108 | -------------------------------------------------------------------------------- /fsremap/src/io/util_dir.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/util.hh 21 | * 22 | * Created on: Mar 6, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_UTIL_DIR_HH 27 | #define FSREMAP_UTIL_DIR_HH 28 | 29 | #include "../types.hh" 30 | 31 | FT_IO_NAMESPACE_BEGIN 32 | 33 | /** 34 | * create a directory, return 0 (success) or error. 35 | * note: path MUST NOT end with '/' 36 | * 37 | * depending on the caller expectations whether the directory 38 | * can already exist or not, error==EEXIST may also indicate success 39 | */ 40 | int ff_mkdir(const char * path, ft_mode mode = 0755); 41 | 42 | /** 43 | * same as ff_mkdir(), plus calls ff_log(WARN) on errors. 44 | * if error==EEXIST, it is returned but not logged. 45 | */ 46 | int ff_mkdir_or_warn(const char * path, ft_mode mode = 0755); 47 | 48 | /** 49 | * create a directory, return 0 (success) or error. 50 | * 51 | * depending on the caller expectations whether the directory 52 | * can already exist or not, error==EEXIST may also indicate success 53 | */ 54 | int ff_mkdir_recursive(const ft_string & path); 55 | 56 | int ff_remove_recursive(const ft_string & path); 57 | 58 | FT_IO_NAMESPACE_END 59 | 60 | #endif /* FSREMAP_UTIL_DIR_HH */ 61 | -------------------------------------------------------------------------------- /fsremap/src/io/util_posix.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * io/util_posix.hh 21 | * 22 | * Created on: Feb 24, 2011 23 | * Author: max 24 | */ 25 | #ifndef FSREMAP_IO_POSIX_UTIL_HH 26 | #define FSREMAP_IO_POSIX_UTIL_HH 27 | 28 | #include "../types.hh" // for ft_uoff, ft_stat, ft_dev, ft_mode */ 29 | 30 | FT_IO_NAMESPACE_BEGIN 31 | 32 | /** invoke ioctl() */ 33 | int ff_posix_ioctl(int fd, int request, void * arg); 34 | 35 | /** return file stats in (*ret_stat) */ 36 | int ff_posix_stat(int fd, ft_stat * ret_stat); 37 | 38 | /** return file stats in (*ret_stat) */ 39 | int ff_posix_stat(const char * path, ft_stat * ret_stat); 40 | 41 | /** return file size in (*ret_size) */ 42 | int ff_posix_size(int fd, ft_uoff * ret_size); 43 | 44 | /** return block size of file-system containing file */ 45 | int ff_posix_blocksize(int fd, ft_uoff * ret_block_size); 46 | 47 | /** return ID of device containing file in (*ret_dev) */ 48 | int ff_posix_dev(int fd, ft_dev * ret_dev); 49 | 50 | /** if file is special block device, return its device ID in (*ret_dev) */ 51 | int ff_posix_blkdev_dev(int fd, ft_dev * ret_dev); 52 | 53 | /** if file is special block device, return its length in (*ret_dev) */ 54 | int ff_posix_blkdev_size(int fd, ft_uoff * ret_size); 55 | 56 | 57 | /** 58 | * seek file descriptor to specified position from file beginning. 59 | * note: if an error is returned, file descriptor position will be undefined! 60 | */ 61 | int ff_posix_lseek(int fd, ft_uoff pos); 62 | 63 | /** 64 | * read from a file descriptor. 65 | * keep retrying in case of EINTR or short reads. 66 | * on return, ret_length will be increased by the number of bytes actually read 67 | */ 68 | int ff_posix_read(int fd, void * mem, ft_uoff length); 69 | 70 | /** 71 | * write to a file descriptor. 72 | * keep retrying in case of EINTR or short writes. 73 | * on return, ret_length will be increased by the number of bytes actually written 74 | */ 75 | int ff_posix_write(int fd, const void * mem, ft_uoff length); 76 | 77 | /** 78 | * preallocate and fill with zeroes 'length' bytes on disk for a file descriptor. 79 | * uses fallocate() if available, else posix_fallocate(), else plain write() loop. 80 | */ 81 | int ff_posix_fallocate(int fd, ft_off length, const ft_string & err_msg); 82 | 83 | /** 84 | * spawn a system command, wait for it to complete and return its exit status. 85 | * argv[0] is conventionally the program name. 86 | * argv[1...] are program arguments and must be terminated with a NULL pointer. 87 | */ 88 | int ff_posix_exec(const char * path, const char * const argv[]); 89 | 90 | FT_IO_NAMESPACE_END 91 | 92 | 93 | #endif /* FSREMAP_IO_POSIX_UTIL_HH */ 94 | -------------------------------------------------------------------------------- /fsremap/src/map.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * map.cc 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" // for FT_*TEMPLATE* macros */ 27 | 28 | #ifdef FT_HAVE_EXTERN_TEMPLATE 29 | # include "map.t.hh" 30 | FT_TEMPLATE_INSTANTIATE(FT_TEMPLATE_map_hh) 31 | #endif /* FT_HAVE_EXTERN_TEMPLATE */ 32 | -------------------------------------------------------------------------------- /fsremap/src/map_stat.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * map_stat.cc 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" // for FT_*TEMPLATE* macros */ 27 | 28 | #ifdef FT_HAVE_EXTERN_TEMPLATE 29 | # include "map_stat.t.hh" 30 | FT_TEMPLATE_INSTANTIATE(FT_TEMPLATE_map_stat_hh) 31 | #endif /* FT_HAVE_EXTERN_TEMPLATE */ 32 | -------------------------------------------------------------------------------- /fsremap/src/map_stat.t.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * map_stat.t.hh 21 | * 22 | * Created on: Mar 12, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #include "map_stat.hh" // for fr_map_stat 29 | 30 | FT_NAMESPACE_BEGIN 31 | 32 | // construct empty fr_map_stat 33 | template 34 | fr_map_stat::fr_map_stat() 35 | : super_type(), this_total_count(0), this_used_count(0) 36 | { } 37 | 38 | // destroy fr_map_stat 39 | template 40 | fr_map_stat::~fr_map_stat() 41 | { } 42 | 43 | 44 | 45 | // duplicate a fr_map_stat, i.e. initialize this fr_map_stat as a copy of other. 46 | template 47 | fr_map_stat::fr_map_stat(const fr_map & other) 48 | : super_type(other), this_total_count(0), this_used_count(0) 49 | { } 50 | 51 | // duplicate a fr_map_stat, i.e. initialize this fr_map_stat as a copy of other. 52 | template 53 | fr_map_stat::fr_map_stat(const fr_map_stat & other) 54 | : super_type(other), this_total_count(other.this_total_count), this_used_count(other.this_used_count) 55 | { } 56 | 57 | 58 | 59 | 60 | // copy fr_map_stat, i.e. set this fr_map_stat contents as a copy of other's contents. 61 | template 62 | const fr_map_stat & fr_map_stat::operator=(const fr_map & other) 63 | { 64 | super_type::operator=(other); 65 | this_total_count = this_used_count = 0; 66 | return * this; 67 | } 68 | 69 | // copy fr_map_stat, i.e. set this fr_map_stat contents as a copy of other's contents. 70 | template 71 | const fr_map_stat & fr_map_stat::operator=(const fr_map_stat & other) 72 | { 73 | super_type::operator=(other); 74 | this_total_count = other.this_total_count; 75 | this_used_count = other.this_used_count; 76 | return * this; 77 | } 78 | 79 | 80 | /** clear this fr_map_stat. also sets total_count, used_count and free_count to zero */ 81 | template 82 | void fr_map_stat::clear() 83 | { 84 | super_type::clear(); 85 | this_total_count = this_used_count = 0; 86 | } 87 | 88 | FT_NAMESPACE_END 89 | -------------------------------------------------------------------------------- /fsremap/src/mstring.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * mstring.hh 21 | * 22 | * Created on: Apr 25, 2012 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #include "misc.hh" // for ft_min2() 29 | #include "mstring.hh" // for ft_mstring 30 | 31 | #if defined(FT_HAVE_STRING_H) 32 | # include // for memcmp(), memcpy(), memrchr() 33 | #elif defined(FT_HAVE_CSTRING) 34 | # include // for memcmp(), memcpy(), memrchr() 35 | #endif 36 | 37 | FT_NAMESPACE_BEGIN 38 | 39 | /** default constructor. */ 40 | ft_mstring::ft_mstring() 41 | : txt(NULL), len(0) 42 | { } 43 | 44 | /** copy constructor. */ 45 | ft_mstring::ft_mstring(const ft_mstring & other) 46 | : txt(other.txt), len(other.len) 47 | { } 48 | 49 | 50 | /** constructor. shares the char array inside 'other', does not copy it */ 51 | ft_mstring::ft_mstring(const ft_mstring & other, ft_size offset, ft_size length) 52 | : txt(other.txt + ff_min2(offset, other.len)), 53 | len(other.len <= offset ? 0 : ff_min2(length, other.len - offset)) 54 | { } 55 | 56 | /** constructor. shares the char array 'str', does not copy it */ 57 | ft_mstring::ft_mstring(const char * str, ft_size str_len) 58 | : txt(str), len(str_len) 59 | { } 60 | 61 | 62 | /** assignment operator */ 63 | const ft_mstring & ft_mstring::operator=(const ft_mstring & other) 64 | { 65 | // ok also if this == & other 66 | txt = other.txt; 67 | len = other.len; 68 | 69 | return * this; 70 | } 71 | 72 | // comparison operator 73 | bool ft_mstring::operator==(const ft_mstring & other) const 74 | { 75 | if (len != other.len) 76 | return false; 77 | if (txt == other.txt) 78 | // also catches this == & other 79 | return true; 80 | return memcmp(txt, other.txt, len) == 0; 81 | } 82 | 83 | // comparison operator 84 | bool ft_mstring::operator<(const ft_mstring & other) const 85 | { 86 | if (len != 0 && other.len != 0 && txt != other.txt) 87 | { 88 | int cmp = memcmp(txt, other.txt, ff_min2(len, other.len)); 89 | if (cmp != 0) 90 | // different contents 91 | return cmp < 0; 92 | } 93 | // at least one empty string, or same contents in the common prefix. 94 | // also catches this == & other 95 | return len < other.len; 96 | } 97 | 98 | 99 | 100 | ft_size ft_mstring::rfind(char ch) const 101 | { 102 | if (len != 0) { 103 | const char * match = (const char *) memrchr(txt, (unsigned char) ch, len); 104 | if (match != NULL) 105 | return match - txt; 106 | } 107 | return npos; 108 | } 109 | 110 | FT_NAMESPACE_END 111 | -------------------------------------------------------------------------------- /fsremap/src/mstring.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * mstring.hh 21 | * 22 | * Created on: Apr 25, 2012 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_MSTRING_HH 27 | #define FSTRANSFORM_MSTRING_HH 28 | 29 | #include "types.hh" // for ft_size 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | /** 34 | * immutable string. initialized with a const char *, 35 | * keeps a reference to the char array instead of copying its contents 36 | */ 37 | class ft_mstring 38 | { 39 | private: 40 | const char * txt; 41 | ft_size len; 42 | 43 | public: 44 | enum { npos = (ft_size)-1 }; 45 | 46 | /** default constructor. */ 47 | ft_mstring(); 48 | 49 | /** copy constructor. */ 50 | ft_mstring(const ft_mstring & other); 51 | 52 | /** constructor. shares the char array inside 'other', does not copy it */ 53 | ft_mstring(const ft_mstring & other, ft_size offset, ft_size length); 54 | 55 | /** constructor. shares the char array 'str', does not copy it */ 56 | ft_mstring(const char * str, ft_size str_len); 57 | 58 | /** constructor. shares the char array 'str', does not copy it */ 59 | template 60 | ft_mstring(const char (& str)[N]) 61 | : txt(str), len(N-1) 62 | { } 63 | 64 | /** assignment operator */ 65 | const ft_mstring & operator=(const ft_mstring & other); 66 | 67 | /** destructor. */ 68 | FT_INLINE ~ft_mstring() 69 | { } 70 | 71 | FT_INLINE const char & operator[](ft_size i) const { return txt[i]; } 72 | FT_INLINE ft_size size() const { return len; } 73 | 74 | // comparison operators 75 | bool operator==(const ft_mstring & other) const; 76 | FT_INLINE bool operator!=(const ft_mstring & other) const { return !(*this == other); } 77 | 78 | // comparison operators 79 | bool operator<(const ft_mstring & other) const; 80 | FT_INLINE bool operator<=(const ft_mstring & other) const { return !(other < *this); } 81 | FT_INLINE bool operator> (const ft_mstring & other) const { return other < *this; } 82 | FT_INLINE bool operator>=(const ft_mstring & other) const { return !(*this < other); } 83 | 84 | 85 | ft_size rfind(char ch) const; 86 | }; 87 | 88 | FT_NAMESPACE_END 89 | 90 | #endif /* FSTRANSFORM_MSTRING_HH */ 91 | -------------------------------------------------------------------------------- /fsremap/src/pool.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * pool.cc 21 | * 22 | * Created on: Mar 8, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" // for FT_*TEMPLATE* macros */ 27 | 28 | #include "types.hh" // for ft_uint, ft_uoff 29 | 30 | #ifdef FT_HAVE_EXTERN_TEMPLATE 31 | # include "pool.t.hh" 32 | FT_TEMPLATE_INSTANTIATE(FT_TEMPLATE_pool_hh) 33 | #endif /* FT_HAVE_EXTERN_TEMPLATE */ 34 | -------------------------------------------------------------------------------- /fsremap/src/traits.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * traits.hh 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_TRAITS_HH 27 | #define FSTRANSFORM_TRAITS_HH 28 | 29 | #include "check.hh" 30 | 31 | FT_NAMESPACE_BEGIN 32 | 33 | template struct ft_type_traits; 34 | /** 35 | * whether char is signed or unsigned is implementation dependent. 36 | * in any case, the compiler treats (char), (unsigned char) and (signed char) as different types 37 | */ 38 | template<> struct ft_type_traits { typedef unsigned char unsigned_type; typedef signed char signed_type; }; 39 | template<> struct ft_type_traits { typedef unsigned char unsigned_type; typedef signed char signed_type; }; 40 | template<> struct ft_type_traits { typedef unsigned char unsigned_type; typedef signed char signed_type; }; 41 | template<> struct ft_type_traits { typedef unsigned short unsigned_type; typedef short signed_type; }; 42 | template<> struct ft_type_traits { typedef unsigned short unsigned_type; typedef short signed_type; }; 43 | template<> struct ft_type_traits { typedef unsigned int unsigned_type; typedef int signed_type; }; 44 | template<> struct ft_type_traits { typedef unsigned int unsigned_type; typedef int signed_type; }; 45 | template<> struct ft_type_traits { typedef unsigned long unsigned_type; typedef long signed_type; }; 46 | template<> struct ft_type_traits { typedef unsigned long unsigned_type; typedef long signed_type; }; 47 | 48 | #ifdef FT_HAVE_LONG_LONG 49 | template<> struct ft_type_traits { typedef unsigned long long unsigned_type; typedef long long signed_type; }; 50 | template<> struct ft_type_traits { typedef unsigned long long unsigned_type; typedef long long signed_type; }; 51 | #endif /* FT_HAVE_LONG_LONG */ 52 | 53 | #define FT_TYPE_TO_UNSIGNED(T) FT_NS ft_type_traits< T >::unsigned_type 54 | #define FT_TYPE_TO_SIGNED(T) FT_NS ft_type_traits< T >::signed_type 55 | 56 | FT_NAMESPACE_END 57 | 58 | #endif /* FSTRANSFORM_TRAITS_HH */ 59 | -------------------------------------------------------------------------------- /fsremap/src/ui/ui.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * ui/ui.cc 21 | * 22 | * Created on: Mar 23, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "../first.hh" 27 | 28 | #include "ui.hh" 29 | 30 | FT_UI_NAMESPACE_BEGIN 31 | 32 | /** default constructor */ 33 | fr_ui::fr_ui() 34 | { } 35 | 36 | 37 | /** destructor */ 38 | fr_ui::~fr_ui() 39 | { } 40 | 41 | 42 | FT_UI_NAMESPACE_END 43 | -------------------------------------------------------------------------------- /fsremap/src/ui/ui.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * ui/ui.hh 21 | * 22 | * Created on: Mar 23, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_UI_UI_HH 27 | #define FSREMAP_UI_UI_HH 28 | 29 | #include "../types.hh" // for ft_uoff 30 | #include "../fwd.hh" // for fr_vector forward declaration 31 | #include "../extent.hh" // for fr_dir 32 | 33 | FT_UI_NAMESPACE_BEGIN 34 | 35 | class fr_ui 36 | { 37 | private: 38 | /** cannot call copy constructor */ 39 | fr_ui(const fr_ui &); 40 | 41 | /** cannot call assignment operator */ 42 | const fr_ui & operator=(const fr_ui &); 43 | 44 | protected: 45 | /** default constructor */ 46 | fr_ui(); 47 | 48 | public: 49 | /** destructor */ 50 | virtual ~fr_ui(); 51 | 52 | virtual int start(FT_IO_NS fr_io * io) = 0; 53 | 54 | virtual void show_io_read(fr_from from, ft_uoff offset, ft_uoff length) = 0; 55 | 56 | virtual void show_io_write(fr_to to, ft_uoff offset, ft_uoff length) = 0; 57 | 58 | virtual void show_io_copy(fr_dir dir, ft_uoff from_physical, ft_uoff to_physical, ft_uoff length) = 0; 59 | 60 | virtual void show_io_flush() = 0; 61 | }; 62 | 63 | 64 | FT_UI_NAMESPACE_END 65 | 66 | #endif /* FSREMAP_UI_TTY_HH */ 67 | -------------------------------------------------------------------------------- /fsremap/src/ui/ui_tty.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * gui/tty.hh 21 | * 22 | * Created on: Mar 23, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSREMAP_UI_UI_TTY_HH 27 | #define FSREMAP_UI_UI_TTY_HH 28 | 29 | #if defined (FT_HAVE_STDIO_H) 30 | # include // for FILE. also for fdopen() used in ui_tty.cc 31 | #elif defined(FT_HAVE_CSTDIO) 32 | # include // for FILE. also for fdopen() used in ui_tty.cc 33 | #endif 34 | 35 | #include "../fwd.hh" // for fr_io 36 | #include "../types.hh" // for ft_uint, ft_uoff 37 | #include "ui.hh" // for fr_ui 38 | 39 | FT_UI_NAMESPACE_BEGIN 40 | 41 | class fr_ui_tty : public fr_ui 42 | { 43 | private: 44 | typedef fr_ui super_type; 45 | 46 | struct fr_tty_window { 47 | ft_uoff len; 48 | ft_uint h0, h; 49 | 50 | fr_tty_window(); 51 | }; 52 | fr_tty_window this_dev, this_storage; 53 | ft_uint this_w, this_h; /*< tty width and height */ 54 | FILE * this_file; 55 | bool need_clr; 56 | 57 | /** cannot call copy constructor */ 58 | fr_ui_tty(const fr_ui_tty &); 59 | 60 | /** cannot call assignment operator */ 61 | const fr_ui_tty & operator=(const fr_ui_tty &); 62 | 63 | void show_io_op(bool is_write, const fr_tty_window & window, ft_uoff offset, ft_uoff length); 64 | 65 | public: 66 | /** default constructor */ 67 | fr_ui_tty(); 68 | 69 | /** destructor */ 70 | virtual ~fr_ui_tty(); 71 | 72 | int init(const char * tty_name); 73 | 74 | virtual int start(FT_IO_NS fr_io * io); 75 | 76 | virtual void show_io_read(fr_from from, ft_uoff offset, ft_uoff length); 77 | 78 | virtual void show_io_write(fr_to to, ft_uoff offset, ft_uoff length); 79 | 80 | virtual void show_io_copy(fr_dir dir, ft_uoff from_physical, ft_uoff to_physical, ft_uoff length); 81 | 82 | virtual void show_io_flush(); 83 | }; 84 | 85 | 86 | FT_UI_NAMESPACE_END 87 | 88 | #endif /* FSREMAP_UI_UI_TTY_HH */ 89 | -------------------------------------------------------------------------------- /fsremap/src/unsorted_map.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * inode_cache.hh 21 | * 22 | * Created on: Aug 18, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" 27 | 28 | #include "copy.hh" 29 | 30 | #if defined(FT_HAVE_STDIO_H) 31 | # include /* for snprintf() */ 32 | #elif defined(FT_HAVE_CSTDIO) && defined(__cplusplus) 33 | # include /* for snprintf() */ 34 | #endif 35 | 36 | 37 | FT_NAMESPACE_BEGIN 38 | 39 | void ff_set(ft_string & dst, const ft_string & src) 40 | { 41 | dst = src; 42 | } 43 | 44 | void ff_set(ft_string & dst, ft_ull src) 45 | { 46 | enum { maxlen = sizeof(ft_ull) * 3 + 1 }; 47 | dst.resize(maxlen); 48 | char * buf = &dst[0]; 49 | 50 | int delta = snprintf(buf, maxlen, "%" FT_XLL, src); 51 | dst.resize(delta > 0 ? delta : 0); 52 | } 53 | 54 | void ff_set(ft_ull & dst, const ft_string & src) 55 | { 56 | dst = 0; 57 | sscanf(src.c_str(), "%" FT_XLL, &dst); 58 | } 59 | 60 | 61 | void ff_cat(ft_string & dst, const ft_string & src) 62 | { 63 | dst += src; 64 | } 65 | 66 | void ff_cat(ft_string & dst, ft_ull src) 67 | { 68 | enum { maxlen = sizeof(ft_ull) * 3 + 1 }; 69 | size_t oldlen = dst.length(); 70 | dst.resize(oldlen + maxlen); 71 | char * buf = &dst[oldlen]; 72 | 73 | int delta = snprintf(buf, maxlen, "%" FT_XLL, src); 74 | dst.resize(oldlen + (delta > 0 ? delta : 0)); 75 | } 76 | 77 | FT_NAMESPACE_END 78 | -------------------------------------------------------------------------------- /fsremap/src/unsorted_map.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * inode_cache.hh 21 | * 22 | * Created on: Aug 18, 2011 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_UNSORTED_MAP_HH 27 | #define FSTRANSFORM_UNSORTED_MAP_HH 28 | 29 | #include "check.hh" 30 | 31 | #if defined(FT_HAVE_STD_UNORDERED_MAP) 32 | 33 | # ifdef FT_HAVE_UNORDERED_MAP 34 | # include 35 | # endif 36 | # define ft_unsorted_map std::unordered_map 37 | 38 | #elif defined(FT_HAVE_STD_TR1_UNORDERED_MAP) 39 | 40 | # ifdef FT_HAVE_TR1_UNORDERED_MAP 41 | # include 42 | # endif 43 | # define ft_unsorted_map std::tr1::unordered_map 44 | 45 | #endif 46 | 47 | #endif /* FSTRANSFORM_UNSORTED_MAP_HH */ 48 | -------------------------------------------------------------------------------- /fsremap/src/vector.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * vector.cc 21 | * 22 | * Created on: Feb 27, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" // for FT_*TEMPLATE* macros */ 27 | 28 | #ifdef FT_HAVE_EXTERN_TEMPLATE 29 | # include "vector.t.hh" 30 | FT_TEMPLATE_INSTANTIATE(FT_TEMPLATE_vector_hh) 31 | #else 32 | #endif /* FT_HAVE_EXTERN_TEMPLATE */ 33 | -------------------------------------------------------------------------------- /fsremap/src/work.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * work.cc 21 | * 22 | * Created on: Feb 28, 2011 23 | * Author: max 24 | */ 25 | 26 | #include "first.hh" // for FT_*TEMPLATE* macros */ 27 | 28 | #ifdef FT_HAVE_EXTERN_TEMPLATE 29 | # include "work.t.hh" 30 | FT_TEMPLATE_INSTANTIATE(FT_TEMPLATE_work_hh) 31 | #endif /* FT_HAVE_EXTERN_TEMPLATE */ 32 | -------------------------------------------------------------------------------- /fstransform/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fstransform 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /fstransform/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /fstransform/build/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_SCRIPTS = fstransform 2 | 3 | fstransform: ../fstransform-sh 4 | sed 's/%PACKAGE_VERSION%/$(PACKAGE_VERSION)/g' <$< >fstransform.tmp 5 | if test -x /bin/dash ; then \ 6 | sed 's_#!/bin/bash_#!/bin/dash_g' $@ ; \ 7 | rm -f fstransform.tmp ; \ 8 | else \ 9 | mv fstransform.tmp $@ ; \ 10 | fi 11 | chmod +x $@ 12 | 13 | ../fstransform-sh: 14 | 15 | clean: clean-am 16 | rm -f fstransform fstransform.tmp 17 | -------------------------------------------------------------------------------- /fstransform/build/Makefile.am.work: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | 3 | sbin_PROGRAMS = fstransform 4 | 5 | fstransform_SOURCES = \ 6 | ../src/log.cc \ 7 | ../src/main.cc \ 8 | ../src/mstring.cc \ 9 | ../src/transform.cc 10 | -------------------------------------------------------------------------------- /fstransform/src/features.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/features.hh -------------------------------------------------------------------------------- /fstransform/src/first.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/first.hh -------------------------------------------------------------------------------- /fstransform/src/log.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.cc -------------------------------------------------------------------------------- /fstransform/src/log.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/log.hh -------------------------------------------------------------------------------- /fstransform/src/main.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - modify file-system internal data structures 3 | * 4 | * Copyright (C) 2016 Massimiliano Ghilardi 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * main.cc 20 | * Created on: Feb 29, 2016 21 | * Author: max 22 | */ 23 | #include "first.hh" 24 | #include "transform.hh" // for ft_transform 25 | 26 | #define FT_MAIN(argc, argv) FT_NS ft_transform::main(argc, argv) 27 | 28 | int main(int argc, char ** argv) { 29 | return FT_MAIN(argc, argv); 30 | } 31 | -------------------------------------------------------------------------------- /fstransform/src/mstring.cc: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.cc -------------------------------------------------------------------------------- /fstransform/src/mstring.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/mstring.hh -------------------------------------------------------------------------------- /fstransform/src/transform.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * fstransform - transform a file-system to another file-system type, 3 | * preserving its contents and without the need for a backup 4 | * 5 | * Copyright (C) 2011-2012 Massimiliano Ghilardi 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | * move.hh 21 | * 22 | * Created on: Feb 29, 2016 23 | * Author: max 24 | */ 25 | 26 | #ifndef FSTRANSFORM_TRANSFORM_HH 27 | #define FSTRANSFORM_TRANSFORM_HH 28 | 29 | FT_NAMESPACE_BEGIN 30 | 31 | /** 32 | * class doing the core of recursive move work. 33 | */ 34 | class ft_transform 35 | { 36 | private: 37 | /** true if usage() or version() was called. */ 38 | bool quit_immediately; 39 | 40 | /** cannot call copy constructor */ 41 | ft_transform(const ft_transform &); 42 | 43 | /** cannot call assignment operator */ 44 | const ft_transform & operator=(const ft_transform &); 45 | 46 | /** display command-line usage to stdout and return 0 */ 47 | int usage(const char * program_name); 48 | 49 | /** output version information and return 0 */ 50 | int version(); 51 | 52 | static int invalid_cmdline(const char * program_name, int err, const char * fmt, ...); 53 | 54 | /** return EISCONN if transformer is initialized, else call quit() and return 0 */ 55 | int check_is_closed(); 56 | 57 | /** return 0 if transformer is initialized, else call quit() and return ENOTCONN */ 58 | int check_is_open(); 59 | 60 | /** initialize transformer */ 61 | int init(); 62 | 63 | /** core of transformation algorithm */ 64 | int transform(); 65 | 66 | /** show progress status and E.T.A. */ 67 | void show_progress(); 68 | 69 | public: 70 | /** default constructor */ 71 | ft_transform(); 72 | 73 | /** destructor. calls quit() */ 74 | ~ft_transform(); 75 | 76 | /** 77 | * high-level do-everything method. calls in sequence init(), run() and quit(). 78 | * return 0 if success, else error. 79 | */ 80 | static int main(int argc, char ** argv); 81 | 82 | bool is_initialized() const; 83 | 84 | /** 85 | * parse command line and initialize all subsystems (job, I/O, log...) 86 | * return 0 if success, else error. 87 | * 88 | * implementation: parse command line, fill a ft_args and call init(const ft_args &) 89 | */ 90 | int init(int argc, char const* const* argv); 91 | 92 | /** 93 | * initialize all subsystems (log...) using specified arguments 94 | */ 95 | int init(const ft_args & args); 96 | 97 | /** 98 | * transformation algorithm entry point. calls transform() 99 | */ 100 | int run(); 101 | 102 | /** 103 | * performs cleanup. called by destructor, you can also call it explicitly after (or instead of) run(). 104 | */ 105 | void quit(); 106 | }; 107 | 108 | 109 | FT_NAMESPACE_END 110 | 111 | 112 | #endif /* FSTRANSFORM_TRANSFORM_HH */ 113 | -------------------------------------------------------------------------------- /fstransform/src/types.hh: -------------------------------------------------------------------------------- 1 | ../../fsremap/src/types.hh -------------------------------------------------------------------------------- /tools/config.guess: -------------------------------------------------------------------------------- 1 | /usr/share/automake-1.16/config.guess -------------------------------------------------------------------------------- /tools/config.sub: -------------------------------------------------------------------------------- 1 | /usr/share/automake-1.16/config.sub -------------------------------------------------------------------------------- /tools/ft_cxx_features.m4: -------------------------------------------------------------------------------- 1 | m4_define([FT_CXX_FEATURES], 2 | [ 3 | AC_CACHE_CHECK([whether $CXX supports explicit template instantiation], 4 | [ac_cv_cxx_have_template_instantiation], 5 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 6 | template 7 | class ft_my_class { 8 | public: 9 | void apply(T *); 10 | }; 11 | 12 | template 13 | void ft_my_class::apply(T * arg) 14 | { } 15 | 16 | template class ft_my_class; 17 | ]], [[ 18 | ft_my_class dummy; 19 | ]])], 20 | [ac_cv_cxx_have_template_instantiation=yes], 21 | [ac_cv_cxx_have_template_instantiation=no] 22 | ) 23 | ]) 24 | 25 | AC_CACHE_CHECK([whether $CXX supports inhibiting template instantiation], 26 | [ac_cv_cxx_have_template_inhibition], 27 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 28 | template 29 | class ft_my_class { 30 | public: 31 | void apply(T *); 32 | }; 33 | extern template class ft_my_class; 34 | ]], [[ 35 | ft_my_class dummy; 36 | ]])], 37 | [ac_cv_cxx_have_template_inhibition=yes], 38 | [ac_cv_cxx_have_template_inhibition=no] 39 | ) 40 | ]) 41 | 42 | if test "$ac_cv_cxx_have_template_instantiation" = yes -a "$ac_cv_cxx_have_template_inhibition" = yes; then 43 | AC_DEFINE([HAVE_EXTERN_TEMPLATE], [1], 44 | [define if C++ compiler supports forcing and inhibiting template instantiation]) 45 | fi 46 | ]) 47 | -------------------------------------------------------------------------------- /tools/ft_cxx_flags.m4: -------------------------------------------------------------------------------- 1 | m4_define([FT_CXX_FLAGS], 2 | [ 3 | AC_CACHE_CHECK([whether $CXX accepts -Wall], 4 | [ac_cv_cxx_flag_Wall], 5 | [save_CXXFLAGS="$CXXFLAGS" 6 | CXXFLAGS="$CXXFLAGS -Wall" 7 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 8 | ]], [[ 9 | return 0; 10 | ]])], 11 | [ac_cv_cxx_flag_Wall=yes], 12 | [ac_cv_cxx_flag_Wall=no 13 | CXXFLAGS="$save_CXXFLAGS"] 14 | ) 15 | ]) 16 | 17 | AC_CACHE_CHECK([whether $CXX accepts -Wextra], 18 | [ac_cv_cxx_flag_Wextra], 19 | [save_CXXFLAGS="$CXXFLAGS" 20 | CXXFLAGS="$CXXFLAGS -Wextra" 21 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 22 | ]], [[ 23 | return 0; 24 | ]])], 25 | [ac_cv_cxx_flag_Wextra=yes], 26 | [ac_cv_cxx_flag_Wextra=no 27 | CXXFLAGS="$save_CXXFLAGS"] 28 | ) 29 | ]) 30 | 31 | AC_CACHE_CHECK([whether $CXX accepts -W], 32 | [ac_cv_cxx_flag_W], 33 | [save_CXXFLAGS="$CXXFLAGS" 34 | CXXFLAGS="$CXXFLAGS -W" 35 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 36 | ]], [[ 37 | return 0; 38 | ]])], 39 | [ac_cv_cxx_flag_W=yes], 40 | [ac_cv_cxx_flag_W=no 41 | CXXFLAGS="$save_CXXFLAGS"] 42 | ) 43 | ]) 44 | 45 | AC_CACHE_CHECK([whether $CXX accepts -Wno-missing-field-initializers], 46 | [ac_cv_cxx_flag_Wno_missing_field_initializers], 47 | [save_CXXFLAGS="$CXXFLAGS" 48 | CXXFLAGS="$CXXFLAGS -Wno-missing-field-initializers" 49 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 50 | ]], [[ 51 | return 0; 52 | ]])], 53 | [ac_cv_cxx_flag_Wno_missing_field_initializers=yes], 54 | [ac_cv_cxx_flag_Wno_missing_field_initializers=no 55 | CXXFLAGS="$save_CXXFLAGS"] 56 | ) 57 | ]) 58 | ]) 59 | -------------------------------------------------------------------------------- /tools/ft_cxx_unordered_map.m4: -------------------------------------------------------------------------------- 1 | m4_define([FT_CXX_STD_UNORDERED_MAP], 2 | [AC_CACHE_CHECK([whether C++ library implements std::unordered_map], 3 | [ac_cv_cxx_have_std_unordered_map], 4 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 5 | #ifdef HAVE_UNORDERED_MAP 6 | #include 7 | #endif 8 | ]], [[ 9 | std::unordered_map my_map; 10 | ]])], 11 | [ac_cv_cxx_have_std_unordered_map=yes], 12 | [ac_cv_cxx_have_std_unordered_map=no])]) 13 | 14 | if test "$ac_cv_cxx_have_std_unordered_map" = yes; then 15 | AC_DEFINE([HAVE_STD_UNORDERED_MAP], [1], 16 | [define if C++ library implements std::unordered_map]) 17 | fi] 18 | ) 19 | 20 | 21 | m4_define([FT_CXX_STD_TR1_UNORDERED_MAP], 22 | [AC_CACHE_CHECK([whether C++ library implements std::tr1::unordered_map], 23 | [ac_cv_cxx_have_std_tr1_unordered_map], 24 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 25 | #ifdef HAVE_TR1_UNORDERED_MAP 26 | #include 27 | #endif 28 | ]], [[ 29 | std::tr1::unordered_map my_map; 30 | ]])], 31 | [ac_cv_cxx_have_std_tr1_unordered_map=yes], 32 | [ac_cv_cxx_have_std_tr1_unordered_map=no])]) 33 | 34 | if test "$ac_cv_cxx_have_std_tr1_unordered_map" = yes; then 35 | AC_DEFINE([HAVE_STD_TR1_UNORDERED_MAP], [1], 36 | [define if C++ library implements std::tr1::unordered_map]) 37 | fi] 38 | ) 39 | -------------------------------------------------------------------------------- /tools/ft_need_funcs.m4: -------------------------------------------------------------------------------- 1 | m4_define([FT_NEED_ALL_FUNCS], [ 2 | ft_funcs_missing= 3 | for ft_func in $@ 4 | do : 5 | if test "`eval echo '$ac_cv_func_'$ft_func`" != "yes" 6 | then 7 | ft_funcs_missing="$ft_funcs_missing$ft_func " 8 | fi 9 | done 10 | if test "x$ft_funcs_missing" != "x" 11 | then 12 | as_fn_error $? "missing required functions: $ft_funcs_missing" 13 | fi 14 | ]) 15 | 16 | m4_define([FT_NEED_ANY_FUNC], [ 17 | ft_funcs_missing= 18 | ft_funcs_found= 19 | for ft_func in $@ 20 | do : 21 | ft_funcs_missing="$ft_funcs_missing$ft_func " 22 | 23 | if test "`eval echo '$ac_cv_func_'$ft_func`" = "yes" 24 | then 25 | ft_funcs_found=1 26 | fi 27 | done 28 | if test "x$ft_funcs_found" = "x" 29 | then 30 | as_fn_error $? "least one of the following functions is required: $ft_funcs_missing" 31 | fi 32 | ]) 33 | 34 | -------------------------------------------------------------------------------- /tools/ft_need_libs.m4: -------------------------------------------------------------------------------- 1 | m4_define([FT_NEED_ALL_LIBS], [ 2 | ft_libs_missing= 3 | for ft_lib in $@ 4 | do : 5 | if test "`eval echo '$ac_cv_lib_'$ft_lib`" != "yes" 6 | then 7 | ft_libs_missing="${ft_libs_missing}lib$(echo $ft_lib | sed 's/_/:/')() " 8 | fi 9 | done 10 | if test "x$ft_libs_missing" != "x" 11 | then 12 | as_fn_error $? "missing required library functions: $ft_libs_missing" 13 | fi 14 | ]) 15 | -------------------------------------------------------------------------------- /tools/ft_output.m4: -------------------------------------------------------------------------------- 1 | m4_define([FT_OUTPUT], [[ 2 | sed -e 's/define \([A-Z]\)/define FT_\1/g' -e 's/undef \([A-Z]\)/undef FT_\1/g' < fsremap/src/config.hh > fsremap/src/ft_config.hh 3 | ]]) 4 | --------------------------------------------------------------------------------