赞
踩
需求
获取EMMC内存大小
对应无法得知EMMC总内存的大小,基于这个问题所写的代码。
#define PATH_MAX_STRING_SIZE 256 #define BLKGETSIZE64 _IOR(0x12,114,size_t) #define BLKGETSIZE _IO(0x12,96) unsigned long rtk_get_size_emmc(void) { int fd; unsigned long long v64; unsigned long longsectors; char *pblock_name = "/dev/block/mmcblk0"; fd = open(pblock_name, O_RDWR|O_SYNC); if(fd < 0) { return -1; } if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { /* Got bytes, convert to 512 byte sectors */ v64 >>= 9; if (v64 != (unsigned long)v64) { ret_trunc: /* Not only DOS, but all other partition tables * we support can't record more than 32 bit * sector counts or offsets */ v64 = (unsigned long)-1L; } close(fd); return v64; } /* Needs temp of type long */ if (ioctl(fd, BLKGETSIZE, &longsectors)) { /* Perhaps this is a disk image */ unsigned long sz = lseek(fd, 0, SEEK_END); longsectors = 0; if (sz > 0) longsectors = (unsigned long)sz / 512; lseek(fd, 0, SEEK_SET); } if (sizeof(long) > sizeof(unsigned long) && longsectors != (unsigned long)longsectors ) { goto ret_trunc; } close(fd); return longsectors; }
对应参数解释:
[https://blog.csdn.net/csljl11/article/details/78621545]
工作记录…
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。