判断分区中是否有ext4文件系统:
static int ckext4(char *fsdev)
{
int fd;
int ret;
struct ext4_super_block sb;
//if (setjmp(setjmp_env))
//return -1;
fd = open(fsdev, O_RDWR);
if (fd < 0)
return -1;
ret = lseek64(fd, 1024, SEEK_SET);
if (ret < 0)
goto ckext4_fs_error;
ret = read(fd, &sb, sizeof(sb));
if (ret < 0)
goto ckext4_fs_error;
if (ret != sizeof(sb))
goto ckext4_fs_error;
if (sb.s_magic != EXT4_SUPER_MAGIC)
goto ckext4_sbmagic_error;
if ((sb.s_state & EXT4_VALID_FS) != EXT4_VALID_FS)
goto ckext4_sbstatus_error;
if(sb.s_feature_incompat & EXT4_FEATURE_INCOMPAT_RECOVER==0)
goto ckext4_needrecovery_error;
close(fd);
return 0;
ckext4_fs_error:
close(fd);
return -2;
ckext4_sbmagic_error:
close(fd);
return -3;
ckext4_sbstatus_error:
close(fd);
return -4;
ckext4_needrecovery_error:
close(fd);
return -5;
}