1 /*
2  * support.h - Header file for specific support.c
3  *
4  * Copyright (C) 1997 R�gis Duchesne
5  * Copyright (c) 2001 Anton Altaparmakov (AIA)
6  */
7 
8 /* Debug levels */
9 #define DEBUG_OTHER	1
10 #define DEBUG_MALLOC	2
11 #define DEBUG_BSD       4
12 #define DEBUG_LINUX     8
13 #define DEBUG_DIR1     16
14 #define DEBUG_DIR2     32
15 #define DEBUG_DIR3     64
16 #define DEBUG_FILE1   128
17 #define DEBUG_FILE2   256
18 #define DEBUG_FILE3   512
19 #define DEBUG_NAME1  1024
20 #define DEBUG_NAME2  2048
21 
22 #ifdef DEBUG
23 void ntfs_debug(int mask, const char *fmt, ...);
24 #else
25 #define ntfs_debug(mask, fmt...)	do {} while (0)
26 #endif
27 
28 #include <linux/slab.h>
29 #include <linux/vmalloc.h>
30 
31 #define ntfs_malloc(size)  kmalloc(size, GFP_KERNEL)
32 
33 #define ntfs_free(ptr)     kfree(ptr)
34 
35 /**
36  * ntfs_vmalloc - allocate memory in multiples of pages
37  * @size	number of bytes to allocate
38  *
39  * Allocates @size bytes of memory, rounded up to multiples of PAGE_SIZE and
40  * returns a pointer to the allocated memory.
41  *
42  * If there was insufficient memory to complete the request, return NULL.
43  */
ntfs_vmalloc(unsigned long size)44 static inline void *ntfs_vmalloc(unsigned long size)
45 {
46 	if (size <= PAGE_SIZE) {
47 		if (size) {
48 			/* kmalloc() has per-CPU caches so if faster for now. */
49 			return kmalloc(PAGE_SIZE, GFP_NOFS);
50 			/* return (void *)__get_free_page(GFP_NOFS |
51 					__GFP_HIGHMEM); */
52 		}
53 		BUG();
54 	}
55 	if (size >> PAGE_SHIFT < num_physpages)
56 		return __vmalloc(size, GFP_NOFS | __GFP_HIGHMEM, PAGE_KERNEL);
57 	return NULL;
58 }
59 
ntfs_vfree(void * addr)60 static inline void ntfs_vfree(void *addr)
61 {
62 	if ((unsigned long)addr < VMALLOC_START) {
63 		return kfree(addr);
64 		/* return free_page((unsigned long)addr); */
65 	}
66 	vfree(addr);
67 }
68 
69 void ntfs_bzero(void *s, int n);
70 
71 void ntfs_memcpy(void *dest, const void *src, ntfs_size_t n);
72 
73 void ntfs_memmove(void *dest, const void *src, ntfs_size_t n);
74 
75 void ntfs_error(const char *fmt,...);
76 
77 int ntfs_read_mft_record(ntfs_volume *vol, int mftno, char *buf);
78 
79 int ntfs_getput_clusters(ntfs_volume *pvol, int cluster, ntfs_size_t offs,
80 			 ntfs_io *buf);
81 
82 ntfs_time64_t ntfs_now(void);
83 
84 int ntfs_dupuni2map(ntfs_volume *vol, ntfs_u16 *in, int in_len, char **out,
85 		    int *out_len);
86 
87 int ntfs_dupmap2uni(ntfs_volume *vol, char* in, int in_len, ntfs_u16 **out,
88 		    int *out_len);
89 
90