This source file includes following definitions.
- unix2dostime
- dos2unixtime
- dos2unixfn
- unix2dosfn
- unix2winfn
- winChkName
- win2unixfn
- winChksum
- winSlotCnt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/time.h>
57 #include <sys/kernel.h>
58 #include <sys/dirent.h>
59 #include <sys/vnode.h>
60
61
62
63
64 #include <msdosfs/direntry.h>
65 #include <msdosfs/denode.h>
66
67
68
69
70 const u_short regyear[] = {
71 31, 28, 31, 30, 31, 30,
72 31, 31, 30, 31, 30, 31
73 };
74
75
76
77
78 const u_short leapyear[] = {
79 31, 29, 31, 30, 31, 30,
80 31, 31, 30, 31, 30, 31
81 };
82
83
84
85
86
87 uint32_t lasttime;
88 uint32_t lastday;
89 u_short lastddate;
90 u_short lastdtime;
91
92
93
94
95
96 void
97 unix2dostime(tsp, ddp, dtp, dhp)
98 struct timespec *tsp;
99 u_int16_t *ddp;
100 u_int16_t *dtp;
101 u_int8_t *dhp;
102 {
103 uint32_t t;
104 uint32_t days;
105 uint32_t inc;
106 uint32_t year;
107 uint32_t month;
108 const u_short *months;
109
110
111
112
113
114 t = tsp->tv_sec - (tz.tz_minuteswest * 60)
115 ;
116 t &= ~1;
117 if (lasttime != t) {
118 lasttime = t;
119 lastdtime = (((t / 2) % 30) << DT_2SECONDS_SHIFT)
120 + (((t / 60) % 60) << DT_MINUTES_SHIFT)
121 + (((t / 3600) % 24) << DT_HOURS_SHIFT);
122
123
124
125
126
127
128 days = t / (24 * 60 * 60);
129 if (days != lastday) {
130 lastday = days;
131 for (year = 1970;; year++) {
132 inc = year & 0x03 ? 365 : 366;
133 if (days < inc)
134 break;
135 days -= inc;
136 }
137 months = year & 0x03 ? regyear : leapyear;
138 for (month = 0; month < 12; month++) {
139 if (days < months[month])
140 break;
141 days -= months[month];
142 }
143 lastddate = ((days + 1) << DD_DAY_SHIFT)
144 + ((month + 1) << DD_MONTH_SHIFT);
145
146
147
148
149
150
151 if (year > 1980)
152 lastddate += (year - 1980) << DD_YEAR_SHIFT;
153 }
154 }
155
156 if (dtp != NULL)
157 *dtp = lastdtime;
158 if (dhp != NULL)
159 *dhp = (tsp->tv_sec & 1) * 100 + tsp->tv_nsec / 10000000;
160
161 *ddp = lastddate;
162 }
163
164
165
166
167
168 #define SECONDSTO1980 (((8 * 365) + (2 * 366)) * (24 * 60 * 60))
169
170 u_short lastdosdate;
171 uint32_t lastseconds;
172
173
174
175
176
177
178 void
179 dos2unixtime(dd, dt, dh, tsp)
180 u_int dd;
181 u_int dt;
182 u_int dh;
183 struct timespec *tsp;
184 {
185 uint32_t seconds;
186 uint32_t m, month;
187 uint32_t y, year;
188 uint32_t days;
189 const u_short *months;
190
191 if (dd == 0) {
192
193
194
195 tsp->tv_sec = 0;
196 tsp->tv_nsec = 0;
197 return;
198 }
199 seconds = ((dt & DT_2SECONDS_MASK) >> DT_2SECONDS_SHIFT) * 2
200 + ((dt & DT_MINUTES_MASK) >> DT_MINUTES_SHIFT) * 60
201 + ((dt & DT_HOURS_MASK) >> DT_HOURS_SHIFT) * 3600
202 + dh / 100;
203
204
205
206
207 if (lastdosdate != dd) {
208 lastdosdate = dd;
209 days = 0;
210 year = (dd & DD_YEAR_MASK) >> DD_YEAR_SHIFT;
211 for (y = 0; y < year; y++)
212 days += y & 0x03 ? 365 : 366;
213 months = year & 0x03 ? regyear : leapyear;
214
215
216
217
218 month = (dd & DD_MONTH_MASK) >> DD_MONTH_SHIFT;
219 if (month == 0) {
220 printf("dos2unixtime(): month value out of range (%ld)\n",
221 month);
222 month = 1;
223 }
224 for (m = 0; m < month - 1; m++)
225 days += months[m];
226 days += ((dd & DD_DAY_MASK) >> DD_DAY_SHIFT) - 1;
227 lastseconds = (days * 24 * 60 * 60) + SECONDSTO1980;
228 }
229 tsp->tv_sec = seconds + lastseconds + (tz.tz_minuteswest * 60)
230 ;
231 tsp->tv_nsec = (dh % 100) * 10000000;
232 }
233
234 static const u_char
235 unix2dos[256] = {
236 0, 0, 0, 0, 0, 0, 0, 0,
237 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0x21, 0, 0x23, 0x24, 0x25, 0x26, 0x27,
241 0x28, 0x29, 0, 0, 0, 0x2d, 0, 0,
242 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
243 0x38, 0x39, 0, 0, 0, 0, 0, 0,
244 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
245 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
246 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
247 0x58, 0x59, 0x5a, 0, 0, 0, 0x5e, 0x5f,
248 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
249 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
250 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
251 0x58, 0x59, 0x5a, 0x7b, 0, 0x7d, 0x7e, 0,
252 0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 0, 0, 0,
254 0, 0, 0, 0, 0, 0, 0, 0,
255 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 0xad, 0xbd, 0x9c, 0xcf, 0xbe, 0xdd, 0xf5,
257 0xf9, 0xb8, 0xa6, 0xae, 0xaa, 0xf0, 0xa9, 0xee,
258 0xf8, 0xf1, 0xfd, 0xfc, 0xef, 0xe6, 0xf4, 0xfa,
259 0xf7, 0xfb, 0xa7, 0xaf, 0xac, 0xab, 0xf3, 0xa8,
260 0xb7, 0xb5, 0xb6, 0xc7, 0x8e, 0x8f, 0x92, 0x80,
261 0xd4, 0x90, 0xd2, 0xd3, 0xde, 0xd6, 0xd7, 0xd8,
262 0xd1, 0xa5, 0xe3, 0xe0, 0xe2, 0xe5, 0x99, 0x9e,
263 0x9d, 0xeb, 0xe9, 0xea, 0x9a, 0xed, 0xe8, 0xe1,
264 0xb7, 0xb5, 0xb6, 0xc7, 0x8e, 0x8f, 0x92, 0x80,
265 0xd4, 0x90, 0xd2, 0xd3, 0xde, 0xd6, 0xd7, 0xd8,
266 0xd1, 0xa5, 0xe3, 0xe0, 0xe2, 0xe5, 0x99, 0xf6,
267 0x9d, 0xeb, 0xe9, 0xea, 0x9a, 0xed, 0xe8, 0x98,
268 };
269
270 static const u_char
271 dos2unix[256] = {
272 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
273 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
274 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
275 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
276 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
277 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
278 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
279 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
280 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
281 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
282 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
283 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
284 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
285 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
286 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
287 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
288 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7,
289 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,
290 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,
291 0xff, 0xd6, 0xdc, 0xf8, 0xa3, 0xd8, 0xd7, 0x3f,
292 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,
293 0xbf, 0xae, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,
294 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0xc1, 0xc2, 0xc0,
295 0xa9, 0x3f, 0x3f, 0x3f, 0x3f, 0xa2, 0xa5, 0x3f,
296 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0xe3, 0xc3,
297 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0xa4,
298 0xf0, 0xd0, 0xca, 0xcb, 0xc8, 0x3f, 0xcd, 0xce,
299 0xcf, 0x3f, 0x3f, 0x3f, 0x3f, 0xa6, 0xcc, 0x3f,
300 0xd3, 0xdf, 0xd4, 0xd2, 0xf5, 0xd5, 0xb5, 0xfe,
301 0xde, 0xda, 0xdb, 0xd9, 0xfd, 0xdd, 0xaf, 0x3f,
302 0xad, 0xb1, 0x3f, 0xbe, 0xb6, 0xa7, 0xf7, 0xb8,
303 0xb0, 0xa8, 0xb7, 0xb9, 0xb3, 0xb2, 0x3f, 0x3f,
304 };
305
306 static const u_char
307 u2l[256] = {
308 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
309 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
310 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
311 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
312 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
313 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
314 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
315 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
316 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
317 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
318 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
319 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
320 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
321 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
322 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
323 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
324 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
325 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
326 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
327 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
328 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
329 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
330 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
331 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
332 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
333 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
334 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xd7,
335 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xdf,
336 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
337 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
338 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
339 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
340 };
341
342
343
344
345
346
347
348
349
350
351
352
353
354 int
355 dos2unixfn(dn, un, lower)
356 u_char dn[11];
357 u_char *un;
358 int lower;
359 {
360 int i;
361 int thislong = 1;
362 u_char c;
363
364
365
366
367
368
369
370 if (*dn == SLOT_E5)
371 c = dos2unix[0xe5];
372 else
373 c = dos2unix[*dn];
374 *un++ = lower ? u2l[c] : c;
375 dn++;
376
377
378
379
380 for (i = 1; i < 8 && *dn != ' '; i++) {
381 c = dos2unix[*dn++];
382 *un++ = lower ? u2l[c] : c;
383 thislong++;
384 }
385 dn += 8 - i;
386
387
388
389
390
391 if (*dn != ' ') {
392 *un++ = '.';
393 thislong++;
394 for (i = 0; i < 3 && *dn != ' '; i++) {
395 c = dos2unix[*dn++];
396 *un++ = lower ? u2l[c] : c;
397 thislong++;
398 }
399 }
400 *un++ = 0;
401
402 return (thislong);
403 }
404
405
406
407
408
409
410
411
412
413
414
415
416 int
417 unix2dosfn(un, dn, unlen, gen)
418 u_char *un;
419 u_char dn[12];
420 int unlen;
421 u_int gen;
422 {
423 int i, j, l;
424 int conv = 1;
425 u_char *cp, *dp, *dp1;
426 u_char gentext[6];
427
428
429
430
431
432 for (i = 0; i < 11; i++)
433 dn[i] = ' ';
434 dn[11] = 0;
435
436
437
438
439
440 if (un[0] == '.' && unlen == 1) {
441 dn[0] = '.';
442 return gen <= 1;
443 }
444 if (un[0] == '.' && un[1] == '.' && unlen == 2) {
445 dn[0] = '.';
446 dn[1] = '.';
447 return gen <= 1;
448 }
449
450
451
452
453 for (cp = un, i = unlen; --i >= 0; cp++)
454 if (*cp != ' ' && *cp != '.')
455 break;
456 if (i < 0)
457 return 0;
458
459
460
461
462
463
464 dp = dp1 = 0;
465 for (cp = un + 1, i = unlen - 1; --i >= 0;) {
466 switch (*cp++) {
467 case '.':
468 if (!dp1)
469 dp1 = cp;
470 break;
471 case ' ':
472 break;
473 default:
474 if (dp1)
475 dp = dp1;
476 dp1 = 0;
477 break;
478 }
479 }
480
481
482
483
484 if (dp) {
485 if (dp1)
486 l = dp1 - dp;
487 else
488 l = unlen - (dp - un);
489 for (i = 0, j = 8; i < l && j < 11; i++, j++) {
490 if (dp[i] != (dn[j] = unix2dos[dp[i]])
491 && conv != 3)
492 conv = 2;
493 if (!dn[j]) {
494 conv = 3;
495 dn[j--] = ' ';
496 }
497 }
498 if (i < l)
499 conv = 3;
500 dp--;
501 } else {
502 for (dp = cp; *--dp == ' ' || *dp == '.';);
503 dp++;
504 }
505
506
507
508
509 for (i = j = 0; un < dp && j < 8; i++, j++, un++) {
510 if (*un != (dn[j] = unix2dos[*un])
511 && conv != 3)
512 conv = 2;
513 if (!dn[j]) {
514 conv = 3;
515 dn[j--] = ' ';
516 }
517 }
518 if (un < dp)
519 conv = 3;
520
521
522
523
524 if (!j)
525 dn[0] = '_';
526
527
528
529
530
531 if (dn[0] == 0xe5)
532 dn[0] = SLOT_E5;
533
534
535
536
537
538 if (conv != 3) {
539 if (gen > 1)
540 return 0;
541 return conv;
542 }
543
544
545
546
547 for (cp = gentext + sizeof(gentext); cp > gentext && gen; gen /= 10)
548 *--cp = gen % 10 + '0';
549 if (gen)
550 return 0;
551 for (i = 8; dn[--i] == ' ';);
552 if (gentext + sizeof(gentext) - cp + 1 > 8 - i)
553 i = 8 - (gentext + sizeof(gentext) - cp + 1);
554 dn[i++] = '~';
555 while (cp < gentext + sizeof(gentext))
556 dn[i++] = *cp++;
557 return 3;
558 }
559
560
561
562
563
564
565 int
566 unix2winfn(un, unlen, wep, cnt, chksum)
567 u_char *un;
568 int unlen;
569 struct winentry *wep;
570 int cnt;
571 int chksum;
572 {
573 u_int8_t *cp;
574 int i;
575
576
577
578
579 for (cp = un + unlen; *--cp == ' ' || *cp == '.'; unlen--);
580
581 un += (cnt - 1) * WIN_CHARS;
582 unlen -= (cnt - 1) * WIN_CHARS;
583
584
585
586
587 for (cp = (u_int8_t *)wep, i = sizeof(*wep); --i >= 0; *cp++ = 0xff);
588 wep->weCnt = cnt;
589 wep->weAttributes = ATTR_WIN95;
590 wep->weReserved1 = 0;
591 wep->weChksum = chksum;
592 wep->weReserved2 = 0;
593
594
595
596
597 for (cp = wep->wePart1, i = sizeof(wep->wePart1)/2; --i >= 0;) {
598 if (--unlen < 0)
599 goto done;
600 *cp++ = *un++;
601 *cp++ = 0;
602 }
603 for (cp = wep->wePart2, i = sizeof(wep->wePart2)/2; --i >= 0;) {
604 if (--unlen < 0)
605 goto done;
606 *cp++ = *un++;
607 *cp++ = 0;
608 }
609 for (cp = wep->wePart3, i = sizeof(wep->wePart3)/2; --i >= 0;) {
610 if (--unlen < 0)
611 goto done;
612 *cp++ = *un++;
613 *cp++ = 0;
614 }
615 if (!unlen)
616 wep->weCnt |= WIN_LAST;
617 return unlen;
618
619 done:
620 *cp++ = 0;
621 *cp++ = 0;
622 wep->weCnt |= WIN_LAST;
623 return 0;
624 }
625
626
627
628
629
630 int
631 winChkName(un, unlen, wep, chksum)
632 u_char *un;
633 int unlen;
634 struct winentry *wep;
635 int chksum;
636 {
637 u_int8_t *cp;
638 int i;
639
640
641
642
643 if (wep->weCnt&WIN_LAST)
644 chksum = wep->weChksum;
645 else if (chksum != wep->weChksum)
646 chksum = -1;
647 if (chksum == -1)
648 return -1;
649
650
651
652
653 i = ((wep->weCnt&WIN_CNT) - 1) * WIN_CHARS;
654 if ((unlen -= i) <= 0)
655 return -1;
656 un += i;
657
658 if ((wep->weCnt&WIN_LAST) && unlen > WIN_CHARS)
659 return -1;
660
661
662
663
664 for (cp = wep->wePart1, i = sizeof(wep->wePart1)/2; --i >= 0;) {
665 if (--unlen < 0) {
666 if (!*cp++ && !*cp)
667 return chksum;
668 return -1;
669 }
670 if (u2l[*cp++] != u2l[*un++] || *cp++)
671 return -1;
672 }
673 for (cp = wep->wePart2, i = sizeof(wep->wePart2)/2; --i >= 0;) {
674 if (--unlen < 0) {
675 if (!*cp++ && !*cp)
676 return chksum;
677 return -1;
678 }
679 if (u2l[*cp++] != u2l[*un++] || *cp++)
680 return -1;
681 }
682 for (cp = wep->wePart3, i = sizeof(wep->wePart3)/2; --i >= 0;) {
683 if (--unlen < 0) {
684 if (!*cp++ && !*cp)
685 return chksum;
686 return -1;
687 }
688 if (u2l[*cp++] != u2l[*un++] || *cp++)
689 return -1;
690 }
691 return chksum;
692 }
693
694
695
696
697
698 int
699 win2unixfn(wep, dp, chksum)
700 struct winentry *wep;
701 struct dirent *dp;
702 int chksum;
703 {
704 u_int8_t *cp;
705 u_int8_t *np, *ep = dp->d_name + WIN_MAXLEN;
706 int i;
707
708 if ((wep->weCnt&WIN_CNT) > howmany(WIN_MAXLEN, WIN_CHARS)
709 || !(wep->weCnt&WIN_CNT))
710 return -1;
711
712
713
714
715 if (wep->weCnt&WIN_LAST) {
716 chksum = wep->weChksum;
717
718
719
720 dp->d_namlen = (wep->weCnt&WIN_CNT) * WIN_CHARS;
721 } else if (chksum != wep->weChksum)
722 chksum = -1;
723 if (chksum == -1)
724 return -1;
725
726
727
728
729 i = ((wep->weCnt&WIN_CNT) - 1) * WIN_CHARS;
730 np = (u_int8_t *)dp->d_name + i;
731
732
733
734
735 for (cp = wep->wePart1, i = sizeof(wep->wePart1)/2; --i >= 0;) {
736 switch (*np++ = *cp++) {
737 case 0:
738 dp->d_namlen -= sizeof(wep->wePart2)/2
739 + sizeof(wep->wePart3)/2 + i + 1;
740 return chksum;
741 case '/':
742 np[-1] = 0;
743 return -1;
744 }
745
746
747
748
749 if (WIN_MAXLEN % WIN_CHARS < sizeof(wep->wePart1) / 2
750 && np > ep) {
751 np[-1] = 0;
752 return -1;
753 }
754 if (*cp++)
755 return -1;
756 }
757 for (cp = wep->wePart2, i = sizeof(wep->wePart2)/2; --i >= 0;) {
758 switch (*np++ = *cp++) {
759 case 0:
760 dp->d_namlen -= sizeof(wep->wePart3)/2 + i + 1;
761 return chksum;
762 case '/':
763 np[-1] = 0;
764 return -1;
765 }
766
767
768
769 if (WIN_MAXLEN % WIN_CHARS >= sizeof(wep->wePart1) / 2
770 && WIN_MAXLEN % WIN_CHARS < (sizeof(wep->wePart1) + sizeof(wep->wePart2)) / 2
771 && np > ep) {
772 np[-1] = 0;
773 return -1;
774 }
775 if (*cp++)
776 return -1;
777 }
778 for (cp = wep->wePart3, i = sizeof(wep->wePart3)/2; --i >= 0;) {
779 switch (*np++ = *cp++) {
780 case 0:
781 dp->d_namlen -= i + 1;
782 return chksum;
783 case '/':
784 np[-1] = 0;
785 return -1;
786 }
787
788
789
790 if (WIN_MAXLEN % WIN_CHARS >= (sizeof(wep->wePart1) + sizeof(wep->wePart2)) / 2
791 && np > ep) {
792 np[-1] = 0;
793 return -1;
794 }
795 if (*cp++)
796 return -1;
797 }
798 return chksum;
799 }
800
801
802
803
804 u_int8_t
805 winChksum(name)
806 u_int8_t *name;
807 {
808 int i;
809 u_int8_t s;
810
811 for (s = 0, i = 11; --i >= 0; s += *name++)
812 s = (s << 7)|(s >> 1);
813 return s;
814 }
815
816
817
818
819 int
820 winSlotCnt(un, unlen)
821 u_char *un;
822 int unlen;
823 {
824 for (un += unlen; unlen > 0; unlen--)
825 if (*--un != ' ' && *un != '.')
826 break;
827 if (unlen > WIN_MAXLEN)
828 return 0;
829 return howmany(unlen, WIN_CHARS);
830 }