This file is indexed.

/usr/src/blcr-0.8.5/tests/dev_null.c is in blcr-dkms 0.8.5-2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  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
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Berkeley Lab Checkpoint/Restart (BLCR) for Linux is Copyright (c)
 * 2003, The Regents of the University of California, through Lawrence
 * Berkeley National Laboratory (subject to receipt of any required
 * approvals from the U.S. Dept. of Energy).  All rights reserved.
 *
 * Portions may be copyrighted by others, as may be noted in specific
 * copyright notices within specific files.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: dev_null.c,v 1.6 2008/08/29 21:36:53 phargrov Exp $
 *
 * Test of /dev/{null,zero,full}
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

#include "crut.h"

struct testdata {
    int null;
    int zero;
    int full;
};

static int
dev_null_setup(void **testdata)
{
    struct testdata *td;
    int fd;

    CRUT_DEBUG("Initializing dev_null.");
    td = malloc(sizeof(struct testdata));
    if (!td) return -1;

    td->null = fd = open("/dev/null", O_RDWR);
    if (fd < 0) {
	CRUT_FAIL("open(/dev/null): %s", strerror(errno));
	return -1;
    }
    td->zero = fd = open("/dev/zero", O_RDWR);
    if (fd < 0) {
	CRUT_FAIL("open(/dev/zero): %s", strerror(errno));
	return -1;
    }
    td->full = fd = open("/dev/full", O_WRONLY);
    if (fd < 0) {
	CRUT_FAIL("open(/dev/full): %s", strerror(errno));
	return -1;
    }

    *testdata = td;

    return 0;
}

static int check_it(struct testdata *td) {
    int retval = 0;
    int i;
    int rc;

    
    /* /dev/null: reads get EOF, writes succeed */
    i = 0x12345678;
    rc = read(td->null, &i, sizeof(i));
    if (rc < 0) {
	CRUT_FAIL("read(/dev/null) failed: %s", strerror(errno));
	retval = -1;
    } else if (rc != 0) {
	CRUT_FAIL("read(/dev/null) returned %d (expect 0)", rc);
	retval = -1;
    }
    rc = write(td->null, &i, sizeof(i));
    if (rc < 0) {
	CRUT_FAIL("write(/dev/null) failed: %s", strerror(errno));
	retval = -1;
    } else if (rc != sizeof(i)) {
	CRUT_FAIL("write(/dev/null) returned %d (expect %d)", rc, (int)sizeof(i));
	retval = -1;
    }

    /* /dev/zero: reads get zeroed bytes, writes succeed */
    i = 0x12345678;
    rc = read(td->zero, &i, sizeof(i));
    if (rc < 0) {
	CRUT_FAIL("read(/dev/zero) failed: %s", strerror(errno));
	retval = -1;
    } else if (rc != sizeof(i)) {
	CRUT_FAIL("read(/dev/zero) returned %d (expect %d)", rc, (int)sizeof(i));
	retval = -1;
    } else if (i != 0) {
	CRUT_FAIL("read(/dev/zero) read value %d (expect 0)", i);
	retval = -1;
    }
    rc = write(td->zero, &i, sizeof(i));
    if (rc < 0) {
	CRUT_FAIL("write(/dev/zero) failed: %s", strerror(errno));
	retval = -1;
    } else if (rc != sizeof(i)) {
	CRUT_FAIL("write(/dev/zero) returned %d (expect %d)", rc, (int)sizeof(i));
	retval = -1;
    }

    /* /dev/full: writes fail w/ ENOSPC */
    i = 0x12345678;
    rc = write(td->full, &i, sizeof(i));
    if (rc >= 0) {
	CRUT_FAIL("write(/dev/zero) returned %d (expect < 0)", rc);
	retval = -1;
    } else if (errno != ENOSPC) {
	CRUT_FAIL("write(/dev/full) failed: %s", strerror(errno));
	retval = -1;
    }

    return retval;
}

static int
dev_null_precheckpoint(void *p)
{
    CRUT_DEBUG("Testing sanity before we checkpoint");
    return check_it((struct testdata *)p);
}

static int
dev_null_continue(void *p)
{
    CRUT_DEBUG("Continuing after checkpoint.");
    return check_it((struct testdata *)p);
}

static int
dev_null_restart(void *p)
{
    CRUT_DEBUG("Restarting from checkpoint.");
    return check_it((struct testdata *)p);
}

static int
dev_null_teardown(void *p)
{
    struct testdata *td = (struct testdata *)p;

    close(td->null);
    close(td->zero);
    close(td->full);
    free(td);

    return 0;
}

int
main(int argc, char *argv[])
{
    int ret;
    struct crut_operations dev_null_test_ops = {
	test_scope:CR_SCOPE_PROC,
	test_name:"/dev/null",
        test_description:"Test of /dev/{null,zero,full}",
	test_setup:dev_null_setup,
	test_precheckpoint:dev_null_precheckpoint,
	test_continue:dev_null_continue,
	test_restart:dev_null_restart,
	test_teardown:dev_null_teardown,
    };

    /* add the basic tests */
    crut_add_test(&dev_null_test_ops);

    ret = crut_main(argc, argv);

    return ret;
}