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

📄 getlabel.iso9660.c

📁 linux下的一个mount工具
💻 C
字号:
/* * $Id: getlabel.iso9660.c,v 1.1.1.1 2000/09/13 19:36:43 lyonel Exp $ * * based on isoinfo.c by Steffen Solyga <solyga@tetibm3.ee.tu-berlin.de> * * Copyright (C) 2000 Lyonel Vincent <vincentl@ec-lyon.fr> *  * 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 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., 675 Mass Ave, Cambridge, MA 02139, USA. */#undef	DEBUG#include <unistd.h>		/* read(), write(), close(), STDIN_FILENO */#include <sys/types.h>		/* open() */#include <sys/stat.h>		/* open() */#include <fcntl.h>		/* open(), O_RDONLY */#include <linux/ioctl.h>	/* ioctl() */#include <linux/cdrom.h>	/* multisession handling*/#include "iso_fs.h"		/* iso9660 structures & definitions (mkisofs)*/#define	ISO_BLOCK_SIZE	2048#define	ISO_PD_BLOCK	16			/* PD = primary desciptor */#define	ISO_STR( A )	iso_str( (A), sizeof(A) )static unsigned int isofs_get_last_session(int fd){	struct cdrom_multisession ms_info;	unsigned int vol_desc_start = 0;	if(ioctl(fd, CDROMMULTISESSION, &ms_info)==0)		if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */			vol_desc_start=ms_info.addr.lba;	return vol_desc_start;}static longiso_num_733( char* p ) {  return(   (p[0] & 0xffL)          | (p[1] & 0xffL) <<  8          | (p[2] & 0xffL) << 16          | (p[3] & 0xffL) << 24 );}intisonum_711 (char * p){        return (*p & 0xff);}static char*iso_str( char* p, int n ) {  static char string[256];  int i= 0;  while( i < n ) string[i]= p[i++];  string[i--]= '\0';  while( string[i] == ' ' ) string[i--]= '\0';  return( string );}int iso9660_getlabel(int in_fd, char * label){	int result=0;	unsigned int iso_blknum;	unsigned int vol_desc_start;	vol_desc_start = isofs_get_last_session(in_fd);	for (iso_blknum=vol_desc_start+ISO_PD_BLOCK; iso_blknum<vol_desc_start+100; iso_blknum++)	{		char buffer[ISO_BLOCK_SIZE];		struct hs_volume_descriptor   * hdp;		struct iso_volume_descriptor  * vdp;		if(lseek(in_fd,iso_blknum*ISO_BLOCK_SIZE,SEEK_SET) == -1)			break;  		if(read(in_fd,&buffer,sizeof(buffer)) != sizeof(buffer))			break;		vdp = (struct iso_volume_descriptor *)buffer;		hdp = (struct hs_volume_descriptor *)buffer;		/* first we test for ISO9660 */		if(strncmp(vdp->id, ISO_STANDARD_ID, sizeof(vdp->id)) == 0)		{			if(isonum_711(vdp->type) == ISO_VD_END)				break;			if(isonum_711(vdp->type) == ISO_VD_PRIMARY)			{				struct iso_primary_descriptor *pri = NULL;								pri = (struct iso_primary_descriptor *)vdp;				strcpy(label, ISO_STR(pri->volume_id) );				result = 1;				break;			}		}		else	/* now we test for High Sierra */		if(strncmp(hdp->id, HS_STANDARD_ID, sizeof(hdp->id)) == 0)		{			struct hs_primary_descriptor * pri = NULL;			if(isonum_711(hdp->type) != ISO_VD_PRIMARY)				break;			pri = (struct hs_primary_descriptor *)vdp;			strcpy(label, ISO_STR(pri->volume_id) );			result = 1;			break;		}	}	return result;}

⌨️ 快捷键说明

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