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

📄 support.c

📁 一个linux下NTFS文件格式源代码
💻 C
字号:
/* *  support.c *  Specific support functions * *  Copyright (C) 1997 Martin von L鰓is *//* for va_* macros */#include <stdarg.h>#include <sys/param.h>#include <sys/types.h>#include <sys/malloc.h>#include <sys/buf.h>/* bzero is a pointer! */#include <sys/systm.h>#include <sys/syslog.h>#include <sys/sysctl.h>#include "ntfstypes.h"#include "struct.h"#include "macros.h"#include "util.h"#include "support.h"#include "inode.h"static int ntdebug=DEBUG_BSD|DEBUG_OTHER;#define DEBUG_NTFSDEBUG 1SYSCTL_INT(_vfs,OID_AUTO,ntfsdebug,CTLFLAG_RW,&ntdebug,0,"");static int debug_to_console=0;static char dbuf[2000];void ntfs_debug(int mask,const char *s,...){	if(mask & ntdebug){		va_list ap;		va_start(ap,s);		if(debug_to_console)			vprintf(s,ap);		else{			int len;			/*FIXME: buffer size*/			len=kvprintf(s,0,dbuf,10,ap);			dbuf[len]='\0';			log(LOG_DEBUG,"%s",dbuf);		}		va_end(ap);	}}void ntfs_error(const char *s,...){	va_list ap;	va_start(ap,s);	vprintf(s,ap);	va_end(ap);}void *ntfs_malloc(int size){	void *ret;	MALLOC(ret,void*,size,M_TEMP,M_WAITOK);	ntfs_debug(DEBUG_MALLOC,"Allocating %x at %x\n",size,(unsigned)ret);	return ret;}void ntfs_free(void *block){	ntfs_debug(DEBUG_MALLOC,"Releasing memory at %x\n",(unsigned)block);	FREE(block,M_TEMP);}/* support functions */void ntfs_memcpy(void*dest,const void*src,size_t len){	memcpy(dest,src,len);}void ntfs_bzero(void *dest,int n){	bzero(dest,n);}int ntfs_strlen(char*s){	return strlen(s);}void ntfs_memmove(void *dest, const void *src, ntfs_size_t n){	bcopy(src, dest, n);}int ntfs_getput_clusters(ntfs_volume *vol,int cluster,			 ntfs_size_t start_offs,ntfs_io *buf){	struct mount* mnt=NTFS_MNT(vol);	struct buf* bp=NULL;	int error;	int length=buf->size;	int last;	/*round up to multiple of block size */	last=(start_offs+length + DEV_BSIZE - 1) & ~(DEV_BSIZE-1);	/*FIXME: transfers larger than BLKDEV_IOSIZE */	error=bread(vol->devvp,cluster*vol->clusterfactor,last,NOCRED, &bp);	if(error)	{		printf("%s failed with %d\n", buf->do_read?"Reading":"Writing",error);		if(bp)			brelse(bp);		return EIO;	}	if(buf->do_read)		buf->fn_put(buf,bp->b_data+start_offs,length);	else	{		printf("Writing not supported\n");	}	brelse(bp);	return 0;}int ntfs_read_mft_record(ntfs_volume *vol,int mftno,char *buf){	ntfs_io io;	int error;	if(mftno==FILE_MFT)	{		memcpy(buf,vol->mft,vol->mft_recordsize);		return 0;	}	if(!vol->mft_ino)	{		printf("ntfs:something is terribly wrong here\n");		return EINVAL;	}	io.fn_put=ntfs_put;	io.fn_get=0;	io.param=buf;	io.size=vol->mft_recordsize;	error=ntfs_read_attr(vol->mft_ino,vol->at_data,NULL,			     mftno*vol->mft_recordsize,&io);	if(io.size!=vol->mft_recordsize)	{		printf("read_mft_record: read %x failed\n",mftno);		return error?error:EIO;	}	if(!ntfs_check_mft_record(vol,buf))	{		printf("Invalid MFT record for %x\n",mftno);		return EINVAL;	}	return 0;}ntfs_time64_t ntfs_now(){	struct timeval atv;	ntfs_time64_t result;	microtime(&atv);	/* seconds since 1.1.1601 */	result = atv.tv_sec + ((ntfs_time64_t)(369*365+89))*24*3600;	/* microseconds */	result *= 1000000;	result += atv.tv_usec;	/* 100 nanoseconds */	return 10*result;}int ntfs_dupuni2map(ntfs_volume *vol, ntfs_u16 *in, int in_len, char **out,        int *out_len){	/* Not supported here */	return EINVAL;}int ntfs_dupmap2uni(ntfs_volume *vol, char* in, int in_len, ntfs_u16 **out,        int *out_len){	/* Not supported here */	return EINVAL;}/* * Local variables: * c-file-style: "linux" * End: */

⌨️ 快捷键说明

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