Snippets

Takehiko NOZAKI V1 UNIX(unix-jun72) build patch for Cygwin

Created by Takehiko NOZAKI
  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
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
diff --git a/build/Makefile b/build/Makefile
index 7b23f41..a77cc82 100644
--- a/build/Makefile
+++ b/build/Makefile
@@ -105,7 +105,7 @@ $(ALLSRCS) patched : $(CLEANSRCS)
 unix usyms : $(KSRCS)
 	@echo Building kernel...
 	@$(AS) u?.s
-	@$(NM) a.out | sort > usyms
+	@$(NM) a.out | LANG=C sort > usyms
 	@mv a.out unix
 
 # build a prototype filesystems
@@ -143,6 +143,7 @@ tape : protofs
 
 install : rf0.dsk rk0.dsk
 	@echo Installing...
+	@mkdir -p ../images
 	@cp rf0.dsk rk0.dsk ../boot/m792low.load ../images
 	
 # clean intermediate files
diff --git a/patches/core/initorig.patch b/patches/core/initorig.patch
index 3f13b20..01c4590 100644
--- a/patches/core/initorig.patch
+++ b/patches/core/initorig.patch
@@ -1,5 +1,5 @@
---- init.clean	2008-06-25 08:39:57.000000000 -1000
-+++ init.s	2008-06-25 08:40:08.000000000 -1000
+--- build/init.clean	2024-02-21 09:38:45.071459600 +0900
++++ build/init.s	2024-02-21 09:38:48.915208600 +0900
 @@ -1,4 +1,5 @@
  / init -- process control initialization
 +.. = 40014
diff --git a/tools/apout/bsd_ioctl.c b/tools/apout/bsd_ioctl.c
index 3fd1e0f..d1496e9 100644
--- a/tools/apout/bsd_ioctl.c
+++ b/tools/apout/bsd_ioctl.c
@@ -6,6 +6,9 @@
 #ifdef EMU211
 #include "defines.h"
 #include <sys/ioctl.h>
+#if !defined(FIOCLEX) || !defined(FIOSETOWN)
+#include <fcntl.h>
+#endif
 #include <termios.h>
 #include "bsdtrap.h"
 #ifdef __linux__
@@ -20,8 +23,12 @@
 #define TR_TIOCSETP	0x40067409	/* 0x8 is a write */
 #define	TR_TIOCSETN	0x8006740a
 #define	TR_TIOCSETC	0x80067411
+#if defined(TIOCGETD)
 #define TR_TIOCGETD	0x40027400
+#endif
+#if defined(TIOCSETD)
 #define TR_TIOCSETD	0x80027401
+#endif
 #define TR_TIOCGETC	0x40067412
 #define TR_TIOCGLTC	0x40067474
 #define TR_TIOCSLTC	0x80067475
@@ -132,8 +139,12 @@ int trap_ioctl()
       case TR_TIOCSETP:	  fprintf(dbg_file, "TIOCSETP "); break;
       case TR_TIOCSETN:	  fprintf(dbg_file, "TIOCSETN "); break;
       case TR_TIOCSETC:	  fprintf(dbg_file, "TIOCSETC "); break;
+#if defined(TIOCGETD)
       case TR_TIOCGETD:	  fprintf(dbg_file, "TIOCGETD "); break;
+#endif
+#if defined(TIOCSETD)
       case TR_TIOCSETD:	  fprintf(dbg_file, "TIOCSETD "); break;
+#endif
       case TR_TIOCGETC:	  fprintf(dbg_file, "TIOCGETC "); break;
       case TR_TIOCGLTC:	  fprintf(dbg_file, "TIOCGLTC "); break;
       case TR_TIOCSLTC:	  fprintf(dbg_file, "TIOCSLTC "); break;
@@ -171,12 +182,18 @@ int trap_ioctl()
       i = trap_settermios(uarg1, larg1, uarg4); break;
 
     case TR_FIOCLEX:
+#if defined(FIOCLEX)
       i = ioctl(uarg1, FIOCLEX, NULL); break;
+#else
+      i = fcntl(uarg1, F_SETFD, FD_CLOEXEC); break;
+#endif
+#if defined(TIOCGETD)
     case TR_TIOCGETD:
       shortptr = (int16_t *) &dspace[uarg4];
       i = ioctl(uarg1, TIOCGETD, &val);
       if (i==0) *shortptr= val;
       break;
+#endif
     case TR_TIOCGPGRP:
       shortptr = (int16_t *) &dspace[uarg4];
       i = ioctl(uarg1, TIOCGPGRP, &val);
@@ -185,15 +202,21 @@ int trap_ioctl()
     case TR_TIOCSPGRP:
       shortptr = (int16_t *) &dspace[uarg4];
       val= *shortptr; i = ioctl(uarg1, TIOCSPGRP, &val); break;
+#if defined(TIOCSETD)
     case TR_TIOCSETD:
       shortptr = (int16_t *) &dspace[uarg4];
       val= *shortptr; i = ioctl(uarg1, TIOCSETD, &val); break;
+#endif
     case TR_FIOSETOWN:
       shortptr = (int16_t *) &dspace[uarg4];
       val= *shortptr;
 				/* Something wrong here, wonder why! */
       TrapDebug((dbg_file, "fd %d val %d ",uarg1,val));
+#if defined(FIOSETOWN)
       i = ioctl(uarg1, FIOSETOWN, &val); break;
+#else
+      i = fcntl(uarg1, F_SETOWN, val); break;
+#endif
     case TR_TIOCMGET:
       shortptr = (int16_t *) &dspace[uarg4];
       i = ioctl(uarg1, TIOCMGET, &val);
diff --git a/tools/apout/bsdtrap.c b/tools/apout/bsdtrap.c
index 2c450d5..ff3017e 100644
--- a/tools/apout/bsdtrap.c
+++ b/tools/apout/bsdtrap.c
@@ -57,11 +57,16 @@ bsdtrap()
     char *buf, *buf2;
     int16_t *shortptr;
     long larg1;
+#ifdef STREAM_BUFFERING
     char *fmode;				/* used with fdopen only */
+#endif
     struct stat stbuf;				/* used in STAT */
     struct tr_stat *tr_stbuf;			/* used in STAT */
     struct tr_timeval *tr_del, *tr_oldel;	/* used in ADJTIME */
-    struct timeval del, oldel;			/* used in ADJTIME */
+    struct timeval del;				/* used in ADJTIME */
+#if !defined(NO_ADJTIME)
+    struct timeval oldel;			/* used in ADJTIME */
+#endif
     struct timeval utv[2];			/* used in UTIMES */
     struct tr_timezone *tr_zone;		/* used in GETTIMEOFDAY */
     struct timezone zone;			/* used in GETTIMEOFDAY */
@@ -222,9 +227,11 @@ bsdtrap()
     case S_RMDIR:				/* DONE */
 	buf = xlate_filename((char *)&dspace[uarg1]);
 	i = rmdir(buf); break;
+#if !defined(NO_ACCT)
     case S_ACCT:				/* DONE */
 	buf = xlate_filename((char *)&dspace[uarg1]);
 	i = acct(buf); break;
+#endif
     case S_WRITEV:				/* DONE */
     case S_READV:				/* DONE */
 	ivec= (struct iovec *)malloc(uarg3 * sizeof(struct iovec));
@@ -323,6 +330,7 @@ dostat:
 	copylong(tr_oldel->tv_sec,  utv[1].tv_sec);
 	copylong(tr_oldel->tv_usec, utv[1].tv_usec);
 	break;
+#if !defined(NO_ADJTIME)
     case S_ADJTIME:				/* DONE */
 	tr_del = (struct tr_timeval *) &dspace[uarg1];
 						/* Convert tr_del to del */
@@ -336,6 +344,7 @@ dostat:
 	    copylong(tr_oldel->tv_usec, oldel.tv_usec);
 	}
 	break;
+#endif
     case S_GETTIMEOFDAY:			/* DONE */
 	tr_del = (struct tr_timeval *)	 &dspace[uarg1];
 	tr_zone = (struct tr_timezone *) &dspace[uarg2];
@@ -385,17 +394,21 @@ dostat:
 	i = stat(buf, &stbuf);	/* If file is a directory */
 	if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
 	    i = bsdopen_dir(buf);
+#ifdef STREAM_BUFFERING
 	    fmode = "w+";
+#endif
             TrapDebug((dbg_file, "(dir) on %s ",buf));
 	} else {
 #ifdef NEED_MAP_FCNTL
 	    sarg2= map_fcntl(sarg2);
 #endif
+#ifdef STREAM_BUFFERING
  	    switch (sarg2 & O_ACCMODE) {
               case O_RDONLY: fmode = "r"; break;
               case O_WRONLY: fmode = "w"; break;
               default: fmode = "w+"; break;
             }
+#endif
 	    i = open(buf, sarg2, sarg3);
             TrapDebug((dbg_file, "on %s ",buf));
             TrapDebug((dbg_file, "sarg2 is %d, sarg3 is 0x%x ",sarg2,sarg3));
@@ -506,9 +519,11 @@ dostat:
 	regs[1] = i & 0xffff;
 	i= (i >> 16) & 0xffff;
 	break;
+#if !defined(NO_SETHOSTID)
     case S_SETHOSTID:				/* DONE */
 	larg1 = (sarg2 << 16) | uarg3;
 	sethostid(larg1); i=0; break;
+#endif
     case S_GETUID:				/* DONE */
 	i = getuid(); break;
     case S_SETUID:				/* DONE */
@@ -559,7 +574,7 @@ dostat:
 	tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
 	sock.sa_family= tr_sock->sa_family;
 	ll_word(uarg3, len);
-#ifndef __linux__
+#if !defined(NO_SALEN)
 	sock.sa_len=len;
 #endif
 	memcpy(sock.sa_data, tr_sock->sa_data, len);
@@ -573,7 +588,7 @@ dostat:
 	tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
 	sock.sa_family= tr_sock->sa_family;
 	ll_word(uarg3, len);
-#ifndef __linux__
+#if !defined(NO_SALEN)
 	sock.sa_len=len;
 #endif
 	memcpy(sock.sa_data, tr_sock->sa_data, len);
@@ -587,7 +602,7 @@ dostat:
 	tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
 	sock.sa_family= tr_sock->sa_family;
 	ll_word(uarg3, len);
-#ifndef __linux__
+#if !defined(NO_SALEN)
 	sock.sa_len=len;
 #endif
 	memcpy(sock.sa_data, tr_sock->sa_data, len);
@@ -601,7 +616,7 @@ dostat:
 	tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
 	sock.sa_family= tr_sock->sa_family;
 	len= sarg3;
-#ifndef __linux__
+#if !defined(NO_SALEN)
 	sock.sa_len= sarg3;
 #endif
 	memcpy(sock.sa_data, tr_sock->sa_data, len);
@@ -611,7 +626,7 @@ dostat:
 	tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
 	sock.sa_family= tr_sock->sa_family;
 	len= sarg3;
-#ifndef __linux__
+#if !defined(NO_SALEN)
 	sock.sa_len= sarg3;
 #endif
 	memcpy(sock.sa_data, tr_sock->sa_data, len);
@@ -621,7 +636,7 @@ dostat:
 	tr_sock= (struct tr_sockaddr *)&dspace[uarg5];
 	sock.sa_family= tr_sock->sa_family;
 	ll_word(uarg6, len);
-#ifndef __linux__
+#if !defined(NO_SALEN)
 	sock.sa_len=len;
 #endif
 	memcpy(sock.sa_data, tr_sock->sa_data, len);
diff --git a/tools/apout/defines.h b/tools/apout/defines.h
index 1f27603..59fb5eb 100644
--- a/tools/apout/defines.h
+++ b/tools/apout/defines.h
@@ -7,6 +7,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -47,6 +48,7 @@
 
 #ifdef __linux__
 # define NO_CHFLAGS
+# define NO_SALEN
 # define NO_STFLAGS
 # define NO_GETPGID
 # define NEED_MAP_FCNTL
@@ -68,30 +70,20 @@
 # define Reboot(x) exit(0)
 #endif
 
-#if !defined(__FreeBSD__) && !defined(__NetBSD__) && \
-    !defined(__OpenBSD__) && !defined(__linux__) && !defined(__APPLE__)
-# define NEED_INT_N
+#ifdef __CYGWIN__
+# define NO_ACCT
+# define NO_ADJTIME
+# define NO_CHFLAGS
+# define NO_SALEN
+# define NO_SETHOSTID
+# define NO_STFLAGS
+# define OXTABS XTABS
+# define VDSUSP VSUSP
 #endif
 
-/* Type definitions for PDP data types. You may need to
- * define NEED_INT_N if your system  doesn't provide the
- * types defined below. If you do this, the best way is
- * to add some #if .. #define .. #endif lines above,
- * rather then modifying the ones below. If you make
- * changes to the #if's above, then I would  be very
- * happy to include them.
- *
- * Warren Toomey: wkt@tuhs.org
- */
-
-#ifdef NEED_INT_N
-typedef char int8_t;
-typedef short int16_t;
-typedef long int32_t;
-typedef unsigned char u_int8_t;
-typedef unsigned short u_int16_t;
-typedef unsigned long u_int32_t;
-#endif
+#define u_int8_t uint8_t
+#define u_int16_t uint16_t
+#define u_int32_t uint32_t
 
 /* Macro defines for debug output, makes
  * the code look somewhat cleaner
diff --git a/tools/apout/fp.c b/tools/apout/fp.c
index 3b69cb3..b5f5b51 100644
--- a/tools/apout/fp.c
+++ b/tools/apout/fp.c
@@ -42,7 +42,7 @@ int INTMODE=0;		/* 0 = integers, 1 = longs */
 /* Temporary variables */
 FLOAT Srcflt;		/* Float specified by FSRC field */
 pdpfloat *fladdr;	/* Address of float  in dspace */
-int   AC;		/* Accumulator field in ir */
+extern int   AC;	/* Accumulator field in ir */
 int32_t srclong;	/* Longword from source address */
 int32_t dstlong;	/* Longword for destination address */
 static char *buf, *buf2; /* for copylong */
diff --git a/tools/apout/v7trap.c b/tools/apout/v7trap.c
index 00a2f31..4f1d685 100644
--- a/tools/apout/v7trap.c
+++ b/tools/apout/v7trap.c
@@ -68,7 +68,7 @@ v7trap()
     int whence;
     u_int16_t argbase;
     int trapnum;
-    long larg;
+    long larg = 0;
     char *buf, *buf2;
     char *fmode;		/* used with fdopen only */
     time_t tim;
@@ -692,9 +692,9 @@ static int v7signal(int sig, int val)
 
   switch(val) {
     case V7_SIG_IGN:
-      return((int)signal(v7sig[sig], SIG_IGN));
+      return((intptr_t)signal(v7sig[sig], SIG_IGN));
     case V7_SIG_DFL:
-      return((int)signal(v7sig[sig], SIG_DFL));
+      return((intptr_t)signal(v7sig[sig], SIG_DFL));
     default:
       return(0);      /* No handling of this as yet */
   }
diff --git a/tools/disaout/opset.c b/tools/disaout/opset.c
index 9745d76..4359ca5 100644
--- a/tools/disaout/opset.c
+++ b/tools/disaout/opset.c
@@ -358,7 +358,9 @@ void branch(char *str, int addr, int ins)
  */
 int printins(int addr)
 {
+#if 0
   unsigned int type;
+#endif
   int byte;
   int incr = 2;
   int syscall;
@@ -374,7 +376,9 @@ int printins(int addr)
   /* Get the instruction from the ispace array */
   int ins = ispace[addr] + (ispace[addr + 1] << 8);
 
+#if 0
   type = DSYM;
+#endif
   for (p = optab;; p++) {
     if ((ins & ~p->mask) == p->val) {
       break;
@@ -389,7 +393,9 @@ int printins(int addr)
   switch (p->itype) {
 
   case JMP:
+#if 0
     type = ISYM;
+#endif
 
   case SINGLE:
     if (byte) {
@@ -405,7 +411,9 @@ int printins(int addr)
     break;
 
   case JSR:
+#if 0
     type = ISYM;
+#endif
 
   case DOUBLE:
     if (byte) {
diff --git a/tools/fixaout.py b/tools/fixaout.py
index ce5ac90..ca768d2 100755
--- a/tools/fixaout.py
+++ b/tools/fixaout.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Convert an 0407 binary into an 0405 binary, under the assumption
 that the code starts at 040014 (by ".. = 40014").
@@ -6,6 +6,7 @@ See tools/as.
 """
 
 import struct
+from io import open
 
 def words(bs) :
     l = len(bs) / 2
@@ -15,17 +16,17 @@ def unwords(ws) :
     return struct.pack('<%dH' % l, *ws)
 
 def read(fn) :
-    f = file(fn, 'rb')
+    f = open(fn, 'rb')
     d = f.read()
     f.close()
     return d
 
 def write(fn, d) :
-    f = file(fn, 'wb')
+    f = open(fn, 'wb')
     f.write(d)
     f.close()
 
 d1 = words(read('a.out'))
 hdr = d1[:8]
-d = [0405, 12+hdr[1], 0, 0, hdr[4], 0] + d1[8:]
+d = [0o405, 12+hdr[1], 0, 0, hdr[4], 0] + d1[8:]
 write("a.out", unwords(d))
diff --git a/tools/mkfs.c b/tools/mkfs.c
index a463044..1403f0b 100644
--- a/tools/mkfs.c
+++ b/tools/mkfs.c
@@ -128,7 +128,7 @@ void write_superblock(void)
     printf("Writing inodelist from block 2\n");
   }
   fseek(diskfh, 2 * BLKSIZE, SEEK_SET);
-  if (debug) printf("Writing %d inodes, each size %d, total %d\n",
+  if (debug) printf("Writing %d inodes, each size %ld, total %ld\n",
 	   icount, sizeof(struct v1inode), icount * sizeof(struct v1inode));
   fwrite(&inodelist[1], sizeof(struct v1inode), icount - 1, diskfh);
   if (debug) {
@@ -361,7 +361,7 @@ void write_dir(struct directory *d, char *name)
   }
 
   if (debug)
-    printf("Writing dir %s, size %d, %d blks from block %d (offset 0x%x) on\n",
+    printf("Writing dir %s, size %ld, %ld blks from block %d (offset %#x) on\n",
 	   name, d->numentries * sizeof(struct v1dirent),
 	   d->numentries / DIRENTPERBLOCK, d->block,
 	   d->block * BLKSIZE);
@@ -683,7 +683,9 @@ int main(int argc, char *argv[])
 {
   int i, ch;
   int numiblocks;
+#if 0
   int fs_size;			/* Equal to disksize minus any swap */
+#endif
 
   /* Get any optional arguments */
   while ((ch = getopt(argc, argv, "dp:")) != -1) {
@@ -707,10 +709,14 @@ int main(int argc, char *argv[])
     /* XXX: I can't seem to go past 4864 to 4872 blocks, and I haven't */
     /* worked out why yet. */
     disksize = RK_SIZE;
+#if 0
     fs_size = RK_SIZE;
+#endif
   } else {
     disksize = RF_SIZE;
+#if 0
     fs_size = RF_NOSWAPSIZE;
+#endif
     makedevflag = 1;
   }
 
diff --git a/tools/mktape.py b/tools/mktape.py
index 1682606..4ad2df6 100755
--- a/tools/mktape.py
+++ b/tools/mktape.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Make a tape for 1st ed cold boot.
 
@@ -15,6 +15,7 @@ metadata:
 
 import os, re, sys
 from struct import pack
+from io import open
 
 # unfortunately the permission bits and uids weren't preserved
 # so we have to restore them based on this table...
@@ -120,12 +121,12 @@ noisy = 0
 
 def uMode(s) :
     m = 0
-    if s[0] == 'u' : m |= 040 | 020
-    if s[0] == 'x' : m |= 020
-    if s[1] == 'r' : m |= 010
-    if s[2] == 'w' : m |= 004
-    if s[3] == 'r' : m |= 002
-    if s[4] == '2' : m |= 001
+    if s[0] == 'u' : m |= 0o40 | 0o20
+    if s[0] == 'x' : m |= 0o20
+    if s[1] == 'r' : m |= 0o10
+    if s[2] == 'w' : m |= 0o04
+    if s[3] == 'r' : m |= 0o02
+    if s[4] == '2' : m |= 0o01
     return m
 
 # preprocess the perms table to form perm :: path -> (mode, uid)
@@ -138,31 +139,31 @@ def pad(d) :
     "pad to 512-byte boundary"
     l = len(d)
     m = ((l + 511) & ~511) - l
-    return d + ("\0" * m)
+    return d + str.encode("\0" * m)
 
 def sMode(m) :
     return (
-        ("-","s")[(m & 040) != 0] +
-        ("-","x")[(m & 020) != 0] +
-        ("-","r")[(m & 010) != 0] +
-        ("-","w")[(m & 004) != 0] +
-        ("-","r")[(m & 002) != 0] +
-        ("-","w")[(m & 001) != 0] )
+        ("-","s")[(m & 0o40) != 0] +
+        ("-","x")[(m & 0o20) != 0] +
+        ("-","r")[(m & 0o10) != 0] +
+        ("-","w")[(m & 0o04) != 0] +
+        ("-","r")[(m & 0o02) != 0] +
+        ("-","w")[(m & 0o01) != 0] )
 
 def wrFile(out, fn, d, mode, uid) :
     "write out file."
     if noisy :
-        print sMode(mode), uid, fn
+        print(sMode(mode), uid, fn)
     meta = pack("<HBB", len(d), mode, uid) + fn
     out.write(pad(meta))
     out.write(pad(d))
 
 def wrEof(out) :
-    wrFile(out, "", "", 0, 0)
+    wrFile(out, b"", b"", 0, 0)
     
 def copyFile(root, out, fn) :
     "copy file from local filesystem to tape."
-    f = file(fn, 'rb')
+    f = open(fn, 'rb')
     d = f.read()
     f.close()
     s = os.stat(fn)
@@ -170,19 +171,19 @@ def copyFile(root, out, fn) :
         fn = fn[len(root):]
     # get the perm from the table, if not present, just make it
     # uid=1 mode = 37.
-    mode,uid = perms.get(fn, (037, 1))
-    if not fn in perms : print "making up mode"
-    wrFile(out, fn, d, mode, uid)
+    mode,uid = perms.get(fn, (0o37, 1))
+    if not fn in perms : print("making up mode")
+    wrFile(out, str.encode(fn), d, mode, uid)
 
 def main() :
     if len(sys.argv) < 2 :
-        print "usage: %s root files" % sys.argv[0]
+        print("usage: %s root files" % sys.argv[0])
         raise SystemExit(1)
     root = sys.argv[1]
     files = sys.argv[2:]
 
-    f = file("tape", "wb")
-    f.write("\0" * (512 * 65))		# start at block 65
+    f = open("tape", "wb")
+    f.write(str.encode("\0" * (512 * 65)))	# start at block 65
     for fn in files :
         copyFile(root, f, fn)
     wrEof(f)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.