您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ umount函数代码示例

51自学网 2021-06-03 09:09:04
  C++
这篇教程C++ umount函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中umount函数的典型用法代码示例。如果您正苦于以下问题:C++ umount函数的具体用法?C++ umount怎么用?C++ umount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了umount函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

//.........这里部分代码省略.........    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 );
开发者ID:DavionKnight,项目名称:GT873M_4F,代码行数:67,


示例2: main

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");//.........这里部分代码省略.........
开发者ID:KarenHung,项目名称:ecosgit,代码行数:101,


示例3: try_initrd_mount

/** 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;}
开发者ID:kevstauffer,项目名称:tf201-dev,代码行数:92,


示例4: main

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();}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:65,


示例5: fs_mgr_mount_all

/* 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;//.........这里部分代码省略.........
开发者ID:GameTheory-,项目名称:mkbootimg,代码行数:101,


示例6: li_run_env_setup_with_root

//.........这里部分代码省略.........		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;}
开发者ID:jpumc,项目名称:limba,代码行数:101,


示例7: main

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;}
开发者ID:Ever-Never,项目名称:multirom,代码行数:99,


示例8: start_kernel

//.........这里部分代码省略.........					/* 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);}
开发者ID:omegamoon,项目名称:kexecboot,代码行数:101,


示例9: scan_devices

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) {//.........这里部分代码省略.........
开发者ID:omegamoon,项目名称:kexecboot,代码行数:101,


示例10: is_install_media

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;}
开发者ID:quanganh2627,项目名称:platform_bootable_iago,代码行数:88,


示例11: main

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" );//.........这里部分代码省略.........
开发者ID:janfj,项目名称:dd-wrt,代码行数:101,


示例12: main

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();}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:76,


示例13: main

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;}
开发者ID:nn,项目名称:fs-pkg,代码行数:79,


示例14: main

//.........这里部分代码省略.........				} 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();}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:101,


示例15: mountNfsImage

//.........这里部分代码省略.........            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;        }
开发者ID:redoop,项目名称:installer-redoop,代码行数:67,


示例16: main

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]));}
开发者ID:calebgray,项目名称:trunix,代码行数:5,


示例17: getFileFromNfs

//.........这里部分代码省略.........        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;}
开发者ID:redoop,项目名称:installer-redoop,代码行数:101,


示例18: netfilter

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);}
开发者ID:sshirokov,项目名称:firejail,代码行数:66,


示例19: ensure_dev_unmounted

int ensure_dev_unmounted(const char * mountedPoint){    int ret = umount(mountedPoint);    return ret;}
开发者ID:Bram81,项目名称:BananaPi-Android-4.2.2-Liab,代码行数:4,


示例20: unregister_bdev

void unregister_bdev(struct bdev *bdev){	umount(bdev->mount);	bdev->ops = NULL;}
开发者ID:Taijigamer2,项目名称:libxenon,代码行数:5,


示例21: selinux_init_load_policy

/* * 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();		}		/*//.........这里部分代码省略.........
开发者ID:pexip,项目名称:os-libselinux,代码行数:101,


示例22: init_main

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;}
开发者ID:mr-abhi,项目名称:DualBootPatcher,代码行数:95,


示例23: main

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();}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:89,


示例24: bootup_main

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) {//.........这里部分代码省略.........
开发者ID:nawawi,项目名称:myboxfs,代码行数:101,


示例25: check_fs

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;}
开发者ID:GameTheory-,项目名称:mkbootimg,代码行数:70,


示例26: unmount_mounted_volume

intunmount_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;}
开发者ID:APAR1992,项目名称:recovery_cwm_cn,代码行数:67,


示例27: SLOGE

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;}
开发者ID:optimumpr,项目名称:android_system_vold,代码行数:81,


示例28: format_volume

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;	    }//.........这里部分代码省略.........
开发者ID:26597925,项目名称:mt36k_android_4.0.4,代码行数:101,


示例29: ldiskfs_rename_fsname

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;}
开发者ID:Xyratex,项目名称:lustre-stable,代码行数:62,


示例30: main

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;//.........这里部分代码省略.........
开发者ID:abgoyal,项目名称:pts-mini-gpl,代码行数:101,



注:本文中的umount函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ umount2函数代码示例
C++ umask函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。