mountall.c 92.4 KB
Newer Older
Scott James Remnant's avatar
Scott James Remnant committed
1
2
/* mountall
 *
3
 * Copyright © 2010 Canonical Ltd.
Scott James Remnant's avatar
Scott James Remnant committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 * Author: Scott James Remnant <scott@netsplit.com>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */


#include <libudev.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/mount.h>

#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <stdio.h>
#include <limits.h>
#include <mntent.h>
Scott James Remnant's avatar
Scott James Remnant committed
39
#include <stdarg.h>
Scott James Remnant's avatar
Scott James Remnant committed
40
41
42
43
44
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <fnmatch.h>
Johan Kiviniemi's avatar
Johan Kiviniemi committed
45
#include <dirent.h>
Scott James Remnant's avatar
Scott James Remnant committed
46
47
48
49

#include <nih/macros.h>
#include <nih/alloc.h>
#include <nih/string.h>
Scott James Remnant's avatar
Scott James Remnant committed
50
#include <nih/list.h>
Scott James Remnant's avatar
Scott James Remnant committed
51
52
#include <nih/hash.h>
#include <nih/timer.h>
Scott James Remnant's avatar
Scott James Remnant committed
53
#include <nih/signal.h>
Scott James Remnant's avatar
Scott James Remnant committed
54
#include <nih/child.h>
Scott James Remnant's avatar
Scott James Remnant committed
55
56
#include <nih/io.h>
#include <nih/main.h>
Scott James Remnant's avatar
Scott James Remnant committed
57
#include <nih/option.h>
Scott James Remnant's avatar
Scott James Remnant committed
58
59
#include <nih/logging.h>
#include <nih/error.h>
Scott James Remnant's avatar
Scott James Remnant committed
60
#include <nih/errors.h>
Scott James Remnant's avatar
Scott James Remnant committed
61

Scott James Remnant's avatar
Scott James Remnant committed
62
#include <nih-dbus/dbus_error.h>
Scott James Remnant's avatar
Scott James Remnant committed
63
64
#include <nih-dbus/dbus_connection.h>
#include <nih-dbus/dbus_proxy.h>
Scott James Remnant's avatar
Scott James Remnant committed
65
#include <nih-dbus/errors.h>
Scott James Remnant's avatar
Scott James Remnant committed
66

67
68
69
#include <ply-event-loop.h>
#include <ply-boot-client.h>

70
71
#include "ioprio.h"

Scott James Remnant's avatar
Scott James Remnant committed
72
73
#include "dbus/upstart.h"
#include "com.ubuntu.Upstart.h"
74
#include "control.h"
Scott James Remnant's avatar
Scott James Remnant committed
75
76


77
78
#define BUILTIN_FSTAB   "/lib/init/fstab"

79
#define BOREDOM_TIMEOUT 3
80
#define ROOTDELAY 30
81

82
83
84
85
enum exit {
	EXIT_OK = 0,		/* Ok */
	EXIT_ERROR = 1,		/* General/OS error */
	EXIT_SHELL = 2,		/* Start maintenance shell */
86
	EXIT_SHELL_REBOOT = 3,	/* Start maintenance shell, reboot when done */
87
88
89
	EXIT_REBOOT = 4,	/* System must reboot */
};

90
typedef enum {
91
	TAG_UNKNOWN,
92
93
94
	TAG_LOCAL,
	TAG_REMOTE,
	TAG_VIRTUAL,
95
96
	TAG_SWAP,
	TAG_NOWAIT,
97
	TAG_SKIPPED,
98
	TAG_TIMEOUT,
99
100
} Tag;

101
102
103
104
105
106
107
108
109
typedef enum {
	ERROR_NONE,
	ERROR_BORED,
	ERROR_FSCK_FAILED,
	ERROR_FSCK_FAILED_HARD,
	ERROR_MOUNT_FAILED,
	ERROR_FSCK_IN_PROGRESS,
} Error;

Scott James Remnant's avatar
Scott James Remnant committed
110
111
112
typedef struct mount Mount;

struct mount {
113
114
	NihList             entry;

Scott James Remnant's avatar
Scott James Remnant committed
115
116
117
	char *              mountpoint;
	pid_t               mount_pid;
	int                 mounted;
118
	dev_t               mounted_dev;
Scott James Remnant's avatar
Scott James Remnant committed
119
120
121

	char *              device;
	struct udev_device *udev_device;
Johan Kiviniemi's avatar
Johan Kiviniemi committed
122
123
	NihHash *           physical_dev_ids;
	int                 physical_dev_ids_needed;
Scott James Remnant's avatar
Scott James Remnant committed
124
	pid_t               fsck_pid;
125
	int                 fsck_progress;
126
	int                 fsck_fix;
127
	int                 ready;
Scott James Remnant's avatar
Scott James Remnant committed
128

129
130
	Error               error;

Scott James Remnant's avatar
Scott James Remnant committed
131
	char *              type;
Scott James Remnant's avatar
Scott James Remnant committed
132
	int                 nodev;
Scott James Remnant's avatar
Scott James Remnant committed
133
134
	char *              opts;
	char *              mount_opts;
135
136
137
138
139
	int                 check;

	Tag                 tag;
	int                 has_showthrough;
	Mount *             showthrough;
140
141
	int                 checked_link;
	Mount *             link_target;
142
	NihList             deps;
Scott James Remnant's avatar
Scott James Remnant committed
143
144
};

145
146
147
148
#define MOUNT_NAME(_mnt) (strcmp ((_mnt)->type, "swap")			\
			  && strcmp ((_mnt)->mountpoint, "none")	\
			  ? (_mnt)->mountpoint : (_mnt)->device)

Scott James Remnant's avatar
Scott James Remnant committed
149
150
151
152
153
154
155
156
157
158
159
160
161
typedef struct filesystem {
	char *name;
	int   nodev;
} Filesystem;

typedef struct process {
	Mount *       mnt;
	char * const *args;
	pid_t         pid;
	void (*handler) (Mount *mnt, pid_t pid, int status);
} Process;


162
163
164
165
166
167
168
169
170
171
Mount *new_mount             (const char *mountpoint, const char *device,
			      int check, const char *type, const char *opts);
Mount *find_mount            (const char *mountpoint);
void   update_mount          (Mount *mnt, const char *device, int check,
			      const char *type, const char *opts);

int    has_option            (Mount *mnt, const char *option, int current);
char * get_option            (const void *parent, Mount *mnt, const char *option,
			      int current);
char * cut_options           (const void *parent, Mount *mnt, ...);
Scott James Remnant's avatar
Scott James Remnant committed
172

173
174
void   parse_fstab           (const char *filename);
void   parse_mountinfo       (void);
Scott James Remnant's avatar
Scott James Remnant committed
175

176
void   parse_filesystems     (void);
177

178
void   mount_policy          (void);
179
void   tag_mount             (Mount *mnt, Tag tag);
180
void   mark_mounted          (void);
Scott James Remnant's avatar
Scott James Remnant committed
181

182
void   mounted               (Mount *mnt);
183
void   skip_mount            (Mount *mnt);
184
void   trigger_events        (void);
185

186
187
void   try_mounts            (void);
void   try_mount             (Mount *mnt, int force);
188

189
190
191
int    find_on_path          (const char *name);
int    find_fsck             (const char *type);

192
193
194
195
pid_t  spawn                 (Mount *mnt, char * const *args, int wait,
			      void (*handler) (Mount *mnt, pid_t pid, int status));
void   spawn_child_handler   (Process *proc, pid_t pid,
			      NihChildEvents event, int status);
Scott James Remnant's avatar
Scott James Remnant committed
196

197
198
void   run_mount             (Mount *mnt, int fake);
void   run_mount_finished    (Mount *mnt, pid_t pid, int status);
Scott James Remnant's avatar
Scott James Remnant committed
199

200
201
void   run_swapon            (Mount *mnt);
void   run_swapon_finished   (Mount *mnt, pid_t pid, int status);
Scott James Remnant's avatar
Scott James Remnant committed
202

203
int    missing_fsck          (Mount *mnt);
204
205
void   run_fsck              (Mount *mnt);
void   run_fsck_finished     (Mount *mnt, pid_t pid, int status);
Scott James Remnant's avatar
Scott James Remnant committed
206

207
void   write_mtab            (void);
Scott James Remnant's avatar
Scott James Remnant committed
208

209
void   mount_showthrough     (Mount *root);
Scott James Remnant's avatar
Scott James Remnant committed
210

211
212
213
void   upstart_disconnected  (DBusConnection *connection);
void   emit_event            (const char *name, Mount *mnt);
void   emit_event_error      (void *data, NihDBusMessage *message);
Scott James Remnant's avatar
Scott James Remnant committed
214

215
216
217
void   udev_monitor_watcher  (struct udev_monitor *udev_monitor,
			      NihIoWatch *watch, NihIoEvents events);
void   udev_catchup          (void);
Scott James Remnant's avatar
Scott James Remnant committed
218

219
void   fsck_update           (void);
Scott James Remnant's avatar
Scott James Remnant committed
220

221
222
void   fsck_reader           (Mount *mnt, NihIo *io,
			      const char *buf, size_t len);
223
224
void   boredom_timeout       (void *data, NihTimer *timer);

225
int    plymouth_connect      (void);
226
void   plymouth_disconnected (void *user_data, ply_boot_client_t *client);
Scott James Remnant's avatar
Scott James Remnant committed
227

228
void   plymouth_progress     (Mount *mnt, int progress);
229
230
231
232
233
234
235
void   plymouth_update       (int only_clear);

void   plymouth_response     (void *user_data, ply_boot_client_t *client);
void   plymouth_failed       (void *user_data, ply_boot_client_t *client);
void   plymouth_answer       (void *user_data, const char *keys,
			      ply_boot_client_t *client);

236
void   usr1_handler          (void *data, NihSignal *signal);
237
int    set_dev_wait_time        (NihOption *option, const char *arg);
238

Scott James Remnant's avatar
Scott James Remnant committed
239

240
241
242
243
244
245
246
/**
 * mounts:
 *
 * List of mounts that we need to process, parsed from /etc/fstab
 * (with built-ins and previously mounted filesystems added too).
 * Each list entry is a Mount structure.
 **/
247
NihList *mounts = NULL;
Scott James Remnant's avatar
Scott James Remnant committed
248

249
/**
250
 * Counters for the different tags.
251
252
253
254
255
256
257
258
259
 **/
size_t num_local = 0;
size_t num_local_mounted = 0;
size_t num_remote = 0;
size_t num_remote_mounted = 0;
size_t num_virtual = 0;
size_t num_virtual_mounted = 0;
size_t num_swap = 0;
size_t num_swap_mounted = 0;
260
261
size_t num_timeout = 0;
size_t num_timeout_mounted = 0;
262

263
264
265
266
267
268
/**
 * newly_mounted:
 *
 * Set to TRUE if we've successfully mounted something, informs the main loop
 * to try and mount non-mounted things again.
 **/
269
int newly_mounted = TRUE;
270

271
272
273
274
275
276
277
278
279
280
281
282
283
/**
 * fsck_in_progress:
 *
 * Set to TRUE while filesystem checks are in progress, this isn't quite the
 * same as fsck being running (which fsck_update) checks since fsck might
 * decide not to check the filesystems.
 *
 * Therefore this gets set to TRUE when we receive the first progress
 * information in fsck_progress(), and reset to FALSE in fsck_update() when
 * no fsck is running.
 **/
int fsck_in_progress = FALSE;

Scott James Remnant's avatar
docs    
Scott James Remnant committed
284
285
286
287
288
289
290
/**
 * filesystems:
 *
 * Array of filesystem information parsed from /proc/filesystems, primarily
 * used to eliminate arch-specific filesystems that don't exist when we
 * start and figure out which filesystems don't have devices.
 **/
Scott James Remnant's avatar
Scott James Remnant committed
291
292
293
294
Filesystem *filesystems = NULL;
size_t num_filesystems = 0;


Scott James Remnant's avatar
docs    
Scott James Remnant committed
295
296
297
298
299
/**
 * written_mtab:
 *
 * TRUE once we've successfully written /etc/mtab.
 **/
Scott James Remnant's avatar
Scott James Remnant committed
300
301
int written_mtab = FALSE;

Scott James Remnant's avatar
docs    
Scott James Remnant committed
302
303
304
305
306
307
/**
 * exit_code:
 *
 * Rather than exit immediately in case of error, we delay the exit until
 * any background processes (fsck, mount, etc.) have finished.
 **/
308
int exit_code = -1;
Scott James Remnant's avatar
Scott James Remnant committed
309

Johan Kiviniemi's avatar
Johan Kiviniemi committed
310

Scott James Remnant's avatar
Scott James Remnant committed
311
312
313
314
315
316
317
/**
 * upstart:
 *
 * Proxy to Upstart daemon.
 **/
static NihDBusProxy *upstart = NULL;

318
319
320
321
322
323
324
/**
 * udev:
 *
 * libudev context.
 **/
static struct udev *udev = NULL;

325
326
327
328
329
330
331
/**
 * ply_event_loop:
 *
 * plymouth event loop
 **/
static ply_event_loop_t *ply_event_loop = NULL;

332
333
334
335
336
337
338
/**
 * ply_boot_client:
 *
 * Plymouth boot client.
 **/
static ply_boot_client_t *ply_boot_client = NULL;

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/**
 * plymouth_error:
 *
 * Error currently showing on Plymouth.
 **/
static Error plymouth_error = ERROR_NONE;

/**
 * plymouth_mnt:
 *
 * Mount point currently showing an error on Plymouth.
 **/
static Mount *plymouth_mnt = NULL;

/**
 * plymouth_keys:
 *
 * Keypresses currently being watched for from Plymouth.
 **/
static const char *plymouth_keys = NULL;

360
361
362
363
364
365
366
367
/**
 * boredom_timer:
 *
 * Having waited over BOREDOM_TIMEOUT seconds for certain mounts, print a
 * message to the user.
 **/
static NihTimer *boredom_timer = NULL;

368
369
370
371
372
373
374
375
/**
 * device_ready_timer:
 *
 * Having waited over ROOTDELAY seconds for certain devices to get ready,
 * exit mountall and trigger the upstart jobs for bringing up the device
 **/

NihTimer *device_ready_timer = NULL;
376

Scott James Remnant's avatar
Scott James Remnant committed
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/**
 * daemonise:
 *
 * Set to TRUE if we should become a daemon, rather than just running
 * in the foreground.
 **/
static int daemonise = FALSE;

/**
 * force_fsck:
 *
 * Set to TRUE if we should pass -f to fsck invocations.
 **/
static int force_fsck = FALSE;

/**
 * fsck_fix:
 *
 * Set to TRUE if we should pass -y to fsck invocations.
 **/
static int fsck_fix = FALSE;

399
400
401
402
403
/**
 * no_events:
 *
 * Set to TRUE if we should not emit events.
 **/
404
static int no_events = FALSE;
405

406
407
408
409
410
411
412
413
414
415
/**
 ** dev-wait-time
 **
 ** Set to ROOTDELAY if not set. 
 ** Legal values are between 1sec to 2147483647 seconds.
 **/
static int dev_wait_time = FALSE;



Scott James Remnant's avatar
Scott James Remnant committed
416

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
static void
dequote (char *str)
{
	size_t len;

	nih_assert (str != NULL);

	if ((str[0] != '"') && (str[0] != '\''))
		return;

	len = strlen (str);
	len -= 2;

	memmove (str, str + 1, len);
	str[len] = '\0';
}

434
435
436
437
438
439
440
441
442
443
444
445
446
static void
strip_slashes (char *str)
{
	char *p;

	nih_assert (str != NULL);

	p = str + strlen (str) - 1;
	while ((p > str) && (*p == '/'))
		*(p--) = '\0';
}


Scott James Remnant's avatar
Scott James Remnant committed
447
448
449
450
451
Mount *
new_mount (const char *mountpoint,
	   const char *device,
	   int         check,
	   const char *type,
452
	   const char *opts)
Scott James Remnant's avatar
Scott James Remnant committed
453
454
455
456
{
	Mount *mnt;

	nih_assert (mountpoint != NULL);
457
458
459
	nih_assert (device != NULL);
	nih_assert (type != NULL);
	nih_assert (opts != NULL);
Scott James Remnant's avatar
Scott James Remnant committed
460

461
462
	mnt = NIH_MUST (nih_new (NULL, Mount));
	nih_list_init (&mnt->entry);
Scott James Remnant's avatar
Scott James Remnant committed
463
464

	mnt->mountpoint = NIH_MUST (nih_strdup (mounts, mountpoint));
465
	strip_slashes (mnt->mountpoint);
466
467
	mnt->checked_link = FALSE;
	mnt->link_target = NULL;
468

Scott James Remnant's avatar
Scott James Remnant committed
469
470
	mnt->mount_pid = -1;
	mnt->mounted = FALSE;
471
	mnt->mounted_dev = -1;
Scott James Remnant's avatar
Scott James Remnant committed
472

473
	mnt->device = NULL;
Scott James Remnant's avatar
Scott James Remnant committed
474
	mnt->udev_device = NULL;
Johan Kiviniemi's avatar
Johan Kiviniemi committed
475
	mnt->physical_dev_ids = NULL;
476
	mnt->physical_dev_ids_needed = TRUE;
Scott James Remnant's avatar
Scott James Remnant committed
477
	mnt->fsck_pid = -1;
478
	mnt->fsck_progress = -1;
479
	mnt->fsck_fix = FALSE;
480
	mnt->ready = FALSE;
Scott James Remnant's avatar
Scott James Remnant committed
481

482
483
	mnt->error = ERROR_NONE;

484
	mnt->type = NULL;
Scott James Remnant's avatar
Scott James Remnant committed
485
	mnt->nodev = FALSE;
486
	mnt->opts = NULL;
Scott James Remnant's avatar
Scott James Remnant committed
487
	mnt->mount_opts = NULL;
488
489
	mnt->check = check;

490
	mnt->tag = TAG_UNKNOWN;
491
492
493
	mnt->has_showthrough = FALSE;
	mnt->showthrough = NULL;
	nih_list_init (&mnt->deps);
Scott James Remnant's avatar
Scott James Remnant committed
494

495
496
497
	nih_alloc_set_destructor (mnt, nih_list_destroy);
	nih_list_add (mounts, &mnt->entry);

498
	update_mount (mnt, device, check, type, opts);
Scott James Remnant's avatar
Scott James Remnant committed
499
500
501
502
503
504
505
506
507

	return mnt;
}

Mount *
find_mount (const char *mountpoint)
{
	nih_assert (mountpoint != NULL);

508
509
510
511
512
513
	NIH_LIST_FOREACH (mounts, iter) {
		Mount *mnt = (Mount *)iter;

		if (! strcmp (mnt->mountpoint, mountpoint))
			return mnt;
	}
Scott James Remnant's avatar
Scott James Remnant committed
514
515
516
517
518
519
520
521
522

	return NULL;
}

void
update_mount (Mount *     mnt,
	      const char *device,
	      int         check,
	      const char *type,
523
	      const char *opts)
Scott James Remnant's avatar
Scott James Remnant committed
524
525
526
527
528
529
530
{
	nih_assert (mnt != NULL);

	if (device) {
		if (mnt->device)
			nih_unref (mnt->device, mounts);
		mnt->device = NIH_MUST (nih_strdup (mounts, device));
531
532
533
534
535
536
537

		if (! strncmp (mnt->device, "UUID=", 5)) {
			dequote (mnt->device + 5);
		} else if (! strncmp (mnt->device, "LABEL=", 6)) {
			dequote (mnt->device + 6);
		} else {
			dequote (mnt->device);
538
			strip_slashes (mnt->device);
539
		}
Scott James Remnant's avatar
Scott James Remnant committed
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
	}

	if (check >= 0)
		mnt->check = check;

	if (type) {
		if (mnt->type)
			nih_unref (mnt->type, mounts);
		mnt->type = NIH_MUST (nih_strdup (mounts, type));
	}

	if (opts) {
		if (mnt->opts)
			nih_unref (mnt->opts, mounts);
		mnt->opts = NIH_MUST (nih_strdup (mounts, opts));
	}


558
559
	nih_debug ("%s: %s %s %s %s%s",
		   MOUNT_NAME (mnt),
Scott James Remnant's avatar
Scott James Remnant committed
560
		   mnt->mountpoint,
561
562
563
		   mnt->device,
		   mnt->type,
		   mnt->opts,
564
		   mnt->check ? " check" : "");
Scott James Remnant's avatar
Scott James Remnant committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
}


int
has_option (Mount *     mnt,
	    const char *option,
	    int         current)
{
	const char *opts;
	size_t      i;

	nih_assert (mnt != NULL);
	nih_assert (option != NULL);

	opts = current ? mnt->mount_opts : mnt->opts;
	if (! opts)
		return FALSE;

	i = 0;
	while (i < strlen (opts)) {
		size_t j;
		size_t k;

		j = strcspn (opts + i, ",=");
		k = strcspn (opts + i + j, ",");

		if (! strncmp (opts + i, option, j))
			return TRUE;

		i += j + k + 1;
	}

	return FALSE;
}

char *
get_option (const void *parent,
	    Mount *     mnt,
	    const char *option,
	    int         current)
{
	const char *opts;
	size_t      i;

	nih_assert (mnt != NULL);
	nih_assert (option != NULL);

	opts = current ? mnt->mount_opts : mnt->opts;
	if (! opts)
		return NULL;

	i = 0;
	while (i < strlen (opts)) {
		size_t j;
		size_t k;

		j = strcspn (opts + i, ",=");
		k = strcspn (opts + i + j, ",");

		if (! strncmp (opts + i, option, j))
			return nih_strndup (parent, opts + i + j + 1,
					    k ? k - 1 : 0);

		i += j + k + 1;
	}

	return NULL;
}

char *
cut_options (const void *parent,
	     Mount *     mnt,
	     ...)
{
	va_list args;
	char *  opts;
	size_t  i;

	nih_assert (mnt != NULL);

	va_start (args, mnt);

	opts = NIH_MUST (nih_strdup (parent, mnt->opts));

	i = 0;
	while (i < strlen (opts)) {
		size_t      j;
		size_t      k;
		va_list     options;
		const char *option;

		j = strcspn (opts + i, ",=");
		k = strcspn (opts + i + j, ",");

		va_copy (options, args);
		while ((option = va_arg (options, const char *)) != NULL) {
661
			if (j && ! strncmp (opts + i, option, j))
Scott James Remnant's avatar
Scott James Remnant committed
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
				break;
		}
		va_end (options);

		if (option) {
			memmove (opts + (i ? i - 1 : 0), opts + i + j + k,
				 strlen (opts) - i - j - k + 1);
		} else {
			i += j + k + 1;
		}
	}

	va_end (args);

	return opts;
}


void
681
parse_fstab (const char *filename)
Scott James Remnant's avatar
Scott James Remnant committed
682
683
684
685
{
	FILE *         fstab;
	struct mntent *mntent;

686
687
	nih_assert (filename != NULL);

Scott James Remnant's avatar
Scott James Remnant committed
688
	nih_debug ("updating from %s", filename);
Scott James Remnant's avatar
Scott James Remnant committed
689

690
	fstab = setmntent (filename, "r");
Scott James Remnant's avatar
Scott James Remnant committed
691
	if (! fstab) {
692
		nih_fatal ("%s: %s", filename, strerror (errno));
693
		exit (EXIT_ERROR);
Scott James Remnant's avatar
Scott James Remnant committed
694
695
696
	}

	while ((mntent = getmntent (fstab)) != NULL) {
697
698
		Mount *         mnt;
		nih_local char *fsname = NULL;
Scott James Remnant's avatar
Scott James Remnant committed
699

700
701
702
703
704
705
706
707
708
		/* These are always symlinks into /run now.  Ignore any
		 * explicit attempts to mount them because it vastly
		 * complicates matters when trying to ensure that /run and
		 * /var/run point to the same place.
		 */
		if (! strcmp (mntent->mnt_dir, "/var/run") ||
		    ! strcmp (mntent->mnt_dir, "/var/lock"))
			continue;

Scott James Remnant's avatar
Scott James Remnant committed
709
		mnt = find_mount (mntent->mnt_dir);
710
711
		if (mnt
		    && strcmp (mntent->mnt_type, "swap")) {
Scott James Remnant's avatar
Scott James Remnant committed
712
713
714
715
			update_mount (mnt,
				      mntent->mnt_fsname,
				      mntent->mnt_passno != 0,
				      mntent->mnt_type,
716
				      mntent->mnt_opts);
Scott James Remnant's avatar
Scott James Remnant committed
717
718
719
720
721
		} else {
			mnt = new_mount (mntent->mnt_dir,
					 mntent->mnt_fsname,
					 mntent->mnt_passno != 0,
					 mntent->mnt_type,
722
					 mntent->mnt_opts);
Scott James Remnant's avatar
Scott James Remnant committed
723
724
725
726
727
728
		}
	}

	endmntent (fstab);
}

729
730
731
732
733
static int
needs_remount (Mount *mnt)
{
	nih_assert (mnt != NULL);

734
735
736
	if (mnt->mounted
	    && has_option (mnt, "ro", TRUE)
	    && (! has_option (mnt, "ro", FALSE))) {
737
738
739
740
741
742
		return TRUE;
	} else {
		return FALSE;
	}
}

743
744
745
746
747
748
749
750
751
752
753
static void
mount_proc (void)
{
	Mount *mnt;

	nih_debug ("mounting /proc");
	if (mount ("none", "/proc", "proc",
		   MS_NODEV | MS_NOEXEC | MS_NOSUID, NULL) < 0) {
		nih_fatal ("%s: %s: %s", "/proc",
			   _("unable to mount"),
			   strerror (errno));
754
		exit (EXIT_ERROR);
755
756
757
758
759
760
761
	}

	mnt = find_mount ("/proc");
	if (mnt)
		mnt->mounted = TRUE;
}

762
763
static FILE *mountinfo = NULL;

764
static void
765
parse_mountinfo_file (int reparsed)
Scott James Remnant's avatar
Scott James Remnant committed
766
767
768
769
{
	nih_local char *buf = NULL;
	size_t          bufsz;

770
	nih_assert (mountinfo != NULL);
Scott James Remnant's avatar
Scott James Remnant committed
771

772
773
774
	if (reparsed)
		rewind (mountinfo);

775
	nih_debug ("updating mounts");
Scott James Remnant's avatar
Scott James Remnant committed
776
777
778
779
780
781
782

	bufsz = 4096;
	buf = NIH_MUST (nih_alloc (NULL, bufsz));

	while (fgets (buf, bufsz, mountinfo) != NULL) {
		char * saveptr;
		char * ptr;
783
		char * dev;
Scott James Remnant's avatar
Scott James Remnant committed
784
785
786
		char * mountpoint;
		char * type;
		char * device;
787
		int    maj, min;
Scott James Remnant's avatar
Scott James Remnant committed
788
789
		char * mount_opts;
		char * super_opts;
790
		char * opts;
Scott James Remnant's avatar
Scott James Remnant committed
791
792
793
794
		Mount *mnt;

		while ((! strchr (buf, '\n')) && (! feof (mountinfo))) {
			buf = NIH_MUST (nih_realloc (buf, NULL, bufsz + 4096));
Scott James Remnant's avatar
Scott James Remnant committed
795
796
			if (! fgets (buf + bufsz - 1, 4097, mountinfo))
				break;
Scott James Remnant's avatar
Scott James Remnant committed
797
798
799
800
801
802
803
804
805
806
807
808
809
810
			bufsz += 4096;
		}

		/* mount ID */
		ptr = strtok_r (buf, " \t\n", &saveptr);
		if (! ptr)
			continue;

		/* parent ID */
		ptr = strtok_r (NULL, " \t\n", &saveptr);
		if (! ptr)
			continue;

		/* major:minor */
811
812
		dev = strtok_r (NULL, " \t\n", &saveptr);
		if (! dev)
Scott James Remnant's avatar
Scott James Remnant committed
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
			continue;

		/* root */
		ptr = strtok_r (NULL, " \t\n", &saveptr);
		if (! ptr)
			continue;

		/* mountpoint */
		mountpoint = strtok_r (NULL, " \t\n", &saveptr);
		if (! mountpoint)
			continue;

		/* mount opts */
		mount_opts = strtok_r (NULL, " \t\n", &saveptr);
		if (! mount_opts)
			continue;

		/* optional fields */
		while (((ptr = strtok_r (NULL, " \t\n", &saveptr)) != NULL)
		       && strcmp (ptr, "-"))
			;
		if (! ptr)
			continue;

		/* type */
		type = strtok_r (NULL, " \t\n", &saveptr);
		if (! type)
			continue;

		/* device */
		device = strtok_r (NULL, " \t\n", &saveptr);
		if (! device)
			continue;

		/* superblock opts */
		super_opts = strtok_r (NULL, " \t\n", &saveptr);
		if (! super_opts)
			continue;

852
853
854
		/* ignore ureadahead's mounting of debugfs */
		if (! strcmp (mountpoint, "/var/lib/ureadahead/debugfs"))
			continue;
Scott James Remnant's avatar
Scott James Remnant committed
855

856
857
858
		opts = NIH_MUST (nih_sprintf (mounts, "%s,%s",
					      mount_opts, super_opts));

Scott James Remnant's avatar
Scott James Remnant committed
859
		mnt = find_mount (mountpoint);
860
861
		if (mnt
		    && strcmp (type, "swap")) {
862
863
864
865
866
867
868
			if (! strcmp (type, "rootfs"))
				type = NULL;

			if ((! strcmp (device, "/dev/root"))
			    || (! strcmp (device, "none")))
				device = NULL;

869
			update_mount (mnt, device, -1, type, NULL);
Scott James Remnant's avatar
Scott James Remnant committed
870
871
872

			if (mnt->mount_opts)
				nih_unref (mnt->mount_opts, mounts);
873
			mnt->mount_opts = opts;
Scott James Remnant's avatar
Scott James Remnant committed
874
		} else {
875
876
			mnt = new_mount (mountpoint, device, FALSE, type, opts);
			mnt->mount_opts = opts;
Scott James Remnant's avatar
Scott James Remnant committed
877
878
		}

879
880
881
		if (sscanf (dev, "%d:%d", &maj, &min) == 2)
			mnt->mounted_dev = makedev (maj, min);

Scott James Remnant's avatar
Scott James Remnant committed
882
		if (reparsed && (! mnt->mounted)) {
883
			mounted (mnt);
884
885
886
		} else {
			mnt->mounted = TRUE;
		}
Scott James Remnant's avatar
Scott James Remnant committed
887
	}
888
889
890
891
892
893
894
}

static void
mountinfo_watcher (void *      data,
		   NihIoWatch *watch,
		   NihIoEvents events)
{
895
	nih_assert (mountinfo != NULL);
896
897

	nih_debug ("mountinfo changed, reparsing");
898
	parse_mountinfo_file (TRUE);
899
900
901
902
903
}

void
parse_mountinfo (void)
{
904
905
906
	if (mountinfo) {
		parse_mountinfo_file (TRUE);
	} else {
907
		mountinfo = fopen ("/proc/self/mountinfo", "r");
908
909
910
911
912
913
914
		if ((! mountinfo) && (errno == ENOENT)) {
			mount_proc ();
			mountinfo = fopen ("/proc/self/mountinfo", "r");
		}
		if (! mountinfo) {
			nih_fatal ("%s: %s", "/proc/self/mountinfo",
				   strerror (errno));
915
			exit (EXIT_ERROR);
916
		}
917

918
		parse_mountinfo_file (FALSE);
919

920
921
922
		NIH_MUST (nih_io_add_watch (NULL, fileno (mountinfo), NIH_IO_EXCEPT,
					    mountinfo_watcher, NULL));
	}
Scott James Remnant's avatar
Scott James Remnant committed
923
924
}

925

Scott James Remnant's avatar
Scott James Remnant committed
926
927
928
929
930
931
932
933
934
935
void
parse_filesystems (void)
{
	FILE *          fs;
	nih_local char *buf = NULL;
	size_t          bufsz;

	nih_debug ("reading filesystems");

	fs = fopen ("/proc/filesystems", "r");
936
937
938
939
	if ((! fs) && (errno == ENOENT)) {
		mount_proc ();
		fs = fopen ("/proc/filesystems", "r");
	}
Scott James Remnant's avatar
Scott James Remnant committed
940
941
942
	if (! fs) {
		nih_fatal ("%s: %s", "/proc/filesystems",
			   strerror (errno));
943
		exit (EXIT_ERROR);
Scott James Remnant's avatar
Scott James Remnant committed
944
945
946
947
948
949
950
951
952
953
954
955
	}

	bufsz = 4096;
	buf = NIH_MUST (nih_alloc (NULL, bufsz));

	while (fgets (buf, bufsz, fs) != NULL) {
		char *      ptr;
		int         nodev;
		Filesystem *filesystem;

		while (((ptr = strchr (buf, '\n')) == NULL) && (! feof (fs))) {
			buf = NIH_MUST (nih_realloc (buf, NULL, bufsz + 4096));
Scott James Remnant's avatar
Scott James Remnant committed
956
957
			if (! fgets (buf + bufsz - 1, 4097, fs))
				break;
Scott James Remnant's avatar
Scott James Remnant committed
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
			bufsz += 4096;
		}

		*ptr = '\0';
		if (! strncmp (buf, "nodev\t", 6)) {
			nodev = TRUE;
			ptr = buf + 6;
			nih_debug ("%s (nodev)", ptr);
		} else if (buf[0] == '\t') {
			nodev = FALSE;
			ptr = buf + 1;
			nih_debug ("%s", ptr);
		} else
			continue;

		filesystems = NIH_MUST (nih_realloc (filesystems, NULL,
						     sizeof (Filesystem) * (num_filesystems + 1)));
		filesystem = &filesystems[num_filesystems++];

		filesystem->name = NIH_MUST (nih_strdup (filesystems, ptr));
		filesystem->nodev = nodev;
	}

	if (fclose (fs) < 0) {
		nih_fatal ("%s: %s", "/proc/filesystems",
			  strerror (errno));
984
		exit (EXIT_ERROR);
Scott James Remnant's avatar
Scott James Remnant committed
985
986
987
	}
}

988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012

static int
is_parent (char *root,
	   char *path)
{
	size_t len;

	nih_assert (root != NULL);
	nih_assert (path != NULL);

	len = strlen (root);
	if ((! strncmp (path, root, len))
	    && ((path[len] == '\0')
		|| (path[len] == '/')
		|| (len && path[len-1] == '/')))
		return TRUE;

	return FALSE;
}

static int
is_remote (Mount *mnt)
{
	nih_assert (mnt != NULL);

1013
1014
1015
1016
1017
1018
1019
1020
1021
	if (has_option (mnt, "_netdev", FALSE)
	    || (! strcmp (mnt->type, "nfs"))
	    || (! strcmp (mnt->type, "nfs4"))
	    || (! strcmp (mnt->type, "smbfs"))
	    || (! strcmp (mnt->type, "cifs"))
	    || (! strcmp (mnt->type, "coda"))
	    || (! strcmp (mnt->type, "ncp"))
	    || (! strcmp (mnt->type, "ncpfs"))
	    || (! strcmp (mnt->type, "ocfs2"))
1022
	    || (! strcmp (mnt->type, "gfs"))
1023
1024
	    || (! strcmp (mnt->type, "gfs2"))
	    || (! strcmp (mnt->type, "ceph"))) {
1025
1026
		return TRUE;
	} else {
1027
		return FALSE;
1028
1029
1030
	}
}

Scott James Remnant's avatar
Scott James Remnant committed
1031
void
1032
mount_policy (void)
Scott James Remnant's avatar
Scott James Remnant committed
1033
{
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
	nih_local NihList  *already_mounted = NULL;
	NihListEntry       *entry;

	/* Build a list of mountpoints of already mounted
	 * file systems. Used later to avoid hiding existing
	 * mounted file systems.
	 */
	already_mounted = NIH_MUST (nih_list_new (NULL));
 	NIH_LIST_FOREACH (mounts, iter) {
		Mount *mnt = (Mount *)iter;
		if (mnt->mountpoint && mnt->mounted) {
			entry = NIH_MUST (nih_list_entry_new (already_mounted));
			entry->str = NIH_MUST (nih_strdup (entry, mnt->mountpoint));
			nih_list_add (already_mounted, &entry->entry);
		}
	}

1051
 	NIH_LIST_FOREACH_SAFE (mounts, iter) {
1052
		Mount *mnt = (Mount *)iter;
1053
		size_t j;
1054

1055
1056
1057
1058
		/* Check through the known filesystems, if this is a nodev
		 * filesystem then mark the mount as such so we don't wait
		 * for any device to be ready.
		 */
1059
1060
1061
1062
1063
		for (j = 0; j < num_filesystems; j++) {
			if ((! strcmp (mnt->type, filesystems[j].name))
			    && filesystems[j].nodev) {
				mnt->nodev = TRUE;
				break;
1064
			}
1065
		}
1066

1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
		/* If there's no device spec for this filesystem,
		 * and it's optional, we ignore it.
		 */
		if ((! strcmp (mnt->device, "none"))
		    && has_option (mnt, "optional", FALSE)
		    && (j == num_filesystems)) {
			nih_debug ("%s: dropping unknown filesystem",
				   MOUNT_NAME (mnt));
			nih_free (mnt);
			continue;
		}
1078

1079
1080
1081
		/* Otherwise if there's no device and the type is also "none",
		 * special-case it as a "nodev" virtual filesystem so our
		 * placeholder handling kicks in.
1082
1083
		 */
		if (! strcmp (mnt->device, "none")
1084
		    && ! strcmp (mnt->type, "none"))
1085
1086
			mnt->nodev = TRUE;

1087
1088
1089
1090
1091
1092
		/* Drop anything with ignore as its type. */
		if (! strcmp (mnt->type, "ignore")) {
			nih_debug ("%s: dropping ignored filesystem",
				   MOUNT_NAME (mnt));
			nih_free (mnt);
			continue;
1093
1094
1095
1096
1097
		}

		/* Drop anything that's not auto-mounted which isn't already
		 * mounted.
		 */
1098
1099
		if (has_option (mnt, "noauto", FALSE)
		    && (! mnt->mounted)) {
1100
			nih_debug ("%s: dropping noauto filesystem",
1101
				   MOUNT_NAME (mnt));
1102
			nih_free (mnt);
1103
			continue;
1104
		}
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

		/* Check if our current mount entry would hide
		 * an existing mountpoint. If so, skip it.
		 */
		NIH_LIST_FOREACH (already_mounted, iter) {
			NihListEntry *e = (NihListEntry *)iter;
			if (mnt->mountpoint
			    && mnt->mountpoint != e->str
			    && ! mnt->mounted
			    && is_parent (mnt->mountpoint, e->str)) {
				nih_debug (
				    "%s: dropping filesystem because it has an already mounted child (%s)\n",
				    mnt->mountpoint, e->str);
				nih_free (mnt);
				break;
			}
		}
1122
1123
1124
1125
1126
1127
	}

 	NIH_LIST_FOREACH (mounts, iter) {
		Mount *mnt = (Mount *)iter;
		Mount *mount_parent = NULL;
		Mount *device_parent = NULL;
Scott James Remnant's avatar
Scott James Remnant committed
1128

1129
1130
1131
1132
1133
1134
1135
1136
		/* Iterate through the list of mounts, we're looking for the
		 * parentof the mountpoint (e.g. /var/tmp's parent is /var)
		 * and the parent mountpoint of the device spec
		 * (e.g. /usr/loop.img's parent is /usr).
		 */
		NIH_LIST_FOREACH (mounts, iter) {
			Mount *other = (Mount *)iter;

1137
1138
			/* Skip this mount entry */
			if (other == mnt)
1139
1140
1141
				continue;

			/* Is this a parent of our mountpoint? */
1142
1143
			if (mnt->mountpoint
			    && other->mountpoint
1144
1145
1146
1147
1148
1149
1150
			    && is_parent (other->mountpoint, mnt->mountpoint)){
				if ((! mount_parent)
				    || (strlen (mount_parent->mountpoint) < strlen (other->mountpoint)))
					mount_parent = other;
			}

			/* Is this a parent mountpoint of our device? */
1151
1152
			if ((! mnt->nodev)
			    && other->mountpoint
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
			    && is_parent (other->mountpoint, mnt->device)){
				if ((! device_parent)
				    || (strlen (device_parent->mountpoint) < strlen (other->mountpoint)))
					device_parent = other;
			}
		}

		/* We nearly always depend on our mountpoint's parent, the only
		 * exceptions are swap devices (which aren't mounted),
		 * showthrough entries (which explicitly don't need to wait)
		 * and virtual filesystems directly under the root.
		 */
		if (mount_parent
1166
		    && strcmp (mnt->type, "swap")) {
1167
1168
1169
1170
1171
			if (has_option (mnt, "showthrough", FALSE)
			    && strcmp (mount_parent->mountpoint, "/")) {
				mount_parent->has_showthrough = TRUE;
				mnt->showthrough = mount_parent;
				nih_debug ("%s shows through parent %s",
1172
1173
					   MOUNT_NAME (mnt),
					   MOUNT_NAME (mount_parent));
1174
1175
				mount_parent = NULL;
			} else if ((! strcmp (mount_parent->mountpoint, "/"))
1176
1177
				   && mnt->nodev
				   && strcmp (mnt->type, "none")) {
1178
				nih_debug ("%s can be mounted while root readonly",
1179
					   MOUNT_NAME (mnt));
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
				mount_parent = NULL;
			} else {
				NihListEntry *dep;

				dep = NIH_MUST (nih_list_entry_new (mnt));
				dep->data = mount_parent;
				nih_ref (mount_parent, dep);

				nih_list_add (&mnt->deps, &dep->entry);
				nih_debug ("%s parent is %s",
1190
1191
					   MOUNT_NAME (mnt),
					   MOUNT_NAME (mount_parent));
Scott James Remnant's avatar
Scott James Remnant committed
1192
1193
1194
			}
		}

1195
1196
1197
		/* It's also a pretty good idea to wait for the mountpoint on
		 * which our device exists to appear first, assuming we have
		 * one and that it's a valid path.
Scott James Remnant's avatar
Scott James Remnant committed
1198
		 */
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
		if (device_parent
		    && (! mnt->nodev)
		    && (mnt->device[0] == '/')
		    && strncmp (mnt->device, "/dev/", 5)) {
			NihListEntry *dep;

			dep = NIH_MUST (nih_list_entry_new (mnt));
			dep->data = device_parent;
			nih_ref (device_parent, dep);

			nih_list_add (&mnt->deps, &dep->entry);
			nih_debug ("%s parent is %s (mount %s)",
1211
1212
				   MOUNT_NAME (mnt),
				   MOUNT_NAME (device_parent),
1213
				   mnt->device);
Scott James Remnant's avatar
Scott James Remnant committed
1214
1215
		}

1216
		/* Kernel filesystems can require rather more to mount than
1217
1218
		 * first appears, if a device spec has been given then we
		 * also wait for the previous fstab entry - whatever it was.
1219
1220
		 */
		if (mnt->nodev
1221
		    && strcmp (mnt->device, "none")
1222
		    && strcmp (mnt->device, mnt->type)
1223
		    && (mnt->entry.prev != mounts)
1224
		    && strcmp (((Mount *)mnt->entry.prev)->device, "none")) {
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
			NihListEntry *dep;
			Mount *       prior;

			prior = (Mount *)mnt->entry.prev;

			dep = NIH_MUST (nih_list_entry_new (mnt));
			dep->data = prior;
			nih_ref (prior, dep);

			nih_list_add (&mnt->deps, &dep->entry);
			nih_debug ("%s prior fstab entry %s",
1236
				   MOUNT_NAME (mnt), MOUNT_NAME (prior));
1237
1238
		}

1239
		/* Tag the filesystem so we know which event it blocks */
1240
1241
1242
1243
1244
1245
1246
1247
		tag_mount (mnt, TAG_UNKNOWN);
	}

	NIH_LIST_FOREACH (mounts, iter) {
		Mount *mnt = (Mount *)iter;

		switch (mnt->tag) {
		case TAG_VIRTUAL:
1248
			nih_info (_("%s is %s"), MOUNT_NAME (mnt), "virtual");
1249
1250
1251
			num_virtual++;
			break;
		case TAG_LOCAL:
1252
			nih_info (_("%s is %s"), MOUNT_NAME (mnt), "local");
1253
1254
			num_local++;
			break;
1255
1256
1257
1258
1259
		case TAG_TIMEOUT:
			nih_info (_("%s is %s"), MOUNT_NAME (mnt), "local with timeout");
			num_local++;
			num_timeout++;
			break;
1260
		case TAG_REMOTE:
1261
			nih_info (_("%s is %s"), MOUNT_NAME (mnt), "remote");
1262
1263
1264
			num_remote++;
			break;
		case TAG_SWAP:
1265
			nih_info (_("%s is %s"), MOUNT_NAME (mnt), "swap");
1266
1267
1268
			num_swap++;
			break;
		case TAG_NOWAIT:
1269
			nih_info (_("%s is %s"), MOUNT_NAME (mnt), "nowait");
1270
			break;
1271
1272
1273
		case TAG_SKIPPED:
			nih_info (_("%s is %s"), MOUNT_NAME (mnt), "skipped");
			break;
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
		default:
			nih_assert_not_reached ();
		}
	}
}

void
tag_mount (Mount *mnt,
	   Tag    tag)
{
	nih_assert (mnt != NULL);

	/* If no tag is given, work it out from the device type */
	if (tag == TAG_UNKNOWN) {
		if (! strcmp (mnt->type, "swap")) {
			tag = TAG_SWAP;
1290
		} else if (! strcmp (mnt->mountpoint, "/")) {
1291
1292
			nih_debug ("%s is root filesystem", MOUNT_NAME (mnt));
			tag = TAG_LOCAL;
1293
		} else if (is_remote (mnt)) {
1294
1295
1296
1297
1298
1299
			if (((! strcmp (mnt->mountpoint, "/usr"))
			     || (! strcmp (mnt->mountpoint, "/var"))
			     || (! strncmp (mnt->mountpoint, "/usr/", 5))
			     || (! strncmp (mnt->mountpoint, "/var/", 5))
			     || (has_option (mnt, "bootwait", FALSE)))
			    && ! has_option (mnt, "nobootwait", FALSE))
1300
			{
1301
				tag = TAG_REMOTE;
1302
			} else {
1303
				tag = TAG_NOWAIT;
1304
			}
1305
		} else if (mnt->nodev
1306
			   && strcmp (mnt->type, "fuse")) {
1307
1308
1309
1310
1311
			if (! has_option (mnt, "nobootwait", FALSE)) {
				tag = TAG_VIRTUAL;
			} else {
				tag = TAG_NOWAIT;
			}
1312
		} else {
1313
			if (! has_option (mnt, "nobootwait", FALSE)) {
1314
1315
1316
1317
1318
1319
1320
				if ( has_option (mnt, "timeout", FALSE))
				{
					tag = TAG_TIMEOUT; 
				}
				else
					tag = TAG_LOCAL;
	
1321
			} else {