Exemplo n.º 1
0
int
main(int argc, char **argv)
{
    struct DiskPartition *dp;
    Inode testcreate;
    Device devno;
    int fd, count;
    char *buff="This is a test string";

    InitPartitions("vicetab");
    dp = VGetPartition("simpled");
    devno = dp->device;

    testcreate = icreate(devno, 0, 0, 0, 0, 0);
    printf("icreate returned: %d\n", testcreate);
    if ( testcreate == 0 )
	exit(1);
    
    fd = iopen(devno, testcreate, O_RDONLY);
    printf("iopen returned: %d\n", fd);
    if ( fd != -1 ) 
	close(fd);
    else 
	exit(2);

    count = iwrite(devno, testcreate, 0, 0, buff, strlen(buff));
    printf("iwrite returned %d (of %d)\n", count, strlen(buff));

    printnames(VGetPartition("/tmp/f"), 0, 1, 64);
    dp = VGetPartition("/tmp/f");
    devno = dp->device;
    testcreate = icreate(devno, 0, 0, 0, 0, 0);
    printf("icreate returned: %d\n", testcreate);
    if ( testcreate == 0 )
	exit(1);
    
    fd = iopen(devno, testcreate, O_RDONLY);
    printf("iopen returned: %d\n", fd);
    if ( fd != -1 ) 
	close(fd);
    else 
	exit(2);

    count = iwrite(devno, testcreate, 0, 0, buff, strlen(buff));
    printf("iwrite returned %d (of %d)\n", count, strlen(buff));
    
    return 0;
}
Exemplo n.º 2
0
int
do_open(const char *path, int mode)
{
    int fd;
    struct file *f;
    struct inode *ip;

    if ((mode & O_CREATE) &&!(ip =
            icreate(path, T_FILE, 0, 0)))
        return -1;
    else
        if (!(ip = namei(path)))
            return -1;
    if (ip->type == T_DIR && mode != O_RDONLY) {
        iput(ip);
        return -1;
    }

    if (!(f = filealloc()) || (fd = fdalloc()) < 0) {
        if (f)
            fileclose(f);
        iput(ip);
        return -1;
    }


    f->type = FD_INODE;
    f->ip = ip;
    f->off = 0;
    f->readable = !(mode & O_WRONLY);
    f->writable = (mode & O_WRONLY) || (mode & O_RDWR);

    fs_current->ofile[fd] = f;
    return fd;
}
Exemplo n.º 3
0
int
do_mkdir(char *path)
{
    struct inode *ip;
    if (!(ip = icreate(path, T_DIR, 0, 0)))
        return -1;

    iput(ip);
    return 0;
}
Exemplo n.º 4
0
int
do_mknod(char *path, short major, short minor)
{
    struct inode *ip;

    if ((ip = icreate(path, T_DEV, major, minor)) == NULL)
        return -1;

    iput(ip);
    return 0;
}
void irpc_check_auth_back(struct s_server * serv, struct s_packet * pkt, void * ud)
{
	struct s_core * core = s_servg_gdata_from_serv(serv);
	struct s_string * fname = (struct s_string *)ud;
	struct s_mserver * mserv = s_core_mserv(core);

	struct s_core_mcreating * creating = s_hash_get_str(mserv->file_creating, fname);
	if(!creating) {
		s_log("[Warning] check_auth_back(file:%s), not exist!", s_string_data_p(fname));
		s_string_drop(fname);
		return;
	}

	if(pkt) {
		int ret;
		if(s_packet_read_int(pkt, &ret) < 0) {
			s_log("[Error] check_auth_back(file:%s), miss ret!", s_string_data_p(fname));
			goto label_check_failed;
		}
		if(ret <= 0) {
			goto label_check_failed;
		}
	} else {
		// timeout or conn-broken
	}

	creating->ncheck--;
	if(creating->ncheck == 0) {
		// check ok
		icreate(core, creating);
	}

	s_string_drop(fname);

	return;

label_check_failed:
	{
		icreate_fail_to_client(core, creating->req_id, creating->client_id);

		s_string_drop(fname);
		s_string_drop(creating->fname);
		s_hash_del_str(mserv->file_creating, fname);
	}
}
void s_core_mserv_create(struct s_server * client, struct s_packet * pkt, void * ud)
{
	unsigned int req_id = s_packet_get_req(pkt);
	unsigned int client_id = s_servg_get_id(client);
	struct s_string * fname = NULL;
	struct s_file_size size;

	s_packet_read(pkt, &fname, string, label_error);
	s_packet_read(pkt, &size.low, uint, label_error);
	s_packet_read(pkt, &size.high, uint, label_error);

	s_log("[LOG] create file : %s, size:%u-%u, req_id:%u", s_string_data_p(fname), size.high, size.low, req_id);

	struct s_core * core = (struct s_core *)ud;
	struct s_mserver * mserv = s_core_mserv(core);

	if(!icheck_can_create(core, core->id, fname)) {
		s_log("[LOG] cannot create! already create in this mserver!");
		goto label_failed;
	}

	struct s_core_mcreating * creating = s_hash_set_str(mserv->file_creating, fname);
	creating->fname = s_string_grab(fname);
	creating->core = core;
	creating->client_id = client_id;
	creating->req_id = req_id;
	creating->ncheck = 0;
	creating->size = size;

	// check all other mservs
	int sz = s_packet_size_for_string(fname);
	struct s_packet * pkt_ask = s_packet_easy(S_PKT_TYPE_CREATE_CHECK_AUTH, sz);
	s_packet_write_string(pkt_ask, fname);

	int id = -1;
	struct s_server * serv = s_servg_next_active_serv(core->servg, S_SERV_TYPE_M, &id);
	while(serv) {
		if(s_servg_get_id(serv) != core->id) {
			s_log("[LOG] ask mserv:%d", s_servg_get_id(serv));
			creating->ncheck++;

			// send check-auth-request
			s_servg_rpc_call(serv, pkt_ask, s_string_grab(fname), irpc_check_auth_back, 3000);
		}
		serv = s_servg_next_active_serv(core->servg, S_SERV_TYPE_M, &id);
	}

	s_packet_drop(pkt_ask);

	if(creating->ncheck == 0) {
		// wait for no mserv, decide myself
		s_log("[LOG] create: decide myself");
		icreate(core, creating);
	}

	s_string_drop(fname);
	return;


label_failed:
	icreate_fail_to_client(core, req_id, client_id);

label_error:

	if(fname) {
		s_string_drop(fname);
	}

	return;
}