This source file includes following definitions.
- ntfs_uncompblock
- ntfs_uncompunit
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 #include <sys/cdefs.h>
33 #ifdef __KERNEL_RCSID
34 __KERNEL_RCSID(0, "$NetBSD: ntfs_compr.c,v 1.1 2002/12/23 17:38:31 jdolecek Exp $");
35 #endif
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/namei.h>
40 #include <sys/proc.h>
41 #include <sys/kernel.h>
42 #include <sys/vnode.h>
43 #include <sys/mount.h>
44 #include <sys/buf.h>
45 #include <sys/file.h>
46 #include <sys/malloc.h>
47 #ifdef __FreeBSD__
48 #include <machine/clock.h>
49 #endif
50
51 #include <miscfs/specfs/specdev.h>
52
53 #if defined(__FreeBSD__) || defined(__NetBSD__)
54 #include <fs/ntfs/ntfs.h>
55 #include <fs/ntfs/ntfs_compr.h>
56 #else
57 #include <ntfs/ntfs.h>
58 #include <ntfs/ntfs_compr.h>
59 #endif
60
61 #define GET_UINT16(addr) (*((u_int16_t *)(addr)))
62
63 int
64 ntfs_uncompblock(
65 u_int8_t * buf,
66 u_int8_t * cbuf)
67 {
68 u_int32_t ctag;
69 int len, dshift, lmask;
70 int blen, boff;
71 int i, j;
72 int pos, cpos;
73
74 len = GET_UINT16(cbuf) & 0xFFF;
75 dprintf(("ntfs_uncompblock: block length: %d + 3, 0x%x,0x%04x\n",
76 len, len, GET_UINT16(cbuf)));
77
78 if (!(GET_UINT16(cbuf) & 0x8000)) {
79 if ((len + 1) != NTFS_COMPBLOCK_SIZE) {
80 dprintf(("ntfs_uncompblock: len: %x instead of %d\n",
81 len, 0xfff));
82 }
83 memcpy(buf, cbuf + 2, len + 1);
84 bzero(buf + len + 1, NTFS_COMPBLOCK_SIZE - 1 - len);
85 return len + 3;
86 }
87 cpos = 2;
88 pos = 0;
89 while ((cpos < len + 3) && (pos < NTFS_COMPBLOCK_SIZE)) {
90 ctag = cbuf[cpos++];
91 for (i = 0; (i < 8) && (pos < NTFS_COMPBLOCK_SIZE); i++) {
92 if (ctag & 1) {
93 for (j = pos - 1, lmask = 0xFFF, dshift = 12;
94 j >= 0x10; j >>= 1) {
95 dshift--;
96 lmask >>= 1;
97 }
98 boff = -1 - (GET_UINT16(cbuf + cpos) >> dshift);
99 blen = 3 + (GET_UINT16(cbuf + cpos) & lmask);
100 for (j = 0; (j < blen) && (pos < NTFS_COMPBLOCK_SIZE); j++) {
101 buf[pos] = buf[pos + boff];
102 pos++;
103 }
104 cpos += 2;
105 } else {
106 buf[pos++] = cbuf[cpos++];
107 }
108 ctag >>= 1;
109 }
110 }
111 return len + 3;
112 }
113
114 int
115 ntfs_uncompunit(
116 struct ntfsmount * ntmp,
117 u_int8_t * uup,
118 u_int8_t * cup)
119 {
120 int i;
121 int off = 0;
122 int new;
123
124 for (i = 0; i * NTFS_COMPBLOCK_SIZE < ntfs_cntob(NTFS_COMPUNIT_CL); i++) {
125 new = ntfs_uncompblock(uup + i * NTFS_COMPBLOCK_SIZE, cup + off);
126 if (new == 0)
127 return (EINVAL);
128 off += new;
129 }
130 return (0);
131 }