Example #1
0
static
off_t
filesize(const char *file, int fd)
{
    struct stat st;

    dofstat(file, fd, &st);
    return st.st_size;
}
Example #2
0
/*
 * This is _not_ a 64 bit system call.  It's a 32 bit svc that
 * supports large files
 */
extern "C" int
__k42_linux_fstat64 ( int fd, struct stat64 *output_stat)
{
    struct _gstat64 gstat;
   
    int rc = dofstat(fd, (void *) &gstat);
    if (rc < 0) return rc;

    _convert_gstat2lgstat64(output_stat, &gstat);
    return 0;
}
Example #3
0
/*
 * 32 bit within 64 bit kernel "fstat"
 */
extern "C" int
__k42_linux_compat_sys_newfstat (int fd, struct compat_stat *kstat)
{
    //err_printf("compat_sys_newfstat: on %d(%016lx)\n", fd, (uval)kstat);
    struct _gstat64 gstat;

    int rc = dofstat(fd, (void *) &gstat);
    if (rc < 0) return rc;

    _convert_gstat2kstat32(kstat, &gstat);	// kstat <- gstat
    return 0;
}
Example #4
0
int
__k42_linux_fstat (int fd, struct stat *kstat)
{
    //err_printf("fstat on %d(%016lx)\n", fd, (uval)kstat);
    struct _gstat64 gstat;
   
    int rc = dofstat(fd, (void *) &gstat);
    if (rc < 0) return rc;

    _convert_gstat2kstat(kstat, &gstat);
    return 0;
}
Example #5
0
static
void
doinfo(const char *file)
{
    int fd;
    struct stat st;
    long long amt;

    fd = doopen(file, O_RDWR, 0);
    checkheader(file, fd);
    dofstat(file, fd, &st);

    amt = st.st_size - HEADERSIZE;
    printf("%s size %lld bytes (%lld sectors; %lldK; %lldM)\n", file,
           amt, amt / SECTORSIZE, amt / 1024, amt / (1024*1024));


    amt = st.st_blocks * 512LL;
    printf("%s spaceused %lld bytes (%lld sectors; %lldK; %lldM)\n", file,
           amt, amt / SECTORSIZE, amt / 1024, amt / (1024*1024));

    close(fd);
}
Example #6
0
int
main(int argc, char *argv[])
{
	struct stat putfd_1_stat, putfd_2_stat, getfd_1_stat, getfd_2_stat;
	int fd[2], putfd_1, putfd_2, getfd_1, getfd_2;
	const char *test;

	/*
	 * First test: put a temporary file into a UNIX domain socket, then
	 * take it out and make sure it's the same file.  First time around,
	 * don't close the reference after sending.
	 */
	test = "test1-simplesendfd";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	dofstat(test, putfd_1, &putfd_1_stat);
	sendfd(test, fd[0], putfd_1);
	recvfd(test, fd[1], &getfd_1);
	dofstat(test, getfd_1, &getfd_1_stat);
	samefile(test, &putfd_1_stat, &getfd_1_stat);
	close(putfd_1);
	close(getfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Second test: same as first, only close the file reference after
	 * sending, so that the only reference is the descriptor in the UNIX
	 * domain socket buffer.
	 */
	test = "test2-sendandclose";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	dofstat(test, putfd_1, &putfd_1_stat);
	sendfd(test, fd[0], putfd_1);
	close(putfd_1);
	recvfd(test, fd[1], &getfd_1);
	dofstat(test, getfd_1, &getfd_1_stat);
	samefile(test, &putfd_1_stat, &getfd_1_stat);
	close(getfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Third test: put a temporary file into a UNIX domain socket, then
	 * close both endpoints causing garbage collection to kick off.
	 */
	test = "test3-sendandcancel";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	sendfd(test, fd[0], putfd_1);
	close(putfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Send two files.  Then receive them.  Make sure they are returned
	 * in the right order, and both get there.
	 */

	test = "test4-twofile";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	tempfile(test, &putfd_2);
	dofstat(test, putfd_1, &putfd_1_stat);
	dofstat(test, putfd_2, &putfd_2_stat);
	sendfd(test, fd[0], putfd_1);
	sendfd(test, fd[0], putfd_2);
	close(putfd_1);
	close(putfd_2);
	recvfd(test, fd[1], &getfd_1);
	recvfd(test, fd[1], &getfd_2);
	dofstat(test, getfd_1, &getfd_1_stat);
	dofstat(test, getfd_2, &getfd_2_stat);
	samefile(test, &putfd_1_stat, &getfd_1_stat);
	samefile(test, &putfd_2_stat, &getfd_2_stat);
	close(getfd_1);
	close(getfd_2);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Big bundling test.  Send an endpoint of the UNIX domain socket
	 * over itself, closing the door behind it.
	 */

	test = "test5-bundle";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);

	sendfd(test, fd[0], fd[0]);
	close(fd[0]);
	recvfd(test, fd[1], &getfd_1);
	close(getfd_1);
	close(fd[1]);

	printf("%s passed\n", test);

	/*
	 * Big bundling test part two: Send an endpoint of the UNIX domain
	 * socket over itself, close the door behind it, and never remove it
	 * from the other end.
	 */

	test = "test6-bundlecancel";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	sendfd(test, fd[0], fd[0]);
	sendfd(test, fd[1], fd[0]);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Test for PR 151758: Send an character device over the UNIX
	 * domain socket and then close both sockets to orphan the
	 * device.
	 */

	test = "test7-devfsorphan";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	devnull(test, &putfd_1);
	sendfd(test, fd[0], putfd_1);
	close(putfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);
	
	return (0);
}