当前位置:   article > 正文

如何获取EMMC内存大小_安卓 blkgetsize64

安卓 blkgetsize64

如何获取EMMC内存大小

类别

需求

索引类别

获取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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

参考资料

对应参数解释:
[https://blog.csdn.net/csljl11/article/details/78621545]

改进建议

工作记录…

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号