void ffsb_stat(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); struct ffsb_file *curfile = NULL; randdata_t *rd = ft_get_randdata(ft); curfile = choose_file_reader(bf, rd); fhstat(curfile->name, ft, fs); unlock_file_reader(curfile); ft_incr_op(ft, opnum, 1, 0); }
int vfs_readlink(struct vfs_fsal_obj_handle *myself, fsal_errors_t *fsal_error) { int retval = 0; int fd = -1; ssize_t retlink; struct stat st; #ifndef __FreeBSD__ int flags = O_PATH | O_NOACCESS | O_NOFOLLOW; #endif if (myself->u.symlink.link_content != NULL) { gsh_free(myself->u.symlink.link_content); myself->u.symlink.link_content = NULL; myself->u.symlink.link_size = 0; } #ifndef __FreeBSD__ fd = vfs_fsal_open(myself, flags, fsal_error); if (fd < 0) return fd; retval = vfs_stat_by_handle(fd, &st); if (retval < 0) goto error; #else struct fhandle *handle = v_to_fhandle(myself->handle->handle_data); retval = fhstat(handle, &st); if (retval < 0) goto error; #endif myself->u.symlink.link_size = st.st_size + 1; myself->u.symlink.link_content = gsh_malloc(myself->u.symlink.link_size); retlink = vfs_readlink_by_handle(myself->handle, fd, "", myself->u.symlink.link_content, myself->u.symlink.link_size); if (retlink < 0) goto error; myself->u.symlink.link_content[retlink] = '\0'; #ifndef __FreeBSD__ close(fd); #endif return retval; error: retval = -errno; *fsal_error = posix2fsal_error(errno); #ifndef __FreeBSD__ close(fd); #endif if (myself->u.symlink.link_content != NULL) { gsh_free(myself->u.symlink.link_content); myself->u.symlink.link_content = NULL; myself->u.symlink.link_size = 0; } return retval; }
int main(int argc, char *argv[]) { struct stat st; int ch, rc, errs, am_readlink; int lsF, fmtchar, usestat, nfs_handle, fn, nonl, quiet; const char *statfmt, *options, *synopsis; char dname[sizeof _PATH_DEV + MNAMELEN] = _PATH_DEV; fhandle_t fhnd; const char *file; am_readlink = 0; lsF = 0; fmtchar = '\0'; usestat = 0; nfs_handle = 0; nonl = 0; quiet = 0; linkfail = 0; statfmt = NULL; timefmt = NULL; if (strcmp(getprogname(), "readlink") == 0) { am_readlink = 1; options = "fn"; synopsis = "[-fn] [file ...]"; statfmt = "%Y"; fmtchar = 'f'; quiet = 1; } else { options = "f:FHlLnqrst:x"; synopsis = "[-FLnq] [-f format | -l | -r | -s | -x] " "[-t timefmt] [file|handle ...]"; } while ((ch = getopt(argc, argv, options)) != -1) switch (ch) { case 'F': lsF = 1; break; case 'H': nfs_handle = 1; break; case 'L': usestat = 1; break; case 'n': nonl = 1; break; case 'q': quiet = 1; break; case 'f': if (am_readlink) { statfmt = "%R"; break; } statfmt = optarg; /* FALLTHROUGH */ case 'l': case 'r': case 's': case 'x': if (fmtchar != 0) errx(1, "can't use format '%c' with '%c'", fmtchar, ch); fmtchar = ch; break; case 't': timefmt = optarg; break; default: usage(synopsis); } argc -= optind; argv += optind; fn = 1; if (fmtchar == '\0') { if (lsF) fmtchar = 'l'; else { fmtchar = 'f'; statfmt = DEF_FORMAT; } } if (lsF && fmtchar != 'l') errx(1, "can't use format '%c' with -F", fmtchar); switch (fmtchar) { case 'f': /* statfmt already set */ break; case 'l': statfmt = lsF ? LSF_FORMAT : LS_FORMAT; break; case 'r': statfmt = RAW_FORMAT; break; case 's': statfmt = SHELL_FORMAT; break; case 'x': statfmt = LINUX_FORMAT; if (timefmt == NULL) timefmt = "%c"; break; default: usage(synopsis); /*NOTREACHED*/ } if (timefmt == NULL) timefmt = TIME_FORMAT; errs = 0; do { if (argc == 0) { if (fdevname_r(STDIN_FILENO, dname + sizeof _PATH_DEV - 1, MNAMELEN) == 0) file = dname; else file = "(stdin)"; rc = fstat(STDIN_FILENO, &st); } else { int j; file = argv[0]; if (nfs_handle) { rc = 0; bzero(&fhnd, sizeof(fhnd)); j = MIN(2 * sizeof(fhnd), strlen(file)); if ((j & 1) != 0) { rc = -1; } else { while (j) { rc = hex2byte(&file[j - 2]); if (rc == -1) break; ((char*) &fhnd)[j / 2 - 1] = rc; j -= 2; } } if (rc == -1) errno = EINVAL; else rc = fhstat(&fhnd, &st); } else if (usestat) { /* * Try stat() and if it fails, fall back to * lstat() just in case we're examining a * broken symlink. */ if ((rc = stat(file, &st)) == -1 && errno == ENOENT && (rc = lstat(file, &st)) == -1) errno = ENOENT; } else rc = lstat(file, &st); } if (rc == -1) { errs = 1; linkfail = 1; if (!quiet) warn("%s: stat", file); } else output(&st, file, statfmt, fn, nonl); argv++; argc--; fn++; } while (argc > 0); return (am_readlink ? linkfail : errs); }