]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/drivetype.c
444837071124011ca9430d0e9fa381becb226597
[bacula/bacula] / bacula / src / findlib / drivetype.c
1 /*
2  *  Implement routines to determine drive type (Windows specific).
3  *
4  *   Written by Robert Nelson, June 2006
5  *
6  *   Version $Id$
7  */
8 /*
9    Bacula® - The Network Backup Solution
10
11    Copyright (C) 2006-2006 Free Software Foundation Europe e.V.
12
13    The main author of Bacula is Kern Sibbald, with contributions from
14    many others, a complete list can be found in the file AUTHORS.
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
33    Switzerland, email:ftf@fsfeurope.org.
34 */
35
36 #ifndef TEST_PROGRAM
37
38 #include "bacula.h"
39 #include "find.h"
40
41 #else /* Set up for testing a stand alone program */
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #define SUPPORTEDOSES \
47    "HAVE_WIN32\n"
48 #define false              0
49 #define true               1
50 #define bstrncpy           strncpy
51 #define Dmsg0(n,s)         fprintf(stderr, s)
52 #define Dmsg1(n,s,a1)      fprintf(stderr, s, a1)
53 #define Dmsg2(n,s,a1,a2)   fprintf(stderr, s, a1, a2)
54 #endif
55
56 /*
57  * These functions should be implemented for each OS
58  *
59  *       bool drivetype(const char *fname, char *dt, int dtlen);
60  */
61
62 #if defined (HAVE_WIN32)
63 /* Windows */
64
65 bool drivetype(const char *fname, char *dt, int dtlen)
66 {
67    CHAR rootpath[4];
68    UINT type;
69
70    /* Copy Drive Letter, colon, and backslash to rootpath */
71    bstrncpy(rootpath, fname, 3);
72    rootpath[3] = '\0';
73
74    type = GetDriveType(rootpath);
75
76    switch (type) {
77    case DRIVE_REMOVABLE:   bstrncpy(dt, "removable", dtlen);   return true;
78    case DRIVE_FIXED:       bstrncpy(dt, "fixed", dtlen);       return true;
79    case DRIVE_REMOTE:      bstrncpy(dt, "remote", dtlen);      return true;
80    case DRIVE_CDROM:       bstrncpy(dt, "cdrom", dtlen);       return true;
81    case DRIVE_RAMDISK:     bstrncpy(dt, "ramdisk", dtlen);     return true;
82    case DRIVE_UNKNOWN:
83    case DRIVE_NO_ROOT_DIR:
84    default:
85       return false;
86    }
87 }
88 /* Windows */
89
90 #else    /* No recognised OS */
91
92 bool drivetype(const char *fname, char *dt, int dtlen)
93 {
94    Dmsg0(10, "!!! drivetype() not implemented for this OS. !!!\n");
95 #ifdef TEST_PROGRAM
96    Dmsg1(10, "Please define one of the following when compiling:\n\n%s\n",
97          SUPPORTEDOSES);
98    exit(EXIT_FAILURE);
99 #endif
100
101    return false;
102 }
103 #endif
104
105 #ifdef TEST_PROGRAM
106 int main(int argc, char **argv)
107 {
108    char *p;
109    char dt[1000];
110    int status = 0;
111
112    if (argc < 2) {
113       p = (argc < 1) ? "drivetype" : argv[0];
114       printf("usage:\t%s path ...\n"
115             "\t%s prints the drive type and pathname of the paths.\n",
116             p, p);
117       return EXIT_FAILURE;
118    }
119    while (*++argv) {
120       if (!drivetype(*argv, dt, sizeof(dt))) {
121          status = EXIT_FAILURE;
122       } else {
123          printf("%s\t%s\n", dt, *argv);
124       }
125    }
126    return status;
127 }
128 #endif