From: Wei Qiaomiao Date: Tue, 15 Jan 2019 02:41:14 +0000 (+0800) Subject: client: add ceph_stat/ceph_lstat/ceph_fstat api X-Git-Tag: v14.1.0~339^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3510d2f5c913e26913aaeb5b5fd879f87debf909;p=ceph.git client: add ceph_stat/ceph_lstat/ceph_fstat api This partial reverts from commit ce8c6f3c9f9f35b7458ab95d9affc9ed4712d0eb The purpose of take these api back is maked the application based on UNIX system easier move on Ceph Signed-off-by: Wei Qiaomiao --- diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h old mode 100644 new mode 100755 index dbb84a1e2d2c..36f4c0315d67 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -746,6 +746,37 @@ int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, int ceph_statx(struct ceph_mount_info *cmount, const char *path, struct ceph_statx *stx, unsigned int want, unsigned int flags); +/** + * Get a file's statistics and attributes. + * + * @param cmount the ceph mount handle to use for performing the stat. + * @param path the file or directory to get the statistics of. + * @param stbuf the stat struct that will be filled in with the file's statistics. + * @returns 0 on success or negative error code on failure. + */ +int ceph_stat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf); + +/** + * Get a file's statistics and attributes, without following symlinks. + * + * @param cmount the ceph mount handle to use for performing the stat. + * @param path the file or directory to get the statistics of. + * @param stbuf the stat struct that will be filled in with the file's statistics. + * @returns 0 on success or negative error code on failure. + */ +int ceph_lstat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf); + +/** + * Get the open file's statistics. + * + * @param cmount the ceph mount handle to use for performing the fstat. + * @param fd the file descriptor of the file to get statistics of. + * @param stbuf the stat struct of the file's statistics, filled in by the + * function. + * @returns 0 on success or a negative error code on failure + */ +int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf); + /** * Set a file's attributes. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc old mode 100644 new mode 100755 index 38f9fc7ddd51..a6b8edf84562 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -852,6 +852,27 @@ extern "C" int ceph_fsetxattr(struct ceph_mount_info *cmount, int fd, const char } /* end xattr support */ +extern "C" int ceph_stat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->stat(path, stbuf, cmount->default_perms); +} + +extern "C" int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->fstat(fd, stbuf, cmount->default_perms); +} + +extern int ceph_lstat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->lstat(path, stbuf, cmount->default_perms); +} + extern "C" int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode) { if (!cmount->is_mounted()) @@ -1060,7 +1081,6 @@ extern "C" int ceph_sync_fs(struct ceph_mount_info *cmount) return cmount->get_client()->sync_fs(); } - extern "C" int ceph_get_file_stripe_unit(struct ceph_mount_info *cmount, int fh) { file_layout_t l;