2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
49 #define MIN_HD_DATE 19800101
50 #define MIN_HD_TMSTAMP 315554400 /* timestamp of 19800101 */
52 static int dayno, day_of_week;
56 * The following table is used for USA daylight savings time and
57 * gives the day number of the first day after the Sunday of the
65 {1987, 96, 303}, /* new legislation - 1st Sun in April */
66 {1976, 119, 303}, /* normal Last Sun in Apr - last Sun in Oct */
67 {1975, 58, 303}, /* 1975: Last Sun in Feb - last Sun in Oct */
68 {1974, 5, 333}, /* 1974: Jan 6 - last Sun. in Nov */
69 {1970, 119, 303}, /* start GMT */
71 #define DAYTABSIZE (sizeof(daytab)/sizeof(daytab[0]))
74 /******************************************************************************
79 * Return number of days in year y.
81 ******************************************************************************/
90 temp = ( (y%400) != 0);
95 /******************************************************************************
100 * sunday - return sunday daynumber. Argument d is the day number of the
101 * first Sunday on or before the special day. Variables leap_year, dayno,
102 * and day_of_week must have been set before sunday is called.
105 * The sunday daynumber.
107 ******************************************************************************/
114 return(d - (d - dayno + day_of_week + 700) % 7);
119 cnvdate(int mon, int mday, int year, int hour, int min, int sec)
122 int daylbegin, daylend;
123 int ly_correction; /* Leap Year Correction */
124 int dl_correction; /* Daylight Savings Time Correction */
126 static int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
130 /* Verify Input Parameters. */
138 if (year < 70) year += 2000;
148 if (dysize(year) == 366) {
154 * Set ly_correction = number of leap year days from 1/1/1970 to
157 ly_correction = ((year-1969) / 4);
161 if( (mon < 1) || (mon > 12)) {
167 if ( (mday < 1) || (mday > days[mon]) ) {
173 if( (hour<0) || (hour>23)) {
176 if( (min<0) || (min>59)) {
179 if( (sec<0) || (sec>59)) {
183 /* Calculate Correction for Daylight Savings Time (U.S.) */
188 s = (year-1970)*365L + ly_correction + dayno;
189 day_of_week = (s + 4) % 7;
192 while (year < daytab[i].yrbgn) {
193 /* fall through when in correct interval */
198 daylbegin = daytab[i].daylb;
199 daylend = daytab[i].dayle;
201 daylbegin = sunday(daylbegin);
202 daylend = sunday(daylend);
204 (dayno>daylbegin || (dayno==daylbegin && hour>=2)) &&
205 (dayno<daylend || (dayno==daylend && hour<1)))
206 dl_correction = -1*60*60;
210 /* Calculate seconds since 00:00:00 1/1/1970. */
212 s = ( ( s*24 +hour)*60 +min)*60 + sec + dl_correction;
217 /* Cracks dates in the form YYYYMMDD and YYYYMMDDHHMMSS. */
234 if (strlen(ptr) != 8 && strlen(ptr) != 14)
236 strncpy(date, ptr, 8);
244 if (mon < 0 || mon > 12)
248 /* Note: invalid day numbers are caught in cnvdate */
252 l = strtol(ptr, &last_char, 10);
253 if (l < 0 || l>235959 || *last_char != '\0')
269 if ((*timestamp = cnvdate(mon, day, yr, hr, mn, sec)) < 0) {
277 /* Cracks dates in the form: NNs, NNm, NNh, or NNd which are interpreted
278 as NN seconds, minutes, hours, or days prior to the current time,
292 l = strtol (ptr, &last_char, 10);
293 (void) time(timestamp);
294 if (strcmp(last_char, "s") == 0)
296 else if (strcmp(last_char, "m") == 0)
298 else if (strcmp(last_char, "h") == 0)
300 else if (strcmp(last_char, "d") == 0)
301 l = l * 60 * 60 * 24;
305 if (*timestamp < MIN_HD_TMSTAMP)
314 fprintf(stderr, "Usage: %s [-M mode] [-u uid] [-g gid] [-a atime] \\\n"
315 "\t[-m mtime] [-c ctime] [-d dtime] [-S size] [-s sid] pathname\n",
317 fprintf(stderr, "\nDates can either be absolute:\n");
318 fprintf(stderr, "\t\tYYYYMMDD or YYYYMMDDHHMMSS\n");
319 fprintf(stderr, "or relative (prior to) the current time:\n");
320 fprintf(stderr, "\tNNs (seconds), NNm (minutes), NNh (hours), "
331 dm_sessid_t sid = DM_NO_SESSION;
334 dm_fileattr_t fileattr;
340 if (Progname = strrchr(argv[0], '/')) {
347 while ((opt = getopt(argc, argv, "M:u:g:a:m:c:d:S:s:")) != EOF) {
351 fileattr.fa_mode = strtol (optarg, NULL, 8);
355 fileattr.fa_uid = atol(optarg);
359 fileattr.fa_gid = atol(optarg);
363 if (get_absolute_date(optarg, &fileattr.FA_ATIME))
365 if (get_relative_date(optarg, &fileattr.FA_ATIME))
370 if (get_absolute_date(optarg, &fileattr.FA_MTIME))
372 if (get_relative_date(optarg, &fileattr.FA_MTIME))
377 if (get_absolute_date(optarg, &fileattr.FA_CTIME))
379 if (get_relative_date(optarg, &fileattr.FA_CTIME))
384 if (get_absolute_date(optarg, &fileattr.FA_DTIME))
386 if (get_relative_date(optarg, &fileattr.FA_DTIME))
391 fileattr.fa_size = atol(optarg);
400 if (optind + 1 != argc) {
403 pathname = argv[optind];
405 if (dm_init_service(&name) == -1) {
406 fprintf(stderr, "Can't initialize the DMAPI\n");
409 if (sid == DM_NO_SESSION)
410 find_test_session(&sid);
412 if (dm_path_to_handle(pathname, &hanp, &hlen)) {
413 fprintf(stderr, "dm_path_to_handle failed, %s\n",
418 if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, mask, &fileattr)) {
419 fprintf(stderr, "dm_set_fileattr failed, %s\n",