]> wimlib.net Git - wimlib/blobdiff - src/util.c
imagex unmount --rebuild
[wimlib] / src / util.c
index b68db910ad1abab7ad3576f72cfc955bb71e4419..ed4779516b7501c985080ae3700cac4c5311664f 100644 (file)
@@ -102,12 +102,18 @@ WIMLIBAPI int wimlib_set_print_errors(bool show_error_messages)
 #else
        if (show_error_messages)
                return WIMLIB_ERR_UNSUPPORTED;
+       else
+               return 0;
 #endif
 }
 
 static const char *error_strings[] = {
        [WIMLIB_ERR_SUCCESS]
                = "Success",
+       [WIMLIB_ERR_ALREADY_LOCKED]
+               = "The WIM is already locked for writing",
+       [WIMLIB_ERR_CHAR_CONVERSION]
+               = "Failed to perform a conversion between UTF-8 and UTF-16LE",
        [WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE]
                = "Lookup table is compressed",
        [WIMLIB_ERR_DECOMPRESSION]
@@ -148,10 +154,15 @@ static const char *error_strings[] = {
                = "An entry in the WIM's lookup table is invalid",
        [WIMLIB_ERR_INVALID_PARAM]
                = "An invalid parameter was given",
+       [WIMLIB_ERR_INVALID_PART_NUMBER]
+               = "The part number or total parts of the WIM is invalid",
        [WIMLIB_ERR_INVALID_RESOURCE_HASH]
                = "The SHA1 message digest of a WIM resource did not match the expected value",
        [WIMLIB_ERR_INVALID_RESOURCE_SIZE]
                = "A resource entry in the WIM has an invalid size",
+       [WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE]
+               = "The version of wimlib that has mounted a WIM image is incompatible with the "
+                 "version being used to unmount it",
        [WIMLIB_ERR_LINK]
                = "Failed to create a hard or symbolic link when extracting "
                        "a file from the WIM",
@@ -180,6 +191,10 @@ static const char *error_strings[] = {
                = "Could not read the target of a symbolic link",
        [WIMLIB_ERR_RENAME]
                = "Could not rename a file",
+       [WIMLIB_ERR_REOPEN]
+               = "Could not re-open the WIM after overwriting it",
+       [WIMLIB_ERR_RESOURCE_ORDER]
+               = "The components of the WIM were arranged in an unexpected order",
        [WIMLIB_ERR_SPECIAL_FILE]
                = "Encountered a special file that cannot be archived",
        [WIMLIB_ERR_SPLIT_INVALID]
@@ -348,44 +363,21 @@ char *utf8_to_utf16(const char *utf8_str, size_t utf8_len,
        return orig_utf16_str;
 }
 
-/* Write @n bytes from @buf to the file descriptor @fd, retrying on interupt and
- * on short writes.
- *
- * Returns short count and set errno on failure. */
-ssize_t full_write(int fd, const void *buf, size_t n)
+static bool seeded = false;
+
+static void seed_random()
 {
-       const char *p = buf;
-       ssize_t ret;
-       ssize_t total = 0;
-
-       while (total != n) {
-               ret = write(fd, p, n);
-               if (ret < 0) {
-                       if (errno == EINTR)
-                               continue;
-                       else
-                               break;
-               }
-               total += ret;
-               p += ret;
-       }
-       return total;
+       srand(time(NULL) * getpid());
+       seeded = true;
 }
 
-
-static bool seeded = false;
-
 /* Fills @n bytes pointed to by @p with random alphanumeric characters. */
 void randomize_char_array_with_alnum(char p[], size_t n)
 {
-       int r;
-
-       if (!seeded) {
-               srand(time(NULL));
-               seeded = true;
-       }
+       if (!seeded)
+               seed_random();
        while (n--) {
-               r = rand() % 62;
+               int r = rand() % 62;
                if (r < 26)
                        *p++ = r + 'a';
                else if (r < 52)
@@ -398,10 +390,8 @@ void randomize_char_array_with_alnum(char p[], size_t n)
 /* Fills @n bytes pointer to by @p with random numbers. */
 void randomize_byte_array(u8 *p, size_t n)
 {
-       if (!seeded) {
-               srand(time(NULL));
-               seeded = true;
-       }
+       if (!seeded)
+               seed_random();
        while (n--)
                *p++ = rand();
 }
@@ -525,4 +515,10 @@ u64 get_wim_timestamp()
        return timeval_to_wim_timestamp(&tv);
 }
 
-
+void wim_timestamp_to_str(u64 timestamp, char *buf, size_t len)
+{
+       struct tm tm;
+       time_t t = wim_timestamp_to_unix(timestamp);
+       gmtime_r(&t, &tm);
+       strftime(buf, len, "%a %b %d %H:%M:%S %Y UTC", &tm);
+}