nfsreadlinkres * nfsproc_readlink_2_svc(am_nfs_fh *argp, struct svc_req *rqstp) { static nfsreadlinkres res; am_node *mp; int retry; if (amuDebug(D_TRACE)) plog(XLOG_DEBUG, "readlink:"); mp = fh_to_mp3(argp, &retry, VLOOK_CREATE); if (mp == NULL) { readlink_retry: if (retry < 0) { amd_stats.d_drops++; return 0; } res.rlr_status = nfs_error(retry); } else { char *ln = do_readlink(mp, &retry); if (ln == 0) goto readlink_retry; res.rlr_status = NFS_OK; if (amuDebug(D_TRACE) && ln) plog(XLOG_DEBUG, "\treadlink(%s) = %s", mp->am_path, ln); res.rlr_u.rlr_data_u = ln; mp->am_stats.s_readlink++; } return &res; }
int readlink_w(const char *path, char buf[], size_t buflen) { struct stat statp; if(lstat(path, &statp)) return -1; if(S_ISLNK(statp.st_mode)) return do_readlink(path, buf, buflen); return -1; }
STATIC int xfs_readlink_by_handle( xfs_mount_t *mp, void __user *arg, struct inode *parinode) { struct inode *inode; xfs_fsop_handlereq_t hreq; __u32 olen; void *link; int error; if (!capable(CAP_SYS_ADMIN)) return -XFS_ERROR(EPERM); if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) return -XFS_ERROR(EFAULT); error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode); if (error) return -error; /* Restrict this handle operation to symlinks only. */ if (!S_ISLNK(inode->i_mode)) { error = -XFS_ERROR(EINVAL); goto out_iput; } if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) { error = -XFS_ERROR(EFAULT); goto out_iput; } link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); if (!link) goto out_iput; error = -xfs_readlink(XFS_I(inode), link); if (error) goto out_kfree; error = do_readlink(hreq.ohandle, olen, link); if (error) goto out_kfree; out_kfree: kfree(link); out_iput: iput(inode); return error; }
int xfs_readlink_by_handle( struct file *parfilp, xfs_fsop_handlereq_t *hreq) { struct dentry *dentry; __u32 olen; void *link; int error; if (!capable(CAP_SYS_ADMIN)) return -XFS_ERROR(EPERM); dentry = xfs_handlereq_to_dentry(parfilp, hreq); if (IS_ERR(dentry)) return PTR_ERR(dentry); /* Restrict this handle operation to symlinks only. */ if (!S_ISLNK(dentry->d_inode->i_mode)) { error = -XFS_ERROR(EINVAL); goto out_dput; } if (copy_from_user(&olen, hreq->ohandlen, sizeof(__u32))) { error = -XFS_ERROR(EFAULT); goto out_dput; } link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); if (!link) { error = -XFS_ERROR(ENOMEM); goto out_dput; } error = -xfs_readlink(XFS_I(dentry->d_inode), link); if (error) goto out_kfree; error = do_readlink(hreq->ohandle, olen, link); if (error) goto out_kfree; out_kfree: kfree(link); out_dput: dput(dentry); return error; }
void setMetaDataSourceFileLine(const clang::Decl *decl, const Typelib::Type *type) { const clang::SourceManager &sm = decl->getASTContext().getSourceManager(); const clang::SourceLocation &loc = sm.getExpansionLoc(decl->getLocStart()); // uses "readlink(3)" to normalize symlinks from system-header path. for // example // "/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/$file" // would be turned into // "/usr/include/c++/4.9/bits/$file" // this was done by the gccxml-importer before. this is needed because the // "preprocess" stage of clang++, run later to retrieve the "orogen_include", // can output smth like // "/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/$file" // which cannot be string-compared... so there, is would have to be flattend as well clang::FileManager &fm = sm.getFileManager(); const clang::FileEntry *fileEntry = sm.getFileEntryForID(sm.getFileID(loc)); std::string dirName = fm.getCanonicalName(fileEntry->getDir()).str(); std::string fullFileName(fileEntry->getName()); std::string fileName = fullFileName.substr(fullFileName.find_last_of("/") + 1); if (fileName.empty()) { std::cerr << "ERROR: invalid filename '" << fileEntry->getDir() << "', no forward slash?\n"; exit(-1); } // some headers can be reached via two ways: actual filepath and symlink // inside the ".orogen" folder -- a hack of really bad taste... anyhow, // guard against this... std::string filePath = do_readlink(dirName+"/"+fileName); // typelib needs the '/path/to/file:column' information std::ostringstream stream; stream << filePath << ":" << sm.getExpansionLineNumber(loc); type->getMetaData().add("source_file_line", stream.str()); }
static int process_requests(int sock) { int flags; int size = 0; int retval = 0; uint64_t offset; ProxyHeader header; int mode, uid, gid; V9fsString name, value; struct timespec spec[2]; V9fsString oldpath, path; struct iovec in_iovec, out_iovec; in_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); in_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; out_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); out_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; while (1) { /* * initialize the header type, so that we send * response to proper request type. */ header.type = 0; retval = read_request(sock, &in_iovec, &header); if (retval < 0) { goto err_out; } switch (header.type) { case T_OPEN: retval = do_open(&in_iovec); break; case T_CREATE: retval = do_create(&in_iovec); break; case T_MKNOD: case T_MKDIR: case T_SYMLINK: retval = do_create_others(header.type, &in_iovec); break; case T_LINK: v9fs_string_init(&path); v9fs_string_init(&oldpath); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "ss", &oldpath, &path); if (retval > 0) { retval = link(oldpath.data, path.data); if (retval < 0) { retval = -errno; } } v9fs_string_free(&oldpath); v9fs_string_free(&path); break; case T_LSTAT: case T_STATFS: retval = do_stat(header.type, &in_iovec, &out_iovec); break; case T_READLINK: retval = do_readlink(&in_iovec, &out_iovec); break; case T_CHMOD: v9fs_string_init(&path); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sd", &path, &mode); if (retval > 0) { retval = chmod(path.data, mode); if (retval < 0) { retval = -errno; } } v9fs_string_free(&path); break; case T_CHOWN: v9fs_string_init(&path); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sdd", &path, &uid, &gid); if (retval > 0) { retval = lchown(path.data, uid, gid); if (retval < 0) { retval = -errno; } } v9fs_string_free(&path); break; case T_TRUNCATE: v9fs_string_init(&path); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sq", &path, &offset); if (retval > 0) { retval = truncate(path.data, offset); if (retval < 0) { retval = -errno; } } v9fs_string_free(&path); break; case T_UTIME: v9fs_string_init(&path); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sqqqq", &path, &spec[0].tv_sec, &spec[0].tv_nsec, &spec[1].tv_sec, &spec[1].tv_nsec); if (retval > 0) { retval = utimensat(AT_FDCWD, path.data, spec, AT_SYMLINK_NOFOLLOW); if (retval < 0) { retval = -errno; } } v9fs_string_free(&path); break; case T_RENAME: v9fs_string_init(&path); v9fs_string_init(&oldpath); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "ss", &oldpath, &path); if (retval > 0) { retval = rename(oldpath.data, path.data); if (retval < 0) { retval = -errno; } } v9fs_string_free(&oldpath); v9fs_string_free(&path); break; case T_REMOVE: v9fs_string_init(&path); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "s", &path); if (retval > 0) { retval = remove(path.data); if (retval < 0) { retval = -errno; } } v9fs_string_free(&path); break; case T_LGETXATTR: case T_LLISTXATTR: retval = do_getxattr(header.type, &in_iovec, &out_iovec); break; case T_LSETXATTR: v9fs_string_init(&path); v9fs_string_init(&name); v9fs_string_init(&value); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sssdd", &path, &name, &value, &size, &flags); if (retval > 0) { retval = lsetxattr(path.data, name.data, value.data, size, flags); if (retval < 0) { retval = -errno; } } v9fs_string_free(&path); v9fs_string_free(&name); v9fs_string_free(&value); break; case T_LREMOVEXATTR: v9fs_string_init(&path); v9fs_string_init(&name); retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "ss", &path, &name); if (retval > 0) { retval = lremovexattr(path.data, name.data); if (retval < 0) { retval = -errno; } } v9fs_string_free(&path); v9fs_string_free(&name); break; case T_GETVERSION: retval = do_getversion(&in_iovec, &out_iovec); break; default: goto err_out; break; } if (process_reply(sock, header.type, &out_iovec, retval) < 0) { goto err_out; } } err_out: g_free(in_iovec.iov_base); g_free(out_iovec.iov_base); return -1; }
static void list_file(const char *fname) { STRUCT_STAT buf; char permbuf[PERMSTRING_SIZE]; struct tm *mt; char datebuf[50]; char linkbuf[4096]; if (do_lstat(fname, &buf) < 0) failed("stat", fname); #ifdef SUPPORT_XATTRS if (am_root < 0) stat_xattr(fname, &buf); #endif /* The size of anything but a regular file is probably not * worth thinking about. */ if (!S_ISREG(buf.st_mode)) buf.st_size = 0; /* On some BSD platforms the mode bits of a symlink are * undefined. Also it tends not to be possible to reset a * symlink's mtime, so we default to ignoring it too. */ if (S_ISLNK(buf.st_mode)) { int len; buf.st_mode &= ~0777; if (!link_times) buf.st_mtime = (time_t)0; if (!link_owner) buf.st_uid = buf.st_gid = 0; strlcpy(linkbuf, " -> ", sizeof linkbuf); /* const-cast required for silly UNICOS headers */ len = do_readlink((char *) fname, linkbuf+4, sizeof(linkbuf) - 4); if (len == -1) failed("do_readlink", fname); else /* it's not nul-terminated */ linkbuf[4+len] = 0; } else { linkbuf[0] = 0; } permstring(permbuf, buf.st_mode); if (buf.st_mtime) { int len; mt = gmtime(&buf.st_mtime); len = snprintf(datebuf, sizeof datebuf, "%04d-%02d-%02d %02d:%02d:%02d", (int)mt->tm_year + 1900, (int)mt->tm_mon + 1, (int)mt->tm_mday, (int)mt->tm_hour, (int)mt->tm_min, (int)mt->tm_sec); #ifdef ST_MTIME_NSEC if (nsec_times) { snprintf(datebuf + len, sizeof datebuf - len, ".%09d", (int)buf.ST_MTIME_NSEC); } #endif } else { int len = MIN(19 + 9*nsec_times, (int)sizeof datebuf - 1); memset(datebuf, ' ', len); datebuf[len] = '\0'; } /* TODO: Perhaps escape special characters in fname? */ printf("%s ", permbuf); if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode)) { printf("%5ld,%6ld", (long)major(buf.st_rdev), (long)minor(buf.st_rdev)); } else printf("%15s", do_big_num(buf.st_size, 1, NULL)); printf(" %6ld.%-6ld %6ld %s %s%s\n", (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink, datebuf, fname, linkbuf); }