Some of my favourite graphics programming is done simply with a framebuffer pointer. The simplicity of accessing pixels directly can be alot of fun. In today’s article, I’ll walk through a couple of different ways that you can achieve this inside of Linux.
/dev/fb*
Probably the easiest way to get started with writing to the framebuffer is to start working directly with the /dev/fb0 device.
If your system is anything like mine, this results in zsh: permission denied: /dev/fb0. To get around this, add yourself to the “video” group.
You can now fill your screen with garbage by sending all of those bytes from /dev/urandom.
This works, but it’s not the best way to get it done.
Xlib
Next up we’ll try again using Xlib. This isn’t exactly what we’re after, but I’ve included this one for completeness.
We are performing double-buffering here, but it’s only when the event type of Expose comes through. This can be useful, but not great if you want to do some animation.
In order to compile this particular example, you need to make sure that you have libx11-dev installed.
SDL
For our last example here, we’ll use SDL to achieve pixel access to a backbuffer (or framebuffer) by creating an image. In this example we are continouosly flipping the back image onto video memory which allows for smooth animation.
Before being able to compile and run this, you need to make sure you have SDL installed on your system.
That’s been a few different framebuffer options, all depending on your appetite for dependencies or ease of programming.
GNUstep is a development framework for writing GUI applications. It aims to follow Apple’s Cocoa API but allows you to write applications for more platforms than just OSX.
In today’s article we’ll setup a local environment for writing GNUstep programs, and we’ll also write and compile a simple “Hello, world” application to make sure everything is setup.
Brief History
GNUstep is an open-source implementation of the OpenStep specification, which originated from NeXT, a company founded by Steve Jobs after he left Apple in 1985. NeXT developed the NeXTSTEP operating system, which introduced an advanced object-oriented framework for software development. In 1993, NeXT partnered with Sun Microsystems to create the OpenStep standard, which aimed to make NeXT’s frameworks available on other platforms.
When Apple acquired NeXT in 1996, the technology from NeXTSTEP and OpenStep formed the foundation of Apple’s new operating system, Mac OS X. Apple’s Cocoa framework, a core part of macOS, is directly derived from OpenStep. GNUstep, initiated in the early 1990s, aims to provide a free and portable version of the OpenStep API, allowing developers to create cross-platform applications with a foundation rooted in the same principles that underpin macOS development.
So, this still leaves us with GNUstep to get up and running.
Developer environment
First up, we need to install all of the dependencies in our developer environment. I’m using Debian so all of my package management will be specific to that distribution. All of these packages will be available on all distributions though.
Once this is installed, we can move on to writing some code.
“Hello World” alert
The following program is very basic. It’ll show an alert to screen, and then exit after the user has dismissed the alert.
Walkthrough
First of all, we include AppKit/AppKit.h so that we get access to the programming API. We then define our own AppDelegate so we capture the applicationDidFinishLaunching slot:
The handler sets up the alert to show to screen, runs this modal as “the program” with runModal, and then we finish with `terminate’.
Next is the main program itself.
We start with an NSAutoreleasePool to give our program some automatic memory management. This is cleaned up at the end with a call to [pool drain].
The app variable is setup as an NSApplication which allows us to instantiate and attach our AppDelegate via the [app setDelegate:appDelegate]; call.
Building
Now that we have our code written into hello.m, we can compile and link. There are some compile and link time libraries required to get this running. For this, we’ll use gnustep-config to do all of the heavy lifting for us.
If everything has gone to plan, you should be left with an executable called hello.
Rsync is a powerful tool often utilized for its proficiency in file synchronization and transfer. Widely adopted in various computing environments, rsync excels in efficiently mirroring data across multiple platforms and minimizing data transfer by sending only changes in files. This utility is not only pivotal for maintaining backups but also ensures that the copies are consistent and up-to-date.
Today’s article is designed to guide you through the steps of setting up a basic yet effective backup system using rsync. By the end of this guide, you’ll have the knowledge to implement a reliable backup solution that can be customized to fit your specific needs.
Daily
The daily backup captures all of the changes for the day, giving you a backup with the fastest cadence.
Using whoami and hostname we can generalise this script so that you can reuse it between all of your machines.
The rsync-homedir-excludes.txt file allows you to define files that you’re not interested in backing up.
The switches that we’re sending into rsync are quite significant:
-a puts rsync into archive mode, preserving file structures, and links
-A preserves the ACLs so all of our permissions are preserved
-X any extra attributes that are stored by your file system will be preserved
--delete will delete files in the destination that are no longer present in the source, making the backup a true mirror
Weekly
The weekly backup is very similar to the daily backup. It’ll target different folders, and will have a different execution cadence.
There isn’t much difference here. Just writing to the /weekly folder.
Monthly
The longest cadence that we have is a monthly process which will archive the current state into an archive, and date the file for later use potentially.
Using tar this script builds a full archive, and then sends that off to the backup server.
Scheduling
Finally, we need to setup these scripts to execute automatically for us. For this, we’ll use cron.
Here’s an example crontab scheduling these scripts:
There were some important configurations that I needed to put together in order to get this unit to perform correctly.
Problems
After getting everything setup, I had two 4TB BarraCuda drives plugged in ready to go.
I have this system running as a RAID 1 so that I have a mirror of my data.
After starting to transfer data onto the device, I noticed that copy jobs would grind to a halt; as well as the error log being full of the following:
There’s also signs of crashes from the disk as well:
Ugh …
Disable USB Auto Suspend
I thought there might have been a suspend issue with the USB device. In order to achieve this, I needed to send the kernel some parameters from GRUB.
Opening /etc/default/grub, we can start adding items to GRUB_CMDLINE_LINUX_DEFAULT:
Failing back to usb_storage
Looking at some discussions I can see that a lot of people were having success with blacklisting the uas driver that the vendor provides, failing back to the standard driver from linux.
So, I did that too.
To do that, you need to pass the IDs as quirks into the blacklist request. To get those IDs, you need to look at the output from lsusb:
The Toshiba, and ASMedia items were of interest to me.
Create a file /etc/modprobe.d/blacklist-uas.conf
I added this text:
Remember to specify the u at the end of the ID strings. It’s literal, and need to be there.