static TACommandVerdict __fxstat_cmd(TAThread thread,TAInputStream stream) { struct stat buffer; int res; int fildes; // Prepare fildes = readInt(&stream); START_TARGET_OPERATION(thread); errno=0; #if ( __i386__ || __powerpc__ || (__s390__ && !__s390x__)) res = __fxstat(3, fildes, &buffer); #else res = __fxstat(0, fildes, &buffer); #endif END_TARGET_OPERATION(thread); // Response writeInt(thread, res); writeInt(thread, errno); writeFileStatus(thread, &buffer); sendResponse(thread); return taDefaultVerdict; }
int fstat(int fd, void *st) { #if HAVE___LXSTAT return __fxstat(0, fd, st); #else if (smbw_fd(fd)) { return smbw_fstat(fd, st); } return real_fstat(fd, st); #endif }
int main(int argc, char *argv[]) { std::vector<unsigned long long> results; struct timespec start_time, end_time; struct stat output; int result; int fd; fd = open(argv[0], O_RDONLY); if (fd < 0) { return 1; } unsigned long long min = (unsigned long long) -1, max = 0, sum = 0; double avg, delta, variance = 0.0, sd; results.reserve(ITERATIONS); for (int i = 0; i < ITERATIONS; ++i) { if (clock_gettime(CLOCK_MONOTONIC, &start_time) != 0) { printf("Error calling clock_gettime\n"); break; } result = __fxstat(3, fd, &output); if (clock_gettime(CLOCK_MONOTONIC, &end_time) != 0) { printf("Error calling clock_gettime\n"); break; } unsigned long long start = static_cast<unsigned long long>(start_time.tv_sec) * 1000000000ULL + static_cast<unsigned long long>(start_time.tv_nsec); unsigned long long end = static_cast<unsigned long long>(end_time.tv_sec) * 1000000000ULL + static_cast<unsigned long long>(end_time.tv_nsec); unsigned long long ns = end - start; min = std::min(min, ns); max = std::max(max, ns); sum += ns; results.push_back(ns); } close(fd); avg = ((double)sum)/((double)results.size()); for(std::vector<unsigned long long>::const_iterator itr = results.begin(); itr != results.end(); ++itr) { delta = ((double)(*itr)) - avg; variance += delta * delta; } sd = sqrt(variance / ((double)results.size())); printf("Min: %llu ns, Max: %llu ns, Avg: %f ns, Std Dev: %f\n", min, max, avg, sd); return 0; }
int __fxstat(int ver, int fd, struct stat *buf) { if (iscsi_fd_list[fd].is_iscsi == 1) { if (iscsi_fd_list[fd].dup2fd >= 0) { return __fxstat(ver, iscsi_fd_list[fd].dup2fd, buf); } memset(buf, 0, sizeof(struct stat)); buf->st_mode = S_IRUSR | S_IRGRP | S_IROTH | S_IFREG; buf->st_size = iscsi_fd_list[fd].num_blocks * iscsi_fd_list[fd].block_size; return 0; } return real_fxstat(ver, fd, buf); }
int __lxstat(int ver, const char *path, struct stat *buf) { if (!strncmp(path, "iscsi:", 6)) { int fd, ret; fd = open(path, 0, 0); if (fd == -1) { return fd; } ret = __fxstat(ver, fd, buf); close(fd); return ret; } return real_lxstat(ver, path, buf); }
int __lxstat(int ver, const char *path, struct stat *buf) { if (!strncmp(path, "nfs:", 4)) { int fd, ret; LD_NFS_DPRINTF(9, "__lxstat(%s)", path); fd = open(path, 0, 0); if (fd == -1) { return fd; } ret = __fxstat(ver, fd, buf); close(fd); return ret; } return real_lxstat(ver, path, buf); }
int attribute_hidden __fstat (int fd, struct stat *buf) { return __fxstat (_STAT_VER, fd, buf); }
/* 2 of 3: _fxstat */ int _fxstat (int vers, int fd, struct stat *buf) { return __fxstat (vers, fd, buf); }
__attribute__((weak)) int fstat(int fd, struct stat *buf) { return __fxstat(1, fd, buf); }