source: trunk/minix/commands/i386/mtools-3.9.7/mmount.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.5 KB
Line 
1/*
2 * Mount an MSDOS disk
3 *
4 * written by:
5 *
6 * Alain L. Knaff
7 * alain@linux.lu
8 *
9 */
10
11#include "sysincludes.h"
12#include "msdos.h"
13#include "mtools.h"
14
15#ifdef OS_linux
16#include <sys/wait.h>
17#include "mainloop.h"
18#include "fs.h"
19
20extern int errno;
21
22void mmount(int argc, char **argv, int type)
23{
24 char drive;
25 int pid;
26 int status;
27 struct device dev;
28 char name[EXPAND_BUF];
29 int media;
30 struct bootsector boot;
31 Stream_t *Stream;
32
33 if (argc<2 || !argv[1][0] || argv[1][1] != ':' || argv[1][2]){
34 fprintf(stderr,"Usage: %s -V drive:\n", argv[0]);
35 exit(1);
36 }
37 drive = toupper(argv[1][0]);
38 Stream = find_device(drive, O_RDONLY, &dev, &boot, name, &media, 0);
39 if(!Stream)
40 exit(1);
41 FREE(&Stream);
42
43 destroy_privs();
44
45 if ( dev.partition ) {
46 char part_name[4];
47 sprintf(part_name, "%d", dev.partition %1000);
48 strcat(name, part_name);
49 }
50
51 /* and finally mount it */
52 switch((pid=fork())){
53 case -1:
54 fprintf(stderr,"fork failed\n");
55 exit(1);
56 case 0:
57 close(2);
58 open("/dev/null", O_RDWR);
59 argv[1] = strdup("mount");
60 if ( argc > 2 )
61 execvp("mount", argv + 1 );
62 else
63 execlp("mount", "mount", name, 0);
64 perror("exec mount");
65 exit(1);
66 default:
67 while ( wait(&status) != pid );
68 }
69 if ( WEXITSTATUS(status) == 0 )
70 exit(0);
71 argv[0] = strdup("mount");
72 argv[1] = strdup("-r");
73 if(!argv[0] || !argv[1]){
74 printOom();
75 exit(1);
76 }
77 if ( argc > 2 )
78 execvp("mount", argv);
79 else
80 execlp("mount", "mount","-r", name, 0);
81 exit(1);
82}
83
84#endif /* linux */
85
Note: See TracBrowser for help on using the repository browser.