]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/drivetype.c
Tweak remove SVN Version line
[bacula/bacula] / bacula / src / findlib / drivetype.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2006-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  *  Implement routines to determine drive type (Windows specific).
22  *
23  *   Written by Robert Nelson, June 2006
24  *
25  */
26
27 #ifndef TEST_PROGRAM
28
29 #include "bacula.h"
30 #include "find.h"
31
32 #else /* Set up for testing a stand alone program */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #define SUPPORTEDOSES \
38    "HAVE_WIN32\n"
39 #define false              0
40 #define true               1
41 #define bstrncpy           strncpy
42 #define Dmsg0(n,s)         fprintf(stderr, s)
43 #define Dmsg1(n,s,a1)      fprintf(stderr, s, a1)
44 #define Dmsg2(n,s,a1,a2)   fprintf(stderr, s, a1, a2)
45 #endif
46
47 /*
48  * These functions should be implemented for each OS
49  *
50  *       bool drivetype(const char *fname, char *dt, int dtlen);
51  */
52
53 #if defined (HAVE_WIN32)
54 /* Windows */
55
56 bool drivetype(const char *fname, char *dt, int dtlen)
57 {
58    CHAR rootpath[4];
59    UINT type;
60
61    /* Copy Drive Letter, colon, and backslash to rootpath */
62    bstrncpy(rootpath, fname, 3);
63    rootpath[3] = '\0';
64
65    type = GetDriveType(rootpath);
66
67    switch (type) {
68    case DRIVE_REMOVABLE:   bstrncpy(dt, "removable", dtlen);   return true;
69    case DRIVE_FIXED:       bstrncpy(dt, "fixed", dtlen);       return true;
70    case DRIVE_REMOTE:      bstrncpy(dt, "remote", dtlen);      return true;
71    case DRIVE_CDROM:       bstrncpy(dt, "cdrom", dtlen);       return true;
72    case DRIVE_RAMDISK:     bstrncpy(dt, "ramdisk", dtlen);     return true;
73    case DRIVE_UNKNOWN:
74    case DRIVE_NO_ROOT_DIR:
75    default:
76       return false;
77    }
78 }
79 /* Windows */
80
81 #else    /* No recognised OS */
82
83 bool drivetype(const char *fname, char *dt, int dtlen)
84 {
85    Dmsg0(10, "!!! drivetype() not implemented for this OS. !!!\n");
86 #ifdef TEST_PROGRAM
87    Dmsg1(10, "Please define one of the following when compiling:\n\n%s\n",
88          SUPPORTEDOSES);
89    exit(EXIT_FAILURE);
90 #endif
91
92    return false;
93 }
94 #endif
95
96 #ifdef TEST_PROGRAM
97 int main(int argc, char **argv)
98 {
99    char *p;
100    char dt[1000];
101    int status = 0;
102
103    if (argc < 2) {
104       p = (argc < 1) ? "drivetype" : argv[0];
105       printf("usage:\t%s path ...\n"
106             "\t%s prints the drive type and pathname of the paths.\n",
107             p, p);
108       return EXIT_FAILURE;
109    }
110    while (*++argv) {
111       if (!drivetype(*argv, dt, sizeof(dt))) {
112          status = EXIT_FAILURE;
113       } else {
114          printf("%s\t%s\n", dt, *argv);
115       }
116    }
117    return status;
118 }
119 #endif