1. EXT2: EXT2是最早的Linux文件系统之一,它被广泛应用于Linux操作系统中。它支持大小为16TB的分区和最大文件大小为2TB。由于其简单性和高可靠性,在很长一段时间内仍被许多用户所选择。
2. EXT3: 2001年,Linux社区发布了EXT3作为EXT2的升级版。它添加了日志功能以提高数据完整性和可靠性,并且支持快速备份和恢复功能。这使得它更加适合生产环境中使用。
3. EXT4: 2008年发布的EXT4是EXT系列中最新版本的文件系统。在保持向前兼容性的同时,它引入了许多新特性,如支持更大的文件和分区、更快的读写速度以及更好地处理碎片等特点。
4. 高可靠性:EXT系列文件系统采用日志技术来防止出现文件系统损坏或异常情况时数据丢失或者损坏,保证数据的完整性和一致性。
5. 兼容性:EXT文件系统被广泛用于Linux操作系统中,并且可以在其他类Unix系统中进行兼容和交互操作。
sys文件系统的主要作用,是对系统上的设备与总线进行组织与管理,以形成分级的文件。用户空间可以访问或配置这些文件,进而得知系统状态或者控制系统。
- root@ubuntu:/sys# tree -L 1
- .
- ├── block
- ├── bus
- ├── class
- ├── dev
- ├── devices
- ├── firmware
- ├── fs
- ├── hypervisor
- ├── kernel
- ├── module
- └── power
1.class目录
将设备按照功能分类。
- root@ubuntu:/sys/class# ls
- ata_device dma i2c-adapter powercap scsi_device tty
- ata_link dmi input power_supply scsi_disk vc
- ata_port drm leds ppdev scsi_generic virtio-ports
- backlight extcon mdio_bus ppp scsi_host vtconsole
- bdi firmware mem printer sound watchdog
- block gpio misc pwm spi_host
- bluetooth graphics mmc_host regulator spi_master
- bsg hidraw net rfkill spi_transport
- devfreq hwmon pci_bus rtc thermal
2、block目录
每个块设备在该目录下对应一个子目录。
每个子目录中又包含一些属性文件,它们描述了这个块设备的各方面的属性,比如设备大小。另外,loop块设备是使用文件来模拟的。
通过查看该目录下的详细信息,得知它们都是链接文件,指向/sys/devices/下的设备。
- root@ubuntu:/sys/block# ls
- loop0 loop3 loop6 ram1 ram12 ram15 ram4 ram7 sda
- loop1 loop4 loop7 ram10 ram13 ram2 ram5 ram8 sr0
- loop2 loop5 ram0 ram11 ram14 ram3 ram6 ram9 sr1
- root@ubuntu:/sys/block# cd sr0
- root@ubuntu:/sys/block/sr0# ls
- alignment_offset discard_alignment holders removable subsystem
- bdi events inflight ro trace
- capability events_async power size uevent
- dev events_poll_msecs queue slaves
- device ext_range range stat
- root@ubuntu:/sys/block/sr0# cat size
- 2097151
- root@ubuntu:/sys/block/sr0# cd ..
- root@ubuntu:/sys/block# ls -l sda
- lrwxrwxrwx 1 root root 0 Jul 4 20:50 sda -> ../devices/pci0000:00/0000:00:10.0/host32/target32:0:0/32:0:0:0/block/sda
- root@ubuntu:/sys/block# ls -l sr0
- lrwxrwxrwx 1 root root 0 Aug 2 00:03 sr0 -> ../devices/pci0000:00/0000:00:11.0/0000:02:05.0/ata3/host2/target2:0:0/2:0:0:0/block/sr0
- root@ubuntu:/sys/block# ls -l sr1
- lrwxrwxrwx 1 root root 0 Aug 2 00:03 sr1 -> ../devices/pci0000:00/0000:00:11.0/0000:02:05.0/ata4/host3/target3:0:0/3:0:0:0/block/sr1
- root@ubuntu:/sys/block# ls -l ram1
- lrwxrwxrwx 1 root root 0 Aug 2 00:03 ram1 -> ../devices/virtual/block/ram1
- root@ubuntu:/sys/block# ls -l loop1
- lrwxrwxrwx 1 root root 0 Aug 2 00:03 loop1 -> ../devices/virtual/block/loop1
- root@ubuntu:/sys/block#
3、bus目录
在内核注册的每条总线,在该目录下对应一个子目录,比如i2c、spi、pci、scsi、usb等等。
- root@ubuntu:/sys/bus# ls
- ac97 cpu hid mdio_bus platform sdio virtio
- acpi eisa i2c mmc pnp serio workqueue
- clockevents event_source isa pci rapidio spi xen
- clocksource gameport machinecheck pci_express scsi usb xen-backend
4、devices目录
包含系统的所有设备。
- root@ubuntu:/sys/devices# ls
- breakpoint isa pci0000:00 pnp0 rapidio system virtual
- cpu LNXSYSTM:00 platform pnp1 software tracepoint
5、fs目录
描述系统中的文件系统。
6、filewire目录
描述系统中的固件。
7、power目录
描述系统中的电源选项。
8、module目录
描述系统中的模块信息。
9、kernel目录
内核中的配置参数。
sys文件系统的搭建流程,左边是初始化流程,右边是sys的文件目录:
以ch423为例子,在sys/misc下面添加一个ch423的节点。
- #include <linux/miscdevice.h>
- #include <linux/cdev.h>
- #include <linux/device.h>
- #include <linux/fs.h>
- #include <linux/i2c-dev.h>
- #include <linux/i2c.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/notifier.h>
- #include <linux/slab.h>
- #include <linux/uaccess.h>
- #include <linux/compat.h>
- #include <linux/printk.h>
- #include <linux/kobject.h>
- #include <linux/version.h>
- #include <linux/kthread.h>
- #include <linux/gpio.h>
- #include <linux/of_gpio.h>
- #include <linux/of.h>
- #include <linux/of_device.h>
- #include <linux/platform_device.h>
-
- struct ch423_dev {
- struct device *dev;
- struct device sys_dev;
- struct gpio_desc *ch423_clk;
- struct gpio_desc *ch423_dat;
- };
-
- struct ch423_dev *g_ch423;
- struct ch423_dev *ch423;
-
- static ssize_t ch423_gpio_oc_l_read(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
-
- return sprintf(buf, "%lx\n",CH423_OC_L_STATUS);
- }
-
- static ssize_t ch423_gpio_oc_l_write(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
- {
- return count;
- }
-
- static DEVICE_ATTR(ch423_gpio_oc_l, 0644,
- ch423_gpio_oc_l_read, ch423_gpio_oc_l_write);
-
-
- static const struct file_operations ch423_fops = {
- .owner = THIS_MODULE,
- .read = ch423_read,
- .write = ch423_write,
- .unlocked_ioctl = ch423_ioctl,
- };
-
- struct miscdevice ch423_miscdev = {
- .minor = MISC_DYNAMIC_MINOR,
- .name = "ch423_dev",
- .fops = &ch423_fops,
- };
-
- static int ch423_probe(struct platform_device *pdev)
- {
- struct ch423_dev *ch423;
- int ret = 0;
-
- ch423 = devm_kzalloc(&pdev->dev, sizeof(*ch423), GFP_KERNEL);
- if (!ch423)
- return -ENOMEM;
-
- ch423->dev = &pdev->dev;
-
- ch423->ch423_clk = devm_gpiod_get_optional(ch423->dev,
- "ch423-clk", GPIOD_OUT_HIGH);
- if (IS_ERR(ch423->ch423_clk)) {
- dev_warn(ch423->dev, "Could not get ch423-clk!\n");
- ch423->ch423_clk = NULL;
- }
-
- ch423->ch423_dat = devm_gpiod_get_optional(ch423->dev,
- "ch423-dat", GPIOD_OUT_HIGH);
- if (IS_ERR(ch423->ch423_dat)) {
- dev_warn(ch423->dev, "Could not get ch423-clk!\n");
- ch423->ch423_dat = NULL;
- }
- g_ch423 = ch423;
-
- ret = misc_register(&ch423_miscdev);
- if (ret) {
- ERR("ch423_miscdev ERROR: could not register ch423_miscdev device\n");
- return ret;
- }
-
- ret = device_create_file(ch423_miscdev.this_device,
- &dev_attr_ch423_gpio_oc_l);
- if (ret) {
- dev_err(ch423->dev, "failed to create attr ch423_gpio_oc_l!\n");
- return ret;
- }
- return 0;
- }
-
- static int ch423_remove(struct platform_device *client)
- {
- kfree(ch423);
-
- return 0;
- }
-
- static const struct of_device_id ch423_of_match[] = {
- { .compatible = "ch423" },
- {}
- };
- MODULE_DEVICE_TABLE(of, ch423_of_match);
-
- static struct platform_driver ch423_driver = {
- .probe = ch423_probe,
- .remove = ch423_remove,
- .driver = {
- .owner = THIS_MODULE,
- .name = DRIVER_NAME,
- .of_match_table = of_match_ptr(ch423_of_match),
- },
- };
-
- module_platform_driver(ch423_driver);
-
-
- MODULE_DESCRIPTION("CH423 GPIO Switch");
- MODULE_AUTHOR("Zewei Ye
" ); - MODULE_LICENSE("GPL v2");