예제 #1
0
void delete_stat_cache_entry(const char *path) {
  if(foreground)
    cout << "    delete_stat_cache_entry[path=" << path << "]" << endl;

  pthread_mutex_lock(&stat_cache_lock);
  stat_cache_t::iterator iter = stat_cache.find(path);
  if(iter != stat_cache.end())
    stat_cache.erase(iter);
  pthread_mutex_unlock(&stat_cache_lock);
}
예제 #2
0
int get_stat_cache_entry(const char *path, struct stat *buf) {
  pthread_mutex_lock(&stat_cache_lock);
  stat_cache_t::iterator iter = stat_cache.find(path);
  if(iter != stat_cache.end()) {
    if(foreground)
      cout << "    stat cache hit [path=" << path << "]"
           << " [hit count=" << (*iter).second.hit_count << "]" << endl;

    if(buf != NULL)
      *buf = (*iter).second.stbuf;

    (*iter).second.hit_count++;
    pthread_mutex_unlock(&stat_cache_lock);
    return 0;
  }
  pthread_mutex_unlock(&stat_cache_lock);

  return -1;
}
예제 #3
0
파일: s3fs.cpp 프로젝트: kernelfoo/s3fs
static int
s3fs_getattr(const char *path, struct stat *stbuf) {
	cout << "getattr[path=" << path << "]" << endl;
	memset(stbuf, 0, sizeof(struct stat));
	if (strcmp(path, "/") == 0) {
		stbuf->st_nlink = 1; // see fuse faq
		stbuf->st_mode = root_mode | S_IFDIR;
		return 0;
	}

	{
		auto_lock lock(stat_cache_lock);
		stat_cache_t::iterator iter = stat_cache.find(path);
		if (iter != stat_cache.end()) {
			*stbuf = (*iter).second;
			stat_cache.erase(path);
			return 0;
		}
	}

	string resource = urlEncode(service_path +bucket + path);
	string url = host + resource;

	auto_curl curl;
	curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
	curl_easy_setopt(curl, CURLOPT_NOBODY, true); // HEAD
	curl_easy_setopt(curl, CURLOPT_FILETIME, true); // Last-Modified

	headers_t responseHeaders;
    	curl_easy_setopt(curl, CURLOPT_HEADERDATA, &responseHeaders);
    	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);

	auto_curl_slist headers;
	string date = get_date();
	headers.append("Date: "+date);
	headers.append("Content-Type: ");
	headers.append("Authorization: AWS "+AWSAccessKeyId+":"+calc_signature("HEAD", "", date, headers.get(), resource));
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());
	string my_url = prepare_url(url.c_str());
	curl_easy_setopt(curl, CURLOPT_URL, my_url.c_str());

	VERIFY(my_curl_easy_perform(curl.get()));

	stbuf->st_nlink = 1; // see fuse faq

	stbuf->st_mtime = strtoul(responseHeaders["x-amz-meta-mtime"].c_str(), (char **)NULL, 10);
	if (stbuf->st_mtime == 0) {
		long LastModified;
		if (curl_easy_getinfo(curl, CURLINFO_FILETIME, &LastModified) == 0)
			stbuf->st_mtime = LastModified;
	}

	stbuf->st_mode = strtoul(responseHeaders["x-amz-meta-mode"].c_str(), (char **)NULL, 10);
	char* ContentType = 0;
	if (curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ContentType) == 0) {
		if (ContentType)
			stbuf->st_mode |= strcmp(ContentType, "application/x-directory") == 0 ? S_IFDIR : S_IFREG;
	}

	double ContentLength;
	if (curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &ContentLength) == 0)
		stbuf->st_size = static_cast<off_t>(ContentLength);

	if (S_ISREG(stbuf->st_mode))
		stbuf->st_blocks = stbuf->st_size / 512 + 1;

	stbuf->st_uid = strtoul(responseHeaders["x-amz-meta-uid"].c_str(), (char **)NULL, 10);
  stbuf->st_gid = strtoul(responseHeaders["x-amz-meta-gid"].c_str(), (char **)NULL, 10);

	return 0;
}