FAT file system-FAT Volume Initialization

FAT16与FAT32磁盘配置解析
本文介绍了FAT16和FAT32文件系统的磁盘配置参数及其计算方法,包括不同磁盘大小对应的扇区数和簇大小。详细解释了如何确定合适的磁盘大小及扇区数,以确保文件系统正常运行。

struct DSKSZTOSECPERCLUS {
 DWORD DiskSize;
 BYTE SecPerClusVal;
    };
 /* 
*This is the table for FAT16 drives. NOTE that this table includes
* entries for disk sizes larger than 512 MB even though typically
* only the entries for disks < 512 MB in size are used.
* The way this table is accessed is to look for the first entry
* in the table for which the disk size is less than or equal
* to the DiskSize field in that table entry.  For this table to
* work properly BPB_RsvdSecCnt must be 1, BPB_NumFATs
* must be 2, and BPB_RootEntCnt must be 512. Any of these values
* being different may require the first table entries DiskSize value
* to be changed otherwise the cluster count may be to low for FAT16.
   */
    DSKSZTOSECPERCLUS DskTableFAT16 [] = {
        {        8400,   0}, /* disks up to  4.1 MB, the 0 value for SecPerClusVal trips an error */
        {      32680,   2},  /* disks up to   16 MB,  1k cluster */
        {    262144,   4},   /* disks up to 128 MB,  2k cluster */
        {   524288,    8},   /* disks up to 256 MB,  4k cluster */
        { 1048576,  16},     /* disks up to 512 MB,  8k cluster */
        /* The entries after this point are not used unless FAT16 is forced */
        { 2097152,  32},     /* disks up to     1 GB, 16k cluster */
        { 4194304,  64},     /* disks up to     2 GB, 32k cluster */
        { 0xFFFFFFFF, 0} /* any disk greater than 2GB, 0 value for SecPerClusVal trips an error */
    };
/* 
* This is the table for FAT32 drives. NOTE that this table includes
* entries for disk sizes smaller than 512 MB even though typically
* only the entries for disks >= 512 MB in size are used.
* The way this table is accessed is to look for the first entry
* in the table for which the disk size is less than or equal
* to the DiskSize field in that table entry. For this table to
* work properly BPB_RsvdSecCnt must be 32, and BPB_NumFATs
* must be 2. Any of these values being different may require the first 
* table entries DiskSize value to be changed otherwise the cluster count 
* may be to low for FAT32.
*/
    DSKSZTOSECPERCLUS DskTableFAT32 [] = {
        {       66600,   0},  /* disks up to 32.5 MB, the 0 value for SecPerClusVal trips an error */
        {     532480,   1},   /* disks up to 260 MB,  .5k cluster */
        { 16777216,   8},     /* disks up to     8 GB,    4k cluster */
        { 33554432, 16},      /* disks up to   16 GB,    8k cluster */
        { 67108864, 32},      /* disks up to   32 GB,  16k cluster */
        { 0xFFFFFFFF, 64}/* disks greater than 32GB, 32k cluster */
    };

 

RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec;
TmpVal1 = DskSize – (BPB_ResvdSecCnt + RootDirSectors);
TmpVal2 = (256 * BPB_SecPerClus) + BPB_NumFATs;
If(FATType == FAT32)
    TmpVal2 = TmpVal2 / 2;
FATSz = (TMPVal1 + (TmpVal2 – 1)) / TmpVal2;
If(FATType == FAT32) {
    BPB_FATSz16 = 0;
    BPB_FATSz32 = FATSz;
} else {
    BPB_FATSz16 = LOWORD(FATSz);
    /* there is no BPB_FATSz32 in a FAT16 BPB */
}

Do not spend too much time trying to figure out why this math works. The basis for the computation is complicated; the important point is that this is how Microsoft operating systems do it, and it works. Note, however, that this math does not work perfectly. It will occasionally set a FATSz that is up to 2 sectors too large for FAT16, and occasionally up to 8 sectors too large for FAT32. It will never compute a FATSz value that is too small, however. Because it is OK to have a FATSz that is too large, at the expense of wasting a few sectors, the fact that this computation is surprisingly simple more than makes up for it being off in a safe way in some cases.

在解决 `library initialization failed - unable to allocate file descriptor table - out of memory` 错误时,需要从系统资源限制、程序设计和运行环境等多个层面进行优化和调整。该问题通常与文件描述符的使用和内存分配相关[^3]。 ### 1. **调整文件描述符限制** 操作系统对每个进程能够打开的文件描述符数量有限制。如果程序尝试分配过多文件描述符,可能导致内存不足,从而引发该错误。可以通过以下方式调整: - **临时调整**:使用 `ulimit` 命令调整当前会话的文件描述符限制: ```bash ulimit -n 1024 ``` - **永久调整**:修改 `/etc/security/limits.conf` 文件,添加以下配置: ``` * soft nofile 1024 * hard nofile 65536 ``` - **Docker 容器中调整**:可以在运行容器时通过 `--ulimit` 参数指定文件描述符限制: ```bash docker run --ulimit nofile=1024 -d -p 8080:8080 docker-test:v1.0 ``` ### 2. **优化程序资源使用** 程序中文件描述符泄漏或未及时释放可能导致资源耗尽。建议采取以下措施: - **检查资源泄漏**:确保所有打开的文件、套接字等资源在使用完成后正确关闭。 - **使用资源池**:例如数据库连接池或文件描述符池,减少频繁打开和关闭资源的开销。 - **限制并发连接数**:通过限制最大并发连接数来控制文件描述符的使用。 ### 3. **增加系统内存** 如果系统内存不足,即使文件描述符数量未达到上限,也可能因内存分配失败而导致文件描述符表无法创建。可以通过以下方式增加可用内存: - **升级硬件**:增加物理内存。 - **优化内存使用**:减少不必要的内存占用,确保关键进程有足够的内存可用。 - **调整交换分区**:适当增加交换分区(swap space),以缓解内存压力。 ### 4. **优化内核参数** Linux 内核提供了一些参数可以调整文件描述符和内存的使用行为。可以通过修改 `/etc/sysctl.conf` 文件进行优化: - **调整最大文件描述符数**: ``` fs.file-max = 100000 ``` - **调整内存分配策略**: ``` vm.overcommit_memory = 1 ``` 修改完成后,使用以下命令应用配置: ```bash sysctl -p ``` ### 5. **监控系统资源** 使用工具如 `top`, `htop`, `vmstat`, `iostat`, `lsof` 等监控系统资源使用情况,及时发现和解决问题。 - **查看当前进程的文件描述符使用情况**: ```bash lsof -p <PID> ``` - **查看系统整体文件描述符使用情况**: ```bash cat /proc/sys/fs/file-nr ``` ### 6. **日志分析与调试** 通过分析日志文件(如 `/var/log/messages` 或 `dmesg` 输出)可以获取更多关于内存不足的详细信息: ```bash dmesg | grep -i memory ``` 通过这些方法,可以有效解决 `library initialization failed - unable to allocate file descriptor table - out of memory` 问题[^3]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值