| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | fstab.c |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | This file contains tests for fstab mounting. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #include "lxtcommon.h" |
| 16 | #include "unittests.h" |
| 17 | #include <libmount/libmount.h> |
| 18 | |
| 19 | #define LXT_NAME "fstab" |
| 20 | |
| 21 | LXT_VARIATION_HANDLER FsTabTestMount; |
| 22 | |
| 23 | static const LXT_VARIATION g_LxtVariations[] = {{"FsTab - DrvFs mounted through fstab", FsTabTestMount}}; |
| 24 | |
| 25 | int FstabTestEntry(int Argc, char* Argv[]) |
| 26 | |
| 27 | /*++ |
| 28 | |
| 29 | Routine Description: |
| 30 | |
| 31 | This routine main entry point for the wslpath tests. |
| 32 | |
| 33 | Arguments: |
| 34 | |
| 35 | Argc - Supplies the number of command line arguments. |
| 36 | |
| 37 | Argv - Supplies the command line arguments. |
| 38 | |
| 39 | Return Value: |
| 40 | |
| 41 | Returns 0 on success, -1 on failure. |
| 42 | |
| 43 | --*/ |
| 44 | |
| 45 | { |
| 46 | |
| 47 | LXT_ARGS Args; |
| 48 | int Result; |
| 49 | |
| 50 | LxtCheckResult(LxtInitialize(Argc, Argv, &Args, LXT_NAME)); |
| 51 | LxtCheckResult(LxtRunVariations(&Args, g_LxtVariations, LXT_COUNT_OF(g_LxtVariations))); |
| 52 | |
| 53 | ErrorExit: |
| 54 | LxtUninitialize(); |
| 55 | return !LXT_SUCCESS(Result); |
| 56 | } |
| 57 | |
| 58 | int FsTabTestMount(PLXT_ARGS Args) |
| 59 | |
| 60 | /*++ |
| 61 | |
| 62 | Description: |
| 63 | |
| 64 | This routine tests whether fstab mounting was performed correctly. |
| 65 | |
| 66 | N.B. This test should be run after changing the /etc/fstab file and |
| 67 | restarting the instance. |
| 68 | |
| 69 | Arguments: |
| 70 | |
| 71 | Args - Supplies the command line arguments. |
| 72 | |
| 73 | Return Value: |
| 74 | |
| 75 | Returns 0 on success, -1 on failure. |
| 76 | |
| 77 | --*/ |
| 78 | |
| 79 | { |
| 80 | |
| 81 | struct libmnt_fs* FileSystem; |
| 82 | bool Found; |
| 83 | const char* FsType; |
| 84 | struct libmnt_iter* Iterator; |
| 85 | const char* Options; |
| 86 | int Result; |
| 87 | const char* Source; |
| 88 | struct libmnt_table* Table; |
| 89 | |
| 90 | Iterator = NULL; |
| 91 | Table = mnt_new_table_from_file("/proc/self/mountinfo"); |
| 92 | LxtCheckNotEqual(Table, NULL, "%p"); |
| 93 | Iterator = mnt_new_iter(MNT_ITER_FORWARD); |
| 94 | LxtCheckNotEqual(Iterator, NULL, "%p"); |
| 95 | Found = false; |
| 96 | while (mnt_table_next_fs(Table, Iterator, &FileSystem) == 0) |
| 97 | { |
| 98 | FsType = mnt_fs_get_fstype(FileSystem); |
| 99 | Options = mnt_fs_get_fs_options(FileSystem); |
| 100 | |
| 101 | // |
| 102 | // Check that there is only one mount for C: (or any variation therefore, like C:\ or c:), |
| 103 | // and that its mount uses the exact options specified in fstab. |
| 104 | // |
| 105 | |
| 106 | if (strcmp(FsType, "9p") == 0) |
| 107 | { |
| 108 | if (strcasestr(Options, "aname=drvfs;path=C:") != NULL) |
| 109 | { |
| 110 | LxtCheckTrue(!Found); |
| 111 | LxtCheckNotEqual(strstr(Options, "aname=drvfs;path=C:\\;metadata;"), NULL, "%p"); |
| 112 | Found = true; |
| 113 | } |
| 114 | } |
| 115 | else if (strcmp(FsType, "drvfs") == 0) |
| 116 | { |
| 117 | Source = mnt_fs_get_source(FileSystem); |
| 118 | if (strcasestr(Source, "C:") == Source) |
| 119 | { |
| 120 | LxtCheckTrue(!Found); |
| 121 | LxtCheckStringEqual(Source, "C:\\"); |
| 122 | LxtCheckStringEqual(Options, "rw,metadata,case=off"); |
| 123 | Found = true; |
| 124 | } |
| 125 | } |
| 126 | else if (strcmp(FsType, "virtiofs") == 0) |
| 127 | { |
| 128 | Source = mnt_fs_get_source(FileSystem); |
| 129 | if (strcasestr(Source, "drvfsaC") == Source) |
| 130 | { |
| 131 | LxtCheckTrue(!Found); |
| 132 | LxtCheckStringEqual(Options, "rw"); |
| 133 | Found = true; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | LxtCheckTrue(Found); |
| 139 | |
| 140 | ErrorExit: |
| 141 | if (Iterator != NULL) |
| 142 | { |
| 143 | mnt_free_iter(Iterator); |
| 144 | } |
| 145 | |
| 146 | if (Table != NULL) |
| 147 | { |
| 148 | mnt_free_table(Table); |
| 149 | } |
| 150 | |
| 151 | return Result; |
| 152 | } |