mv.c (3a1874bce34bfd41e0441d7ff74b66ae16826fa3) mv.c (2b9240ecbee722654a256381b9a1b4a7a54caef5)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 1843 unchanged lines hidden (view full) ---

1852/* Copy extended system attributes from source to target */
1853
1854static int
1855copy_sysattr(char *source, char *target)
1856{
1857 struct dirent *dp;
1858 nvlist_t *response;
1859 int error = 0;
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 1843 unchanged lines hidden (view full) ---

1852/* Copy extended system attributes from source to target */
1853
1854static int
1855copy_sysattr(char *source, char *target)
1856{
1857 struct dirent *dp;
1858 nvlist_t *response;
1859 int error = 0;
1860 int chk_support = 0;
1861 int sa_support = 1;
1860 int target_sa_support = 0;
1862
1863 if (sysattr_support(source, _PC_SATTR_EXISTS) != 1)
1864 return (0);
1865
1866 if (open_source(source) != 0)
1867 return (1);
1868
1869 /*
1870 * Gets non default extended system attributes from the
1871 * source file to copy to the target. The target has
1872 * the defaults set when its created and thus no need
1873 * to copy the defaults.
1874 */
1875 response = sysattr_list(cmd, srcfd, source);
1876
1861
1862 if (sysattr_support(source, _PC_SATTR_EXISTS) != 1)
1863 return (0);
1864
1865 if (open_source(source) != 0)
1866 return (1);
1867
1868 /*
1869 * Gets non default extended system attributes from the
1870 * source file to copy to the target. The target has
1871 * the defaults set when its created and thus no need
1872 * to copy the defaults.
1873 */
1874 response = sysattr_list(cmd, srcfd, source);
1875
1877 if (response != NULL &&
1878 sysattr_support(target, _PC_SATTR_ENABLED) != 1) {
1879 (void) fprintf(stderr,
1880 gettext(
1881 "%s: cannot preserve extended system "
1882 "attribute, operation not supported on file"
1883 " %s\n"), cmd, target);
1884 error++;
1885 goto out;
1886 }
1887
1888 if (srcdirp == NULL) {
1889 if (open_target_srctarg_attrdirs(source, target) != 0) {
1876 if (sysattr_support(target, _PC_SATTR_ENABLED) != 1) {
1877 if (response != NULL) {
1878 (void) fprintf(stderr,
1879 gettext(
1880 "%s: cannot preserve extended system "
1881 "attribute, operation not supported on file"
1882 " %s\n"), cmd, target);
1890 error++;
1891 goto out;
1892 }
1883 error++;
1884 goto out;
1885 }
1893 if (open_attrdirp(source) != 0) {
1894 error++;
1895 goto out;
1896 }
1897 } else {
1886 } else {
1898 rewind_attrdir(srcdirp);
1887 target_sa_support = 1;
1899 }
1888 }
1900 while (sa_support && (dp = readdir(srcdirp)) != NULL) {
1901 nvlist_t *res;
1902 int ret;
1903
1889
1904 if ((ret = traverse_attrfile(dp, source, target, 0)) == -1)
1905 continue;
1906 else if (ret > 0) {
1907 ++error;
1908 goto out;
1890 if (target_sa_support) {
1891 if (srcdirp == NULL) {
1892 if (open_target_srctarg_attrdirs(source,
1893 target) != 0) {
1894 error++;
1895 goto out;
1896 }
1897 if (open_attrdirp(source) != 0) {
1898 error++;
1899 goto out;
1900 }
1901 } else {
1902 rewind_attrdir(srcdirp);
1909 }
1903 }
1910 /*
1911 * Gets non default extended system attributes from the
1912 * attribute file to copy to the target. The target has
1913 * the defaults set when its created and thus no need
1914 * to copy the defaults.
1915 */
1916 if (dp->d_name != NULL) {
1917 res = sysattr_list(cmd, srcattrfd, dp->d_name);
1918 if (res == NULL)
1919 goto next;
1904 while ((dp = readdir(srcdirp)) != NULL) {
1905 nvlist_t *res;
1906 int ret;
1920
1907
1921 if (!chk_support &&
1922 sysattr_support(target, _PC_SATTR_ENABLED) != 1) {
1923 (void) fprintf(stderr,
1924 gettext(
1925 "%s: cannot preserve extended "
1926 "system attribute, operation not "
1927 " %s\n"), cmd, target);
1928 error++;
1929 sa_support = 0;
1930 } else {
1931 chk_support = 1;
1908 if ((ret = traverse_attrfile(dp, source, target,
1909 0)) == -1)
1910 continue;
1911 else if (ret > 0) {
1912 ++error;
1913 goto out;
1932 }
1914 }
1915 /*
1916 * Gets non default extended system attributes from the
1917 * attribute file to copy to the target. The target has
1918 * the defaults set when its created and thus no need
1919 * to copy the defaults.
1920 */
1921 if (dp->d_name != NULL) {
1922 res = sysattr_list(cmd, srcattrfd, dp->d_name);
1923 if (res == NULL)
1924 goto next;
1933
1934 /*
1935 * Copy non default extended system attributes of named
1936 * attribute file.
1937 */
1925
1926 /*
1927 * Copy non default extended system attributes of named
1928 * attribute file.
1929 */
1938 if (sa_support && fsetattr(targattrfd,
1939 XATTR_VIEW_READWRITE, res) != 0) {
1940 ++error;
1941 (void) fprintf(stderr, gettext("%s: "
1942 "Failed to copy extended system "
1943 "attributes from attribute file "
1944 "%s of %s to %s\n"), cmd,
1945 dp->d_name, source, target);
1930 if (fsetattr(targattrfd,
1931 XATTR_VIEW_READWRITE, res) != 0) {
1932 ++error;
1933 (void) fprintf(stderr, gettext("%s: "
1934 "Failed to copy extended system "
1935 "attributes from attribute file "
1936 "%s of %s to %s\n"), cmd,
1937 dp->d_name, source, target);
1938 }
1946 }
1939 }
1947 }
1948next:
1940next:
1949 if (srcattrfd != -1)
1950 (void) close(srcattrfd);
1951 if (targattrfd != -1)
1952 (void) close(targattrfd);
1953 srcattrfd = targattrfd = -1;
1954 if (res != NULL)
1955 nvlist_free(res);
1941 if (srcattrfd != -1)
1942 (void) close(srcattrfd);
1943 if (targattrfd != -1)
1944 (void) close(targattrfd);
1945 srcattrfd = targattrfd = -1;
1946 if (res != NULL)
1947 nvlist_free(res);
1948 }
1956 }
1949 }
1957
1958 /* Copy source file non default extended system attributes to target */
1950 /* Copy source file non default extended system attributes to target */
1959 if ((response != NULL) &&
1951 if (target_sa_support && (response != NULL) &&
1960 (fsetattr(targfd, XATTR_VIEW_READWRITE, response)) != 0) {
1961 ++error;
1962 (void) fprintf(stderr, gettext("%s: Failed to "
1963 "copy extended system attributes from "
1964 "%s to %s\n"), cmd, source, target);
1965 }
1966out:
1967 if (response != NULL)

--- 289 unchanged lines hidden ---
1952 (fsetattr(targfd, XATTR_VIEW_READWRITE, response)) != 0) {
1953 ++error;
1954 (void) fprintf(stderr, gettext("%s: Failed to "
1955 "copy extended system attributes from "
1956 "%s to %s\n"), cmd, source, target);
1957 }
1958out:
1959 if (response != NULL)

--- 289 unchanged lines hidden ---