示例#1
0
static void test02(void)
{
    size_t alloc_size0 = get_allocsize();

    tst_resm(TINFO, "read allocated file size '%zu'", alloc_size0);
    tst_resm(TINFO, "make a hole with FALLOC_FL_PUNCH_HOLE");

    if (tst_kvercmp(2, 6, 38) < 0) {
        tst_brkm(TCONF, cleanup,
                 "FALLOC_FL_PUNCH_HOLE needs Linux 2.6.38 or newer");
    }

    if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                  block_size, block_size) == -1) {
        if (errno == EOPNOTSUPP) {
            tst_brkm(TCONF, cleanup,
                     "FALLOC_FL_PUNCH_HOLE not supported");
        }
        tst_brkm(TFAIL | TERRNO, cleanup, "fallocate() failed");
    }

    tst_resm(TINFO, "check that file has a hole with lseek(,,SEEK_HOLE)");
    off_t ret = lseek(fd, 0, SEEK_HOLE);

    if (ret != (ssize_t)block_size) {
        /* exclude error when kernel doesn't have SEEK_HOLE support */
        if (errno != EINVAL) {
            tst_brkm(TFAIL | TERRNO, cleanup,
                     "fallocate() or lseek() failed");
        }
        if (tst_kvercmp(3, 1, 0) < 0) {
            tst_resm(TINFO, "lseek() doesn't support SEEK_HOLE, "
                     "this is expected for < 3.1 kernels");
        } else {
            tst_brkm(TBROK | TERRNO, cleanup,
                     "lseek() doesn't support SEEK_HOLE");
        }
    } else {
        tst_resm(TINFO, "found a hole at '%ld' offset", ret);
    }

    size_t alloc_size1 = get_allocsize();

    tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
             alloc_size0, alloc_size1);
    if ((alloc_size0 - block_size) != alloc_size1)
        tst_brkm(TFAIL, cleanup, "not expected allocated size");

    char exp_buf[buf_size];

    fill_tst_buf(exp_buf);
    memset(exp_buf + block_size, 0, block_size);

    check_file_data(exp_buf, buf_size);

    tst_resm(TPASS, "test-case succeeded");
}
示例#2
0
static void test03(void)
{
    tst_resm(TINFO, "zeroing file space with FALLOC_FL_ZERO_RANGE");

    if (tst_kvercmp(3, 15, 0) < 0) {
        tst_brkm(TCONF, cleanup,
                 "FALLOC_FL_ZERO_RANGE needs Linux 3.15 or newer");
    }

    size_t alloc_size0 = get_allocsize();

    tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);

    if (fallocate(fd, FALLOC_FL_ZERO_RANGE, block_size - 1,
                  block_size + 2) == -1) {
        if (errno == EOPNOTSUPP) {
            tst_brkm(TCONF, cleanup,
                     "FALLOC_FL_ZERO_RANGE not supported");
        }
        tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
    }

    /* The file hole in the specified range must be allocated and
     * filled with zeros. Check it.
     */
    size_t alloc_size1 = get_allocsize();

    tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
             alloc_size0, alloc_size1);
    if ((alloc_size0 + block_size) != alloc_size1)
        tst_brkm(TFAIL, cleanup, "not expected allocated size");

    char exp_buf[buf_size];

    fill_tst_buf(exp_buf);
    memset(exp_buf + block_size - 1, 0, block_size + 2);

    check_file_data(exp_buf, buf_size);

    tst_resm(TPASS, "test-case succeeded");
}
示例#3
0
static void test04(void)
{
    tst_resm(TINFO, "collapsing file space with FALLOC_FL_COLLAPSE_RANGE");

    size_t alloc_size0 = get_allocsize();

    tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);

    if (fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, block_size,
                  block_size) == -1) {
        if (errno == EOPNOTSUPP) {
            tst_brkm(TCONF, cleanup,
                     "FALLOC_FL_COLLAPSE_RANGE not supported");
        }
        tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
    }

    size_t alloc_size1 = get_allocsize();

    tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
             alloc_size0, alloc_size1);
    if ((alloc_size0 - block_size) != alloc_size1)
        tst_brkm(TFAIL, cleanup, "not expected allocated size");

    size_t size = buf_size - block_size;
    char tmp_buf[buf_size];
    char exp_buf[size];

    fill_tst_buf(tmp_buf);

    memcpy(exp_buf, tmp_buf, block_size);
    memcpy(exp_buf + block_size, tmp_buf + size, block_size);

    exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
    check_file_data(exp_buf, size);

    tst_resm(TPASS, "test-case succeeded");
}
示例#4
0
文件: profile.c 项目: Barrell/wine
static void test_WritePrivateProfileString(void)
{
    BOOL ret;
    LPCSTR data;
    CHAR path[MAX_PATH];
    CHAR temp[MAX_PATH];

    SetLastError(0xdeadbeef);
    ret = WritePrivateProfileStringW(NULL, NULL, NULL, NULL);
    if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        /* Win9x/WinME needs (variable) timeouts between tests and even long timeouts don't
         * guarantee a correct result.
         * Win9x/WinMe also produces different ini files where there is always a newline before
         * a section start (except for the first one).
         */
        win_skip("WritePrivateProfileString on Win9x/WinME is hard to test reliably\n");
        return;
    }

    GetTempPathA(MAX_PATH, temp);
    GetTempFileNameA(temp, "wine", 0, path);
    DeleteFileA(path);

    /* path is not created yet */

    /* NULL lpAppName */
    SetLastError(0xdeadbeef);
    ret = WritePrivateProfileStringA(NULL, "key", "string", path);
    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
    ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
       broken(GetLastError() == ERROR_INVALID_PARAMETER) || /* NT4 */
       broken(GetLastError() == 0xdeadbeef), /* Win9x and WinME */
       "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
    ok(GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES,
       "Expected path to not exist\n");

    GetTempFileNameA(temp, "wine", 0, path);

    /* NULL lpAppName, path exists */
    data = "";
    SetLastError(0xdeadbeef);
    ret = WritePrivateProfileStringA(NULL, "key", "string", path);
    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
    ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
       broken(GetLastError() == ERROR_INVALID_PARAMETER) || /* NT4 */
       broken(GetLastError() == 0xdeadbeef), /* Win9x and WinME */
       "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
    ok(check_file_data(path, data), "File doesn't match\n");
    DeleteFileA(path);

    if (0)
    {
    /* empty lpAppName, crashes on NT4 and higher */
    data = "[]\r\n"
           "key=string\r\n";
    ret = WritePrivateProfileStringA("", "key", "string", path);
    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
    ok(check_file_data(path, data), "File doesn't match\n");
    DeleteFileA(path);
    }

    /* NULL lpKeyName */
    data = "";
    ret = WritePrivateProfileStringA("App", NULL, "string", path);
    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
    todo_wine
    {
        ok(check_file_data(path, data), "File doesn't match\n");
    }
    DeleteFileA(path);

    if (0)
    {
    /* empty lpKeyName, crashes on NT4 and higher */
    data = "[App]\r\n"
           "=string\r\n";
    ret = WritePrivateProfileStringA("App", "", "string", path);
    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
    todo_wine
    {
        ok(check_file_data(path, data), "File doesn't match\n");
    }
    DeleteFileA(path);
    }
示例#5
0
文件: profile.c 项目: Barrell/wine
    todo_wine
    {
        ok(check_file_data(path, data) ||
           (broken(GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES)), /* Win9x and WinME */
           "File doesn't match\n");
    }
    DeleteFileA(path);

    /* empty lpString */
    data = "[App]\r\n"
           "key=\r\n";
    ret = WritePrivateProfileStringA("App", "key", "", path);
    ok(ret == TRUE ||
       broken(!ret), /* Win9x and WinME */
       "Expected TRUE, got %d\n", ret);
    ok(check_file_data(path, data) ||
       (broken(GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES)), /* Win9x and WinME */
       "File doesn't match\n");
    DeleteFileA(path);

    /* empty lpFileName */
    SetLastError(0xdeadbeef);
    ret = WritePrivateProfileStringA("App", "key", "string", "");
    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
    ok(GetLastError() == ERROR_ACCESS_DENIED ||
       broken(GetLastError() == ERROR_PATH_NOT_FOUND), /* Win9x and WinME */
       "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());

    /* The resulting file will be  X:\\%WINDIR%\\win1.tmp */
    GetWindowsDirectoryA(temp, MAX_PATH);
    GetTempFileNameA(temp, "win", 1, path);