1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
2 | * |
---|
3 | * Copyright (C) 2008 William Jon McCann <mccann@jhu.edu> |
---|
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 2 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, write to the Free Software |
---|
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | */ |
---|
19 | |
---|
20 | #include "config.h" |
---|
21 | |
---|
22 | #include <stdlib.h> |
---|
23 | #include <libintl.h> |
---|
24 | #include <locale.h> |
---|
25 | #include <string.h> |
---|
26 | #include <unistd.h> |
---|
27 | #include <signal.h> |
---|
28 | #include <errno.h> |
---|
29 | |
---|
30 | #include <glib/gi18n.h> |
---|
31 | #include <gio/gio.h> |
---|
32 | |
---|
33 | static char * |
---|
34 | get_filesystem_type (const char *path) |
---|
35 | { |
---|
36 | GFile *file; |
---|
37 | GFileInfo *file_info; |
---|
38 | GError *error; |
---|
39 | char *filesystem_type; |
---|
40 | |
---|
41 | file = g_file_new_for_path (path); |
---|
42 | error = NULL; |
---|
43 | file_info = g_file_query_filesystem_info (file, |
---|
44 | G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, |
---|
45 | NULL, |
---|
46 | &error); |
---|
47 | if (file_info == NULL) { |
---|
48 | g_warning ("Unable to query filesystem type: %s", error->message); |
---|
49 | g_error_free (error); |
---|
50 | g_object_unref (file); |
---|
51 | return NULL; |
---|
52 | } |
---|
53 | |
---|
54 | filesystem_type = g_strdup (g_file_info_get_attribute_string (file_info, |
---|
55 | G_FILE_ATTRIBUTE_FILESYSTEM_TYPE)); |
---|
56 | |
---|
57 | g_object_unref (file); |
---|
58 | g_object_unref (file_info); |
---|
59 | |
---|
60 | return filesystem_type; |
---|
61 | } |
---|
62 | |
---|
63 | static void |
---|
64 | print_fstype (char **paths) |
---|
65 | { |
---|
66 | int i; |
---|
67 | |
---|
68 | i = 0; |
---|
69 | while (paths[i] != NULL) { |
---|
70 | char *fstype; |
---|
71 | fstype = get_filesystem_type (paths[i]); |
---|
72 | g_print ("%s is %s\n", paths[i], fstype); |
---|
73 | g_free (fstype); |
---|
74 | i++; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | int |
---|
79 | main (int argc, char *argv[]) |
---|
80 | { |
---|
81 | GOptionContext *ctx; |
---|
82 | char **paths = NULL; |
---|
83 | GOptionEntry options[] = { |
---|
84 | {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &paths, NULL}, |
---|
85 | {NULL} |
---|
86 | }; |
---|
87 | |
---|
88 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
---|
89 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
---|
90 | textdomain (GETTEXT_PACKAGE); |
---|
91 | |
---|
92 | setlocale (LC_ALL, ""); |
---|
93 | |
---|
94 | g_type_init (); |
---|
95 | |
---|
96 | /* Option parsing */ |
---|
97 | ctx = g_option_context_new ("- Test filesystem type"); |
---|
98 | g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); |
---|
99 | g_option_context_parse (ctx, &argc, &argv, NULL); |
---|
100 | g_option_context_free (ctx); |
---|
101 | |
---|
102 | if (paths != NULL) { |
---|
103 | print_fstype (paths); |
---|
104 | |
---|
105 | g_strfreev (paths); |
---|
106 | } |
---|
107 | |
---|
108 | return 0; |
---|
109 | } |
---|