]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
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 | ||
8507f105 DD |
20 | static char *cvsid = "\n%%% $Id$\n"; |
21 | ||
23c9e63c DD |
22 | #include "win32.h" |
23 | ||
24 | #include <stdio.h> | |
25 | #include "../cygwin/include/cygwin/version.h" | |
26 | #include "../cygwin/include/sys/mount.h" | |
27 | ||
28 | #include "mount.h" | |
29 | #include "msg.h" | |
30 | #include "resource.h" | |
31 | #include "dialog.h" | |
32 | ||
33 | ||
34 | static char * | |
35 | find2 (HKEY rkey, int *istext) | |
36 | { | |
37 | char buf[1000]; | |
38 | char *retval = 0; | |
39 | HKEY key; | |
40 | DWORD retvallen = 0; | |
41 | DWORD flags = 0; | |
42 | DWORD type; | |
43 | ||
44 | sprintf (buf, "Software\\%s\\%s\\%s\\/", | |
45 | CYGWIN_INFO_CYGNUS_REGISTRY_NAME, | |
46 | CYGWIN_INFO_CYGWIN_REGISTRY_NAME, | |
47 | CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME); | |
48 | ||
49 | if (RegOpenKeyEx (rkey, buf, 0, KEY_READ, &key) != ERROR_SUCCESS) | |
50 | return 0; | |
51 | ||
52 | if (RegQueryValueEx (key, "native", 0, &type, 0, &retvallen) | |
53 | == ERROR_SUCCESS) | |
54 | { | |
55 | retval = new char[retvallen+1]; | |
56 | if (RegQueryValueEx (key, "native", 0, &type, (BYTE *)retval, &retvallen) | |
57 | != ERROR_SUCCESS) | |
58 | { | |
59 | delete retval; | |
60 | retval = 0; | |
61 | } | |
62 | } | |
63 | ||
64 | retvallen = sizeof (flags); | |
65 | RegQueryValueEx (key, "flags", 0, &type, (BYTE *)&flags, &retvallen); | |
66 | ||
67 | RegCloseKey (key); | |
68 | ||
69 | if (retval) | |
70 | *istext = (flags & MOUNT_BINARY) ? 0 : 1; | |
71 | return retval; | |
72 | } | |
73 | ||
74 | char * | |
24e259bb | 75 | find_root_mount (int *istext, int *issystem) |
23c9e63c DD |
76 | { |
77 | char *rv; | |
78 | if (rv = find2 (HKEY_CURRENT_USER, istext)) | |
24e259bb DD |
79 | { |
80 | *issystem = 0; | |
81 | return rv; | |
82 | } | |
83 | if (rv = find2 (HKEY_LOCAL_MACHINE, istext)) | |
84 | { | |
85 | *issystem = 1; | |
86 | return rv; | |
87 | } | |
88 | return 0; | |
23c9e63c DD |
89 | } |
90 | ||
91 | void | |
24e259bb | 92 | create_mount (char *posix, char *win32, int istext, int issystem) |
23c9e63c DD |
93 | { |
94 | char buf[1000]; | |
95 | char *retval = 0; | |
96 | HKEY key; | |
97 | DWORD retvallen = 0, disposition; | |
98 | DWORD flags; | |
99 | ||
100 | remove_mount (posix); | |
101 | ||
102 | sprintf (buf, "Software\\%s\\%s\\%s\\%s", | |
103 | CYGWIN_INFO_CYGNUS_REGISTRY_NAME, | |
104 | CYGWIN_INFO_CYGWIN_REGISTRY_NAME, | |
105 | CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, | |
106 | posix); | |
107 | ||
24e259bb DD |
108 | msg ("mount: istext=%d issystem=%d\n", istext, issystem); |
109 | HKEY kr = issystem ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
110 | if (RegCreateKeyEx (kr, buf, 0, "Cygwin", 0, KEY_ALL_ACCESS, | |
23c9e63c DD |
111 | 0, &key, &disposition) != ERROR_SUCCESS) |
112 | fatal ("mount"); | |
113 | ||
114 | RegSetValueEx (key, "native", 0, REG_SZ, (BYTE *)win32, strlen (win32)+1); | |
24e259bb DD |
115 | flags = 0; |
116 | if (!istext) | |
117 | flags |= MOUNT_BINARY; | |
118 | if (issystem) | |
119 | flags |= MOUNT_SYSTEM; | |
23c9e63c DD |
120 | RegSetValueEx (key, "flags", 0, REG_DWORD, (BYTE *)&flags, sizeof (flags)); |
121 | } | |
122 | ||
123 | static void | |
124 | remove1 (HKEY rkey, char *posix) | |
125 | { | |
126 | char buf[1000]; | |
127 | ||
128 | sprintf (buf, "Software\\%s\\%s\\%s\\%s", | |
129 | CYGWIN_INFO_CYGNUS_REGISTRY_NAME, | |
130 | CYGWIN_INFO_CYGWIN_REGISTRY_NAME, | |
131 | CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, | |
132 | posix); | |
133 | ||
134 | RegDeleteKey (rkey, buf); | |
135 | } | |
136 | ||
137 | void | |
138 | remove_mount (char *posix) | |
139 | { | |
140 | remove1 (HKEY_LOCAL_MACHINE, posix); | |
141 | remove1 (HKEY_CURRENT_USER, posix); | |
142 | } |