File: support.c

package info (click to toggle)
ntfs 971218-4
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 692 kB
  • ctags: 670
  • sloc: ansic: 7,774; sh: 1,509; makefile: 232
file content (144 lines) | stat: -rw-r--r-- 2,733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 *  support.c
 *  Specific support functions
 *
 *  Copyright (C) 1997 Rgis Duchesne
 */

#include "types.h"
#include "struct.h"
#include "support.h"

#include <stdlib.h>
/* Solaris defines bzero() here */
#include <strings.h>
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include "inode.h"
#include "nttools.h"
#include "macros.h"
#include "util.h"

void ntfs_debug(int mask, const char *fmt, ...)
{
}

void *ntfs_malloc(int size)
{
    return malloc(size);
}

void ntfs_free(void *block)
{
    free(block);
}

void ntfs_bzero(void *s, int n)
{
    bzero(s, n);
}

void *ntfs_memcpy(void *dest, const void *src, ntfs_size_t n)
{
	return memcpy(dest, src, n);
}

void *ntfs_memmove(void *dest, const void *src, ntfs_size_t n)
{
	return memmove(dest, src, n);
}

/* Warn that an error occured */
void ntfs_error(const char *fmt,...)
{
        va_list ap;

        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
        va_end(ap);
        fputs("", stderr);
}

int ntfs_read_mft_record(ntfs_volume *vol, int mftno, char *buf)
{
	ntfs_io io;
	int error;

	io.fn_put=0;
	io.fn_get=0;
	/* record 0 of file 0 is always in memory */
	if(mftno==0)
	{
		memcpy(buf,vol->mft,vol->mft_recordsize);
		return 0;
	}
	if(!vol->mft_ino)
	{
		fprintf(stderr,"Cannot load mft %x without mft 0\n",mftno);
		return ENODATA;
	}
	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(error)return error;
	if(io.size!=vol->mft_recordsize)return ENODATA;
	if(!ntfs_check_mft_record(vol,buf))
	{
		fprintf(stderr,"Inode not found\n");
		return EINVAL;
	}
	return 0;
}

/* pmemcpy is ignored here */
int ntfs_getput_clusters(ntfs_volume *pvol, int cluster, ntfs_size_t offs,
	ntfs_io *buf)
{
	int result;
	if(ntfs_lseek(NTFS_FD(pvol),
		      pvol->partition_bias+cluster*pvol->clustersize+offs,
		      SEEK_SET)==-1)
		return 0;
	/* MAGIC: We *know* at this place that we were originally passed a plain
	   pointer */
	if(buf->do_read)
		result=read(NTFS_FD(pvol),buf->param,buf->size);
	else
		result=write(NTFS_FD(pvol),buf->param,buf->size);
	if(result==buf->size){
		/* increment target pointer */
		buf->param+=buf->size;
		return 0;
	}
	if(result==-1)return errno;
	return EIO;
}

ntfs_time64_t ntfs_now(void)
{
	return ntfs_unixutc2ntutc(time(0));
}

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:
 */