Print this page
10134 mv needs smatch fixes


  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  32 /*        All Rights Reserved   */
  33 
  34 /*




  35  * University Copyright- Copyright (c) 1982, 1986, 1988
  36  * The Regents of the University of California
  37  * All Rights Reserved
  38  *
  39  * University Acknowledgment- Portions of this document are derived from
  40  * software developed by the University of California, Berkeley, and its
  41  * contributors.
  42  */
  43 
  44 /*
  45  * Combined mv/cp/ln command:
  46  *      mv file1 file2
  47  *      mv dir1 dir2
  48  *      mv file1 ... filen dir1
  49  */
  50 #include <sys/time.h>
  51 #include <signal.h>
  52 #include <locale.h>
  53 #include <stdarg.h>
  54 #include <sys/acl.h>


1922                 } else {
1923                         rewind_attrdir(srcdirp);
1924                 }
1925                 while ((dp = readdir(srcdirp)) != NULL) {
1926                         nvlist_t        *res;
1927                         int             ret;
1928 
1929                         if ((ret = traverse_attrfile(dp, source, target,
1930                             0)) == -1)
1931                                 continue;
1932                         else if (ret > 0) {
1933                                 ++error;
1934                                 goto out;
1935                         }
1936                         /*
1937                          * Gets non default extended system attributes from the
1938                          * attribute file to copy to the target. The target has
1939                          * the defaults set when its created and thus  no need
1940                          * to copy the defaults.
1941                          */
1942                         if (dp->d_name != NULL) {
1943                                 res = sysattr_list(cmd, srcattrfd, dp->d_name);
1944                                 if (res == NULL)
1945                                         goto next;
1946 
1947                         /*
1948                          * Copy non default extended system attributes of named
1949                          * attribute file.
1950                          */
1951                                 if (fsetattr(targattrfd,
1952                                     XATTR_VIEW_READWRITE, res) != 0) {
1953                                         ++error;
1954                                         (void) fprintf(stderr, gettext("%s: "
1955                                             "Failed to copy extended system "
1956                                             "attributes from attribute file "
1957                                             "%s of %s to %s\n"), cmd,
1958                                             dp->d_name, source, target);
1959                                 }
1960                         }
1961 next:
1962                         if (srcattrfd != -1)
1963                                 (void) close(srcattrfd);
1964                         if (targattrfd != -1)
1965                                 (void) close(targattrfd);
1966                         srcattrfd = targattrfd = -1;
1967                         nvlist_free(res);
1968                 }
1969         }
1970         /* Copy source file non default extended system attributes to target */
1971         if (target_sa_support && (response != NULL) &&
1972             (fsetattr(targfd, XATTR_VIEW_READWRITE, response)) != 0) {
1973                 ++error;
1974                 (void) fprintf(stderr, gettext("%s: Failed to "
1975                     "copy extended system attributes from "
1976                     "%s to %s\n"), cmd, source, target);
1977         }
1978 out:
1979         nvlist_free(response);
1980         close_all();




  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  32 /*        All Rights Reserved   */
  33 
  34 /*
  35  * Copyright (c) 2018, Joyent, Inc.
  36  */
  37 
  38 /*
  39  * University Copyright- Copyright (c) 1982, 1986, 1988
  40  * The Regents of the University of California
  41  * All Rights Reserved
  42  *
  43  * University Acknowledgment- Portions of this document are derived from
  44  * software developed by the University of California, Berkeley, and its
  45  * contributors.
  46  */
  47 
  48 /*
  49  * Combined mv/cp/ln command:
  50  *      mv file1 file2
  51  *      mv dir1 dir2
  52  *      mv file1 ... filen dir1
  53  */
  54 #include <sys/time.h>
  55 #include <signal.h>
  56 #include <locale.h>
  57 #include <stdarg.h>
  58 #include <sys/acl.h>


1926                 } else {
1927                         rewind_attrdir(srcdirp);
1928                 }
1929                 while ((dp = readdir(srcdirp)) != NULL) {
1930                         nvlist_t        *res;
1931                         int             ret;
1932 
1933                         if ((ret = traverse_attrfile(dp, source, target,
1934                             0)) == -1)
1935                                 continue;
1936                         else if (ret > 0) {
1937                                 ++error;
1938                                 goto out;
1939                         }
1940                         /*
1941                          * Gets non default extended system attributes from the
1942                          * attribute file to copy to the target. The target has
1943                          * the defaults set when its created and thus  no need
1944                          * to copy the defaults.
1945                          */

1946                         res = sysattr_list(cmd, srcattrfd, dp->d_name);
1947                         if (res == NULL)
1948                                 goto next;
1949 
1950                         /*
1951                          * Copy non default extended system attributes of named
1952                          * attribute file.
1953                          */
1954                         if (fsetattr(targattrfd,
1955                             XATTR_VIEW_READWRITE, res) != 0) {
1956                                 ++error;
1957                                 (void) fprintf(stderr, gettext("%s: "
1958                                     "Failed to copy extended system "
1959                                     "attributes from attribute file "
1960                                     "%s of %s to %s\n"), cmd,
1961                                     dp->d_name, source, target);
1962                         }
1963 
1964 next:
1965                         if (srcattrfd != -1)
1966                                 (void) close(srcattrfd);
1967                         if (targattrfd != -1)
1968                                 (void) close(targattrfd);
1969                         srcattrfd = targattrfd = -1;
1970                         nvlist_free(res);
1971                 }
1972         }
1973         /* Copy source file non default extended system attributes to target */
1974         if (target_sa_support && (response != NULL) &&
1975             (fsetattr(targfd, XATTR_VIEW_READWRITE, response)) != 0) {
1976                 ++error;
1977                 (void) fprintf(stderr, gettext("%s: Failed to "
1978                     "copy extended system attributes from "
1979                     "%s to %s\n"), cmd, source, target);
1980         }
1981 out:
1982         nvlist_free(response);
1983         close_all();