OSDN Git Service

da69497f7f463640022ef29464484da75ab66b2c
[android-x86/external-parted.git] / libparted / fs / ntfs / ntfs.c
1 /*
2     libparted - a library for manipulating disk partitions
3     Copyright (C) 2000, 2007, 2009-2011 Free Software Foundation, Inc.
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 3 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <config.h>
20
21 #include <parted/parted.h>
22 #include <parted/endian.h>
23
24 #if ENABLE_NLS
25 #  include <libintl.h>
26 #  define _(String) dgettext (PACKAGE, String)
27 #else
28 #  define _(String) (String)
29 #endif /* ENABLE_NLS */
30
31 #include <unistd.h>
32
33 #define NTFS_BLOCK_SIZES       ((int[2]){512, 0})
34
35 #define NTFS_SIGNATURE  "NTFS"
36
37 static PedGeometry*
38 ntfs_probe (PedGeometry* geom)
39 {
40         char    buf[512];
41
42         if (!ped_geometry_read (geom, buf, 0, 1))
43                 return 0;
44
45         if (strncmp (NTFS_SIGNATURE, buf + 3, strlen (NTFS_SIGNATURE)) == 0)
46                 return ped_geometry_new (geom->dev, geom->start,
47                                          PED_LE64_TO_CPU (*(uint64_t*)
48                                                           (buf + 0x28)));
49         else
50                 return NULL;
51 }
52
53 static PedFileSystemOps ntfs_ops = {
54         probe:          ntfs_probe,
55 };
56
57 static PedFileSystemType ntfs_type = {
58         next:   NULL,
59         ops:    &ntfs_ops,
60         name:   "ntfs",
61         block_sizes: NTFS_BLOCK_SIZES
62 };
63
64 void
65 ped_file_system_ntfs_init ()
66 {
67         ped_file_system_type_register (&ntfs_type);
68 }
69
70 void
71 ped_file_system_ntfs_done ()
72 {
73         ped_file_system_type_unregister (&ntfs_type);
74 }