]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/drivetype.c
Switch from GPLv2 to AGPLv3
[bacula/bacula] / bacula / src / findlib / drivetype.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2006-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *  Implement routines to determine drive type (Windows specific).
30  *
31  *   Written by Robert Nelson, June 2006
32  *
33  *   Version $Id$
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