mv.c (e1636a06d48740791132319d080862a95596e07e) | mv.c (78cca7e25deead6e03a496fee27183f7d9c04242) |
---|---|
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 --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 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 */ | 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 --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 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 |
|
21/* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27/* All Rights Reserved */ 28 --- 63 unchanged lines hidden (view full) --- 92static int copyspecial(char *); 93static int getrealpath(char *, char *); 94static void usage(void); 95static void Perror(char *); 96static void Perror2(char *, char *); 97static int use_stdin(void); 98static int copyattributes(char *, char *); 99static int copy_sysattr(char *, char *); | 22/* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28/* All Rights Reserved */ 29 --- 63 unchanged lines hidden (view full) --- 93static int copyspecial(char *); 94static int getrealpath(char *, char *); 95static void usage(void); 96static void Perror(char *); 97static void Perror2(char *, char *); 98static int use_stdin(void); 99static int copyattributes(char *, char *); 100static int copy_sysattr(char *, char *); |
100static void timestruc_to_timeval(timestruc_t *, struct timeval *); | |
101static tree_node_t *create_tnode(dev_t, ino_t); 102 103static struct stat s1, s2, s3, s4; 104static int cpy = FALSE; 105static int mve = FALSE; 106static int lnk = FALSE; 107static char *cmd; 108static int silent = 0; --- 1227 unchanged lines hidden (view full) --- 1336 exit(2); 1337} 1338 1339/* 1340 * chg_time() 1341 * 1342 * Try to preserve modification and access time. 1343 * If 1) pflg is not set, or 2) pflg is set and this is the Solaris version, | 101static tree_node_t *create_tnode(dev_t, ino_t); 102 103static struct stat s1, s2, s3, s4; 104static int cpy = FALSE; 105static int mve = FALSE; 106static int lnk = FALSE; 107static char *cmd; 108static int silent = 0; --- 1227 unchanged lines hidden (view full) --- 1336 exit(2); 1337} 1338 1339/* 1340 * chg_time() 1341 * 1342 * Try to preserve modification and access time. 1343 * If 1) pflg is not set, or 2) pflg is set and this is the Solaris version, |
1344 * don't report a utime() failure. 1345 * If this is the XPG4 version and utime fails, if 1) pflg is set (cp -p) | 1344 * don't report a utimensat() failure. 1345 * If this is the XPG4 version and utimensat fails, if 1) pflg is set (cp -p) |
1346 * or 2) we are doing a mv, print a diagnostic message; arrange for a non-zero 1347 * exit status only if pflg is set. | 1346 * or 2) we are doing a mv, print a diagnostic message; arrange for a non-zero 1347 * exit status only if pflg is set. |
1348 * utimes(2) is being used to achieve granularity in 1349 * microseconds while setting file times. | 1348 * utimensat(2) is being used to achieve granularity in nanoseconds 1349 * (if supported by the underlying file system) while setting file times. |
1350 */ 1351static int 1352chg_time(char *to, struct stat ss) 1353{ | 1350 */ 1351static int 1352chg_time(char *to, struct stat ss) 1353{ |
1354 struct timeval times[2]; | 1354 struct timespec times[2]; |
1355 int rc; 1356 | 1355 int rc; 1356 |
1357 timestruc_to_timeval(&ss.st_atim, times); 1358 timestruc_to_timeval(&ss.st_mtim, times + 1); | 1357 times[0] = ss.st_atim; 1358 times[1] = ss.st_mtim; |
1359 | 1359 |
1360 rc = utimes(to, times); | 1360 rc = utimensat(AT_FDCWD, to, times, 0); |
1361#ifdef XPG4 1362 if ((pflg || mve) && rc != 0) { 1363 (void) fprintf(stderr, 1364 gettext("%s: cannot set times for %s: "), cmd, to); 1365 perror(""); 1366 if (pflg) 1367 return (1); 1368 } --- 256 unchanged lines hidden (view full) --- 1625{ 1626 struct dirent *dp; 1627 int error = 0; 1628 int aclerror; 1629 mode_t mode; 1630 int clearflg = 0; 1631 acl_t *xacl = NULL; 1632 acl_t *attrdiracl = NULL; | 1361#ifdef XPG4 1362 if ((pflg || mve) && rc != 0) { 1363 (void) fprintf(stderr, 1364 gettext("%s: cannot set times for %s: "), cmd, to); 1365 perror(""); 1366 if (pflg) 1367 return (1); 1368 } --- 256 unchanged lines hidden (view full) --- 1625{ 1626 struct dirent *dp; 1627 int error = 0; 1628 int aclerror; 1629 mode_t mode; 1630 int clearflg = 0; 1631 acl_t *xacl = NULL; 1632 acl_t *attrdiracl = NULL; |
1633 struct timeval times[2]; | 1633 struct timespec times[2]; |
1634 1635 1636 if (pathconf(source, _PC_XATTR_EXISTS) != 1) 1637 return (0); 1638 1639 if (pathconf(target, _PC_XATTR_ENABLED) != 1) { 1640 if (!attrsilent) { 1641 (void) fprintf(stderr, --- 30 unchanged lines hidden (view full) --- 1672 " ownership correctly on attribute" 1673 " directory of file %s: "), cmd, target); 1674 perror(""); 1675 ++error; 1676 } 1677 } 1678 /* 1679 * Now that we are the owner we can update st_ctime by calling | 1634 1635 1636 if (pathconf(source, _PC_XATTR_EXISTS) != 1) 1637 return (0); 1638 1639 if (pathconf(target, _PC_XATTR_ENABLED) != 1) { 1640 if (!attrsilent) { 1641 (void) fprintf(stderr, --- 30 unchanged lines hidden (view full) --- 1672 " ownership correctly on attribute" 1673 " directory of file %s: "), cmd, target); 1674 perror(""); 1675 ++error; 1676 } 1677 } 1678 /* 1679 * Now that we are the owner we can update st_ctime by calling |
1680 * futimesat. | 1680 * utimensat. |
1681 */ | 1681 */ |
1682 times[0].tv_sec = attrdir.st_atime; 1683 times[0].tv_usec = 0; 1684 times[1].tv_sec = attrdir.st_mtime; 1685 times[1].tv_usec = 0; 1686 if (futimesat(targetdirfd, ".", times) < 0) { | 1682 times[0] = attrdir.st_atim; 1683 times[1] = attrdir.st_mtim; 1684 if (utimensat(targetdirfd, ".", times, 0) < 0) { |
1687 if (!attrsilent) { 1688 (void) fprintf(stderr, 1689 gettext("%s: cannot set attribute times" 1690 " for %s: "), cmd, target); 1691 perror(""); 1692 ++error; 1693 } 1694 } --- 92 unchanged lines hidden (view full) --- 1787 ++error; 1788 } 1789 if (mode & (S_ISUID | S_ISGID)) { 1790 /* try to clear S_ISUID and S_ISGID */ 1791 mode &= ~S_ISUID & ~S_ISGID; 1792 ++clearflg; 1793 } 1794 } | 1685 if (!attrsilent) { 1686 (void) fprintf(stderr, 1687 gettext("%s: cannot set attribute times" 1688 " for %s: "), cmd, target); 1689 perror(""); 1690 ++error; 1691 } 1692 } --- 92 unchanged lines hidden (view full) --- 1785 ++error; 1786 } 1787 if (mode & (S_ISUID | S_ISGID)) { 1788 /* try to clear S_ISUID and S_ISGID */ 1789 mode &= ~S_ISUID & ~S_ISGID; 1790 ++clearflg; 1791 } 1792 } |
1795 /* tv_usec were cleared above */ 1796 times[0].tv_sec = s3.st_atime; 1797 times[1].tv_sec = s3.st_mtime; 1798 if (futimesat(targetdirfd, dp->d_name, times) < 0) { | 1793 times[0] = s3.st_atim; 1794 times[1] = s3.st_mtim; 1795 if (utimensat(targetdirfd, dp->d_name, times, 0) < 0) { |
1799 if (!attrsilent) { 1800 (void) fprintf(stderr, 1801 gettext("%s: cannot set attribute" 1802 " times for %s: "), cmd, target); 1803 perror(""); 1804 ++error; 1805 } 1806 } --- 161 unchanged lines hidden (view full) --- 1968 } 1969out: 1970 if (response != NULL) 1971 nvlist_free(response); 1972 close_all(); 1973 return (error == 0 ? 0 : 1); 1974} 1975 | 1796 if (!attrsilent) { 1797 (void) fprintf(stderr, 1798 gettext("%s: cannot set attribute" 1799 " times for %s: "), cmd, target); 1800 perror(""); 1801 ++error; 1802 } 1803 } --- 161 unchanged lines hidden (view full) --- 1965 } 1966out: 1967 if (response != NULL) 1968 nvlist_free(response); 1969 close_all(); 1970 return (error == 0 ? 0 : 1); 1971} 1972 |
1976/* 1977 * nanoseconds are rounded off to microseconds by flooring. 1978 */ 1979static void 1980timestruc_to_timeval(timestruc_t *ts, struct timeval *tv) 1981{ 1982 tv->tv_sec = ts->tv_sec; 1983 tv->tv_usec = ts->tv_nsec / 1000; 1984} 1985 | |
1986/* Open the source file */ 1987 1988int 1989open_source(char *src) 1990{ 1991 int error = 0; 1992 1993 srcfd = -1; --- 269 unchanged lines hidden --- | 1973/* Open the source file */ 1974 1975int 1976open_source(char *src) 1977{ 1978 int error = 0; 1979 1980 srcfd = -1; --- 269 unchanged lines hidden --- |