---
# System prepended metadata

title: 2022q1 Homework3 (fibdrv)
tags: [linux_class]

---

# 2022q1 Homework3 (fibdrv)
contributed by < [`RoyWFHuang`](https://github.com/RoyWFHuang) > (網路旁聽)

###### tags: `linux_class`

開發環境為:
OS: ubuntu 20.04
kernel ver: 5.4.0-100-generic 
CPU arch: x86_64
使用 multipass 開發
```shell
$ multipass info dev
Name:           dev
State:          Running
IPv4:           10.195.227.138
Release:        Ubuntu 20.04.3 LTS
Image hash:     db49f99b5162 (Ubuntu 20.04 LTS)
Load:           0.00 0.00 0.00
Disk usage:     4.2G out of 9.5G
Memory usage:   167.2M out of 3.8G
Mounts:         /home/roy/src-code => /home/roy/src-code
                    UID map: 1000:default
                    GID map: 1000:default

In multipass shell
$ uname -a
Linux dev 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ gcc -v
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
```
[fibdrv 作業描述](https://hackmd.io/@sysprog/linux2022-fibdrv#K04-fibdrv)

```shell
$ cat /sys/class/fibonacci/fibonacci/dev
241:0
```
[241](https://www.kernel.org/doc/Documentation/admin-guide/devices.txt) 是major number, 是由 [alloc_chrdev_region](https://www.kernel.org/doc/htmldocs/kernel-api/API-alloc-chrdev-region.html) 產生出來, 而 0 是 ==alloc_chrdev_region(&fib_dev, 0, 1, DEV_FIBONACCI_NAME)== 這段程式碼帶出來的, 其中 0 是表示base number, 1 表示 count

