## Monday, October 28, 2019

### How to use IS_ERR and PTR_ERR? What do they mean?

From the kernel definition there are three macros:
1. IS_ERR - used to check, Returns non-0 value if the ptr is an error. Otherwise 0 if it’s not an error.
2. PTR_ERR - used to print. Current value of the pointer.
3. IS_ERR_VALUE - is explained a little bit more detail here1.
I find this the most useful for kernel space programming. Used as follows- if ptr is the pointer you want to check then use it as follows:
if (IS_ERR(ptr))
printk("Error here: %ld", PTR_ERR(ptr));

## Saturday, October 26, 2019

### Apple IOS: How to backup health data to windows or MAC

This is an old post, but keeping it here for archival.

Before starting you need to have email correctly configured on your phone.
1. Start the health app
2. Navigate through "Health Data (folder with heart on it)" -> "All" -> Share icon in top right corner (the square box with the arrow on it).
3. When you do that you will be prompted for confirmation as below:

## Wednesday, October 23, 2019

### Linux: Easy solution vim caught deadly signal segv vim preserving files vim finished

Ran into this irritating problem when everything was initially working fine on my system.

I had copy pasted something into the command window by mistake which caused vi to crash and keep spitting this out. I am using a Fedora version.

Thing that I tried which did not work:
1. Rebooting
2. Uninstalling and reinstalling vi

Solution: Under your home directory there is a file .viminfo which contains all the cached vi information. Delete this file. It will get recreated afresh the  next time vi starts. Just deleting this file fixed the problem for me.

## Tuesday, October 22, 2019

### Linux: Solution Unknown symbol “__aeabi_ldivmod”

You might notice that while compiling for your 32bit platforms your kernel module compiles. However, when you are inserting it we see a failure (either at boot or while explicitly doing an insmod or modprobe).

The reason this "Unknown symbol in module" is seen is because you are in some instruction trying to do a 64bit division in the Linux kernel for an ARM platform (32bit).

Why is the symbol missing though if everything compiles. The compiler wants to do the 64bit div with slow library functions which Linux does not implement. So when the code is run, the symbol (__aeabi_ldivmod) is not found.

The solution to this problem is to use do_div() while including <asm/div64.h>.

## Monday, October 21, 2019

### Linux: Solution Fatal section header offset is bigger than file size

The error I was seeing while recompiling a driver:
fatal section header offset 32425246532452 in file 'vmlinux' is bigger than filesize=35524847

What helped was trying from scratch:
sudo make distclean
make modules
sudo make modules_install

## Friday, October 18, 2019

I ran into this error when I was creating a new clientspec and tried to checkout a new tree with this clientspec. I was using
p4 sync ...

Found out through debugging that this error was not being generated due to a problem with the permissions on the local directory but rather because the clientspec was incorrectly pointing to a non-existing path on the repository. You are trying to access some part of the repo that is not setup or you dont have permissions to access. Run p4 client and fix the clientspec, and things should work.

Fix the client spec and things work.

## Wednesday, October 16, 2019

### p4 shelve equivalent in Git with an example

The equivalent of p4 shelve on GIT is stashing.

Say I have modified the file on my repository and I see the following:
techmuser@gw2:~/repositories/softlockup_repo/scripts$git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: vimrc no changes added to commit (use "git add" and/or "git commit -a") Now to shelve these changes, techmuser@gw2:~/repositories/softlockup_repo/scripts$ git stash
Saved working directory and index state WIP on master: 80e892a Track git aliases.       modified:   generic_aliases
HEAD is now at 80e892a Track git aliases.

## Tuesday, October 15, 2019

### Windows: Creating a disk catalog for your external hard drive

On my windows machine, I wanted to create a disk catalog that I could use to see the movies I already had watched or downloaded from my provider.
1. I found that the easiest way to do this is by creating a text file which has a list of all files on the external drive from that directory and saving that info to a file.
2. When needed, search the text file which is used as a catalog.

Creation of the catalog is very easy. For your destination path (on the external drive),  do the following:
1. From the windows start menu, type and search for "cmd"
2. This will launch the command window.
3. In the command window run the following command:
DIR "F:\path\to\dir" /s > "C:\List.txt"
This command assumes that F:\path\to\dir is the directory which you are planning to list. The catalog file is the C:\List.txt file which can be read and searched like a normal text file.

For making a catalog from any directory use something like this in a .bat file:
DIR /s > "Catalog.txt"

## Sunday, October 13, 2019

### Thought Experiment: Why not have multiple woofers for each channel

Ever wondered why there is a single subwoofer and multiple small speakers for higher frequencies?
Because the human hear can only distinguish the higher frequencies spatially. Why?
Because of the wavelength. The base (subwoofer) is the lower frequency sound which is usually a few HZ which would typically have a wavelength of the order of 10s of feet. Hence in this case, the two human ears which are placed less than a feet apart on our head cant differentiate between base sound  from different channels. Hence we only have one subwoofer for the base sounds and multiple smaller  speakers (5.1 or 2.1 stereo) for the higher frequency sounds.

## Wednesday, September 4, 2019

### Linux: How to check the IO address space on your Linux machine

The parallel port is at address 0x0378?
This is the IO address space and this information is provided under the /proc file system as:

b=$(md5sum$2 | awk '{print $1}') echo "Comparing$1 and $2" [ "$a" = "$b" ] && echo "Equal" || echo "Not Equal" } ### Linux: Sleeping while atomic during kmalloc solved So you ran into a crash where the kernel complains that you were sleeping while atomic. You were either able to run objdump or gdb and track down that the crash is caused due to a kmalloc? How is that possible? Did you make recent changes which included putting in a kmalloc? ## Monday, June 17, 2019 ### Linux: How to tar only selected folders and files Step 1: Select the files and prepare a list. I do this with a simple function in my .bashrc script:$> cat >> ~/.bashrc
99 function cscopesetup()
100 {
101     rm cscope.files;

102
103     echo "Populating filenames...";
104     find $SRC/folder1/ -iname "*.c" -print >> cscope.files #folder1 105 find$SRC/folder9/ -iname "*.h" -print >> cscope.files #folder9
106     echo "Driver done"
107 }

## Sunday, May 19, 2019

### Linux: When to use kmalloc vs kmem_cache_alloc vs Vmalloc?

Gautam Bhanage | www.Bhanage.com | Pub2: GDB2019-001 June 2019

At a high level:
1. kmalloc for all generic memory allocation
2. kmem_cache_alloc for repeatetive structs that need allocations. These structures typically need to be accessed frequently (and are L1 & L2 cache aligned by the kernel).This is done much more efficiently through the slab allocator.
3. vmalloc() - allocates virtually contiguous memory. Not really useful from a linux kernel driver perspective.

## Wednesday, April 24, 2019

### Linux: Why Deleting Files Does Not Free Up Memory

This is a very old blog post from a place I contributed to:

You are in the middle of compiling your code and you see errors:
/disk/user1/platform_dev/driver/openwrt/staging_dir_arm_platform/bin/arm-unknown-linux-uclibcgnueabi-objcopy:/disk/user1/platform_dev/driver/base/build_platform/kmod/linuxmodule/stI4AuYi: No space left on device
make[5]: *** Waiting for unfinished jobs....

So this is just like old times. You run df -h and check if you are running at disk capacity.
I find that I am at 70% disk usage but still the make process is complaining.

I decide to be conservative and free up more space on the system.
Then I see something interesting. Despite doing the rm -Rf on a couple of big chunks of data,
I do not see the free space on my system going up.

That gets me thinking why this might be happening. The reason is that the deletes I did were through screen. And, Linux will not free up any descriptors (Inodes) as long as they are being referred through some process.