Whamcloud - gitweb
LU-13837 lnet: Introduce constant for net ID of LNET_NID_ANY
[fs/lustre-release.git] / lustre / utils / lfs_project.c
index 8d3ee2f..9f82b74 100644 (file)
@@ -69,7 +69,7 @@ lfs_project_item_alloc(struct list_head *head, const char *pathname)
                return -ENOMEM;
        }
 
-       strncpy(lpi->lpi_pathname, pathname, sizeof(lpi->lpi_pathname));
+       strncpy(lpi->lpi_pathname, pathname, sizeof(lpi->lpi_pathname) - 1);
        list_add_tail(&lpi->lpi_list, head);
 
        return 0;
@@ -90,12 +90,12 @@ static const char *mode_to_type(mode_t mode)
        return "unknown";
 }
 
-static int project_get_xattr(const char *pathname, struct fsxattr *fsx)
+static int project_get_xattr(const char *pathname, struct fsxattr *fsx,
+                            struct stat *st)
 {
        int ret, fd;
-       struct stat st;
 
-       ret = lstat(pathname, &st);
+       ret = lstat(pathname, st);
        if (ret) {
                fprintf(stderr, "%s: failed to stat '%s': %s\n",
                        progname, pathname, strerror(errno));
@@ -103,10 +103,10 @@ static int project_get_xattr(const char *pathname, struct fsxattr *fsx)
        }
 
        /* currently, only file and dir supported */
-       if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) {
+       if (!S_ISREG(st->st_mode) && !S_ISDIR(st->st_mode)) {
                errno = ENOTSUP;
                fprintf(stderr, "%s: unable to get xattr for %s '%s': %s\n",
-                               progname, mode_to_type(st.st_mode), pathname,
+                               progname, mode_to_type(st->st_mode), pathname,
                                strerror(errno));
                return -errno;
        }
@@ -118,7 +118,7 @@ static int project_get_xattr(const char *pathname, struct fsxattr *fsx)
                return -errno;
        }
 
-       ret = ioctl(fd, LL_IOC_FSGETXATTR, fsx);
+       ret = ioctl(fd, FS_IOC_FSGETXATTR, fsx);
        if (ret) {
                fprintf(stderr, "%s: failed to get xattr for '%s': %s\n",
                        progname, pathname, strerror(errno));
@@ -133,8 +133,9 @@ project_check_one(const char *pathname, struct project_handle_control *phc)
 {
        struct fsxattr fsx;
        int ret;
+       struct stat st;
 
-       ret = project_get_xattr(pathname, &fsx);
+       ret = project_get_xattr(pathname, &fsx, &st);
        if (ret < 0)
                return ret;
 
@@ -144,7 +145,8 @@ project_check_one(const char *pathname, struct project_handle_control *phc)
                phc->projid = fsx.fsx_projid;
        }
 
-       if (!(fsx.fsx_xflags & FS_XFLAG_PROJINHERIT)) {
+       if (!(fsx.fsx_xflags & FS_XFLAG_PROJINHERIT) &&
+           S_ISDIR(st.st_mode)) {
                if (!phc->newline) {
                        printf("%s%c", pathname, '\0');
                        goto out;
@@ -170,9 +172,10 @@ static int
 project_list_one(const char *pathname, struct project_handle_control *phc)
 {
        struct fsxattr fsx;
+       struct stat st;
        int ret;
 
-       ret = project_get_xattr(pathname, &fsx);
+       ret = project_get_xattr(pathname, &fsx, &st);
        if (ret < 0)
                return ret;
 
@@ -188,9 +191,10 @@ static int
 project_set_one(const char *pathname, struct project_handle_control *phc)
 {
        struct fsxattr fsx;
+       struct stat st;
        int fd, ret = 0;
 
-       fd = project_get_xattr(pathname, &fsx);
+       fd = project_get_xattr(pathname, &fsx, &st);
        if (fd < 0)
                return fd;
 
@@ -203,7 +207,7 @@ project_set_one(const char *pathname, struct project_handle_control *phc)
        if (phc->set_projid)
                fsx.fsx_projid = phc->projid;
 
-       ret = ioctl(fd, LL_IOC_FSSETXATTR, &fsx);
+       ret = ioctl(fd, FS_IOC_FSSETXATTR, &fsx);
        if (ret)
                fprintf(stderr, "%s: failed to set xattr for '%s': %s\n",
                        progname, pathname, strerror(errno));
@@ -216,9 +220,10 @@ static int
 project_clear_one(const char *pathname, struct project_handle_control *phc)
 {
        struct fsxattr fsx;
+       struct stat st;
        int ret = 0, fd;
 
-       fd = project_get_xattr(pathname, &fsx);
+       fd = project_get_xattr(pathname, &fsx, &st);
        if (fd < 0)
                return fd;
 
@@ -230,7 +235,7 @@ project_clear_one(const char *pathname, struct project_handle_control *phc)
        if (!phc->keep_projid)
                fsx.fsx_projid = 0;
 
-       ret = ioctl(fd, LL_IOC_FSSETXATTR, &fsx);
+       ret = ioctl(fd, FS_IOC_FSSETXATTR, &fsx);
        if (ret)
                fprintf(stderr, "%s: failed to set xattr for '%s': %s\n",
                        progname, pathname, strerror(errno));