RSSAmplifier

Blog

(untitled)

aligned words

kdave.github.ioRSS feed ↗26 posts

Latest posts

Update: Atomic cross-rename of two paths (mv --exchange, exch)

I did not notice that the cross rename already existed when I was writing about it but it’s been there since coreutils v9.5 released in Mar 2024. $ mv --exchange file1 file2 And it also landed in util-linux v2.40 at about the same time as utility exch (added in commit cd094a05880c ): $ exch file1 file2 The two projects have an overlap in what they provide so the journey of mv --exchange took a few…

Case study: link C++ standalone executable to another C executable (ntfs2btrfs to btrfs-convert)

Problem statement : there’s a tool written in C, btrfs-convert , that implements conversion from one filesystem to btrfs. For ext2/3/4 and reiserfs this is done using existing C libraries. There’s a standalone project ntfs2btrfs written in C++, not providing a library interface at all, but the equivalent functionality. The question : can the functionality of ntfs2btrfs be provided by btrfs-convert…

Python auto increment variables

Although everybody knows the python language does not provide the unary increment/decrement operators, I’d still like to use that for some specific cases. Let’s explore an unconventional way how to do that. Python operator overview The Stackoverflow Increment and decrement operator question provides some insights why ++x works but does not do what one expects. This is parsed as +(+(x)) . The…

Self Makefile and C source

I’ve seen this trick long time ago, one file that’s a C source and also usable as it’s own Makefile , also known as polyglot code . While the polyglot has probably little use in practice, the combination with build system can be handy, to distribute a single file. Build instructions can be of course in a comment in the file. Let’s see a minimal example: Source: #include <stdio.h> int main () {…

Atomic cross-rename of two paths

Since version v3.15 linux supports a file operation that will exchange any two directory entries atomically. This needs support of the filesystem so it’s not universal, but the commonly used filesystems can do it. The underlying syscall is renameat2 . Obligatory LWN article . #define _GNU_SOURCE #include <fcntl.h> #include <stdio.h> int renameat2 ( int olddirfd , const char * oldpath , int…

Linux kernel tip: build with custom CFLAGS

Build linux kernel, either whole or a selected directory with compiler flags, without editing any Makefiles or such. cd linux.git make ccflags-y = '-Wundef' kernel/ Any change to flags will be detected and leads to full rebuild of all affected files. Building whole directory must have the trailing / . Whole modules can be built with M=fs/btrfs , where M= does not require the trailing / . What to…

Interactive sleep

The sleep utility is something I’d hardly consider worth enhancing by features, the task is simple to sleep for a given time. Nothing else is needed when it’s used from scripts. However, it can be also used from manually typed command line, e.g. to let some command start later to offset initial IO load or not to overload network. Let’s say for example that we’d like to download a big data set, but…

VIM tip: split file to 2 panes, lines continued

Vim has the excellent feature to split the window to multiple panes, but can it open one file in two vertical tabs and let the contents of left pane continue in the one next to it? From 1 ... 2 ... 3 ... 4 ... 5 ... 6 ... to 1 ... 7 ... 2 ... 8 ... 3 ... 9 ... 4 ... 10 ... 5 ... 11 ... 6 ... 12 ... Not by default, certainly with some scripting or by a set of a few commands entered manually. We…

JSON format dumper (a C API)

We’ve had users asking for a machine readable output of btrfs-progs commands, suggesting to add an alternative way to dump the data in a structured format e.g. json. And nowadays this is very common in many if not all commands provided by util-linux . Try lscpu --json , or lsblk --json . Feeding such output to python or a shell-friendly json parser is going to make life easier. So that’s the…

CUDA not initialized after resume (unknown error)

tl;dr CUDA returning an unknown error upon initialization after resume on linux can be solved by reloading kernel module nvidia_uvm. There are some problems reported where with CUDA returns an unknown error upon initialization, while there’s no clear cause nor a clear way how to fix it. I’ve found https://victorwyee.com/engineering/failed-call-to-cuinit-cuda-error-unknown/ listing various…

Authenticated hashes for btrfs (part 1)

There was a request to provide authenticated hashes in btrfs, natively as one of the btrfs checksum algorithms. Sounds fun but there’s always more to it, even if this sounds easy to implement. Johaness T. at that time in SUSE sent the patchset adding the support for SHA256 [1] with a Labs conference paper, summarizing existing solutions and giving details about the proposed implementation and use…

Btrfs hilights in 5.4: tree checker updates

A bit more detailed overview of a btrfs update that I find interesting, see the pull request for the rest. There’s not much to show in this release. Some users find that good too, a boring release. But still there are some changes of interest. The 5.4 is a long-term support stable tree, stability and core improvements are perhaps more appropriate than features that need a release or two to…

Btrfs hilights in 5.5: new hashes

A bit more detailed overview of a btrfs update that I find interesting, see the pull request for the rest. More checksum algorithms The first request for more checksums is several years old (2014), it was SHA256 . There was no followup of the patch but the discussion in the mail thread brought the topic into light. Questions about why SHA256 and why not something else (welcome to the zoo:…

Btrfs hilights in 5.5: 3-copy and 4-copy block groups

A bit more detailed overview of a btrfs update that I find interesting, see the pull request for the rest. New block group profiles RAID1C3 and RAID1C4 There are two new block group profiles enhancing capabilities of the RAID1 types with more copies than 2. Brief overview of the profiles is in the table below, for table with all profiles see manual page of mkfs.brtfs , also available on wiki .…

BLAKE3 vs BLAKE2 for BTRFS

Irony isn’t it. The paint of BLAKE2 as BTRFS checksum algorithm hasn’t dried yet, 1-2 weeks to go but there’s a successor to it. Faster, yet still supposed to be strong. For a second or two I considered ripping out all the work and … no not really but I do admit the excitement. Speed and strength are competing goals for a hash algorithm. The speed can be evaluated by anyone, not so much for the…

Btrfs hilights in 5.3

A bit more detailed overview of a btrfs update that I find interesting, see the pull request for the rest. CRC32C uses accelerated versions on other architectures … than just Intel-based ones. There was a hard coded check for the intel SSE feature providing the accelerated instruction, but this totally skipped other architectures. A brief check in linux.git/arch/*/crypto for files implementing the…

Simple asm diff filter

One thing you windows guys have is a decent binary diff. I know there’s radare2 on linux, but I’m a noob to set it up and I’d be fine with something less fancy. Something like 2 objdump -dr files, intelligent filter and vimdiff . The tricky part is the intelligent filter. I say intelligent , but in fact it’s a 20 line perl script that basically filters out things that are not important or are…

Selecting the next checksum for btrfs

The currently used and the only one checksum algorithm that’s implemented in btrfs is crc32c, with 32bit digest. It has served well for the years but has some weaknesses so we’re looking for a replacements and also for enhancing the use cases based on possibly better hash algorithms. The advantage of crc32c is it’s simplicity of implementation, various optimized versions exist and hardware CPU…

Btrfs hilights in 5.2

A bit more detailed overview of a btrfs update that I find interesting, see the pull request for the rest. Read-time, write-time corruption detection The tree-checker is a recent addition to the sanity checks, a functionality that verifies a subset of metadata structures. The capabilities and strength is limited by the context and bits of information available at some point, but still there’s…

Here, have a pyramid made of BLAKE2 hashes

Fun stuff only … Hash some bytes with changing digest length from 1 to 64. [ 1] 3b [ 2] cf5b [ 3] 68a2fa [ 4] ac6de759 [ 5] 022847e13c [ 6] fd2965be0997 [ 7] d4c93ad6ffbcbb [ 8] 87c1dcb224fd2a57 [ 9] 6017c4f8c4bcb1d115 [10] 9b3f7b15df8867b8214c [11] 8087b2861bbdf3d0356ea6 [12] 7a035413d62f0774148a12cc [13] 697cabcfcade7114a271373039 [14] 784e3578c7b5a031237296225e26 [15]…

Linux crypto: testing blake2s

The BLAKE2 algorithm is out for some time, yet there’s no port to linux crypto API. The recent push of WireGuard would add it to linux kernel, but using a different API (zinc) than the existing one. I haven’t explored zinc, I assume there will be a way to use it from inside kernel, but this would need another layer to switch the APIs according to the algorithm. As btrfs is going to use more…

Some btrfs benchmarks of changes pending for 4.20

Update: enhance the text, still a bit raw, check the numbers Example of benchmarks of patches going to 4.20 kernel. The goal was to identify potential differences between the devleopment branch with and without merge to the mainline. The factors affecting the difference are usually in other subsystems like block layer (IO queuing) or memory management (namely page cache, memory allocator,…

qemu 2.12 does not support if=scsi

After update of qemu to version 2.12, my testing vms stopped to just warn about the if=scsi (with a bit more cryptic message), and did not want to start. qemu-system-x86_64: -drive file = root,if = scsi,media = disk,cache = none,index = 0,format = raw: machine type does not support if = scsi,bus = 0,unit = 0 The if=scsi shortcut was handy, the maze of qemu command line options may take some time…

gitstats: btrfs-progs for v4.14

gitstats

errno.h for the masses

The errno values, in various formats you may encounter. The standard errno is a positive number, linux kernel uses the negative values. Besides the sources (going through like 5 include hops from /usr/include/errno.h to /usr/include/asm-generic/errno.h and /usr/include/asm-generic/errno-base.h ) there’s no direct way to get the symbolic <-> numeric mapping. The hexa values commonly appear in the…

Escaped snapper snapshots

Happened to me, that space on my root partition was going low, no matter what I removed. I have snapper hourly snapshots enabled, tuned the daily and weekly settings, so the usual problem of running out of space is prevented. Also before doing a big update of Tumbleweed (openSUSE rolling distro) I check the available space to roughly match what zypper says it’d need. $ snapper ls Type | # | Pre #…