getlabel.ext2.c

来自「linux下的一个mount工具」· C语言 代码 · 共 44 行

C
44
字号
/* * $Id: getlabel.ext2.c,v 1.1.1.1 2000/09/13 19:36:41 lyonel Exp $ * * Copyright (c) 2000, Lyonel VINCENT <vincentl@ec-lyon.fr> * * This file may be redistributed under the terms of the GNU Public * License. * * Taken from aeb's mount, 990619 */#include <stdio.h>#include <string.h>#include <ctype.h>#include <fcntl.h>#include <unistd.h>#define EXT2_SUPER_MAGIC    0xEF53struct ext2_super_block_struct {        unsigned char   s_dummy1[56];        unsigned char   s_magic[2];        unsigned char   s_dummy2[46];        unsigned char   s_uuid[16];        unsigned char   s_volume_name[16];};typedef struct ext2_super_block_struct ext2_super_block;#define ext2magic(s)    ((unsigned int) s.s_magic[0] + (((unsigned int) s.s_magic[1]) << 8))int ext2_getlabel(int fd, char *label) {	/* start with a test for ext2, taken from mount_guess_fstype */	ext2_super_block e2sb;	if (lseek(fd, 1024, SEEK_SET) != 1024	    || read(fd, (char *) &e2sb, sizeof(e2sb)) != sizeof(e2sb)	    || (ext2magic(e2sb) != EXT2_SUPER_MAGIC)) {		return 0;	}	strncpy(label, e2sb.s_volume_name, sizeof(e2sb.s_volume_name));	return 1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?