1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
23 #define MIN_HD_DATE 19800101
24 #define MIN_HD_TMSTAMP 315554400 /* timestamp of 19800101 */
26 static int dayno, day_of_week;
30 * The following table is used for USA daylight savings time and
31 * gives the day number of the first day after the Sunday of the
39 {1987, 96, 303}, /* new legislation - 1st Sun in April */
40 {1976, 119, 303}, /* normal Last Sun in Apr - last Sun in Oct */
41 {1975, 58, 303}, /* 1975: Last Sun in Feb - last Sun in Oct */
42 {1974, 5, 333}, /* 1974: Jan 6 - last Sun. in Nov */
43 {1970, 119, 303}, /* start GMT */
45 #define DAYTABSIZE (sizeof(daytab)/sizeof(daytab[0]))
48 /******************************************************************************
53 * Return number of days in year y.
55 ******************************************************************************/
64 temp = ( (y%400) != 0);
69 /******************************************************************************
74 * sunday - return sunday daynumber. Argument d is the day number of the
75 * first Sunday on or before the special day. Variables leap_year, dayno,
76 * and day_of_week must have been set before sunday is called.
79 * The sunday daynumber.
81 ******************************************************************************/
88 return(d - (d - dayno + day_of_week + 700) % 7);
93 cnvdate(int mon, int mday, int year, int hour, int min, int sec)
96 int daylbegin, daylend;
97 int ly_correction; /* Leap Year Correction */
98 int dl_correction; /* Daylight Savings Time Correction */
100 static int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
104 /* Verify Input Parameters. */
112 if (year < 70) year += 2000;
122 if (dysize(year) == 366) {
128 * Set ly_correction = number of leap year days from 1/1/1970 to
131 ly_correction = ((year-1969) / 4);
135 if( (mon < 1) || (mon > 12)) {
141 if ( (mday < 1) || (mday > days[mon]) ) {
147 if( (hour<0) || (hour>23)) {
150 if( (min<0) || (min>59)) {
153 if( (sec<0) || (sec>59)) {
157 /* Calculate Correction for Daylight Savings Time (U.S.) */
162 s = (year-1970)*365L + ly_correction + dayno;
163 day_of_week = (s + 4) % 7;
166 while (year < daytab[i].yrbgn) {
167 /* fall through when in correct interval */
172 daylbegin = daytab[i].daylb;
173 daylend = daytab[i].dayle;
175 daylbegin = sunday(daylbegin);
176 daylend = sunday(daylend);
178 (dayno>daylbegin || (dayno==daylbegin && hour>=2)) &&
179 (dayno<daylend || (dayno==daylend && hour<1)))
180 dl_correction = -1*60*60;
184 /* Calculate seconds since 00:00:00 1/1/1970. */
186 s = ( ( s*24 +hour)*60 +min)*60 + sec + dl_correction;
191 /* Cracks dates in the form YYYYMMDD and YYYYMMDDHHMMSS. */
208 if (strlen(ptr) != 8 && strlen(ptr) != 14)
210 strncpy(date, ptr, 8);
218 if (mon < 0 || mon > 12)
222 /* Note: invalid day numbers are caught in cnvdate */
226 l = strtol(ptr, &last_char, 10);
227 if (l < 0 || l>235959 || *last_char != '\0')
243 if ((*timestamp = cnvdate(mon, day, yr, hr, mn, sec)) < 0) {
251 /* Cracks dates in the form: NNs, NNm, NNh, or NNd which are interpreted
252 as NN seconds, minutes, hours, or days prior to the current time,
266 l = strtol (ptr, &last_char, 10);
267 (void) time(timestamp);
268 if (strcmp(last_char, "s") == 0)
270 else if (strcmp(last_char, "m") == 0)
272 else if (strcmp(last_char, "h") == 0)
274 else if (strcmp(last_char, "d") == 0)
275 l = l * 60 * 60 * 24;
279 if (*timestamp < MIN_HD_TMSTAMP)
288 fprintf(stderr, "Usage: %s [-M mode] [-u uid] [-g gid] [-a atime] \\\n"
289 "\t[-m mtime] [-c ctime] [-d dtime] [-S size] [-s sid] pathname\n",
291 fprintf(stderr, "\nDates can either be absolute:\n");
292 fprintf(stderr, "\t\tYYYYMMDD or YYYYMMDDHHMMSS\n");
293 fprintf(stderr, "or relative (prior to) the current time:\n");
294 fprintf(stderr, "\tNNs (seconds), NNm (minutes), NNh (hours), "
305 dm_sessid_t sid = DM_NO_SESSION;
308 dm_fileattr_t fileattr;
314 Progname = strrchr(argv[0], '/');
322 while ((opt = getopt(argc, argv, "M:u:g:a:m:c:d:S:s:")) != EOF) {
326 fileattr.fa_mode = strtol (optarg, NULL, 8);
330 fileattr.fa_uid = atol(optarg);
334 fileattr.fa_gid = atol(optarg);
338 if (get_absolute_date(optarg, &fileattr.FA_ATIME))
340 if (get_relative_date(optarg, &fileattr.FA_ATIME))
345 if (get_absolute_date(optarg, &fileattr.FA_MTIME))
347 if (get_relative_date(optarg, &fileattr.FA_MTIME))
352 if (get_absolute_date(optarg, &fileattr.FA_CTIME))
354 if (get_relative_date(optarg, &fileattr.FA_CTIME))
359 if (get_absolute_date(optarg, &fileattr.FA_DTIME))
361 if (get_relative_date(optarg, &fileattr.FA_DTIME))
366 fileattr.fa_size = atol(optarg);
375 if (optind + 1 != argc) {
378 pathname = argv[optind];
380 if (dm_init_service(&name) == -1) {
381 fprintf(stderr, "Can't initialize the DMAPI\n");
384 if (sid == DM_NO_SESSION)
385 find_test_session(&sid);
387 if (dm_path_to_handle(pathname, &hanp, &hlen)) {
388 fprintf(stderr, "dm_path_to_handle failed, %s\n",
393 if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, mask, &fileattr)) {
394 fprintf(stderr, "dm_set_fileattr failed, %s\n",