Example #1
0
char *asktowhere(char *dev)
{
	while(1)
	{
		if(fw_inputbox(g_strdup_printf(_("Select mount point for %s"), dev),
		"You need to specify where you want the new partition mounted. "
		"For example, if you want to put it under /usr/local, then "
		"respond: /usr/local\n\nWhere would you like to mount this "
		"partition?", 0, 0, "", 0) == -1)
		return(NULL);
		if(!findmount(dialog_vars.input_result, 1))
			break;
	}
	return(strdup(dialog_vars.input_result));
}
Example #2
0
/*
 * Unmount a filesystem/device by name.
 * First calls FSOP_SYNC on the filesystem; then calls FSOP_UNMOUNT.
 */
int
vfs_unmount(const char *devname)
{
	struct knowndev *kd;
	int result;

	vfs_biglock_acquire();

	result = findmount(devname, &kd);
	if (result) {
		goto fail;
	}

	if (kd->kd_fs == NULL) {
		result = EINVAL;
		goto fail;
	}
	KASSERT(kd->kd_rawname != NULL);
	KASSERT(kd->kd_device != NULL);

	/* sync the fs */
	result = FSOP_SYNC(kd->kd_fs);
	if (result) {
		goto fail;
	}

	result = FSOP_UNMOUNT(kd->kd_fs);
	if (result) {
		goto fail;
	}

	kprintf("vfs: Unmounted %s:\n", kd->kd_name);

	/* now drop the filesystem */
	kd->kd_fs = NULL;

	KASSERT(result==0);

 fail:
	vfs_biglock_release();
	return result;
}
Example #3
0
/*
 * Mount a filesystem. Once we've found the device, call MOUNTFUNC to
 * set up the filesystem and hand back a struct fs.
 *
 * The DATA argument is passed through unchanged to MOUNTFUNC.
 */
int
vfs_mount(const char *devname, void *data,
	  int (*mountfunc)(void *data, struct device *, struct fs **ret))
{
	const char *volname;
	struct knowndev *kd;
	struct fs *fs;
	int result;

	vfs_biglock_acquire();

	result = findmount(devname, &kd);
	if (result) {
		vfs_biglock_release();
		return result;
	}

	if (kd->kd_fs != NULL) {
		vfs_biglock_release();
		return EBUSY;
	}
	KASSERT(kd->kd_rawname != NULL);
	KASSERT(kd->kd_device != NULL);

	result = mountfunc(data, kd->kd_device, &fs);
	if (result) {
		vfs_biglock_release();
		return result;
	}

	KASSERT(fs != NULL);

	kd->kd_fs = fs;

	volname = FSOP_GETVOLNAME(fs);
	kprintf("vfs: Mounted %s: on %s\n",
		volname ? volname : kd->kd_name, kd->kd_name);

	vfs_biglock_release();
	return 0;
}
Example #4
0
int mountdev(char *dev, char *mountpoint, GList **config)
{
	char *type=NULL;
	char *tmp=NULL;
	FILE* fp;

	// open fstab
	if ((fp = fopen((char*)data_get(*config, "fstab"), "a")) == NULL)
	{
		perror(_("Could not open output file for writing"));
		return(-1);
	}

	// mount
	tmp = g_strdup_printf("%s/%s", TARGETDIR, mountpoint);
	makepath(tmp);
	FREE(tmp);

	umount_if_needed(mountpoint);
	tmp = g_strdup_printf("mount %s %s/%s",
			dev, TARGETDIR, mountpoint);
	fw_system(tmp);
	FREE(tmp);
	// unlink a possible stale lockfile
	tmp = g_strdup_printf("%s/%s/tmp/pacman-g2.lck", TARGETDIR, mountpoint);
	unlink(tmp);
	FREE(tmp);

	// make fstab entry
	type = findmount(dev, 0);
	char *uuid = get_uuid(dev);
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n", uuid, mountpoint,
		type, "defaults", "1", "1");
	free(uuid);
	free(type);
	fclose(fp);
	return(0);
}
Example #5
0
int mkfss(char *dev, char *fs, int check)
{
	char *opts=NULL;
	char *cmd=NULL;
	int ret=1;

	opts = strdup(check ? "-c" : "");

	fw_info(_("Formatting"), g_strdup_printf(check ?
		_("Creating %s filesystem on %s and checking for bad blocks") :
		_("Creating %s filesystem on %s"),
		fs, dev));
	umount(findmount(dev, 1));
	if(!strcmp(fs, "ext2"))
	{
		cmd = g_strdup_printf("mke2fs %s %s", opts, dev);
		ret = fw_system(cmd);
		goto cleanup;
	}
	else if(!strcmp(fs, "ext3"))
	{
		cmd = g_strdup_printf("mke2fs -j %s %s", opts, dev);
		ret = fw_system(cmd);
		goto cleanup;
	}
	else if(!strcmp(fs, "ext4"))
	{
		cmd = g_strdup_printf("mkfs.ext4 %s %s", opts, dev);
		ret = fw_system(cmd);
		goto cleanup;
	}
	else if(!strcmp(fs, "reiserfs"))
	{
		cmd = g_strdup_printf("echo y |mkreiserfs %s", dev);
		ret = fw_system(cmd);
		goto cleanup;
	}
	else if(!strcmp(fs, "jfs"))
	{
		cmd = g_strdup_printf("mkfs.jfs -q %s %s", opts, dev);
		ret = fw_system(cmd);
		goto cleanup;
	}
	else if(!strcmp(fs, "xfs"))
	{
		cmd = g_strdup_printf("mkfs.xfs -f %s", dev);
		ret = fw_system(cmd);
		goto cleanup;
	}
	else if(!strcmp(fs, "btrfs"))
	{
		cmd = g_strdup_printf("mkfs.btrfs %s", dev);
		ret = fw_system(cmd);
		goto cleanup;
	}
	// never reached
	cleanup:
	FREE(opts);
	if (cmd)
		FREE(cmd);
	return(ret);
}
Example #6
0
/*
 * Rewrite the results of a directory read to reflect current
 * name space bindings and mounts.  Specifically, replace
 * directory entries for bind and mount points with the results
 * of statting what is mounted there.  Except leave the old names.
 */
static int32_t
mountfix(Chan *c, uint8_t *op, int32_t n, int32_t maxn)
{
	Proc *up = externup();
	char *name;
	int nbuf;
	Chan *nc;
	Mhead *mh;
	Mount *mount;
	usize dirlen, nname, r, rest;
	int32_t l;
	uint8_t *buf, *e, *p;
	Dir d;

	p = op;
	buf = nil;
	nbuf = 0;
	for(e=&p[n]; p+BIT16SZ<e; p+=dirlen){
		dirlen = dirfixed(p, e, &d);
		if(dirlen == 0)
			break;
		nc = nil;
		mh = nil;
		if(findmount(&nc, &mh, d.type, d.dev, d.qid)){
			/*
			 * If it's a union directory and the original is
			 * in the union, don't rewrite anything.
			 */
			for(mount=mh->mount; mount; mount=mount->next)
				if(eqchanddq(mount->to, d.type, d.dev, d.qid, 1))
					goto Norewrite;

			name = dirname(p, &nname);
			/*
			 * Do the stat but fix the name.  If it fails,
			 * leave old entry.
			 * BUG: If it fails because there isn't room for
			 * the entry, what can we do?  Nothing, really.
			 * Might as well skip it.
			 */
			if(buf == nil){
				buf = smalloc(4096);
				nbuf = 4096;
			}
			if(waserror())
				goto Norewrite;
			l = nc->dev->stat(nc, buf, nbuf);
			r = dirsetname(name, nname, buf, l, nbuf);
			if(r == BIT16SZ)
				error("dirsetname");
			poperror();

			/*
			 * Shift data in buffer to accomodate new entry,
			 * possibly overflowing into rock.
			 */
			rest = e - (p+dirlen);
			if(r > dirlen){
				while(p+r+rest > op+maxn){
					mountrock(c, p, &e);
					if(e == p){
						dirlen = 0;
						goto Norewrite;
					}
					rest = e - (p+dirlen);
				}
			}
			if(r != dirlen){
				memmove(p+r, p+dirlen, rest);
				dirlen = r;
				e = p+dirlen+rest;
			}

			/*
			 * Rewrite directory entry.
			 */
			memmove(p, buf, r);

		    Norewrite:
			cclose(nc);
			putmhead(mh);
		}
	}
	if(buf)
		free(buf);

	if(p != e)
		error("oops in mountfix");

	return e-op;
}
Example #7
0
/*
 * Rewrite the results of a directory read to reflect current 
 * name space bindings and mounts.  Specifically, replace
 * directory entries for bind and mount points with the results
 * of statting what is mounted there.  Except leave the old names.
 */
static long
mountfix(Chan *c, uchar *op, long n, long maxn)
{
	char *name;
	int nbuf, nname;
	Chan *nc;
	Mhead *mh;
	Mount *m;
	uchar *p;
	int dirlen, rest;
	long l;
	uchar *buf, *e;
	Dir d;

	p = op;
	buf = nil;
	nbuf = 0;
	for(e=&p[n]; p+BIT16SZ<e; p+=dirlen){
		dirlen = dirfixed(p, e, &d);
		if(dirlen < 0)
			break;
		nc = nil;
		mh = nil;
		if(findmount(&nc, &mh, d.type, d.dev, d.qid)){
			/*
			 * If it's a union directory and the original is
			 * in the union, don't rewrite anything.
			 */
			for(m=mh->mount; m; m=m->next)
				if(eqchantdqid(m->to, d.type, d.dev, d.qid, 1))
					goto Norewrite;

			name = dirname(p, &nname);
			/*
			 * Do the stat but fix the name.  If it fails, leave old entry.
			 * BUG: If it fails because there isn't room for the entry,
			 * what can we do?  Nothing, really.  Might as well skip it.
			 */
			if(buf == nil){
				buf = smalloc(4096);
				nbuf = 4096;
			}
			if(waserror())
				goto Norewrite;
			l = devtab[nc->type]->stat(nc, buf, nbuf);
			l = dirsetname(name, nname, buf, l, nbuf);
			if(l == BIT16SZ)
				error("dirsetname");
			poperror();

			/*
			 * Shift data in buffer to accomodate new entry,
			 * possibly overflowing into rock.
			 */
			rest = e - (p+dirlen);
			if(l > dirlen){
				while(p+l+rest > op+maxn){
					mountrock(c, p, &e);
					if(e == p){
						dirlen = 0;
						goto Norewrite;
					}
					rest = e - (p+dirlen);
				}
			}
			if(l != dirlen){
				memmove(p+l, p+dirlen, rest);
				dirlen = l;
				e = p+dirlen+rest;
			}

			/*
			 * Rewrite directory entry.
			 */
			memmove(p, buf, l);

		    Norewrite:
			cclose(nc);
			putmhead(mh);
		}
	}
	if(buf)
		free(buf);

	if(p != e)
		error("oops in rockfix");

	return e-op;
}