示例#1
0
文件: fuse_nfs.c 项目: kklt92/libnfs
static int fuse_nfs_getattr(const char *path, struct stat *stbuf)
{
    int ret = 0;
    struct nfs_stat_64 nfs_st;

    ret = nfs_stat64(nfs, path, &nfs_st);

    stbuf->st_dev          = nfs_st.nfs_dev;
    stbuf->st_ino          = nfs_st.nfs_ino;
    stbuf->st_mode         = nfs_st.nfs_mode;
    stbuf->st_nlink        = nfs_st.nfs_nlink;
    stbuf->st_uid          = nfs_st.nfs_uid;
    stbuf->st_gid          = nfs_st.nfs_gid;
    stbuf->st_rdev         = nfs_st.nfs_rdev;
    stbuf->st_size         = nfs_st.nfs_size;
    stbuf->st_blksize      = nfs_st.nfs_blksize;
    stbuf->st_blocks       = nfs_st.nfs_blocks;
    stbuf->st_atim.tv_sec  = nfs_st.nfs_atime;
    stbuf->st_atim.tv_usec = nfs_st.nfs_atime_nsec / 1000;
    stbuf->st_mtim.tv_sec  = nfs_st.nfs_mtime;
    stbuf->st_mtim.tv_usec = nfs_st.nfs_mtime_nsec / 1000;
    stbuf->st_ctim.tv_sec  = nfs_st.nfs_ctime;
    stbuf->st_ctim.tv_usec = nfs_st.nfs_ctime_nsec / 1000;

    return ret;
}
示例#2
0
int main(int argc, char *argv[])
{
	struct nfs_context *nfs;
	struct nfs_url *url;
        uint64_t length;
	struct nfs_stat_64 st;

	if (argc != 5) {
		usage();
	}

        length = strtol(argv[4], NULL, 10);

	nfs = nfs_init_context();
	if (nfs == NULL) {
		printf("failed to init context\n");
		exit(1);
	}

	url = nfs_parse_url_full(nfs, argv[1]);
	if (url == NULL) {
		fprintf(stderr, "%s\n", nfs_get_error(nfs));
		exit(1);
	}

	if (nfs_mount(nfs, url->server, url->path) != 0) {
 		fprintf(stderr, "Failed to mount nfs share : %s\n",
			nfs_get_error(nfs));
		exit(1);
	}

	if (nfs_chdir(nfs, argv[2]) != 0) {
 		fprintf(stderr, "Failed to chdir to \"%s\" : %s\n",
			argv[2], nfs_get_error(nfs));
                exit(1);
	}

	if (nfs_truncate(nfs, argv[3], length)) {
 		fprintf(stderr, "Failed to truncate file : %s\n",
			nfs_get_error(nfs));
		exit(1);
	}

	if (nfs_stat64(nfs, argv[3], &st)) {
 		fprintf(stderr, "Failed to stat file : %s\n",
			nfs_get_error(nfs));
                exit(1);
	}

        if (st.nfs_size != length) {
 		fprintf(stderr, "Unexpected file size. Expected %d got %d\n",
                        (int)length, (int)st.nfs_size);
                exit(1);
        }
        
	nfs_destroy_url(url);
	nfs_destroy_context(nfs);

	return 0;
}
示例#3
0
int main(int argc, char *argv[])
{
	int ret = 1;
	struct nfs_context *nfs = NULL;
	struct nfsfh *nfsfh = NULL;
	struct nfs_url *url = NULL;

#ifdef WIN32
	if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
		printf("Failed to start Winsock2\n");
		exit(10);
	}
#endif

#ifdef AROS
	aros_init_socket();
#endif

	if (argc < 3) {
		fprintf(stderr, "No URL specified.\n");
		goto finished;
	}

	nfs = nfs_init_context();
	if (nfs == NULL) {
		printf("failed to init context\n");
		goto finished;
	}

	url = nfs_parse_url_full(nfs, argv[argc - 1]);
	if (url == NULL) {
		fprintf(stderr, "%s\n", nfs_get_error(nfs));
		goto finished;
	}

	if (nfs_mount(nfs, url->server, url->path) != 0) {
 		fprintf(stderr, "Failed to mount nfs share : %s\n", nfs_get_error(nfs));
		goto finished;
	}

	if (!strncmp(argv[1], "creat", 5)) {
		ret = nfs_creat(nfs, url->file, 0600, &nfsfh);
	} else if (!strncmp(argv[1], "unlink", 6)) {
		ret = nfs_unlink(nfs, url->file);
	} else if (!strncmp(argv[1], "mkdir", 5)) {
		ret = nfs_mkdir(nfs, url->file);
	} else if (!strncmp(argv[1], "rmdir", 5)) {
		ret = nfs_rmdir(nfs, url->file);
	} else if (!strncmp(argv[1], "stat", 4)) {
		struct nfs_stat_64 st;
		ret = nfs_stat64(nfs, url->file, &st);
		if (!ret) {
			switch (st.nfs_mode & S_IFMT) {
	#ifndef WIN32
			case S_IFLNK:
				printf("l");
				break;
	#endif
			case S_IFREG:
				printf("-");
				break;
			case S_IFDIR:
				printf("d");
				break;
			case S_IFCHR:
				printf("c");
				break;
			case S_IFBLK:
				printf("b");
				break;
			}
			printf("%c%c%c",
			       "-r"[!!(st.nfs_mode & S_IRUSR)],
			       "-w"[!!(st.nfs_mode & S_IWUSR)],
			       "-x"[!!(st.nfs_mode & S_IXUSR)]
			);
			printf("%c%c%c",
			       "-r"[!!(st.nfs_mode & S_IRGRP)],
			       "-w"[!!(st.nfs_mode & S_IWGRP)],
			       "-x"[!!(st.nfs_mode & S_IXGRP)]
			);
			printf("%c%c%c",
			       "-r"[!!(st.nfs_mode & S_IROTH)],
			       "-w"[!!(st.nfs_mode & S_IWOTH)],
			       "-x"[!!(st.nfs_mode & S_IXOTH)]
			);
			printf(" %2d", (int)st.nfs_nlink);
			printf(" %5d", (int)st.nfs_uid);
			printf(" %5d", (int)st.nfs_gid);
			printf(" %12" PRId64, st.nfs_size);
			printf("\n");
		}
	} else {
		goto finished;
	}
	
	if (ret) {
		fprintf(stderr, "ERROR: %s\n", nfs_get_error(nfs));
	}

finished:
	if (ret > 0) {
		print_usage();
	}
	nfs_destroy_url(url);
	if (nfs != NULL) {		
		if (nfsfh) {
			nfs_close(nfs, nfsfh);
		}
		nfs_destroy_context(nfs);
	}
	return !!ret;
}