]> cygwin.com Git - cygwin-apps/setup.git/blob - mount.cc
* Replace everything with a new GUI version
[cygwin-apps/setup.git] / mount.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 /* The purpose of this file is to hide all the details about accessing
17 Cygwin's mount table. If the format or location of the mount table
18 changes, this is the file to change to match it. */
19
20 #include "win32.h"
21
22 #include <stdio.h>
23 #include "../cygwin/include/cygwin/version.h"
24 #include "../cygwin/include/sys/mount.h"
25
26 #include "mount.h"
27 #include "msg.h"
28 #include "resource.h"
29 #include "dialog.h"
30
31
32 static char *
33 find2 (HKEY rkey, int *istext)
34 {
35 char buf[1000];
36 char *retval = 0;
37 HKEY key;
38 DWORD retvallen = 0;
39 DWORD flags = 0;
40 DWORD type;
41
42 sprintf (buf, "Software\\%s\\%s\\%s\\/",
43 CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
44 CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
45 CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME);
46
47 if (RegOpenKeyEx (rkey, buf, 0, KEY_READ, &key) != ERROR_SUCCESS)
48 return 0;
49
50 if (RegQueryValueEx (key, "native", 0, &type, 0, &retvallen)
51 == ERROR_SUCCESS)
52 {
53 retval = new char[retvallen+1];
54 if (RegQueryValueEx (key, "native", 0, &type, (BYTE *)retval, &retvallen)
55 != ERROR_SUCCESS)
56 {
57 delete retval;
58 retval = 0;
59 }
60 }
61
62 retvallen = sizeof (flags);
63 RegQueryValueEx (key, "flags", 0, &type, (BYTE *)&flags, &retvallen);
64
65 RegCloseKey (key);
66
67 if (retval)
68 *istext = (flags & MOUNT_BINARY) ? 0 : 1;
69 return retval;
70 }
71
72 char *
73 find_root_mount (int *istext)
74 {
75 char *rv;
76 if (rv = find2 (HKEY_CURRENT_USER, istext))
77 return rv;
78 return find2 (HKEY_LOCAL_MACHINE, istext);
79 }
80
81 void
82 create_mount (char *posix, char *win32, int istext)
83 {
84 char buf[1000];
85 char *retval = 0;
86 HKEY key;
87 DWORD retvallen = 0, disposition;
88 DWORD flags;
89
90 remove_mount (posix);
91
92 sprintf (buf, "Software\\%s\\%s\\%s\\%s",
93 CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
94 CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
95 CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
96 posix);
97
98 if (RegCreateKeyEx (HKEY_CURRENT_USER, buf, 0, "Cygwin", 0, KEY_ALL_ACCESS,
99 0, &key, &disposition) != ERROR_SUCCESS)
100 fatal ("mount");
101
102 RegSetValueEx (key, "native", 0, REG_SZ, (BYTE *)win32, strlen (win32)+1);
103 if (istext)
104 flags = 0;
105 else
106 flags = MOUNT_BINARY;
107 RegSetValueEx (key, "flags", 0, REG_DWORD, (BYTE *)&flags, sizeof (flags));
108 }
109
110 static void
111 remove1 (HKEY rkey, char *posix)
112 {
113 char buf[1000];
114
115 sprintf (buf, "Software\\%s\\%s\\%s\\%s",
116 CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
117 CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
118 CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
119 posix);
120
121 RegDeleteKey (rkey, buf);
122 }
123
124 void
125 remove_mount (char *posix)
126 {
127 remove1 (HKEY_LOCAL_MACHINE, posix);
128 remove1 (HKEY_CURRENT_USER, posix);
129 }
This page took 0.040525 seconds and 5 git commands to generate.