示例#1
0
int main( int argc, char **argv )
{
    int err;
    int existingdirents=-1;
#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    struct cyg_fs_block_usage usage;
#endif

    CYG_TEST_INIT();

    // --------------------------------------------------------------

    err = mount( "/dev/disk0/1", "/", "fatfs" );    
    if( err < 0 ) SHOW_RESULT( mount, err );    

    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/" );
    
    listdir( "/", true, -1, &existingdirents );

    // --------------------------------------------------------------
#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
    if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
    diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
		usage.total_blocks, usage.total_blocks * usage.block_size); 
    diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
		usage.free_blocks, usage.free_blocks * usage.block_size); 
    diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
#endif
    // --------------------------------------------------------------

    createfile( "/foo", 20257 );
    checkfile( "foo" );
    copyfile( "foo", "fee");
    checkfile( "fee" );
    comparefiles( "foo", "/fee" );
    diag_printf("<INFO>: mkdir bar\n");
    err = mkdir( "/bar", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "/" , true, existingdirents+3, NULL );

    copyfile( "fee", "/bar/fum" );
    checkfile( "bar/fum" );
    comparefiles( "/fee", "bar/fum" );

    diag_printf("<INFO>: cd bar\n");
    err = chdir( "bar" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/bar" );
    
    diag_printf("<INFO>: rename /foo bundy\n");    
    err = rename( "/foo", "bundy" );
    if( err < 0 ) SHOW_RESULT( rename, err );
    
    listdir( "/", true, existingdirents+2, NULL );
    listdir( "" , true, 4, NULL );

    checkfile( "/bar/bundy" );
    comparefiles("/fee", "bundy" );

#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
    if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
    diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
		usage.total_blocks, usage.total_blocks * usage.block_size); 
    diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
		usage.free_blocks, usage.free_blocks * usage.block_size); 
    diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
#endif
    // --------------------------------------------------------------

    diag_printf("<INFO>: unlink fee\n");    
    err = unlink( "/fee" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink fum\n");        
    err = unlink( "fum" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink /bar/bundy\n");        
    err = unlink( "/bar/bundy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd /\n");        
    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/" );
    
    diag_printf("<INFO>: rmdir /bar\n");        
    err = rmdir( "/bar" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
    
    listdir( "/", false, existingdirents, NULL );

    // --------------------------------------------------------------

#if 0
    diag_printf("<INFO>: mkdir disk2\n");
    err = mkdir( "/disk2", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
#else
    diag_printf("<INFO>: mount /disk2\n");    
    err = mount( "/dev/disk0/2", "/disk2", "fatfs" );    
    if( err < 0 ) SHOW_RESULT( mount, err );    
#endif
    
    listdir( "/disk2" , true, -1, &existingdirents);
        
    createfile( "/disk2/tinky", 4567 );
    copyfile( "/disk2/tinky", "/disk2/laalaa" );
    checkfile( "/disk2/tinky");
    checkfile( "/disk2/laalaa");
    comparefiles( "/disk2/tinky", "/disk2/laalaa" );

    diag_printf("<INFO>: cd /disk2\n");    
    err = chdir( "/disk2" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/disk2" );
        
    diag_printf("<INFO>: mkdir noonoo\n");    
    err = mkdir( "noonoo", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "/disk2" , true, existingdirents+3, NULL);

    diag_printf("<INFO>: cd noonoo\n");
    err = chdir( "noonoo" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/disk2/noonoo" );
    
    createfile( "tinky", 6789 );
    checkfile( "tinky" );

    createfile( "dipsy", 34567 );
    checkfile( "dipsy" );
    copyfile( "dipsy", "po" );
    checkfile( "po" );
    comparefiles( "dipsy", "po" );

    listdir( ".", true, 5, NULL );
    listdir( "", true, 5, NULL );
    listdir( "..", true, existingdirents+3, NULL );

    // --------------------------------------------------------------

    diag_printf("<INFO>: unlink tinky\n");    
    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink dipsy\n");    
    err = unlink( "dipsy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink po\n");    
    err = unlink( "po" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd ..\n"); 
    err = chdir( ".." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2" );
    
    diag_printf("<INFO>: rmdir noonoo\n"); 
    err = rmdir( "noonoo" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    // --------------------------------------------------------------

    err = mkdir( "x", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    err = mkdir( "x/y", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    err = mkdir( "x/y/z", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    err = mkdir( "x/y/z/w", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    diag_printf("<INFO>: cd /disk2/x/y/z/w\n");
    err = chdir( "/disk2/x/y/z/w" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y/z/w" );

    diag_printf("<INFO>: cd ..\n");
    err = chdir( ".." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y/z" );
    
    diag_printf("<INFO>: cd .\n");
    err = chdir( "." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y/z" );

    diag_printf("<INFO>: cd ../../y\n");
    err = chdir( "../../y" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y" );

    diag_printf("<INFO>: cd ../..\n");
    err = chdir( "../.." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2" );

    diag_printf("<INFO>: rmdir x/y/z/w\n"); 
    err = rmdir( "x/y/z/w" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x/y/z\n"); 
    err = rmdir( "x/y/z" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x/y\n"); 
    err = rmdir( "x/y" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x\n"); 
    err = rmdir( "x" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
    
    // --------------------------------------------------------------

    checkcwd( "/disk2" );
    
    diag_printf("<INFO>: unlink tinky\n");    
    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink laalaa\n");    
    err = unlink( "laalaa" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd /\n");    
    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/" );

    listdir( "/disk2", true, -1, NULL );
    
#if 0
    diag_printf("<INFO>: rmdir dir\n"); 
    err = rmdir( "disk2" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
#else
    diag_printf("<INFO>: umount /disk2\n");    
    err = umount( "/disk2" );
    if( err < 0 ) SHOW_RESULT( umount, err );    
#endif
    
#ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
    // Create file
    diag_printf("<INFO>: create /foo\n");
    createfile( "/foo", 20257 );

    // Verify it is created with archive bit set
    checkattrib( "/foo", S_FATFS_ARCHIVE );

    // Make it System
    diag_printf("<INFO>: attrib -A+S /foo\n");
    err = cyg_fs_set_attrib( "/foo", S_FATFS_SYSTEM );
    if( err < 0 ) SHOW_RESULT( chmod system , err );

    // Verify it is now System
    checkattrib( "/foo", S_FATFS_SYSTEM );

    // Make it Hidden
    diag_printf("<INFO>: attrib -S+H /foo\n");
    err = cyg_fs_set_attrib( "/foo", S_FATFS_HIDDEN );
    if( err < 0 ) SHOW_RESULT( chmod system , err );

    // Verify it is now Hidden
    checkattrib( "/foo", S_FATFS_HIDDEN );

    // Make it Read-only
    diag_printf("<INFO>: attrib -H+R /foo\n");
    err = cyg_fs_set_attrib( "/foo", S_FATFS_RDONLY );
    if( err < 0 ) SHOW_RESULT( chmod system , err );

    // Verify it is now Read-only
    checkattrib( "/foo", S_FATFS_RDONLY );

    // Verify we cannot unlink a read-only file
    diag_printf("<INFO>: unlink /foo\n");
    err = unlink( "/foo" );
    if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( unlink, err );

    // Verify we cannot rename a read-only file
    diag_printf("<INFO>: rename /foo bundy\n");
    err = rename( "/foo", "bundy" );
    if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( rename, err );

    // Verify we cannot open read-only file for writing
    int fd;
    diag_printf("<INFO>: create file /foo\n");
    fd = open( "/foo", O_WRONLY );
    if( (err != -1) || (errno != EACCES) ) SHOW_RESULT( open, err );
    if( err > 0 ) close(fd);

    // Make it Normal
    diag_printf("<INFO>: attrib -H /foo\n");
    err = cyg_fs_set_attrib( "/foo", 0 );
    if( err < 0 ) SHOW_RESULT( chmod none , err );

    // Verify it is now nothing
    checkattrib( "/foo", 0 );

    // Now delete our test file
    diag_printf("<INFO>: unlink /foo\n");
    err = unlink( "/foo" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

#endif // CYGCFG_FS_FAT_USE_ATTRIBUTES

    maxfile("file.max");

    listdir( "/", true, -1, NULL );    
        
    diag_printf("<INFO>: unlink file.max\n");    
    err = unlink( "file.max" );
    if( err < 0 ) SHOW_RESULT( unlink, err );    
    diag_printf("<INFO>: umount /\n");    
    err = umount( "/" );
    if( err < 0 ) SHOW_RESULT( umount, err );    
    
    CYG_TEST_PASS_FINISH("fatfs1");
}
示例#2
0
int main( int argc, char **argv )
{
    int err;
    FILE *stream;
    long pos;
    unsigned int i;
    char header[3];

    CYG_TEST_INIT();

    // --------------------------------------------------------------

    CYG_TEST_INFO("mount /");    
    err = mount( "", "/", "ramfs" );

    if( err < 0 ) SHOW_RESULT( mount, err );    
    
    CYG_TEST_INFO("creating /fseek");
    stream = fopen("/fseek","w+");
    if (!stream) {
      SHOW_RESULT( fopen, NULL);
      CYG_TEST_FAIL_FINISH("done");\
    }

    for (i = 0; i < sizeof(buf); i++) {
      buf[i] = i % 256;
    }
    
    CYG_TEST_INFO("writing test pattern");    
    err=fwrite(buf,sizeof(buf), 1, stream);
    if ( err < 0 ) SHOW_RESULT( fwrite, err );
    
    pos = ftell(stream);
    if (pos < 0) SHOW_RESULT( ftell, pos );
    if (pos != sizeof(buf))
      diag_printf("<FAIL>: ftell is not telling the truth.");
    
    CYG_TEST_INFO("fseek()ing to 85");
    err = fseek(stream, 85, SEEK_SET);
    if ( err < 0 ) SHOW_RESULT( fseek, err );

    pos = ftell(stream);
    if (pos < 0) SHOW_RESULT( ftell, pos );
    if (pos != 85) CYG_TEST_FAIL("ftell is not telling the truth");

    err = fread(header,3,1,stream);
    if ( err < 0 ) SHOW_RESULT( fwrite, err );
    if ((header[0] != 85) ||
        (header[1] != 86) ||
        (header[2] != 87))
      CYG_TEST_FAIL("Read returned false data");
    
    pos = ftell(stream);
    if (pos < 0) SHOW_RESULT( ftell, pos );
    if (pos != 88)  CYG_TEST_FAIL("ftell is not telling the truth");

    for (i = 88; i < 161; i++) {
      buf[i] = 0x42;
    }
    
    CYG_TEST_INFO("writing");
    err = fwrite(buf+88, 73, 1, stream);
    if ( err < 0 ) SHOW_RESULT( fwrite, err );

    pos = ftell(stream);
    if (pos < 0) SHOW_RESULT( ftell, pos );
    if (pos != 161)  CYG_TEST_FAIL("ftell is not telling the truth");

    CYG_TEST_INFO("closing file");
    err = fclose(stream);
    if (err != 0) SHOW_RESULT( fclose, err );

    CYG_TEST_INFO("open file /fseek");
    stream = fopen("/fseek", "r+");
    if (!stream) {
      SHOW_RESULT( fopen, NULL);
      CYG_TEST_FAIL_FINISH("done");\
    }

    CYG_TEST_INFO("Seeking to beginning of file");
    err = fseek(stream, 0, SEEK_SET);
    if ( err < 0 ) SHOW_RESULT( fseek, err );

    CYG_TEST_INFO("Reading buf1");
    err = fread(buf1,sizeof(buf1),1, stream);
    if (err != 1) SHOW_RESULT( fread, err );

    CYG_TEST_INFO("Comparing contents");
    if (memcmp(buf, buf1, sizeof(buf1))) 
      CYG_TEST_FAIL("File contents inconsistent");

    CYG_TEST_INFO("closing file");
    err = fclose(stream);
    if (err != 0) SHOW_RESULT( fclose, err );
    
    CYG_TEST_INFO("umount /");    
    err = umount( "/" );
    if( err < 0 ) SHOW_RESULT( umount, err );    
    
    CYG_TEST_PASS_FINISH("ramfs3");
}
示例#3
0
/** try to mount an initrd on mountpoint
 * @file: path to the initrd file
 * @mountpoint: the directory where we mount to
 */
int try_initrd_mount(char **file, const char *mountpoint)
{
	struct stat st;
	int fd;
	unsigned long len,readed;
	char magic[6],buff[1024],*cpio_archive;

	if(stat(*file,&st))
		return -1;
	if(S_ISREG(st.st_mode))
	{
		cpio_archive=NULL;
		fd = open(*file,O_RDONLY);
		if(fd<0)
			return -1;
		if((len = read(fd,magic,6)) != 6)
		{
			close(fd);
			return -1;
		}
		// gzip magic
		if(magic[0] == 0x1f && magic[1] == 0x8b)
		{
			close(fd);
			cpio_archive = zlib_decompress_file(*file,&len);
			if(!cpio_archive)
				return -1;
			memcpy(magic,cpio_archive,6);
		}
		else // get file size
		{
			while((readed = read(fd,buff,1024)) > 0)
				len+=readed;
			close(fd);
			if(readed)
				return -1;
		}
		// cpio magic
		if(magic[0] == '0' && magic[1] == '7' && magic[2] == '0' && magic[3] == '7' && magic[4] == '0' && magic[5] == '7')
		{
			if(!cpio_archive) // we have to read it
			{
				cpio_archive = malloc(len); // len is the size in bytes ( man 2 read )
				if(!cpio_archive)
				{
					return -1;
				}
				fd = open(*file,O_RDONLY);
				if(fd<0)
				{
					free(cpio_archive);
					return -1;
				}
				if((readed = read(fd,cpio_archive,len)) != len)
				{
					free(cpio_archive);
					close(fd);
					return -1;
				}
				close(fd);
			}
			umount(mountpoint);
			if(mount("tmpfs",mountpoint,"tmpfs",MS_RELATIME,""))
			{
				free(cpio_archive);
				return -1;
			}
			if(cpio_copyin(cpio_archive,len,mountpoint))
			{
				umount(mountpoint);
				free(cpio_archive);
				return -1;
			}
			free(cpio_archive);
			len = strlen(mountpoint);
			free(*file);
			*file = malloc((len+1)*sizeof(char));
			if(!*file)
			{
				umount(mountpoint);
				return -1;
			}
			strncpy(*file,mountpoint,len);
			(*file)[len] = '\0';
		}
	}
	return 0;
}
示例#4
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, options, &help)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	/* Check for mandatory option of the testcase */
	if (!Dflag)
		tst_brkm(TBROK, NULL,
		    "you must specify the device used for mounting with the -D "
		    "option");

	if (Tflag) {
		Fstype = malloc(strlen(fstype) + 1);
		if (Fstype == NULL) {
			tst_brkm(TBROK|TERRNO, NULL,
			    "malloc - failed to alloc %zd", strlen(fstype));
		}
		strncpy(Fstype, fstype, strlen(fstype) + 1);
	} else {
		Fstype = malloc(strlen(DEFAULT_FSTYPE) + 1);
		if (Fstype == NULL) {
			tst_brkm(TBROK, NULL, "malloc - failed to alloc %zu",
			    strlen(DEFAULT_FSTYPE));
		}
		strncpy(Fstype, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE) + 1);
	}

	if (STD_COPIES != 1) {
		tst_resm(TINFO, "-c option has no effect for this testcase - "
			 "%s doesn't allow running more than one instance "
			 "at a time", TCID);
		STD_COPIES = 1;
	}

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/* Call mount(2) */
		TEST(mount(device, mntpoint, Fstype, 0, NULL));

		/* check return code */
		if (TEST_RETURN != 0) {
			tst_resm(TFAIL|TTERRNO, "mount(2) failed");
		} else {
			tst_resm(TPASS, "mount(2) passed ");
			TEST(umount(mntpoint));
			if (TEST_RETURN != 0) {
				tst_brkm(TBROK|TTERRNO, cleanup,
				    "umount(2) failed");
			}
		}
	}

	/* cleanup and exit */
	cleanup();

	tst_exit();
}
示例#5
0
/* When multiple fstab records share the same mount_point, it will
 * try to mount each one in turn, and ignore any duplicates after a
 * first successful mount.
 * Returns -1 on error, and  FS_MGR_MNTALL_* otherwise.
 */
int fs_mgr_mount_all(struct fstab *fstab)
{
    int i = 0;
    int encryptable = FS_MGR_MNTALL_DEV_NOT_ENCRYPTED;
    int error_count = 0;
    int mret = -1;
    int mount_errno = 0;
    int attempted_idx = -1;

    if (!fstab) {
        return -1;
    }

    for (i = 0; i < fstab->num_entries; i++) {
        /* Don't mount entries that are managed by vold */
        if (fstab->recs[i].fs_mgr_flags & (MF_VOLDMANAGED | MF_RECOVERYONLY)) {
            continue;
        }

        /* Skip swap and raw partition entries such as boot, recovery, etc */
        if (!strcmp(fstab->recs[i].fs_type, "swap") ||
            !strcmp(fstab->recs[i].fs_type, "emmc") ||
            !strcmp(fstab->recs[i].fs_type, "mtd")) {
            continue;
        }

        if (fstab->recs[i].fs_mgr_flags & MF_WAIT) {
            wait_for_file(fstab->recs[i].blk_device, WAIT_TIMEOUT);
        }

        if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) &&
            !device_is_debuggable()) {
            wait_for_file("/dev/device-mapper", WAIT_TIMEOUT);
            if (fs_mgr_setup_verity(&fstab->recs[i]) < 0) {
                ERROR("Could not set up verified partition, skipping!\n");
                continue;
            }
        }
        int last_idx_inspected;
        mret = mount_with_alternatives(fstab, i, &last_idx_inspected, &attempted_idx);
        i = last_idx_inspected;
        mount_errno = errno;

        /* Deal with encryptability. */
        if (!mret) {
            /* If this is encryptable, need to trigger encryption */
            if ((fstab->recs[attempted_idx].fs_mgr_flags & MF_FORCECRYPT)) {
                if (umount(fstab->recs[attempted_idx].mount_point) == 0) {
                    if (encryptable == FS_MGR_MNTALL_DEV_NOT_ENCRYPTED) {
                        ERROR("Will try to encrypt %s %s\n", fstab->recs[attempted_idx].mount_point,
                              fstab->recs[attempted_idx].fs_type);
                        encryptable = FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION;
                    } else {
                        ERROR("Only one encryptable/encrypted partition supported\n");
                        encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED;
                    }
                } else {
                    INFO("Could not umount %s - allow continue unencrypted\n",
                         fstab->recs[attempted_idx].mount_point);
                    continue;
                }
            }
            /* Success!  Go get the next one */
            continue;
        }

        /* mount(2) returned an error, check if it's encryptable and deal with it */
        if (mret && mount_errno != EBUSY && mount_errno != EACCES &&
            fs_mgr_is_encryptable(&fstab->recs[attempted_idx])) {
            if(partition_wiped(fstab->recs[attempted_idx].blk_device)) {
                ERROR("%s(): %s is wiped and %s %s is encryptable. Suggest recovery...\n", __func__,
                      fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point,
                      fstab->recs[attempted_idx].fs_type);
                encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY;
                continue;
            } else {
                /* Need to mount a tmpfs at this mountpoint for now, and set
                 * properties that vold will query later for decrypting
                 */
                ERROR("%s(): possibly an encryptable blkdev %s for mount %s type %s )\n", __func__,
                      fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point,
                      fstab->recs[attempted_idx].fs_type);
                if (fs_mgr_do_tmpfs_mount(fstab->recs[attempted_idx].mount_point) < 0) {
                    ++error_count;
                    continue;
                }
            }
            encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED;
        } else {
            ERROR("Failed to mount an un-encryptable or wiped partition on"
                   "%s at %s options: %s error: %s\n",
                   fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point,
                   fstab->recs[attempted_idx].fs_options, strerror(mount_errno));
            ++error_count;
            continue;
        }
    }

    if (error_count) {
        return -1;
    } else {
        return encryptable;
    }
}
示例#6
0
文件: li-run.c 项目: jpumc/limba
/**
 * li_run_env_setup_with_root:
 *
 * Setup a new environment to run the application in,
 * using a specific root filesystem.
 * This function prints errors to stderr at time.
 *
 * Returns: A path to the new root filesystem, or %NULL on error.
 */
gchar*
li_run_env_setup_with_root (const gchar *root_fs)
{
	int res = 0;
	gchar *fname = NULL;
	uid_t uid;
	int mount_count;
	g_autofree gchar *newroot = NULL;
	g_autofree gchar *approot_dir = NULL;

	/* perform some preparation before we can mount the app */
	g_debug ("creating new namespace");
	res = unshare (CLONE_NEWNS);
	if (res != 0) {
		g_printerr ("Failed to create new namespace: %s\n", strerror(errno));
		return NULL;
	}

	/* Mark everything as slave, so that we still
	 * receive mounts from the real root, but don't
	 * propagate mounts to the real root. */
	if (mount (NULL, root_fs, NULL, MS_SLAVE | MS_REC, NULL) < 0) {
		g_printerr ("Failed to make / slave.\n");
		return NULL;
	}

	uid = getuid ();
	newroot = g_strdup_printf ("/run/user/%d/.limba-root", uid);
	if (g_mkdir_with_parents (newroot, 0755) != 0) {
		g_printerr ("Failed to create root tmpfs.\n");
		return NULL;
	}

	/* Create a tmpfs which we will use as / in the namespace */
	if (mount ("", newroot, "tmpfs", MS_NODEV | MS_NOEXEC | MS_NOSUID, NULL) != 0) {
		g_printerr ("Failed to mount tmpfs.\n");
		return NULL;
	}

	/* build & bindmount the root filesystem */
	if (mkdir_and_bindmount (newroot, root_fs, "/bin", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/cdrom", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/dev", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/etc", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/home", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/lib", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/lib64", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/media", TRUE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/mnt", TRUE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/opt", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/proc", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/srv", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/sys", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/usr", FALSE) != 0)
		return NULL;
	if (mkdir_and_bindmount (newroot, root_fs, "/var", TRUE) != 0)
		return NULL;

	/* prepare /run - give access to session data and DBus system bus */
	fname = g_strdup_printf ("/run/user/%d/", uid);
	if (mkdir_and_bindmount (newroot, root_fs, fname, TRUE) != 0) {
		g_free (fname);
		return NULL;
	}
	g_free (fname);
	if (mkdir_and_bindmount (newroot, root_fs, "/run/dbus", TRUE) != 0)
		return NULL;

	fname = g_build_filename (newroot, "tmp", NULL);
	if (g_mkdir_with_parents (fname, 0755) != 0) {
		g_free (fname);
		g_printerr ("Unable to create root /tmp dir.\n");
		return NULL;
	}
	if (chmod (fname, 01777) != 0) {
		g_free (fname);
		g_printerr ("Unable to set permissions on /tmp dir.\n");
		return NULL;
	}
	g_free (fname);

	fname = g_build_filename (newroot, ".oldroot", NULL);
	if (g_mkdir_with_parents (fname, 0755) != 0) {
		g_free (fname);
		g_printerr ("Unable to create root /.oldroot dir.\n");
		return NULL;
	}
	g_free (fname);

	/* the place where we will mount the application data to */
	approot_dir = g_build_filename (newroot, "app", NULL);
	if (g_mkdir_with_parents (approot_dir, 0755) != 0) {
		g_printerr ("Unable to create /app dir.\n");
		return NULL;
	}

	g_debug ("mount (private)");
	mount_count = 0;
	res = mount (approot_dir, approot_dir,
				 NULL, MS_PRIVATE, NULL);
	if (res != 0 && errno == EINVAL) {
		/* Maybe if failed because there is no mount
		 * to be made private at that point, lets
		 * add a bind mount there. */
		g_debug (("mount (bind)\n"));
		res = mount (approot_dir, approot_dir,
					 NULL, MS_BIND, NULL);
		/* And try again */
		if (res == 0) {
			mount_count++; /* Bind mount succeeded */
			g_debug ("mount (private)");
			res = mount (approot_dir, approot_dir,
						 NULL, MS_PRIVATE, NULL);
		}
	}

	if (res != 0) {
		g_error ("Failed to make prefix namespace private");
		goto error_out;
	}

	return g_strdup (newroot);

error_out:
	/* we have an error */
	while (mount_count-- > 0)
		umount (approot_dir);

	return NULL;
}
示例#7
0
int main(int argc, char *argv[])
{
    int i, res;
    static char *const cmd[] = { "/init", NULL };
    struct fstab *fstab = NULL;

    for(i = 1; i < argc; ++i)
    {
        if(strcmp(argv[i], "-v") == 0)
        {
            printf("%d\n", VERSION_TRAMPOLINE);
            fflush(stdout);
            return 0;
        }
    }

    umask(000);

    // Init only the little we need, leave the rest for real init
    mkdir("/dev", 0755);
    mkdir("/dev/pts", 0755);
    mkdir("/dev/socket", 0755);
    mkdir("/proc", 0755);
    mkdir("/sys", 0755);

    mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
    mount("devpts", "/dev/pts", "devpts", 0, NULL);
    mount("proc", "/proc", "proc", 0, NULL);
    mount("sysfs", "/sys", "sysfs", 0, NULL);

    klog_init();
    ERROR("Running trampoline v%d\n", VERSION_TRAMPOLINE);

    if(is_charger_mode())
    {
        ERROR("Charger mode detected, skipping multirom\n");
        goto run_main_init;
    }

#if MR_DEVICE_HOOKS >= 3
    tramp_hook_before_device_init();
#endif

    ERROR("Initializing devices...");
    devices_init();
    ERROR("Done initializing");

    if(wait_for_file("/dev/graphics/fb0", 5) < 0)
    {
        ERROR("Waiting too long for fb0");
        goto exit;
    }

    fstab = fstab_auto_load();
    if(!fstab)
        goto exit;

#if 0 
    fstab_dump(fstab); //debug
#endif

    // mount and run multirom from sdcard
    mount_and_run(fstab);

exit:
    if(fstab)
        fstab_destroy(fstab);

    // close and destroy everything
    devices_close();

run_main_init:
    if(access(KEEP_REALDATA, F_OK) < 0)
    {
        umount(REALDATA);
        umount("/dev/pts");
        umount("/dev");
        rmdir("/dev/pts");
        rmdir("/dev/socket");
        rmdir("/dev");
        rmdir(REALDATA);
    }

    umount("/proc");
    umount("/sys");
    rmdir("/proc");
    rmdir("/sys");

    ERROR("Running main_init\n");

    fixup_symlinks();

    chmod("/main_init", EXEC_MASK);
    rename("/main_init", "/init");

    res = execve(cmd[0], cmd, NULL);
    ERROR("execve returned %d %d %s\n", res, errno, strerror(errno));
    return 0;
}
示例#8
0
void start_kernel(struct params_t *params, int choice)
{
	/* we use var[] instead of *var because sizeof(var) using */
#ifdef USE_HOST_DEBUG
	const char kexec_path[] = "/bin/echo";
#else
	const char kexec_path[] = KEXEC_PATH;
#endif
	const char mount_point[] = MOUNTPOINT;

	const char str_cmdline_start[] = "--command-line=root=";
	const char str_rootfstype[] = " rootfstype=";
	const char str_rootwait[] = " rootwait";
	const char str_ubirootdev[] = "ubi0";
	const char str_ubimtd[] = " ubi.mtd="; /* max ' ubi.mtd=15' len 11 +1 = 12 */

#ifdef UBI_VID_HDR_OFFSET
	const char str_ubimtd_off[] = UBI_VID_HDR_OFFSET;
#else
	const char str_ubimtd_off[] = "";
#endif

	char mount_dev[16];
	char mount_fstype[16];
	char str_mtd_id[3];

	/* Tags passed from host kernel cmdline to kexec'ed kernel */
	const char str_mtdparts[] = " mtdparts=";
	const char str_fbcon[] = " fbcon=";

	const char str_initrd_start[] = "--initrd=";

	/* empty environment */
	char *const envp[] = { NULL };

	const char *load_argv[] = { NULL, "-l", NULL, NULL, NULL, NULL };
	const char *exec_argv[] = { NULL, "-e", NULL, NULL};

	char *cmdline_arg = NULL, *initrd_arg = NULL;
	int n, idx, u;
	struct stat sinfo;
	struct boot_item_t *item;

	item = params->bootcfg->list[choice];

	exec_argv[0] = kexec_path;
	load_argv[0] = kexec_path;

	/* --command-line arg generation */
	idx = 2;	/* load_argv current option index */

	/* fill '--command-line' option */
	if (item->device) {
		/* default device to mount */
		strcpy(mount_dev, item->device);

		/* allocate space */
		n = sizeof(str_cmdline_start) + strlen(item->device) +
				sizeof(str_ubirootdev) + 2 +
				sizeof(str_ubimtd) + 2 + sizeof(str_ubimtd_off) + 1 +
				sizeof(str_rootwait) +
				sizeof(str_rootfstype) + strlen(item->fstype) + 2 +
				sizeof(str_mtdparts) + strlenn(params->cfg->mtdparts) +
				sizeof(str_fbcon) + strlenn(params->cfg->fbcon) +
				sizeof(char) + strlenn(item->cmdline);

		cmdline_arg = (char *)malloc(n);
		if (NULL == cmdline_arg) {
			perror("Can't allocate memory for cmdline_arg");
		} else {

			strcpy(cmdline_arg, str_cmdline_start);	/* --command-line=root= */

			if (item->fstype) {

				/* default fstype to mount */
				strcpy(mount_fstype, item->fstype);

				/* extra tags when we detect UBI */
				if (!strncmp(item->fstype,"ubi",3)) {

					/* mtd id [0-15] - one or two digits */
					if(isdigit(atoi(item->device+strlen(item->device)-2))) {
						strcpy(str_mtd_id, item->device+strlen(item->device)-2);
						strcat(str_mtd_id, item->device+strlen(item->device)-1);
					} else {
						strcpy(str_mtd_id, item->device+strlen(item->device)-1);
					}
					/* get corresponding ubi dev to mount */
					u = find_attached_ubi_device(str_mtd_id);

					sprintf(mount_dev, "/dev/ubi%d", u);
					 /* FIXME: first volume is hardcoded */
					strcat(mount_dev, "_0");

					/* HARDCODED: we assume it's ubifs */
					strcpy(mount_fstype,"ubifs");

					/* extra cmdline tags when we detect ubi */
					strcat(cmdline_arg, str_ubirootdev);
					 /* FIXME: first volume is hardcoded */
					strcat(cmdline_arg, "_0");

					strcat(cmdline_arg, str_ubimtd);
					strcat(cmdline_arg, str_mtd_id);
#ifdef UBI_VID_HDR_OFFSET
					strcat(cmdline_arg, ",");
					strcat(cmdline_arg, str_ubimtd_off);
#endif
				} else {
					strcat(cmdline_arg, item->device); /* root=item->device */
				}
				strcat(cmdline_arg, str_rootfstype);
				strcat(cmdline_arg, mount_fstype);
			}
			strcat(cmdline_arg, str_rootwait);

			if (params->cfg->mtdparts) {
				strcat(cmdline_arg, str_mtdparts);
				strcat(cmdline_arg, params->cfg->mtdparts);
			}

			if (params->cfg->fbcon) {
				strcat(cmdline_arg, str_fbcon);
				strcat(cmdline_arg, params->cfg->fbcon);
			}

			if (item->cmdline) {
				strcat(cmdline_arg, " ");
				strcat(cmdline_arg, item->cmdline);
			}
			load_argv[idx] = cmdline_arg;
			++idx;
		}
	}

	/* fill '--initrd' option */
	if (item->initrd) {
		/* allocate space */
		n = sizeof(str_initrd_start) + strlen(item->initrd);

		initrd_arg = (char *)malloc(n);
		if (NULL == initrd_arg) {
			perror("Can't allocate memory for initrd_arg");
		} else {
			strcpy(initrd_arg, str_initrd_start);	/* --initrd= */
			strcat(initrd_arg, item->initrd);
			load_argv[idx] = initrd_arg;
			++idx;
		}
	}

	/* Append kernelpath as last arg of kexec */
	load_argv[idx] = item->kernelpath;

	DPRINTF("load_argv: %s, %s, %s, %s, %s", load_argv[0],
			load_argv[1], load_argv[2],
			load_argv[3], load_argv[4]);

	/* Mount boot device */
	if ( -1 == mount(mount_dev, mount_point, mount_fstype,
			MS_RDONLY, NULL) ) {
		perror("Can't mount boot device");
		exit(-1);
	}

	/* Load kernel */
	n = fexecw(kexec_path, (char *const *)load_argv, envp);
	if (-1 == n) {
		perror("Kexec can't load kernel");
		exit(-1);
	}

	umount(mount_point);

	dispose(cmdline_arg);
	dispose(initrd_arg);

	/* Check /proc/sys/net presence */
	if ( -1 == stat("/proc/sys/net", &sinfo) ) {
		if (ENOENT == errno) {
			/* We have no network, don't issue ifdown() while kexec'ing */
			exec_argv[2] = "-x";
			DPRINTF("No network is detected, disabling ifdown()");
		} else {
			perror("Can't stat /proc/sys/net");
		}
	}

	DPRINTF("exec_argv: %s, %s, %s", exec_argv[0],
			exec_argv[1], exec_argv[2]);

	/* Boot new kernel */
	execve(kexec_path, (char *const *)exec_argv, envp);
}
示例#9
0
int scan_devices(struct params_t *params)
{
	struct charlist *fl;
	struct bootconf_t *bootconf;
	struct device_t dev;
	struct cfgdata_t cfgdata;
	int rc,n;
	FILE *f;

	char mount_dev[16];
	char mount_fstype[16];
	char str_mtd_id[3];

#ifdef USE_ICONS
	kx_cfg_section *sc;
	int i;
	int rows;
	char **xpm_data;

#endif

	bootconf = create_bootcfg(4);
	if (NULL == bootconf) {
		DPRINTF("Can't allocate bootconf structure");
		return -1;
	}

	f = devscan_open(&fl);
	if (NULL == f) {
		log_msg(lg, "Can't initiate device scan");
		return -1;
	}

#ifdef USE_ZAURUS
	struct zaurus_partinfo_t pinfo;
	int zaurus_error = 0;
	zaurus_error = zaurus_read_partinfo(&pinfo);
	if (0 == zaurus_error) {
		/* Fix mtdparts tag */
		dispose(params->cfg->mtdparts);
		params->cfg->mtdparts = zaurus_mtdparts(&pinfo);
	}
#endif

	for (;;) {
		rc = devscan_next(f, fl, &dev);
		if (rc < 0) continue;	/* Error */
		if (0 == rc) break;		/* EOF */

		/* initialize with defaults */
		strcpy(mount_dev, dev.device);
		strcpy(mount_fstype, dev.fstype);

		/* We found an ubi erase counter */
		if (!strncmp(dev.fstype, "ubi",3)) {

			/* attach ubi boot device - mtd id [0-15] */
			if(isdigit(atoi(dev.device+strlen(dev.device)-2))) {
				strcpy(str_mtd_id, dev.device+strlen(dev.device)-2);
				strcat(str_mtd_id, dev.device+strlen(dev.device)-1);
			} else {
				strcpy(str_mtd_id, dev.device+strlen(dev.device)-1);
			}
			n = ubi_attach(str_mtd_id);

			/* we have attached ubiX and we mount /dev/ubiX_0  */
			sprintf(mount_dev, "/dev/ubi%d", n);
			 /* HARDCODED: first volume */
			strcat(mount_dev, "_0");

			/* HARDCODED: we assume it's ubifs */
			strcpy(mount_fstype, "ubifs");
		}

		/* Mount device */
		if (-1 == mount(mount_dev, MOUNTPOINT, mount_fstype, MS_RDONLY, NULL)) {
			log_msg(lg, "+ can't mount device %s: %s", mount_dev, ERRMSG);
			goto free_device;
		}

		/* NOTE: Don't go out before umount'ing */

		/* Search boot method and return boot info */
		rc = get_bootinfo(&cfgdata);

		if (-1 == rc) {	/* Error */
			goto umount;
		}

#ifdef USE_ICONS
		/* Iterate over sections found */
		if (params->gui) {
			for (i = 0; i < cfgdata.count; i++) {
				sc = cfgdata.list[i];
				if (!sc) continue;

				/* Load custom icon */
				if (sc->iconpath) {
					rows = xpm_load_image(&xpm_data, sc->iconpath);
					if (-1 == rows) {
						log_msg(lg, "+ can't load xpm icon %s", sc->iconpath);
						continue;
					}

					sc->icondata = xpm_parse_image(xpm_data, rows);
					if (!sc->icondata) {
						log_msg(lg, "+ can't parse xpm icon %s", sc->iconpath);
						continue;
					}
					xpm_destroy_image(xpm_data, rows);
				}
			}
		}
#endif

umount:
		/* Umount device */
		if (-1 == umount(MOUNTPOINT)) {
			log_msg(lg, "+ can't umount device: %s", ERRMSG);
			goto free_cfgdata;
		}

		if (-1 == rc) {	/* Error */
			goto free_cfgdata;
		}

#ifdef USE_ZAURUS
		/* Fix partition sizes. We can have kernel in root and home partitions on NAND */
		/* HACK: mtdblock devices are hardcoded */
		if (0 == zaurus_error) {
			if (0 == strcmp(dev.device, "/dev/mtdblock2")) {	/* root */
				log_msg(lg, "+ [zaurus root] size of %s will be changed from %llu to %lu",
						dev.device, dev.blocks, pinfo.root);
				dev.blocks = pinfo.root;
			} else if (0 == strcmp(dev.device, "/dev/mtdblock3")) {	/* home */
				log_msg(lg, "+ [zaurus home] size of %s will be changed from %llu to %lu",
						dev.device, dev.blocks, pinfo.home);
				dev.blocks = pinfo.home;
			}
		}
#endif

		/* Now we have something in cfgdata */
		rc = addto_bootcfg(bootconf, &dev, &cfgdata);

free_cfgdata:
		destroy_cfgdata(&cfgdata);
free_device:
		free(dev.device);
	}

	free_charlist(fl);
	params->bootcfg = bootconf;
	return 0;
}
int is_install_media(char *name)
{
    char pathbuf[PATH_MAX] = {0};
    char devinfo[PATH_MAX] = {0};
    int fd;
    char *minor_s;
    dev_t dev;
    int ret = 0;
    struct stat statbuf;
    char *src;
    const char *fst;

    dbg("------> examining %s\n", name);

    /* Read the "dev" node in the sysfs dir which has major:minor
     * and create a temp device node to work with */
    snprintf(pathbuf, sizeof(pathbuf), "%s/dev", name);
    fd = open(pathbuf, O_RDONLY);
    if (fd < 0) {
        dbg_perror("open");
        return 0;
    }
    if ((ret = read(fd, devinfo, sizeof(devinfo)-1)) <= 0) {
        dbg_perror("read");
        return 0;
    }
    close(fd);

    devinfo[ret] = '\0';
    ret = 0;

    minor_s = strchr(devinfo, ':');
    if (!minor_s)
        return 0;
    *minor_s = '\0';
    minor_s++;

    dev = makedev(atoi(devinfo), atoi(minor_s));

    if (mknod(TMP_NODE, S_IFBLK, dev)) {
        dbg_perror("mknod");
        return 0;
    }

    fst = detect_fs(TMP_NODE);

    if (!fst) {
        dbg("Not the right fs type\n");
        goto out_unlink;
    }

    strcpy(pathbuf, INSTALL_MOUNT);
    if ((src = getenv("SRC"))) {
        strcat(pathbuf, src);
    } else if ((src = getenv("BOOT_IMAGE"))) {
        strcat(pathbuf, src);
        if ((src = strrchr(pathbuf, '/')))
            *src = '\0';
    }

    dbg("Mounting device %d:%d type=%s\n", major(dev), minor(dev), fst);
    /* Try to mount the fs */
    if (mount(TMP_NODE, INSTALL_MOUNT, fst, MS_RDONLY, "")) {
        dbg_perror("mount");
        goto out_unlink;
    }

    if (mount(pathbuf, INSTALL_MEDIA, "", MS_BIND, NULL)) {
        dbg_perror("mount_bind");
        umount(INSTALL_MOUNT);
        goto out_unlink;
    }

    /* It mounted - check for cookie */
    if (stat(INSTALL_MEDIA "/iago-cookie", &statbuf)) {
        dbg_perror("stat iago cookie");
        umount(INSTALL_MEDIA);
        umount(INSTALL_MOUNT);
    } else {
        dbg("'%s %s' is Iago media\n", name, pathbuf);
        ret = 1;
    }

out_unlink:
    unlink(TMP_NODE);

    return ret;
}
示例#11
0
文件: fileio1.c 项目: janfj/dd-wrt
int main( int argc, char **argv )
{
    int err;

    CYG_TEST_INIT();

    // --------------------------------------------------------------

    createfile( "/foo", 202 );
    checkfile( "foo" );
    copyfile( "foo", "fee");
    checkfile( "fee" );
    comparefiles( "foo", "/fee" );

    err = mkdir( "/bar", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "/" , false);

    copyfile( "fee", "/bar/fum" );
    checkfile( "bar/fum" );
    comparefiles( "/fee", "bar/fum" );


    err = chdir( "bar" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    err = rename( "/foo", "bundy" );
    if( err < 0 ) SHOW_RESULT( rename, err );

    listdir( "/", true );
    listdir( "" , true );

    checkfile( "/bar/bundy" );
    comparefiles("/fee", "bundy" );

    testfs_dump();

    // --------------------------------------------------------------

    err = unlink( "/fee" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "fum" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "/bar/bundy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    err = rmdir( "/bar" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    listdir( "/", false );

    // --------------------------------------------------------------

    err = mount( "", "/ram", "testfs" );
    if( err < 0 ) SHOW_RESULT( mount, err );

    createfile( "/ram/tinky", 456 );
    copyfile( "/ram/tinky", "/ram/laalaa" );
    checkfile( "/ram/tinky");
    checkfile( "/ram/laalaa");
    comparefiles( "/ram/tinky", "/ram/laalaa" );

    err = chdir( "/ram" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    createfile( "tinky", 678 );
    checkfile( "tinky" );

    maxfile( "dipsy" );
    checkfile( "dipsy" );
    copyfile( "dipsy", "po" );
    checkfile( "po" );
    comparefiles( "dipsy", "po" );

    testfs_dump();

    // --------------------------------------------------------------

    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "dipsy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "po" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "laalaa" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    err = umount( "/ram" );
    if( err < 0 ) SHOW_RESULT( umount, err );

    CYG_TEST_PASS_FINISH("fileio1");
}
示例#12
0
int main(int ac, char **av)
{
	int lc, i;
	char *msg;

	if ((msg = parse_opts(ac, av, options, &help)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	/* Check for mandatory option of the testcase */
	if (!Dflag) {
		tst_brkm(TBROK, NULL,
		    "you must specify the device used for mounting with -D "
		    "option");
	}

	if (Tflag) {
		Fstype = (char *)malloc(strlen(fstype)+1);
		if (Fstype == NULL) {
			tst_brkm(TBROK|TERRNO, NULL, "malloc failed");
		}
		Fstype[strlen(fstype)] = '\0';
		strncpy(Fstype, fstype, strlen(fstype));
	} else {
		Fstype = (char *)malloc(strlen(DEFAULT_FSTYPE)+1);
		if (Fstype == NULL) {
			tst_brkm(TBROK|TERRNO, NULL, "malloc failed");
		}
		strncpy(Fstype, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE));
		Fstype[strlen(DEFAULT_FSTYPE)] = '\0';
	}

	if (STD_COPIES != 1) {
		tst_resm(TINFO, "-c option has no effect for this testcase - "
			 "%s doesn't allow running more than one instance "
			 "at a time", TCID);
		STD_COPIES = 1;
	}

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {

			/* Call mount(2) */
			TEST(mount(device, mntpoint, Fstype, rwflags[i], NULL));

			/* check return code */
			if (TEST_RETURN != 0) {
				tst_resm(TFAIL|TTERRNO, "mount(2) failed");
				continue;
			}

			/* Validate the rwflag */
			if (test_rwflag(i, lc) == 1) {
				tst_resm(TFAIL, "mount(2) failed while"
				    " validating %ld", rwflags[i]);
			} else {
				tst_resm(TPASS, "mount(2) passed with "
				    "rwflag = %ld", rwflags[i]);
			}
			TEST(umount(mntpoint));
			if (TEST_RETURN != 0) {
				tst_brkm(TBROK|TTERRNO, cleanup,
				    "umount(2) failed for %s", mntpoint);
			}
		}
	}

	/* cleanup and exit */
	cleanup();

	tst_exit();
}
示例#13
0
文件: main.c 项目: nn/fs-pkg
int main(int argc, char **argv) {
   int         fd;
#if	defined(USE_FUSE)
   struct fuse_args margs = FUSE_ARGS_INIT(0, NULL);
#endif
   conf.born = time(NULL);
   umask(0);

   atexit(goodbye);

   signal_init();
   evt_init();
   blockheap_init();
   dconf_init("fs-pkg.cf");
   dlink_init();
   pkg_init();
   inode_init();

   if (dconf_get_bool("sys.daemonize", 0) == 1) {
      fprintf(stdout, "going bg, bye!\n");
      /*
       * XXX: add daemon crud 
       */
   }

   /*
    * open log file, if its valid, otherwise assume debug mode and use stdout 
    */
   if ((conf.log_fp = log_open(dconf_get_str("path.log", NULL))) == NULL)
      conf.log_fp = stdout;

   Log(LOG_INFO, "%s %s starting up...", argv[0], VERSION);

   if (!conf.mountpoint)
      conf.mountpoint = dconf_get_str("path.mountpoint", "/test");

#if	defined(USE_FUSE)
   /*
    * only way to make gcc happy...argh;) -bk 
    */
   vfs_fuse_args = margs;

   /*
    * The fuse_mount() options get modified, so we always rebuild it 
    */
   if ((fuse_opt_add_arg(&vfs_fuse_args, argv[0]) == -1 ||
        fuse_opt_add_arg(&vfs_fuse_args, "-o") == -1 ||
        fuse_opt_add_arg(&vfs_fuse_args, "nonempty,allow_other") == -1))
      Log(LOG_ERROR, "Failed to set FUSE options.\n");

   umount(conf.mountpoint);
   vfs_fuse_init();
#endif

   Log(LOG_DEBUG, "Opening database %s", dconf_get_str("path.db", ":memory"));
   db_sqlite_open(dconf_get_str("path.db", ":memory"));

   /*
    * set up the watch subsystem 
    */
   vfs_watch_init();

   /*
    * walk the package dirs and import all existing packages 
    */
   vfs_dir_walk();

   /*
    * the big event loop 
    */
   while (!conf.dying) {
      ev_loop(evt_loop, 0);
   }

   /*
    * shouldnt be reached... 
    */
   return EXIT_SUCCESS;
}
示例#14
0
int main(int argc, char **argv)
{

	char *varstr;
	int   rc;
	int   varStatus;
	char *szSessionInfo = "dm_test session info";
	dm_eventset_t events;

	DMOPT_PARSE(argc, argv);
	DMLOG_START();

	DMEV_ZERO(events);
	DMEV_SET(DM_EVENT_MOUNT, events);

	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
	if ((rc = dm_init_service(&varstr)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno);
		DM_EXIT();
	} else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
		DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno);
		dm_destroy_session(sid);
		DM_EXIT();
	} else {
		sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
		sprintf(DummyFile2, "%s/%s", mountPt, DUMMY_FILE2);
		sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR);
		sprintf(DummySubdir2, "%s/%s", mountPt, DUMMY_SUBDIR2);
		sprintf(DummyLink, "%s/%s", mountPt, DUMMY_LINK);

		remove(DummyFile);
		remove(DummyFile2);
		unlink(DummyLink);
		rmdir(DummySubdir);
		rmdir(DummySubdir2);
	}

	DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI synchronous namespace event tests\n") ;

	/*
	 * TEST    : mkdir - DM_RESP_CONTINUE
	 * EXPECTED: DM_EVENT_CREATE
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 1)) {
		dm_ino_t ino;

		/* Variation set up */
		eventExpected = DM_EVENT_CREATE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;

		/* Variation */
		EVENT_DELIVERY_DELAY;
		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir);
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir, rc);
		if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
			rc = dm_handle_to_ino(hanp1, hlen1, &ino);
		        if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
				varStatus = DMSTAT_FAIL;
			} else if (ino != ROOT_INODE) {
				DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
				varStatus = DMSTAT_FAIL;
			} else if (strcmp(name1, DUMMY_SUBDIR) != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR);
				varStatus = DMSTAT_FAIL;
			}
		}
		DMVAR_END(varStatus);

		/* Variation clean up */
		EVENT_DELIVERY_DELAY;
		rc = rmdir(DummySubdir);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
		}
	}

	/*
	 * TEST    : mkdir - DM_RESP_ABORT
	 * EXPECTED: DM_EVENT_CREATE
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 2)) {
		dm_ino_t ino;

		/* Variation set up */
		eventExpected = DM_EVENT_CREATE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_ABORT;

		/* Variation */
		EVENT_DELIVERY_DELAY;
		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir);
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir, rc);
		if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
			rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
				varStatus = DMSTAT_FAIL;
			} else if (ino != ROOT_INODE) {
				DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
				varStatus = DMSTAT_FAIL;
			} else if (strcmp(name1, DUMMY_SUBDIR) != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR);
				varStatus = DMSTAT_FAIL;
			}
		}
		DMVAR_END(varStatus);

		/* Variation clean up */
	}

	/*
	 * TEST    : rmdir - DM_RESP_CONTINUE
	 * EXPECTED: DM_EVENT_REMOVE
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 3)) {
		dm_ino_t ino;

		/* Variation set up */
		eventExpected = DM_EVENT_REMOVE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir);
			rc = rmdir(DummySubdir);
			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n", DummySubdir, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_SUBDIR) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
		}
	}

	/*
	 * TEST    : rmdir - DM_RESP_ABORT
	 * EXPECTED: DM_EVENT_REMOVE
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 4)) {
		dm_ino_t ino;

		/* Variation set up */
		eventExpected = DM_EVENT_REMOVE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir);
			rc = rmdir(DummySubdir);
			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n", DummySubdir, rc);
			if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_SUBDIR) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = rmdir(DummySubdir);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : mv - DM_RESP_CONTINUE
	 * EXPECTED: DM_EVENT_RENAME
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 5)) {
		dm_ino_t ino1, ino2;

		/* Variation set up */
		eventExpected = DM_EVENT_RENAME;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		sprintf(command, "mv %s %s", DummySubdir, DummySubdir2);
		EVENT_DELIVERY_DELAY;
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummySubdir, DummySubdir2);
			rc = system(command);
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummySubdir, DummySubdir2, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n");
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_SUBDIR) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DUMMY_SUBDIR2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_SUBDIR2);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			EVENT_DELIVERY_DELAY;
			rc = rmdir(DummySubdir2);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : mv - DM_RESP_ABORT
	 * EXPECTED: DM_EVENT_RENAME
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 6)) {
		dm_ino_t ino1, ino2;

		/* Variation set up */
		eventExpected = DM_EVENT_RENAME;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		sprintf(command, "mv %s %s", DummySubdir, DummySubdir2);
		EVENT_DELIVERY_DELAY;
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummySubdir, DummySubdir2);
			rc = system(command);
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummySubdir, DummySubdir2, rc);
			if ((varStatus = (rc == 0 ? DMSTAT_FAIL : DMSTAT_PASS)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n");
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_SUBDIR) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DUMMY_SUBDIR2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_SUBDIR2);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = rmdir(DummySubdir);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : symlink - DM_RESP_CONTINUE
	 * EXPECTED: DM_EVENT_SYMLINK
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 7)) {
		dm_ino_t ino;

		/* Variation set up */
		eventExpected = DM_EVENT_SYMLINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummySubdir, DummySubdir2);
			rc = symlink(DummySubdir, DummySubdir2);
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummySubdir, DummySubdir2, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_SUBDIR2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR2);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DummySubdir) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummySubdir);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			EVENT_DELIVERY_DELAY;
			rc = unlink(DummySubdir2);
			rc |= rmdir(DummySubdir);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : symlink - DM_RESP_ABORT
	 * EXPECTED: DM_EVENT_SYMLINK
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 8)) {
		dm_ino_t ino;

		/* Variation set up */
		eventExpected = DM_EVENT_SYMLINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummySubdir, DummySubdir2);
			rc = symlink(DummySubdir, DummySubdir2);
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummySubdir, DummySubdir2, rc);
			EVENT_DELIVERY_DELAY;
			if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_SUBDIR2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR2);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DummySubdir) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummySubdir);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = rmdir(DummySubdir);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : link - DM_RESP_CONTINUE
	 * EXPECTED: DM_EVENT_LINK
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 9)) {
#ifdef DIRECTORY_LINKS
		dm_ino_t ino1, ino2, ino3;
		void *hanp;
		size_t hlen;

		/* Variation set up */
		eventExpected = DM_EVENT_LINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) {
			rmdir(DummySubdir);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir, DummyLink);
			rc = link(DummySubdir, DummyLink);
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummySubdir, DummyLink, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
				rc |= dm_handle_to_ino(hanp, hlen, &ino3);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ino3) {
					DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_LINK) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			EVENT_DELIVERY_DELAY;
			rc = rmdir(DummySubdir);
			rc |= unlink(DummyLink);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
#else
		DMLOG_PRINT(DMLVL_WARN, "Test case not built with DIRECTORY_LINKS defined\n");
		DMVAR_SKIP();
#endif
	}

	/*
	 * TEST    : link - DM_RESP_ABORT
	 * EXPECTED: DM_EVENT_LINK
	 */
	if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 10)) {
#ifdef DIRECTORY_LINKS
		dm_ino_t ino1, ino2, ino3;
		void *hanp;
		size_t hlen;

		/* Variation set up */
		eventExpected = DM_EVENT_LINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
			/* No clean up */
		} else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) {
			rmdir(DummySubdir);
		}
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir, DummyLink);
			rc = link(DummySubdir, DummyLink);
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummySubdir, DummyLink, rc);
			if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
				rc |= dm_handle_to_ino(hanp, hlen, &ino3);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ino3) {
					DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_LINK) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = rmdir(DummySubdir);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
#else
		DMLOG_PRINT(DMLVL_WARN, "Test case not built with DIRECTORY_LINKS defined\n");
		DMVAR_SKIP();
#endif
	}

	/*
	 * TEST    : open
	 * EXPECTED: DM_EVENT_CREATE, DM_RESP_CONTINUE
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 1)) {
		int fd;
		dm_ino_t ino;

		/* Variation set up */
		eventExpected = DM_EVENT_CREATE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;

		/* Variation */
		EVENT_DELIVERY_DELAY;
		DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile);
		fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
		DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile, fd);
		rc = (fd == -1) ? -1 : 0;
		if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
			rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
				varStatus = DMSTAT_FAIL;
			} else if (ino != ROOT_INODE) {
				DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
				varStatus = DMSTAT_FAIL;
			} else if (strcmp(name1, DUMMY_FILE) != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s %s)\n", name1, DUMMY_SUBDIR);
				varStatus = DMSTAT_FAIL;
			}
		}
		DMVAR_END(varStatus);

		/* Variation clean up */
		EVENT_DELIVERY_DELAY;
		rc = close(fd);
		rc |= remove(DummyFile);
		if (rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
		}
	}

	/*
	 * TEST    : open
	 * EXPECTED: DM_EVENT_CREATE, DM_RESP_ABORT
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 2)) {
		dm_ino_t ino;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_CREATE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_ABORT;

		/* Variation */
		EVENT_DELIVERY_DELAY;
		DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile);
		fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
		DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile, fd);
		if ((varStatus = DMVAR_CHKFAILEXP(-1, fd, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
			rc = dm_handle_to_ino(hanp1, hlen1, &ino);
		        if (rc == -1) {
				DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
				varStatus = DMSTAT_FAIL;
			} else if (ino != ROOT_INODE) {
				DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
				varStatus = DMSTAT_FAIL;
			} else if (strcmp(name1, DUMMY_FILE) != 0) {
				DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE);
				varStatus = DMSTAT_FAIL;
			}
		}
		DMVAR_END(varStatus);

		/* Variation clean up */
	}

	/*
	 * TEST    : remove
	 * EXPECTED: DM_EVENT_REMOVE, DM_RESP_CONTINUE
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 3)) {
		dm_ino_t ino;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_REMOVE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) {
			rc = close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile);
			rc = remove(DummyFile);
			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n", DummyFile, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_FILE) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
		}
	}

	/*
	 * TEST    : remove
	 * EXPECTED: DM_EVENT_REMOVE, DM_RESP_ABORT
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 4)) {
		dm_ino_t ino;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_REMOVE;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) {
			rc = close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile);
			rc = remove(DummyFile);
			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n", DummyFile, rc);
			if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_FILE) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : mv
	 * EXPECTED: DM_EVENT_RENAME, DM_RESP_CONTINUE
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 5)) {
		dm_ino_t ino1, ino2;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_RENAME;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		sprintf(command, "mv %s %s", DummyFile, DummyFile2);
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) {
			rc = close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummyFile, DummyFile2);
			rc = system(command);
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummyFile, DummyFile2, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n");
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_FILE) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DUMMY_FILE2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_FILE2);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			EVENT_DELIVERY_DELAY;
			rc = remove(DummyFile2);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : mv
	 * EXPECTED: DM_EVENT_RENAME, DM_RESP_ABORT
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 6)) {
		dm_ino_t ino1, ino2;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_RENAME;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		sprintf(command, "mv %s %s", DummyFile, DummyFile2);
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) {
			rc = close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummyFile, DummyFile2);
			rc = system(command);
			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummyFile, DummyFile2, rc);
			if ((varStatus = (rc == 0 ? DMSTAT_FAIL : DMSTAT_PASS)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n");
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_FILE) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DUMMY_FILE2) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_FILE2);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : symlink
	 * EXPECTED: DM_EVENT_SYMLINK, DM_RESP_CONTINUE
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 7)) {
		dm_ino_t ino;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_SYMLINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) {
			rc = close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile, DummyLink);
			rc = symlink(DummyFile, DummyLink);
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummyFile, DummyLink, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_LINK) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DummyFile) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummyFile);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			EVENT_DELIVERY_DELAY;
			rc = unlink(DummyLink);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : symlink
	 * EXPECTED: DM_EVENT_SYMLINK, DM_RESP_ABORT
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 8)) {
		dm_ino_t ino;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_SYMLINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) {
			rc = close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile, DummyLink);
			rc = symlink(DummyFile, DummyLink);
			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummyFile, DummyLink, rc);
			if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino);
				if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_LINK) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name2, DummyFile) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummyFile);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
		}
	}

	/*
	 * TEST    : link
	 * EXPECTED: DM_EVENT_LINK, DM_RESP_CONTINUE
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 9)) {
		dm_ino_t ino1, ino2, ino3;
		void *hanp;
		size_t hlen;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_LINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) {
			/* No clean up */
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile, DummyLink);
			rc = link(DummyFile, DummyLink);
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummyFile, DummyLink, rc);
			if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
				rc |= dm_handle_to_ino(hanp, hlen, &ino3);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ino3) {
					DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_LINK) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			EVENT_DELIVERY_DELAY;
			rc = close(fd);
			rc |= remove(DummyFile);
			rc |= remove(DummyLink);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	/*
	 * TEST    : link
	 * EXPECTED: DM_EVENT_LINK, DM_RESP_ABORT
	 */
	if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 10)) {
		dm_ino_t ino1, ino2, ino3;
		void *hanp;
		size_t hlen;
		int fd;

		/* Variation set up */
		eventExpected = DM_EVENT_LINK;
		eventReceived = DM_EVENT_INVALID;
		eventResponse = DM_RESP_CONTINUE;
		EVENT_DELIVERY_DELAY;
		if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) {
			/* No clean up */
		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
			close(fd);
		}
		if (fd == -1 || rc == -1) {
			DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno);
			DMVAR_SKIP();
		} else {
			/* Variation */
			eventResponse = DM_RESP_ABORT;
			EVENT_DELIVERY_DELAY;
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile, DummyLink);
			rc = link(DummyFile, DummyLink);
			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummyFile, DummyLink, rc);
			if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) {
				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
				rc |= dm_handle_to_ino(hanp, hlen, &ino3);
			        if (rc == -1) {
					DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n");
					varStatus = DMSTAT_FAIL;
				} else if (ino1 != ROOT_INODE) {
					DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE);
					varStatus = DMSTAT_FAIL;
				} else if (ino2 != ino3) {
					DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3);
					varStatus = DMSTAT_FAIL;
				} else if (strcmp(name1, DUMMY_LINK) != 0) {
					DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK);
					varStatus = DMSTAT_FAIL;
				}
			}
			DMVAR_END(varStatus);

			/* Variation clean up */
			eventResponse = DM_RESP_CONTINUE;
			EVENT_DELIVERY_DELAY;
			rc = close(fd);
			rc |= remove(DummyFile);
			if (rc == -1) {
				DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno);
			}
			dm_handle_free(hanp, hlen);
		}
	}

	rc = umount(mountPt);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	pthread_join(tid, NULL);

	rc = dm_destroy_session(sid);
	if (rc == -1) {
		DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno);
	}

	DMLOG_STOP();

	tst_exit();
}
示例#15
0
char * mountNfsImage(struct installMethod * method,
                     char * location, struct loaderData_s * loaderData) {
    char * host = NULL;
    char * directory = NULL;
    char * mountOpts = NULL;
    char * fullPath = NULL;
    char * url = NULL;

    enum { NFS_STAGE_NFS, NFS_STAGE_MOUNT, NFS_STAGE_DONE,
           NFS_STAGE_UPDATES } stage = NFS_STAGE_NFS;

    int rc;

    /* JKFIXME: ASSERT -- we have a network device setup when we get here */
    while (stage != NFS_STAGE_DONE) {
        switch (stage) {
        case NFS_STAGE_NFS:
            logMessage(INFO, "going to do nfsGetSetup");
            if (loaderData->method == METHOD_NFS && loaderData->stage2Data) {
                host = ((struct nfsInstallData *)loaderData->stage2Data)->host;
                directory = ((struct nfsInstallData *)loaderData->stage2Data)->directory;

                if (((struct nfsInstallData *)
                    loaderData->stage2Data)->mountOpts == NULL) {
                    mountOpts = strdup("ro");
                } else {
                    if (asprintf(&mountOpts, "ro,%s",
                                 ((struct nfsInstallData *)
                                 loaderData->stage2Data)->mountOpts) == -1) {
                        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                        abort();
                    }
                }

                logMessage(INFO, "host is %s, dir is %s, opts are '%s'", host, directory, mountOpts);

                if (!host || !directory) {
                    logMessage(ERROR, "missing host or directory specification");

                    if (loaderData->inferredStage2)
                        loaderData->invalidRepoParam = 1;

                    loaderData->method = -1;
                    break;
                } else {
                    host = strdup(host);
                    directory = strdup(directory);
                }
            } else {
                char *substr, *tmp;

                if (nfsGetSetup(&host, &directory) == LOADER_BACK)
                    return NULL;

                /* If the user-provided URL points at a repo instead of a
                 * stage2 image, fix that up now.
                 */
                substr = strstr(directory, ".img");
                if (!substr || (substr && *(substr+4) != '\0')) {
                    if (asprintf(&(loaderData->instRepo), "nfs:%s:%s",
                                 host, directory) == -1) {
                        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                        abort();
                    }

                    if (asprintf(&tmp, "nfs:%s:%s/images/install.img",
                                 host, directory) == -1) {
                        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                        abort();
                    }

                    setStage2LocFromCmdline(tmp, loaderData);
                    free(host);
                    free(directory);
                    free(tmp);
                    continue;
                }

                loaderData->invalidRepoParam = 1;
            }

            stage = NFS_STAGE_MOUNT;
            break;

        case NFS_STAGE_MOUNT: {
            char *buf;

            if (asprintf(&fullPath, "%s:%.*s", host,
                         (int) (strrchr(directory, '/')-directory),
                         directory) == -1) {
                logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                abort();
            }

            logMessage(INFO, "mounting nfs path %s", fullPath);

            if (FL_TESTING(flags)) {
                stage = NFS_STAGE_DONE;
                break;
            }

            stage = NFS_STAGE_NFS;

            if (!doPwMount(fullPath, "/mnt/stage2", "nfs", mountOpts, NULL)) {
                if (asprintf(&buf, "/mnt/stage2/%s",
                             strrchr(directory, '/')) == -1) {
                    logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                    abort();
                }

                if (!access(buf, R_OK)) {
                    logMessage(INFO, "can access %s", buf);
                    rc = mountStage2(buf);

                    if (rc == 0) {
                        stage = NFS_STAGE_UPDATES;

                        if (asprintf(&url, "nfs:%s:%s", host,
                                     directory) == -1) {
                            logMessage(CRITICAL, "%s: %d: %m", __func__,
                                       __LINE__);
                            abort();
                        }

                        free(buf);
                        break;
                    } else {
                        logMessage(WARNING, "unable to mount %s", buf);
                        free(buf);
                        break;
                    }
                } else {
                    logMessage(WARNING, "unable to access %s", buf);
                    free(buf);
                    umount("/mnt/stage2");
                }
            } else {
                newtWinMessage(_("Error"), _("OK"),
                               _("That directory could not be mounted from "
                                 "the server."));
                if (loaderData->method >= 0)
                    loaderData->method = -1;

                if (loaderData->inferredStage2)
                    loaderData->invalidRepoParam = 1;

                break;
            }

            if (asprintf(&buf, _("That directory does not seem to "
                                 "contain a %s installation image."),
                         getProductName()) == -1) {
                logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                abort();
            }

            newtWinMessage(_("Error"), _("OK"), buf);
            free(buf);

            if (loaderData->method >= 0)
                loaderData->method = -1;

            if (loaderData->inferredStage2)
                loaderData->invalidRepoParam = 1;

            break;
        }

        case NFS_STAGE_UPDATES: {
            char *buf;

            if (asprintf(&buf, "%.*s/RHupdates",
                         (int) (strrchr(fullPath, '/')-fullPath),
                         fullPath) == -1) {
                logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                abort();
            }

            logMessage(INFO, "mounting nfs path %s for updates", buf);

            if (!doPwMount(buf, "/tmp/update-disk", "nfs", mountOpts, NULL)) {
                logMessage(INFO, "Using RHupdates/ for NFS install");
                copyDirectory("/tmp/update-disk", "/tmp/updates", NULL, NULL);
                umount("/tmp/update-disk");
                unlink("/tmp/update-disk");
            } else {
                logMessage(INFO, "No RHupdates/ directory found, skipping");
            }

            stage = NFS_STAGE_DONE;
            break;
        }

        case NFS_STAGE_DONE:
            break;
        }
    }

    free(host);
    free(directory);
    if (fullPath)
        free(fullPath);

    return url;
}
示例#16
0
文件: umount.c 项目: calebgray/trunix
int main(int argc, char **argv) {
  if (argc < 2) return 1;
  if (argc == 2) return umount(argv[1]);
  return umount2(argv[1], atoi(argv[2]));
}
示例#17
0
int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
    char * host = NULL, *path = NULL, * file = NULL, * opts = NULL;
    char * chk = NULL, *ip = NULL;
    int failed = 0;
    iface_t iface;

    if (kickstartNetworkUp(loaderData, &iface)) {
        logMessage(ERROR, "unable to bring up network");
        return 1;
    }

    /* if they just did 'linux ks', they want us to figure it out from
     * the dhcp/bootp information
     */
/* XXX: fixme NetworkManager integration */
/*
    if (url == NULL) {
        char ret[47];
        ip_addr_t *tip;

        if (!(netCfg.dev.set & PUMP_INTFINFO_HAS_NEXTSERVER)) {
            logMessage(ERROR, "no bootserver was found");
            return 1;
        }

        tip = &(netCfg.dev.nextServer);
        if (!(netCfg.dev.set & PUMP_INTFINFO_HAS_BOOTFILE)) {
            inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip));

            if (asprintf(&url, "%s:%s", ret, "/kickstart/") == -1) {
                logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                abort();
            }

            logMessage(ERROR, "bootp: no bootfile received");
        } else {
            inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip));

            if (asprintf(&url, "%s:%s", ret, netCfg.dev.bootFile) == -1) {
                logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                abort();
            }

            logMessage(INFO, "bootp: bootfile is %s", netCfg.dev.bootFile);
        }
    }
*/

    /* get the IP of the target system */
    if ((ip = iface_ip2str(loaderData->netDev, AF_INET)) == NULL) {
        logMessage(ERROR, "nl_ip2str returned NULL");
        return 1;
    }

    logMessage(INFO, "url is %s", url);
    getHostandPath(url, &host, &path, ip);

    opts = strchr(host, ':');
    if (opts && (strlen(opts) > 1)) {
        char * c = opts;
        opts = host;
        host = c + 1;
        *c = '\0';
    } else {
        opts = NULL;
    }

    /* nfs has to be a little bit different... split off the last part as
     * the file and then concatenate host + dir path */
    file = strrchr(path, '/');
    if (!file) {
        file = path;
    } else {
        *file++ ='\0';
        chk = host + strlen(host)-1;

        if (*chk == '/' || *path == '/') {
            if (asprintf(&host, "%s%s", host, path) == -1) {
                logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                abort();
            }
        } else {
            if (asprintf(&host, "%s/%s", host, path) == -1) {
                logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                abort();
            }
        }
    }

    logMessage(INFO, "file location: nfs:%s/%s", host, file);

    if (!doPwMount(host, "/tmp/mnt", "nfs", opts, NULL)) {
        char * buf;

        if (asprintf(&buf, "/tmp/mnt/%s", file) == -1) {
            logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
            abort();
        }

        if (copyFile(buf, dest)) {
            logMessage(ERROR, "failed to copy file to %s", dest);
            failed = 1;
        }

        free(buf);
    } else {
        logMessage(ERROR, "failed to mount nfs source");
        failed = 1;
    }

    free(host);
    free(path);
    if (ip) free(ip);

    umount("/tmp/mnt");
    unlink("/tmp/mnt");

    return failed;
}
示例#18
0
void netfilter(const char *fname) {
	// default filter
	char *filter = client_filter;

	// custom filter
	int allocated = 0;
	if (fname) {
		// buffer the filter
		struct stat s;
		if (stat(fname, &s) == -1) {
			fprintf(stderr, "Error: cannot find network filter file\n");
			exit(1);
		}
				
		filter = malloc(s.st_size + 1);	// + '\0'
		memset(filter, 0, s.st_size + 1);
		if (!filter)
			errExit("malloc");
		
		FILE *fp = fopen(fname, "r");
		if (!fp) {
			fprintf(stderr, "Error: cannot open network filter file\n");
			exit(1);
		}

		size_t sz = fread(filter, 1, s.st_size, fp);
		if (sz != s.st_size) {
			fprintf(stderr, "Error: cannot read network filter file\n");
			exit(1);
		}
		fclose(fp);
		allocated = 1;
	}
		
	// mount a tempfs on top of /tmp directory
	if (mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC,  "mode=755,gid=0") < 0)
		errExit("mounting /tmp");

	// create the filter file
	FILE *fp = fopen("/tmp/netfilter", "w");
	if (!fp) {
		fprintf(stderr, "Error: cannot open /tmp/netfilter file\n");
		exit(1);
	}
	fprintf(fp, "%s\n", filter);
	fclose(fp);

	// push filter
	int rv;
	if (arg_debug)
		printf("Installing network filter:\n%s\n", filter);

	rv = system("/sbin/iptables-restore < /tmp/netfilter");
	if (rv == -1) {
		fprintf(stderr, "Error: failed to configure network filter.\n");
		exit(1);
	}
	if (arg_debug)
		rv = system("/sbin/iptables -vL");
	
	// unmount /tmp
	umount("/tmp");
	
	if (allocated)
		free(filter);
}
示例#19
0
int ensure_dev_unmounted(const char * mountedPoint){
    int ret = umount(mountedPoint);
    return ret;
}
示例#20
0
void unregister_bdev(struct bdev *bdev)
{
	umount(bdev->mount);
	bdev->ops = NULL;
}
示例#21
0
/*
 * Mount point for selinuxfs. 
 * This definition is private to the function below.
 * Everything else uses the location determined during 
 * libselinux startup via /proc/mounts (see init_selinuxmnt).  
 * We only need the hardcoded definition for the initial mount 
 * required for the initial policy load.
 */
int selinux_init_load_policy(int *enforce)
{
	int rc = 0, orig_enforce = 0, seconfig = -2, secmdline = -1;
	FILE *cfg;
	char *buf;

	/*
	 * Reread the selinux configuration in case it has changed.
	 * Example:  Caller has chroot'd and is now loading policy from
	 * chroot'd environment.
	 */
	selinux_reset_config();

	/*
	 * Get desired mode (disabled, permissive, enforcing) from 
	 * /etc/selinux/config. 
	 */
	selinux_getenforcemode(&seconfig);

	/* Check for an override of the mode via the kernel command line. */
	rc = mount("proc", "/proc", "proc", 0, 0);
	cfg = fopen("/proc/cmdline", "r");
	if (cfg) {
		char *tmp;
		buf = malloc(selinux_page_size);
		if (!buf) {
			fclose(cfg);
			return -1;
		}
		if (fgets(buf, selinux_page_size, cfg) &&
		    (tmp = strstr(buf, "enforcing="))) {
			if (tmp == buf || isspace(*(tmp - 1))) {
				secmdline =
				    atoi(tmp + sizeof("enforcing=") - 1);
			}
		}
		fclose(cfg);
		free(buf);
	}
#ifndef MNT_DETACH
#define MNT_DETACH 2
#endif
	if (rc == 0)
		umount2("/proc", MNT_DETACH);

	/* 
	 * Determine the final desired mode.
	 * Command line argument takes precedence, then config file. 
	 */
	if (secmdline >= 0)
		*enforce = secmdline;
	else if (seconfig >= 0)
		*enforce = seconfig;
	else
		*enforce = 0;	/* unspecified or disabled */

	/*
	 * Check for the existence of SELinux via selinuxfs, and 
	 * mount it if present for use in the calls below.  
	 */
	if (mount("selinuxfs", SELINUXMNT, "selinuxfs", 0, 0) < 0 && errno != EBUSY) {
		if (errno == ENODEV) {
			/*
			 * SELinux was disabled in the kernel, either
			 * omitted entirely or disabled at boot via selinux=0.
			 * This takes precedence over any config or
			 * commandline enforcing setting.
			 */
			*enforce = 0;
		} else {
			/* Only emit this error if selinux was not disabled */
			fprintf(stderr, "Mount failed for selinuxfs on %s:  %s\n", SELINUXMNT, strerror(errno));
		}
                
		goto noload;
	}
	set_selinuxmnt(SELINUXMNT);

	/*
	 * Note:  The following code depends on having selinuxfs 
	 * already mounted and selinuxmnt set above.
	 */

	if (seconfig == -1) {
		/* Runtime disable of SELinux. */
		rc = security_disable();
		if (rc == 0) {
			/* Successfully disabled, so umount selinuxfs too. */
			umount(SELINUXMNT);
			fini_selinuxmnt();
		}
		/*
		 * If we failed to disable, SELinux will still be 
		 * effectively permissive, because no policy is loaded. 
		 * No need to call security_setenforce(0) here.
		 */
		goto noload;
	}

	/*
	 * If necessary, change the kernel enforcing status to match 
	 * the desired mode. 
	 */
	orig_enforce = rc = security_getenforce();
	if (rc < 0)
		goto noload;
	if (orig_enforce != *enforce) {
		rc = security_setenforce(*enforce);
		if (rc < 0) {
			fprintf(stderr, "SELinux:  Unable to switch to %s mode:  %s\n", (*enforce ? "enforcing" : "permissive"), strerror(errno));
			if (*enforce)
				goto noload;
		}
	}

	/* Load the policy. */
	return selinux_mkload_policy(0);

      noload:
	/*
	 * Only return 0 on a successful completion of policy load.
	 * In any other case, we want to return an error so that init
	 * knows not to proceed with the re-exec for the domain transition.
	 * Depending on the *enforce setting, init will halt (> 0) or proceed
	 * normally (otherwise).
	 */
	return -1;
}
示例#22
0
int init_main(int argc, char *argv[])
{
    for (int i = 1; i < argc; ++i) {
        if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
            init_usage(true);
            return EXIT_SUCCESS;
        }
    }

    umask(0);

    mkdir("/dev", 0755);
    mkdir("/proc", 0755);
    mkdir("/sys", 0755);

    mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
    mkdir("/dev/pts", 0755);
    mkdir("/dev/socket", 0755);
    mount("devpts", "/dev/pts", "devpts", 0, nullptr);
    mount("proc", "/proc", "proc", 0, nullptr);
    mount("sysfs", "/sys", "sysfs", 0, nullptr);

    open_devnull_stdio();
    util::log_set_logger(std::make_shared<util::KmsgLogger>());
    if (klogctl(KLOG_CONSOLE_LEVEL, nullptr, 8) < 0) {
        LOGE("Failed to set loglevel: %s", strerror(errno));
    }

    LOGV("Booting up with version %s (%s)",
         get_mbtool_version(), get_git_version());

    // Start probing for devices
    device_init();

    std::string fstab = find_fstab();
    if (fstab.empty()) {
        LOGE("Failed to find a suitable fstab file");
        emergency_reboot();
        return EXIT_FAILURE;
    }

    mkdir("/system", 0755);
    mkdir("/cache", 0770);
    mkdir("/data", 0771);
    util::chown("/cache", "system", "cache", 0);
    util::chown("/data", "system", "system", 0);

    fix_arter97();

    // Mount fstab and write new redacted version
    if (!mount_fstab(fstab, true)) {
        LOGE("Failed to mount fstab");
        emergency_reboot();
        return EXIT_FAILURE;
    }

    LOGE("Successfully mounted fstab");

    fix_file_contexts();
    add_mbtool_services();
    strip_manual_mounts();

    struct stat sb;
    if (stat("/sepolicy", &sb) == 0) {
        if (!patch_sepolicy("/sepolicy", "/sepolicy")) {
            LOGW("Failed to patch /sepolicy");
            emergency_reboot();
            return EXIT_FAILURE;
        }
    }

    // Kill uevent thread and close uevent socket
    device_close();

    // Unmount partitions
    umount("/dev/pts");
    umount("/dev");
    umount("/proc");
    umount("/sys");
    // Do not remove these as Android 6.0 init's stage 1 no longer creates these
    // (platform/system/core commit a1f6a4b13921f61799be14a2544bdbf95958eae7)
    //rmdir("/dev");
    //rmdir("/proc");
    //rmdir("/sys");

    // Start real init
    unlink("/init");
    rename("/init.orig", "/init");

    LOGD("Launching real init ...");
    execlp("/init", "/init", nullptr);
    LOGE("Failed to exec real init: %s", strerror(errno));
    emergency_reboot();
    return EXIT_FAILURE;
}
示例#23
0
int main(int ac, char **av)
{
	int lc, i;		/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, options, &help)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

	/* Check for mandatory option of the testcase */
	if (Dflag == 0) {
		tst_brkm(TBROK, NULL, "You must specifiy the device used for "
			 " mounting with -D option, Run '%s  -h' for option "
			 " information.", TCID);
		tst_exit();
	}

	Type = (char *)malloc(FSTYPE_LEN);
	if (!Type) {
		tst_brkm(TBROK, NULL, "malloc - alloc of %d failed",
			 FSTYPE_LEN);
		tst_exit();
	}

	if (Tflag == 1) {
		strncpy(Type, fstype,
			(FSTYPE_LEN <
			 (strlen(fstype)+1)) ? FSTYPE_LEN : (strlen(fstype)+1));
	} else {
		strncpy(Type, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE)+1);
	}

	if (STD_COPIES != 1) {
		tst_resm(TINFO, "-c option has no effect for this testcase - "
			 "%s doesn't allow running more than one instance "
			 "at a time", TCID);
		STD_COPIES = 1;
	}

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {

			if (setup_test(i, lc)) {
				tst_resm(TWARN, "Not able to test mount(2) for "
					 "error %s as setup failed",
					 testcases[i].exp_errval);
				continue;
			}

			/* Call umount(2) to test different test conditions.
			 * verify that it fails with -1 return value and
			 * sets appropriate errno.*/

			TEST(umount(Mntpoint));

			/* check return code */
			if ((TEST_RETURN == -1) &&
			    (TEST_ERRNO == testcases[i].exp_errno)) {
				tst_resm(TPASS, "umount(2) expected failure; "
					 "Got errno - %s : %s",
					 testcases[i].exp_errval,
					 testcases[i].err_desc);
			} else {
				tst_resm(TFAIL, "umount(2) failed to produce "
					 "expected error; %d, errno:%s got %d",
					 testcases[i].exp_errno,
					 testcases[i].exp_errval, TEST_ERRNO);
			}

			TEST_ERROR_LOG(TEST_ERRNO);

			(void)cleanup_test(i);

		}
	}

	/* cleanup and exit */
	cleanup();

	tst_exit();

}
示例#24
0
文件: bootup.c 项目: nawawi/myboxfs
int bootup_main(int argc, char **argv) {
    FILE *fp;
    DIR *dp;
    struct dirent *dt;
    int t=0, rc;
    char cmd[1024], buf[1024], name[1024];
    time_t curtime;
    struct tm *loctime;
    signal(SIGINT,SIG_IGN);
    putenv("PATH=/bin");
    putenv("TERM=linux");
    umask(0770);
    chdir("/");
    putchar('\n');
    print_banner();
    putchar('\n');
    xsystem("mount -t proc -o ro virtual /proc");
    xsystem("mount -t sysfs -o ro virtual /sys");

    // STAGE 1
    calculate_mem();
    fprintf_stdout("* Creating Mybox filesystem (%d kB) on shared memory...\n",RAMSIZE);
    xsystem("mount -t tmpfs -o \"rw,size=%dk\" virtual /ramd",RAMSIZE);
    chmod("/ramd",S_IREAD | S_IWRITE | S_IEXEC);
    chdir("/ramd");
    if((dp=opendir("/")) == NULL) {
        perror("opendir");
        exit(1);
    }
    while((dt=readdir(dp))!=NULL) {
        if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..") ||
                !strcmp(dt->d_name,"lost+found") ||
                !strcmp(dt->d_name,"ramd") ||
                !strcmp(dt->d_name,"proc") ||
                !strcmp(dt->d_name,"dev") ||
                !strcmp(dt->d_name,"sys")) continue;
        xsystem("cp -dpR /%s /ramd/",dt->d_name);
    }
    closedir(dp);
    xmkdir("dev/pts");
    xmkdir("initrd");
    umount("/proc");
    umount("/sys");

    // STAGE 2
    rc=pivot_root(".","initrd");
    if(rc==-1) {
        fprintf_stdout("#### ERROR: Change root file system failed!\n");
        exit(1);
    }
    chdir("/");
    xmkdir("proc");
    xmkdir("sys");
    xsystem("mount -t proc -o rw virtual /proc");
    xsystem("mount -t sysfs -o rw virtual /sys");
    save_to_file("/proc/sys/kernel/printk","0 0 0 0\n");
    if((dp=opendir("/tmp")) == NULL) {
        perror("opendir");
        exit(1);
    }
    fprintf_stdout("-> Extracting base tools: ");
    while((dt=readdir(dp))!=NULL) {
        if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..")) continue;
        if(strstr(dt->d_name,".mpk")) {
            fprintf_stdout("#");
            xsystem("tar -C / -axf /tmp/%s",dt->d_name);
        }
    }
    free(dt);
    closedir(dp);
    fprintf_stdout("\r* Extracting base tools. Done.%s\n",SPACE);
    save_to_file("/proc/sys/kernel/modprobe","/bin/modprobe\n");
    xsystem("depmod -a");

    // STAGE 3
    chdir("/");
    xsystem("mdev -s");
    xsystem("mount -t devpts /dev/devpts /dev/pts -o \"rw,gid=0,mode=620\"");
    rename("/dev/random","/dev/random-block");
    symlink("/dev/urandom","/dev/random");
    xsystem("chmod 700 *");
    if((fp=fopen("/etc/inittab","w"))!=NULL) {
        fprintf(fp,"::sysinit:/etc/init.boot/rc.init\n");
        fprintf(fp,"tty1::respawn:/bin/getty -h -n -L tty1 115200 linux\n");
        fprintf(fp,"ttyS0::respawn:/bin/getty -h -n -L ttyS0 115200 vt100\n");
        fprintf(fp,"tty7::respawn:/bin/chkprog\n");
        fprintf(fp,"tty8::respawn:/bin/trafficd\n");
        fprintf(fp,"::restart:/bin/init\n");
        fprintf(fp,"::ctrlaltdel:/bin/bootdown\n");
        fprintf(fp,"::ctrlaltdel:/bin/reset\n");
        fprintf(fp,"::ctrlaltdel:/bin/reboot\n");
        fprintf(fp,"::shutdown:/bin/bootdown\n");
        fclose(fp);
    }
    curtime=time(NULL);
    loctime=localtime(&curtime);
    strftime(cmd, sizeof(cmd), "[%d/%m/%Y %T] TYPE=INFO MSG=****** SYSTEM LOADING ******\n",loctime);
    append_to_file("/tmp/bootup",cmd);
    if(file_exists("/bin/getkey")) {
        if(system("getkey -c 3 -m \"-> Starting Init: %d\" R")==0) {
            fprintf_stdout("\r#### WARNING: LOGIN DISABLED\n");
            xtouch("/etc/noconsole");
        } else {
            fprintf_stdout("\r* Starting Init. Done.\n");
        }
    }
    memset(buf,0x0,sizeof(buf));
    snprintf(buf,sizeof(buf),"%s\n","/bin/mdev");
    save_to_file("/proc/sys/kernel/hotplug",buf);
    do_chroot();
    signal(SIGINT,SIG_DFL);
    fprintf_stdout("#### ERROR: Failed to boot file system!\n");
    fprintf_stdout("#### ERROR: Press Ctrl+Alt+Del or switch off/on for reboot.\n");
    while(1);
    exit(0);
}
示例#25
0
static void check_fs(char *blk_device, char *fs_type, char *target)
{
    int status;
    int ret;
    long tmpmnt_flags = MS_NOATIME | MS_NOEXEC | MS_NOSUID;
    char *tmpmnt_opts = "nomblk_io_submit,errors=remount-ro";
    char *e2fsck_argv[] = {
        E2FSCK_BIN,
        "-y",
        blk_device
    };

    /* Check for the types of filesystems we know how to check */
    if (!strcmp(fs_type, "ext2") || !strcmp(fs_type, "ext3") || !strcmp(fs_type, "ext4")) {
        /*
         * First try to mount and unmount the filesystem.  We do this because
         * the kernel is more efficient than e2fsck in running the journal and
         * processing orphaned inodes, and on at least one device with a
         * performance issue in the emmc firmware, it can take e2fsck 2.5 minutes
         * to do what the kernel does in about a second.
         *
         * After mounting and unmounting the filesystem, run e2fsck, and if an
         * error is recorded in the filesystem superblock, e2fsck will do a full
         * check.  Otherwise, it does nothing.  If the kernel cannot mount the
         * filesytsem due to an error, e2fsck is still run to do a full check
         * fix the filesystem.
         */
        ret = mount(blk_device, target, fs_type, tmpmnt_flags, tmpmnt_opts);
        INFO("%s(): mount(%s,%s,%s)=%d\n", __func__, blk_device, target, fs_type, ret);
        if (!ret) {
            umount(target);
        }

        /*
         * Some system images do not have e2fsck for licensing reasons
         * (e.g. recent SDK system images). Detect these and skip the check.
         */
        if (access(E2FSCK_BIN, X_OK)) {
            INFO("Not running %s on %s (executable not in system image)\n",
                 E2FSCK_BIN, blk_device);
        } else {
            INFO("Running %s on %s\n", E2FSCK_BIN, blk_device);

            ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), e2fsck_argv,
                                        &status, true, LOG_KLOG | LOG_FILE,
                                        true, FSCK_LOG_FILE);

            if (ret < 0) {
                /* No need to check for error in fork, we can't really handle it now */
                ERROR("Failed trying to run %s\n", E2FSCK_BIN);
            }
        }
    } else if (!strcmp(fs_type, "f2fs")) {
            char *f2fs_fsck_argv[] = {
                    F2FS_FSCK_BIN,
                    blk_device
            };
        INFO("Running %s on %s\n", F2FS_FSCK_BIN, blk_device);

        ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv,
                                      &status, true, LOG_KLOG | LOG_FILE,
                                      true, FSCK_LOG_FILE);
        if (ret < 0) {
            /* No need to check for error in fork, we can't really handle it now */
            ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN);
        }
    }

    return;
}
示例#26
0
int
unmount_mounted_volume(const MountedVolume *volume)
{
    /* Intentionally pass NULL to umount if the caller tries
     * to unmount a volume they already unmounted using this
     * function.
     */
    int ret = umount(volume->mount_point);
    if (ret == 0) {
        free_volume_internals(volume, 1);
        return 0;
    }

#if 1 //wschen 2012-10-23

      else {
        DIR *dir, *dir1;
        int fd;
        int len, len1;
        char buf[1024];
        char buf1[1024];
        char pid[1024];
        char file_path[1024];
        struct dirent *ptr, *ptr1;

        printf("%s\n", strerror(errno));

        dir = opendir("/proc/");
        if (dir) {
            while ((ptr = readdir(dir)) != NULL) {
                if (ptr->d_name[0] >= '0' && ptr->d_name[0] <= '9') {
                    snprintf(pid, sizeof(pid), "/proc/%s/cmdline", ptr->d_name);
                    fd = open(pid, O_RDONLY);
                    len1 = 0;
                    if (fd) {
                        len1 = read(fd, buf1, sizeof(buf1));
                        close(fd);

                        snprintf(pid, sizeof(pid), "/proc/%s/fd", ptr->d_name);

                        dir1 = opendir(pid);

                        if (dir1) {
                            while ((ptr1 = readdir(dir1)) != NULL) {
                                snprintf(file_path, sizeof(file_path), "/proc/%s/fd/%s", ptr->d_name, ptr1->d_name);
                                len = readlink(file_path, buf, sizeof(buf));
                                if (len != -1) {
                                    buf[len] = '\0';
                                    if (strstr(buf, volume->mount_point) == buf) {
                                        if (len1) {
                                            printf("process(%s):%s\n", ptr->d_name, buf1);
                                        }
                                        printf("found:%s\n", buf);
                                    }
                                }
                            }
                            closedir(dir1);
                        }
                    }
                }
            }
            closedir(dir);
        }
    }
#endif
    return ret;
}
int VolumeManager::unmountLoopImage(const char *id, const char *idHash,
        const char *fileName, const char *mountPoint, bool force) {
    if (!isMountpointMounted(mountPoint)) {
        SLOGE("Unmount request for %s when not mounted", id);
        errno = ENOENT;
        return -1;
    }

    int i, rc;
    for (i = 1; i <= UNMOUNT_RETRIES; i++) {
        rc = umount(mountPoint);
        if (!rc) {
            break;
        }
        if (rc && (errno == EINVAL || errno == ENOENT)) {
            SLOGI("Container %s unmounted OK", id);
            rc = 0;
            break;
        }
        SLOGW("%s unmount attempt %d failed (%s)",
              id, i, strerror(errno));

        int action = 0; // default is to just complain

        if (force) {
            if (i > (UNMOUNT_RETRIES - 2))
                action = 2; // SIGKILL
            else if (i > (UNMOUNT_RETRIES - 3))
                action = 1; // SIGHUP
        }

        Process::killProcessesWithOpenFiles(mountPoint, action);
        usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS);
    }

    if (rc) {
        errno = EBUSY;
        SLOGE("Failed to unmount container %s (%s)", id, strerror(errno));
        return -1;
    }

    int retries = 10;

    while(retries--) {
        if (!rmdir(mountPoint)) {
            break;
        }

        SLOGW("Failed to rmdir %s (%s)", mountPoint, strerror(errno));
        usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS);
    }

    if (!retries) {
        SLOGE("Timed out trying to rmdir %s (%s)", mountPoint, strerror(errno));
    }

    if (Devmapper::destroy(idHash) && errno != ENXIO) {
        SLOGE("Failed to destroy devmapper instance (%s)", strerror(errno));
    }

    char loopDevice[255];
    if (!Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) {
        Loop::destroyByDevice(loopDevice);
    } else {
        SLOGW("Failed to find loop device for {%s} (%s)", fileName, strerror(errno));
    }

    AsecIdCollection::iterator it;
    for (it = mActiveContainers->begin(); it != mActiveContainers->end(); ++it) {
        ContainerData* cd = *it;
        if (!strcmp(cd->id, id)) {
            free(*it);
            mActiveContainers->erase(it);
            break;
        }
    }
    if (it == mActiveContainers->end()) {
        SLOGW("mActiveContainers is inconsistent!");
    }
    return 0;
}
示例#28
0
int format_volume(const char* volume) {
    Volume* v = volume_for_path(volume);
    if (v == NULL) {
        LOGE("unknown volume \"%s\"\n", volume);
        return -1;
    }
    if (strcmp(v->fs_type, "ramdisk") == 0) {
        // you can't format the ramdisk.
        LOGE("can't format_volume \"%s\"", volume);
        return -1;
    }
    if (strcmp(v->mount_point, volume) != 0) {
        LOGE("can't give path \"%s\" to format_volume\n", volume);
        return -1;
    }

    if (ensure_path_unmounted(volume) != 0) {
        LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point);
        return -1;
    }
    if(!strcmp(v->fs_type, "ubifs"))
    {
    const MtdPartition *partition;
	mtd_scan_partitions();
    if(strcmp(v->mount_point, "/data"))
        partition = mtd_find_partition_by_name(&v->mount_point[1]);
    else
        partition = mtd_find_partition_by_name("userdata");
        if (partition == NULL) {
            LOGE("format_volume: %s cat't find mtd partition\n", v->mount_point);
            return -1;
	        }else{
	        if (strcmp(v->mount_point, "/system") == 0 ||
	            strcmp(v->mount_point, "/cache") == 0 ||
	            strcmp(v->mount_point, "/data") == 0 ){
	            
	           char cmd_line[128];
	            int  ubi_vol = 1;
	//            bool b_org_mounted = false;
	            int status;

	            ui_print("format partition: %s \n", v->mount_point);
#if 1      
	            if (strcmp(v->mount_point, "/system") == 0){
	                ubi_vol = 1;
	            }else if (strcmp(v->mount_point, "/data") == 0){
	            	ubi_vol = 2;
	            }else if(strcmp(v->mount_point, "/cache") == 0){
	                ubi_vol = 3;
	            }else{
	            	ubi_vol = 4; //perm partition
	            }
#endif

				//vapor : it is not properly, so we mask it.
	            //if (ensure_path_mounted(v->mount_point) == 0)  
	            {
	                fprintf(stderr,"umount /%s\r\n", v->mount_point);
	                umount(v->mount_point);
	            }
	            
	            memset(cmd_line, 0, 128);
	            sprintf(cmd_line, "/format.sh %d %d %s", partition->device_index, ubi_vol, partition->name);
                format_ubifs(cmd_line);
	            ui_print("format partition: %s complete\n", v->device);
	        	return 0;
	   		 }
	    	}
		}
	    else if (strcmp(v->fs_type, "yaffs2") == 0 || strcmp(v->fs_type, "mtd") == 0) {
	        mtd_scan_partitions();
	        const MtdPartition* partition = mtd_find_partition_by_name(v->device);
	        if (partition == NULL) {
	            LOGE("format_volume: no MTD partition \"%s\"\n", v->device);
	            return -1;
	        }

	        MtdWriteContext *write = mtd_write_partition(partition);
	        if (write == NULL) {
	            LOGW("format_volume: can't open MTD \"%s\"\n", v->device);
	            return -1;
	        } else if (mtd_erase_blocks(write, -1) == (off_t) -1) {
	            LOGW("format_volume: can't erase MTD \"%s\"\n", v->device);
	            mtd_write_close(write);
	            return -1;
	        } else if (mtd_write_close(write)) {
	            LOGW("format_volume: can't close MTD \"%s\"\n", v->device);
	            return -1;
	        }
	        return 0;
	    }
#if 0
	    else if (strcmp(v->fs_type, "ext4") == 0) {
	        int result = make_ext4fs(v->device, v->length);
	        if (result != 0) {
	            LOGE("format_volume: make_extf4fs failed on %s\n", v->device);
	            return -1;
	        }
	        return 0;
	    }
#endif
    LOGE("format_volume: fs_type \"%s\" unsupported\n", v->fs_type);
    return -1;
}
int ldiskfs_rename_fsname(struct mkfs_opts *mop, const char *oldname)
{
	struct mount_opts opts;
	struct lustre_disk_data *ldd = &mop->mo_ldd;
	char mntpt[] = "/tmp/mntXXXXXX";
	char *dev;
	int ret;

	/* Change the filesystem label. */
	opts.mo_ldd = *ldd;
	opts.mo_source = mop->mo_device;
	ret = ldiskfs_label_lustre(&opts);
	if (ret) {
		if (errno != 0)
			ret = errno;
		fprintf(stderr, "Can't change filesystem label: %s\n",
			strerror(ret));
		return ret;
	}

	/* Mount this device temporarily in order to write these files */
	if (mkdtemp(mntpt) == NULL) {
		if (errno != 0)
			ret = errno;
		else
			ret = EINVAL;
		fprintf(stderr, "Can't create temp mount point %s: %s\n",
			mntpt, strerror(ret));
		return ret;
	}

#ifdef HAVE_SELINUX
	/*
	 * Append file context to mount options if SE Linux is enabled
	 */
	if (is_selinux_enabled() > 0)
		append_context_for_mount(mntpt, mop);
#endif

	if (mop->mo_flags & MO_IS_LOOP)
		dev = mop->mo_loopdev;
	else
		dev = mop->mo_device;
	ret = mount(dev, mntpt, MT_STR(ldd), 0, ldd->ldd_mount_opts);
	if (ret) {
		if (errno != 0)
			ret = errno;
		fprintf(stderr, "Unable to mount %s: %s\n",
			dev, strerror(ret));
		if (ret == ENODEV)
			fprintf(stderr, "Is the %s module available?\n",
				MT_STR(ldd));
		goto out_rmdir;
	}

	ret = lustre_rename_fsname(mop, mntpt, oldname);
	umount(mntpt);

out_rmdir:
	rmdir(mntpt);
	return ret;
}
示例#30
0
int main(int argc, char **argv) {
  /* TODO: Add functionality to rmdir new_root, possibly create a subdir to
   * hide it from other users.
   */
  const char *new_root;
  const char *env[] = { NULL, NULL };
  int got, i, fd, pid, pid2, pfd[2], status;
  int okc, failc;
  DIR *dir;
  FILE *f;
  char *p, *q;
  struct dirent *dirent;

  /* Parse command-line */
  (void)argc;
  if (argv[1] == NULL) {
    fprintf(stderr, "Usage: %s <new-root> [<command> [<arg>]]\n", argv[0]);
    return 1;
  }
  if (strlen(argv[1]) > sizeof(buf) - 10) {
    fprintf(stderr, "error: name of new_root too long\n");
    return 2;
  }
  new_root = argv[1];

  p = getenv("TERM");
  if (p != NULL) {
    /* TODO: Find it in environ manually, so env_buf is not needed. */
    strcpy(env_buf, "TERM=");
    if (strlen(p) >= sizeof(env_buf) - 5) {
      fprintf(stderr, "error: TERM too long\n");
      return 2;
    }
    strncpy(env_buf + 5, p, sizeof(env_buf) - 5);
    env_buf[sizeof(env_buf) - 1] = '\0';  /* Just for extra safety. */
    env[0] = env_buf;
  }

  fd = open(new_root, O_RDONLY | O_DIRECTORY);  /* Can open a directory. */
  if (fd < 0) {
    perror("open new_root");
    return 2;
  }
  got = umount(new_root);
  if (got == 0) {
    /* Can't succeed, we have fd open. */
    fprintf(stderr, "error: unexpected umount success\n");
    return 2;
  }
  
  if (errno == EINVAL) {
    /* TODO: Detect that new_root is a mount point. */
    fprintf(stderr, "error: new_root is not mounted\n");
    return 2;
  }
  if (errno != EBUSY) {
    perror("umount1");
    return 2;
  }
  close(fd);
  got = pipe(pfd);
  if (got != 0) {
    perror("pipe");
    return 2;
  }
  pid = fork();
  if (pid < 0) {
    perror("fork");
    return 2;
  }
  if (pid == 0) {  /* Child: will umount new_root outside. */
    char c;
    close(pfd[1]);
    got = read(pfd[0], &c, 1);  /* Wait for parent to activate us. */
    if (got != 0) {
      if (got == 0)
        return 0;
      perror("read pfd");
      return 2;
    }
    got = umount(new_root);
    if (got != 0) {
      perror("umount child");
      return 2;
    }
    return 0;
  }
  close(pfd[0]);
  /* umount is needed otherwise the child won't be able to umount new_root.
   * TODO: Umount everything in new_root.
   */
  /* buf is long enough, we've checked that */
  strcpy(buf, new_root);  /* TODO: Use snprintf for extra safety. */
  strcat(buf, "/proc");
  umount(buf);  /* Don't check the result. */

  got = syscall(SYS_unshare, CLONE_NEWNS);
  if (got != 0) {
    perror("unshare");
    return 2;
  }
  got = chdir(new_root);
  if (got != 0) {
    perror("chdir1");
    return 2;
  }
  mkdir("put_old", 0700);  /* Don't check the result. */
    
  got = syscall(SYS_pivot_root, ".", "put_old");
  if (got != 0) {
    /* TODO: Report nice error if put_old is not a directory. */
    /* See restrictions is `man 2 pivot_root' for possible error reasons. */
    perror("pivot_root");
    return 2;
  }
  got = chroot(".");
  if (got != 0) {
    perror("chroot");
    return 2;
  }
  got = chdir("/");
  if (got != 0) {
    perror("chdir2");
    return 2;
  }
  close(pfd[1]);  /* Activate the child, who will umount(new_root). */
  /* Wait for the child to finish the umount. */
  pid2 = waitpid(pid, &status, 0);
  if (pid2 < 0) {
    perror("waitpid");
    return 2;
  }
  if (pid != pid2) {
    fprintf(stderr, "error: unexpected child exit\n");
    return 2;
  }
  if (status != 0) {
    fprintf(stderr, "error: child failed with status=0x%x\n", status);
    return 2;
  }

  umount("/proc");  /* Don't check the result. */
  mkdir("/proc", 0755);  /* Don't check the result. */
  got = mount("none", "/proc", "proc", 0, NULL);
  if (got != 0) {
    perror("mount /proc");
    return 2;
  }

  /* Close all file descriptors other than 0, 1 and 2 (/proc/self/fd). */
  dir = opendir("/proc/self/fd");
  if (dir == NULL) {
    perror("opendir /proc/self/fd");
    return 2;
  }
  fd = dirfd(dir);
  while (NULL != (dirent = readdir(dir))) {
    if (1 == sscanf(dirent->d_name, "%d", &i) && i != fd && i > 2) {
      close(i);  /* Don't check the result. */
    }
  }
  closedir(dir);

  /* Umount all filesystems in put_old. */
  do {
    okc = 0; failc = 0;
    f = fopen("/proc/mounts", "r");
    if (f == NULL) {
      perror("fopen /proc/mounts");
      return 2;
    }
    while (NULL != (p = fgets(buf, sizeof(buf) - 1, f))) {
      if (buf[0] == '\0' || buf[strlen(buf) - 1] != '\n') {
        fprintf(stderr, "error: mounts line empty or too long\n");
        return 2;
      }
      p = buf;
      while (p[0] != '\0' && p[0] != ' ' && p[0] != '\n') {
        ++p;
      }
      while (p[0] == ' ') {
        ++p;
      }
      if (p[0] == '\0' || p[0] == '\n') {
        fprintf(stderr, "error: mounts mount point not found: %s", buf);
        return 2;
      }
      q = p;
      while (q[0] != '\0' && q[0] != ' ') {
        ++q;
      }
      if (q[0] == '\0' || q[0] == '\n') {
        /* No \n. */
        fprintf(stderr, "error: mounts mount point ends: %s", buf);
        return 2;
      }
      q[0] = '\0';
      if (0 == strncmp(p, "/put_old", 8) && (p[8] == '/' || p[8] == '\0')) {
        if (umount(p) != 0) {
          /* It's OK to fail here, because some filesystems are inside
           * each other, and we may try to umount the outer filesystem first.
           */
          /* TODO: Sort by the number of slashes. */
          ++failc;
        } else {
          ++okc;
        }
      }
    }
    if (ferror(f)) {
      fprintf(stderr, "error: reading mounts\n");
      return 2;
    }
    fclose(f);
  } while (okc > 0 && failc > 0);  /* Try to make more progress umounting. */
  if (failc > 0) {
    fprintf(stderr, "error: could not umount put_old\n");
    return 2;
  }

  got = rmdir("/put_old");
  if (got != 0) {
    perror("rmdir put_old");
    return 2;
  }

  if (argv[2] == NULL) {
    got = execle("/bin/sh", "sh", "-i", NULL, env);
  } else {
    got = execve(argv[2], argv + 2, (void*)env);
  }
  if (got != 0) {
    perror("execl");
    return 2;
  }
  return 0;
}