Skip to content

Instantly share code, notes, and snippets.

@jiangzc
jiangzc / ext4_hide_file.c
Created June 29, 2020 13:17
hide files and folders
/*
https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Extent_Tree
file:///home/jzc/Desktop/e2fsprogs-1.45.6/doc/aa.html
https://bean-li.github.io/EXT4-packet-meta-blocks/
https://www.cnblogs.com/alantu2018/p/8461272.html
https://ext4.wiki.kernel.org/index.php/Ext4_Metadata_Checksums
https://metebalci.com/blog/a-minimum-complete-tutorial-of-linux-ext4-file-system/
https://wiki.archlinux.org/index.php/ext4
*/
@jiangzc
jiangzc / pipe_redirect.c
Created April 21, 2020 08:27
get sub process's output in parent process using pipe redirection
// get sub process's output in parent process using pipe redirection
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <fcntl.h>
#include <error.h>
#define BUFFSIZE 4000
@jiangzc
jiangzc / dynamic_allocated_arrays.c
Created April 20, 2020 08:09
dynamic allocate memory to 2d or 3d array
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int **malloc_2d(int row, int col)
{
if (row < 0 || col < 0)
return NULL;
int *array = (int *)malloc(row * col * sizeof(int));
int **p = (int **)malloc(row * sizeof(int *));
@jiangzc
jiangzc / blkid_example.c
Created April 15, 2020 05:05
an example using blkid API in C lang
// compile hint: gcc xxx.c -lblkid
#include <unistd.h>
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <blkid/blkid.h>
int list_ext4_partitions(void)
{
int res;
@jiangzc
jiangzc / monitor_mount.c
Created April 15, 2020 04:37
monitor mounting of disks in /proc/self/mountinfo
// complie hint: gcc xxx.c -lmount
#include <stdio.h>
#include <unistd.h>
#include <libmount/libmount.h>
int main()
{
const char *filename;
struct libmnt_monitor *mn = mnt_new_monitor();
@jiangzc
jiangzc / monitor_active.cpp
Created April 8, 2020 11:09
monitor active window and its pid using X11 lib
// monitor active window and its pid using X11 lib
// compile hint: install xlib-dev and then use g++ ./xxx.cpp -lX11
#include <X11/Xlib.h>
#include <cstring>
#include <iostream>
#define MAXSTR 1000
using namespace std;
Display *display;
unsigned char *prop;