]>
sourceware.org Git - newlib-cygwin.git/blob - winsup/utils/mount.cc
3 Copyright 1996, 1997, 1998, 1999 Cygnus Solutions.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
12 #include <sys/mount.h>
16 #include <sys/cygwin.h>
25 static void show_mounts (void);
26 static void change_cygdrive_prefix (const char *new_prefix
, int flags
);
27 static int mount_already_exists (const char *posix_path
, int flags
);
29 // static short create_missing_dirs = FALSE;
30 static short force
= FALSE
;
32 static const char *progname
;
34 /* FIXME: do_mount should also print a warning message if the dev arg
35 is a non-existent Win32 path. */
38 do_mount (const char *dev
, const char *where
, int flags
)
41 char win32_path
[MAX_PATH
];
44 cygwin_conv_to_win32_path (where
, win32_path
);
46 statres
= stat (win32_path
, &statbuf
);
51 /* FIXME: this'll fail if mount dir is missing any parent dirs */
52 if (create_missing_dirs
== TRUE
)
54 if (mkdir (where
, 0755) == -1)
55 fprintf (stderr
, "Warning: unable to create %s!\n", where
);
57 statres
= 0; /* Pretend stat succeeded if we could mkdir. */
62 if (mount (dev
, where
, flags
))
64 perror ("mount failed");
71 fprintf (stderr
, "%s: warning - %s does not exist.\n", progname
, where
);
73 else if (!(statbuf
.st_mode
& S_IFDIR
))
76 fprintf (stderr
, "%s: warning: %s is not a directory!\n", progname
, where
);
85 fprintf (stderr
, "usage %s [-bfstux] <win32path> <posixpath>
86 -b text files are equivalent to binary files (newline = \\n)
87 -f force mount, don't warn about missing mount point directories
88 -s add mount point to system-wide registry location
89 -t text files get \\r\\n line endings (default)
90 -u add mount point to user registry location (default)
91 -x treat all files under mount point as executables
93 [-bs] --change-cygdrive-prefix <posixpath>
94 change the cygdrive path prefix to <posixpath>
96 copy old registry mount table mounts into the current mount areas
102 main (int argc
, const char **argv
)
115 for (i
= 1; i
< argc
; ++i
)
117 if (argv
[i
][0] != '-')
120 if (strcmp (argv
[i
], "--change-cygdrive-prefix") == 0)
125 change_cygdrive_prefix (argv
[i
+1], flags
);
127 else if (strcmp (argv
[i
], "--import-old-mounts") == 0)
132 cygwin_internal (CW_READ_V1_MOUNT_TABLES
);
135 else if (strcmp (argv
[i
], "-b") == 0)
136 flags
|= MOUNT_BINARY
;
137 else if (strcmp (argv
[i
], "-t") == 0)
138 flags
&= ~MOUNT_BINARY
;
139 else if (strcmp (argv
[i
], "-X") == 0)
140 flags
|= MOUNT_CYGWIN_EXEC
;
142 else if (strcmp (argv
[i
], "-x") == 0)
143 create_missing_dirs
= TRUE
;
145 else if (strcmp (argv
[i
], "-s") == 0)
146 flags
|= MOUNT_SYSTEM
;
147 else if (strcmp (argv
[i
], "-u") == 0)
148 flags
&= ~MOUNT_SYSTEM
;
149 else if (strcmp (argv
[i
], "-x") == 0)
151 else if (strcmp (argv
[i
], "-f") == 0)
160 if ((force
== FALSE
) && (mount_already_exists (argv
[i
+ 1], flags
)))
163 perror ("mount failed");
167 do_mount (argv
[i
], argv
[i
+ 1], flags
);
176 FILE *m
= setmntent ("/-not-used-", "r");
178 const char *format
= "%-18s %-18s %-11s %s\n";
180 printf (format
, "Device", "Directory", "Type", "Flags");
181 while ((p
= getmntent (m
)) != NULL
)
192 /* Return 1 if mountpoint from the same registry area is already in
193 mount table. Otherwise return 0. */
195 mount_already_exists (const char *posix_path
, int flags
)
197 int found_matching
= 0;
199 FILE *m
= setmntent ("/-not-used-", "r");
202 while ((p
= getmntent (m
)) != NULL
)
204 /* if the paths match, and they're both the same type of mount. */
205 if (strcmp (p
->mnt_dir
, posix_path
) == 0)
207 if (p
->mnt_type
[0] == 'u' && !(flags
& MOUNT_SYSTEM
)) /* both current_user */
212 else if (p
->mnt_type
[0] == 's' && (flags
& MOUNT_SYSTEM
)) /* both system */
219 fprintf (stderr
, "%s: warning -- couldn't determine mount type.\n", progname
);
226 return found_matching
;
229 /* change_cygdrive_prefix: Change the cygdrive prefix */
231 change_cygdrive_prefix (const char *new_prefix
, int flags
)
235 if (mount (NULL
, new_prefix
, flags
))
237 perror ("mount failed");
This page took 0.044866 seconds and 6 git commands to generate.