コード例 #1
0
	/*
	** Mmm... chunky.
	*/
	void read_chunk()
	{
		#if PLATFORM_KERNEL == PLATFORM_KERNEL_LINUX
			m_read = getdents(m_fd, m_buf.get(), m_bufsz);
		#elif PLATFORM_KERNEL == PLATFORM_KERNEL_XNU
			auto off = ::off_t{};
			m_read = getdirentries64(m_fd, m_buf.get(), m_bufsz, &off);
		#endif

		if (m_read > 0) {
			m_buf_cur = m_buf.get();
			m_buf_end = m_buf.get() + m_read;
		}
		else if (m_read == 0) {
			m_pos = -1;
		}
		else if (m_read == -1) {
			throw std::system_error{errno, std::system_category(),
				"failed to read directory entries"};
		}
	}
コード例 #2
0
ファイル: sanity.c プロジェクト: dmlb2000/lustre-release
int t14(char *name)
{
        char dir[MAX_PATH_LENGTH] = "";
        char path[1024];
        char buf[1024];
        const int nfiles = 256;
        char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
        cfs_dirent_t *ent;
        int fd, i, rc, pos, index;
        loff_t base = 0;
        ENTER(">1 block(4k) directory readdir");
        snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);

        rc = mkdir(dir, 0755);
        if (rc < 0 && errno != EEXIST) {
                printf("mkdir(%s) error: %s\n", dir, strerror(errno));
                exit(1);
        }
        printf("Creating %d files...\n", nfiles);
        for (i = 0; i < nfiles; i++) {
                sprintf(path, "%s%s%05d", dir, prefix, i);
                t_touch(path);
        }
        fd = t_opendir(dir);
        printf("Listing...\n");
        index = 0;
        while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
                pos = 0;
                while (pos < rc) {
                        char *item;

                        ent = (void *) buf + pos;
                        item = (char *) ent->d_name;
                        if (!strcmp(item, ".") || !strcmp(item, ".."))
                                goto iter;
                        if (strstr(item, prefix) != item) {
                                printf("found bad name %s\n", item);
                                return(-1);
                        }
                        printf("[%03d]: %s\t",
                                index++, item + strlen(prefix));
iter:
                        pos += ent->d_reclen;
                }
        }
        printf("\n");
        if (rc < 0) {
                printf("getdents error %d\n", rc);
                return(-1);
        }
        if (index != nfiles) {
                printf("get %d files != %d\n", index, nfiles);
                return(-1);
        }
        t_close(fd);
        printf("Cleanup...\n");
        for (i = 0; i < nfiles; i++) {
                sprintf(path, "%s%s%05d", dir, prefix, i);
                t_unlink(path);
        }
        t_rmdir(dir);
        LEAVE();
}