http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200307311516.tar.bz2
[ntfsprogs.git] / ntfsprogs / utils.h
1 /*
2  * utils.h - Part of the Linux-NTFS project.
3  *
4  * Copyright (c) 2002 Richard Russon
5  *
6  * A set of shared functions for ntfs utilities
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program (in the main directory of the Linux-NTFS
20  * distribution in the file COPYING); if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #ifndef _NTFS_UTILS_H_
25 #define _NTFS_UTILS_H_
26
27 #include "types.h"
28 #include "layout.h"
29 #include "volume.h"
30
31 #include <errno.h>
32 #include <stdarg.h>
33
34 extern const char *ntfs_bugs;
35 extern const char *ntfs_home;
36 extern const char *ntfs_gpl;
37
38 #define PATH_SEP        '/'
39
40 #define GEN_PRINTF(NAME, STREAM, CONTROL, TRIGGER)                              \
41         __attribute__ ((format (printf, 1, 2)))                                 \
42         int NAME (const char *format, ...)                                      \
43         {                                                                       \
44                 int ret, olderr = errno, *control = (CONTROL);                  \
45                 va_list args;                                                   \
46                                                                                 \
47                 if (!(STREAM))                                                  \
48                         return -1;                                              \
49                 if (control &&                                                  \
50                    ((*control && !(TRIGGER)) || (!*control && (TRIGGER))))      \
51                         return -1;                                              \
52                                                                                 \
53                 va_start (args, format);                                        \
54                 ret = vfprintf ((STREAM), format, args);                        \
55                 va_end (args);                                                  \
56                 errno = olderr;                                                 \
57                 return ret;                                                     \
58         }
59
60 struct _IO_FILE;
61
62 int ntfs_printf (struct _IO_FILE *stream, int *control, BOOL trigger,
63                 const char *format, ...) __attribute__ ((format (printf, 4, 5)));
64
65 int utils_valid_device (const char *name, int force);
66 int utils_set_locale (void);
67 ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL force);
68 int utils_parse_size (const char *value, s64 *size, BOOL scale);
69 int utils_parse_range (const char *string, s64 *start, s64 *finish, BOOL scale);
70 int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize);
71 int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int bufsize);
72 int utils_cluster_in_use (ntfs_volume *vol, long long lcn);
73 int utils_mftrec_in_use (ntfs_volume *vol, MFT_REF mref);
74
75 time_t ntfs2utc (s64 time);
76 s64 utc2ntfs (time_t time);
77
78 ATTR_RECORD * find_attribute (const ATTR_TYPES type, ntfs_attr_search_ctx *ctx);
79 ATTR_RECORD * find_first_attribute (const ATTR_TYPES type, MFT_RECORD *mft);
80
81 #endif /* _NTFS_UTILS_H_ */