⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getlabel.hfs.c

📁 linux下的一个mount工具
💻 C
字号:
/* *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Library General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* * $Id: getlabel.hfs.c,v 1.1.1.1 2000/09/13 19:36:42 lyonel Exp $ * * Copyright (c) 2000, Lyonel VINCENT <vincentl@ec-lyon.fr> * * This file may be redistributed under the terms of the GNU Public * License. * */#include <stdio.h>#include <string.h>#include <ctype.h>#include <fcntl.h>#include <unistd.h>#include <stdint.h>typedef uint8_t		UInt8;typedef int8_t		SInt8;typedef uint16_t	UInt16;typedef int16_t		SInt16;typedef uint16_t	UniChar;typedef uint32_t	UInt32;typedef int32_t		SInt32;typedef uint64_t	UInt64;/* Signatures used to differentiate between HFS and HFS Plus volumes */#define kHFSSigWord	(UInt16)0x4244	/* 'BD' in ASCII */#define BLOCKSIZE	512/* Master Directory Block (HFS only) - 162 bytes *//* Stored at sector #2 (3rd sector) */#pragma pack(2)struct HFSMasterDirectoryBlock {	union {		UInt16 		drSigWord;		/* volume signature */		UInt8		drSigWord_[2];	} u;			UInt32 		drCrDate;		/* date and time of volume creation */	UInt32 		drLsMod;		/* date and time of last modification */	UInt16 		drAtrb;			/* volume attributes */	SInt16 		drNmFls;		/* number of files in root folder */	UInt16 		drVBMSt;		/* first block of volume bitmap */	UInt16 		drAllocPtr;		/* start of next allocation search */	UInt16 		drNmAlBlks;		/* number of allocation blocks in volume */	SInt32 		drAlBlkSiz;		/* size (in bytes) of allocation blocks */	SInt32 		drClpSiz;		/* default clump size */	SInt16 		drAlBlSt;		/* first allocation block in volume */	UInt32 		drNxtCNID;		/* next unused catalog node ID */	SInt16 		drFreeBks;		/* number of unused allocation blocks */	char 		drVN[28];		/* volume name */	/* Master Directory Block extensions for HFS follow */	/* ... */};typedef struct HFSMasterDirectoryBlock	HFSMasterDirectoryBlock;#define hfsmagic(s)    ((UInt16) s.u.drSigWord_[1] + (((UInt16) s.u.drSigWord_[0]) << 8))int hfs_getlabel(int fd, char *label) {	HFSMasterDirectoryBlock mdb;	if (lseek(fd, 2*BLOCKSIZE, SEEK_SET) != 2*BLOCKSIZE	    || read(fd, (char *) &mdb, sizeof(mdb)) != sizeof(mdb)	    || (hfsmagic(mdb) != kHFSSigWord)) {		return 0;	}	strncpy(label, &mdb.drVN[1], (UInt8)mdb.drVN[0]);	label[(UInt8)mdb.drVN[0]] = '\0';	return 1;}

⌨️ 快捷键说明

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