17 Haziran 2021 Perşembe

Kernel Module ve Export Symbol

Giriş
Bir module bir başka modülün sadece exported sembollerine erişebilir. Açıklaması şöyle
Modules can only access exported symbols, and exit_task_namespaces isn’t exported — so even though it is visible in the header files, it can’t be used in a module.

Exported symbols can be accessed as you’d expect, there’s nothing special to do.
Örnek
Export edilen şey veri yapısı ise şöyle yaparız
struct snd_card *snd_cards[SNDRV_CARDS];
EXPORT_SYMBOL(snd_cards);
Örnek
modul1 şöyle olsun
/* mod1.c */
#include <linux/module.h>

static int mod1_exp_func(int i)
{
  pr_info("%s:%d the value passed in is %d\n",
            __func__, __LINE__, i);

  return i;
}
EXPORT_SYMBOL(mod1_exp_func); /* export static symbol */

static int __init mod1_init(void)
{
  pr_info("Initializing simple mod\n");
  return 0;
}

static void __exit mod1_exit(void)
{
  pr_info("This module is exiting\n");
}

module_init(mod1_init);
module_exit(mod1_exit);
MODULE_LICENSE("GPL v2");
module2 export edilen sembolleri kullanabilir. Şöyle yaparız
/* mod2.c */
#include <linux/module.h>

extern int mod1_exp_func(int);

static int __init mod2_init(void)
{
  pr_info("Initializing mod2\n");
  pr_info("Calling exported function in mod1\n");
  mod1_exp_func(3);
  return 0;
}

static void __exit mod2_exit(void)
{
  pr_info("mod2 exiting\n");
}

module_init(mod2_init);
module_exit(mod2_exit);
MODULE_LICENSE("GPL v2");

14 Haziran 2021 Pazartesi

bash expansion Sırası

Giriş
Açıklaması şöyle.
The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; and filename expansion.
3. Parameter Expansion - ${variable,,} şeklindedir. String işlemleri gibi düşünülebilir.
3. Variable Expansion - "$var" şeklindedir. Değişkenin değerini açarak bir metoda geçer.
4. Arithmetic expansion
5. Command Substitution
yazılarına da bakabilirsiniz.

 Parameter Expansion vs Variable Expansion
Aslında Parameter Expansion ve Variable Expansion çok benziyor. 

- Eğer değişkenin değerine erişmek istiyorsak "$var" şeklinde kullanırız. Bu durumda variable expansion olur
- Eğer değişken bir string içinde kullanılacaksa bu sefer Parameter Expansion yapmak gerekir. Değişken bu sefer Brace ile sarmalanır string double quote içine alınmaz. Çünkü zaten string içindedir

Örnek - Variable Expansion 
Şöylee yaparız
$ IFS=" elr"
$ var="Hello World"
$ printf '<%s> ' $var; echo
<H> <> <> <o> <Wo> <> <d>

$ printf '<%s> ' "$var"; echo
<Hello World>
Örnek - Parameter Expansion 
Şöyle yaparız
$ var=one
$ echo "The value of var is $varvalue"
The value of var is
$ echo "The value of var is ${var}value"
The value of var is onevalue



8 Haziran 2021 Salı

epoll_ctl metodu

Giriş
epoll_ctl() metodunu anlamadan önce epoll_event yapısını anlamak gerekir.

epoll_create1() ile yaratılan socket set'ine yeni bir socket eklemek için kullanılır

Örnek - EPOLL_CTL_ADD
İzlenecek yeni fd  eklemek için şöyle yaparız. Bu fd'de bir olay olursa ev yapısı geri verilir.
epoll_event ev;
ev.data.fd = timerfd;

epoll_ctl(epollfd, EPOLL_CTL_ADD, timerfd, &ev); 
Örnek - EPOLL_CTL_ADD
Şöyle yaparız.Burada socketin EPOLLIN ve EPOLLRDHUP olayları dinleniyor
int servFd = socket (...);

int efd = epoll_create1 (EPOLL_CLOEXEC);
struct epoll_event epollEvt;
epollEvt.events = EPOLLIN | EPOLLRDHUP;
epollEvt.data.u32 = servFd;
epoll_ctl (efd, EPOLL_CTL_ADD, servFd, &epollEvt);
Örnek
Açıklaması şöyle
A detail to note: it’s important to set the level-trigger (EPOLLIN) but not the edge-trigger (EPOLLET) on the listening socket.
Şöyle yaparız. EPOLLIN olayı dinleniyor
void register_fd(int efd, int fd) {
  struct epoll_event event;
  event.data.fd = fd;
  event.events = EPOLLIN;
  epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event);
  // Error check.
}

6 Haziran 2021 Pazar

ip6tables INPUT Modülü

Giriş
iptables komutu IPv4 içindir. ip6tables komutu IPv6 içindir.

-A seçeneği
Örnek
Şöyle yaparız
ip6tables -A INPUT -p tcp --dport 22 -j REJECT

2 Haziran 2021 Çarşamba

numfmt komutu - Sayıları Kolay Okunabilecek Şekilde Formatlar

Giriş
Açıklaması şöyle
numfmt - Convert numbers from/to human-readable strings
--from seçeneği
Örnek
Kısal sayıdan uzun sayıya çevirmek için şöyle yaparız
$ numfmt --from=iec-i 50.1Gi
53794465383
String'den tekrar sayıya çevirmek için şöyle yaparız
$ echo "50.1Gi" | numfmt --from=iec-i
53794465383

21 Mayıs 2021 Cuma

GUID Partition Table - GPT - Bir Partition Table Tipi

Giriş
Açıklaması şöyle. MBR yetersiz kaldığı için kullanılan yeni partition table tipidir.
GPT is MBR's successor. It supports up to 128 partitions and addresses so large we won't reach them for decades, maybe never.
GPT genellikle UEFI bootloader ile kullanılır. Açıklaması şöyle
GPT is actually defined by UEFI spec and takes a different approach. Since UEFI isn't meant to be as thin and simple as BIOS (it's basically a small operating system, including the ability to load custom modules), its designers didn't bother with BIOS's "KISS" approach. Instead UEFI includes drivers for FAT-family filesystems and can be configured to load bootloader directly from a partition. Basically the filesystem driver which everyone tried to store in MBR is now provided by the platform, along with a built-in boot manager.

chronyd vs NTP service

Chronyd vs NTP service
Açıklaması şöyle. Yani chronyd sistemi saatini NTP'ye göre daha hızlı eşzamanlı hale getiriyor.
Chrony is a different implementation of the network time protocol (NTP) than the network time protocol daemon (ntpd) that is able to synchronize the system clock faster and with better accuracy than ntpd.
Hangisini Ne Zaman Kullanmalı
Açıklaması şöyle. Eğer bilgisayar sık sık kapatılıyor veya uykuya geçiriliyorsa, chronyd daha iyi sonuç verebilir.
When to use chrony
Chrony would be considered a best match for the systems which are frequently suspended or otherwise intermittently disconnected from a network (mobile and virtual servers etc).

When to use NTP
The NTP daemon (ntpd) should be considered for systems which are normally kept permanently on. Systems which are required to use broadcast or multicast IP, or to perform authentication of packets with the Autokey protocol, should consider using ntpd.
for current cloud and container based environment where applications are stateless chronyd play an important role to sync the time on each system.
chrony.conf dosyası
/etc/chrony. conf dosyası Chronyd için ayarları içerir.

Örnek
# Default chrony.conf on Ubuntu, sans comments and blank lines
confdir /etc/chrony/conf.d
pool ntp.ubuntu.com        iburst maxsources 4
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
pool 1.ubuntu.pool.ntp.org iburst maxsources 1
pool 2.ubuntu.pool.ntp.org iburst maxsources 2
sourcedir /run/chrony-dhcp
sourcedir /etc/chrony/sources.d
keyfile /etc/chrony/chrony.keys
driftfile /var/lib/chrony/chrony.drift
ntsdumpdir /var/lib/chrony
logdir /var/log/chrony
maxupdateskew 100.0
rtcsync
makestep 1 3
leapsectz right/UTC