
To understand why not 1, I need to describe some PC history. A long time ago, when the PC was first provided with hard drives, the first block on the drive was used by the Master Boot Record. Thats still true today, the first partition always began on Cylinder 0, Head 1, Sector 0, under the Cylinder/Head/Sector addressing scheme, whic is all there was than. To add to the interest, hard drives actually had differing numbers of sectors per track then and you had to describe the real geometry of the drive to the BIOS. There was no auto dectect or Logical Block Addressing as used today. The Cylinder/Head/Sector addressing scheme broke permently when hard drives reached 4Gb but its legacy lives on. The largest numbers that fit in the CHS addressing scheme is 255 heads and 63 sectors per track. Hence until recently, the first partition always started at sector 63. Thats head 1, sector 0. //CHS方式寻址时,扇
区号是从1开始的。但是实际的物理扇区是从0开始的,对于LBA寻址方式来说扇区号也是从0开始。这里出现的secotr 0是指物理扇区号。Over the years, boot loaders have used some of the 'unallocated' space between the MBR and the start of the first partition. With the death of the legacy BIOS (ok, its not quite dead yet) and its replacement with EFI BIOS, a special boot partitionis needed to allow EFI systems to boot in EFI mode. Starting the first partition at sector 2048 leaves 1Mb for the EFI boot code. Modern partitioning tools do this anyway and fdisk has been updated to follow suit. You can force some tools to give you back most of this 1Mb but its usually a bad idea. Your 2Tb drive will use 4k physical sectors. Its very important that you create partitions that are aligned on 4kb boundaries or your read/write speeds will be very poor. That is, partition starts must be a multiple of eight sectors. Notice that 63 is not a multiple of 8 but that 2048 is. As you really need to leave some space for grub, you should not start your first partition before sector 64. If you know how big grub is, you can make that smaller but its not worth the effort./CHS方式寻址时,扇区号是从1开始的。
但是实际的物理扇区是从0开始的,
对于LBA寻址方式来说扇区号也是从0开始。
这里出现的secotr 0是指物理扇区号。
通过sysfs方式
控制GPIO,先访问/sys/class/gpio目录,向export文件写入GPIO编号,使得该GPIO的 *** 作接口从内核空间暴露到用户空间,GPIO的 *** 作接口包括direction和value等,direction控制GPIO方向,而value可控制GPIO输出或获得GPIO输入。文件IO方式 *** 作GPIO,使用到了4个函数open、close、read、write。
首先,看看系统中有没有“/sys/class/gpio”这个文件夹。如果没有请在编译内核的时候加入 Device Drivers->GPIO Support ->/sys/class/gpio/… (sysfs interface)。
/sys/class/gpio 的使用说明:
gpio_operation 通过/sys/文件接口 *** 作IO端口 GPIO到文件系统的映射
◇ 控制GPIO的目录位于/sys/class/gpio
◇ /sys/class/gpio/export文件用于通知系统需要导出控制的GPIO引脚编号
◇ /sys/class/gpio/unexport 用于通知系统取消导出
◇ /sys/class/gpio/gpiochipX目录保存系统中GPIO寄存器的信息,包括每个寄存器控制引脚的起始编号base,寄存器名称,引脚总数 导出一个引脚的 *** 作步骤
◇ 首先计算此引脚编号,引脚编号 = 控制引脚的寄存器基数 + 控制引脚寄存器位数
◇ 向/sys/class/gpio/export写入此编号,比如12号引脚,在shell中可以通过以下命令实现,命令成功后生成/sys/class/gpio/gpio12目录,如果没有出现相应的目录,说明此引脚不可导出
◇ direction文件,定义输入输入方向,可以通过下面命令定义为输出。direction接受的参数:in, out, high, low。high/low同时设置方向为输出,并将value设置为相应的1/0
◇ value文件是端口的数值,为1或0
评论列表(0条)