2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #define MIN_HD_DATE 19800101
36 #define MIN_HD_TMSTAMP 315554400 /* timestamp of 19800101 */
38 static int dayno, day_of_week;
42 * The following table is used for USA daylight savings time and
43 * gives the day number of the first day after the Sunday of the
51 {1987, 96, 303}, /* new legislation - 1st Sun in April */
52 {1976, 119, 303}, /* normal Last Sun in Apr - last Sun in Oct */
53 {1975, 58, 303}, /* 1975: Last Sun in Feb - last Sun in Oct */
54 {1974, 5, 333}, /* 1974: Jan 6 - last Sun. in Nov */
55 {1970, 119, 303}, /* start GMT */
57 #define DAYTABSIZE (sizeof(daytab)/sizeof(daytab[0]))
60 /******************************************************************************
65 * Return number of days in year y.
67 ******************************************************************************/
76 temp = ( (y%400) != 0);
81 /******************************************************************************
86 * sunday - return sunday daynumber. Argument d is the day number of the
87 * first Sunday on or before the special day. Variables leap_year, dayno,
88 * and day_of_week must have been set before sunday is called.
91 * The sunday daynumber.
93 ******************************************************************************/
100 return(d - (d - dayno + day_of_week + 700) % 7);
105 cnvdate(int mon, int mday, int year, int hour, int min, int sec)
108 int daylbegin, daylend;
109 int ly_correction; /* Leap Year Correction */
110 int dl_correction; /* Daylight Savings Time Correction */
112 static int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
116 /* Verify Input Parameters. */
124 if (year < 70) year += 2000;
134 if (dysize(year) == 366) {
140 * Set ly_correction = number of leap year days from 1/1/1970 to
143 ly_correction = ((year-1969) / 4);
147 if( (mon < 1) || (mon > 12)) {
153 if ( (mday < 1) || (mday > days[mon]) ) {
159 if( (hour<0) || (hour>23)) {
162 if( (min<0) || (min>59)) {
165 if( (sec<0) || (sec>59)) {
169 /* Calculate Correction for Daylight Savings Time (U.S.) */
174 s = (year-1970)*365L + ly_correction + dayno;
175 day_of_week = (s + 4) % 7;
178 while (year < daytab[i].yrbgn) {
179 /* fall through when in correct interval */
184 daylbegin = daytab[i].daylb;
185 daylend = daytab[i].dayle;
187 daylbegin = sunday(daylbegin);
188 daylend = sunday(daylend);
190 (dayno>daylbegin || (dayno==daylbegin && hour>=2)) &&
191 (dayno<daylend || (dayno==daylend && hour<1)))
192 dl_correction = -1*60*60;
196 /* Calculate seconds since 00:00:00 1/1/1970. */
198 s = ( ( s*24 +hour)*60 +min)*60 + sec + dl_correction;
203 /* Cracks dates in the form YYYYMMDD and YYYYMMDDHHMMSS. */
220 if (strlen(ptr) != 8 && strlen(ptr) != 14)
222 strncpy(date, ptr, 8);
230 if (mon < 0 || mon > 12)
234 /* Note: invalid day numbers are caught in cnvdate */
238 l = strtol(ptr, &last_char, 10);
239 if (l < 0 || l>235959 || *last_char != '\0')
255 if ((*timestamp = cnvdate(mon, day, yr, hr, mn, sec)) < 0) {
263 /* Cracks dates in the form: NNs, NNm, NNh, or NNd which are interpreted
264 as NN seconds, minutes, hours, or days prior to the current time,
278 l = strtol (ptr, &last_char, 10);
279 (void) time(timestamp);
280 if (strcmp(last_char, "s") == 0)
282 else if (strcmp(last_char, "m") == 0)
284 else if (strcmp(last_char, "h") == 0)
286 else if (strcmp(last_char, "d") == 0)
287 l = l * 60 * 60 * 24;
291 if (*timestamp < MIN_HD_TMSTAMP)
300 fprintf(stderr, "Usage: %s [-M mode] [-u uid] [-g gid] [-a atime] \\\n"
301 "\t[-m mtime] [-c ctime] [-d dtime] [-S size] [-s sid] pathname\n",
303 fprintf(stderr, "\nDates can either be absolute:\n");
304 fprintf(stderr, "\t\tYYYYMMDD or YYYYMMDDHHMMSS\n");
305 fprintf(stderr, "or relative (prior to) the current time:\n");
306 fprintf(stderr, "\tNNs (seconds), NNm (minutes), NNh (hours), "
317 dm_sessid_t sid = DM_NO_SESSION;
320 dm_fileattr_t fileattr;
326 Progname = strrchr(argv[0], '/');
334 while ((opt = getopt(argc, argv, "M:u:g:a:m:c:d:S:s:")) != EOF) {
338 fileattr.fa_mode = strtol (optarg, NULL, 8);
342 fileattr.fa_uid = atol(optarg);
346 fileattr.fa_gid = atol(optarg);
350 if (get_absolute_date(optarg, &fileattr.FA_ATIME))
352 if (get_relative_date(optarg, &fileattr.FA_ATIME))
357 if (get_absolute_date(optarg, &fileattr.FA_MTIME))
359 if (get_relative_date(optarg, &fileattr.FA_MTIME))
364 if (get_absolute_date(optarg, &fileattr.FA_CTIME))
366 if (get_relative_date(optarg, &fileattr.FA_CTIME))
371 if (get_absolute_date(optarg, &fileattr.FA_DTIME))
373 if (get_relative_date(optarg, &fileattr.FA_DTIME))
378 fileattr.fa_size = atol(optarg);
387 if (optind + 1 != argc) {
390 pathname = argv[optind];
392 if (dm_init_service(&name) == -1) {
393 fprintf(stderr, "Can't initialize the DMAPI\n");
396 if (sid == DM_NO_SESSION)
397 find_test_session(&sid);
399 if (dm_path_to_handle(pathname, &hanp, &hlen)) {
400 fprintf(stderr, "dm_path_to_handle failed, %s\n",
405 if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, mask, &fileattr)) {
406 fprintf(stderr, "dm_set_fileattr failed, %s\n",