@@ -420,27 +420,76 @@ func chmod(pathname *byte, mode uint32) int32 {
420
420
//
421
421
//go:export mkdir
422
422
func mkdir (pathname * byte , mode uint32 ) int32 {
423
+ path := goString (pathname )
424
+ dir , relPath := findPreopenForPath (path )
425
+
426
+ result := dir .CreateDirectoryAt (relPath )
427
+ if err := result .Err (); err != nil {
428
+ libcErrno = uintptr (errorCodeToErrno (* err ))
429
+ return - 1
430
+ }
431
+
423
432
return 0
424
433
}
425
434
426
435
// int rmdir(const char *pathname);
427
436
//
428
437
//go:export rmdir
429
438
func rmdir (pathname * byte ) int32 {
439
+ path := goString (pathname )
440
+ dir , relPath := findPreopenForPath (path )
441
+
442
+ result := dir .RemoveDirectoryAt (relPath )
443
+ if err := result .Err (); err != nil {
444
+ libcErrno = uintptr (errorCodeToErrno (* err ))
445
+ return - 1
446
+ }
447
+
430
448
return 0
431
449
}
432
450
433
451
// int rename(const char *from, *to);
434
452
//
435
453
//go:export rename
436
454
func rename (from , to * byte ) int32 {
455
+ fromPath := goString (from )
456
+ fromDir , fromRelPath := findPreopenForPath (fromPath )
457
+
458
+ toPath := goString (to )
459
+ toDir , toRelPath := findPreopenForPath (toPath )
460
+
461
+ result := fromDir .RenameAt (fromRelPath , toDir , toRelPath )
462
+ if err := result .Err (); err != nil {
463
+ libcErrno = uintptr (errorCodeToErrno (* err ))
464
+ return - 1
465
+ }
466
+
437
467
return 0
438
468
}
439
469
440
470
// int symlink(const char *from, *to);
441
471
//
442
472
//go:export symlink
443
473
func symlink (from , to * byte ) int32 {
474
+ fromPath := goString (from )
475
+ fromDir , fromRelPath := findPreopenForPath (fromPath )
476
+
477
+ toPath := goString (to )
478
+ toDir , toRelPath := findPreopenForPath (toPath )
479
+
480
+ if fromDir != toDir {
481
+ libcErrno = uintptr (EACCES )
482
+ return - 1
483
+ }
484
+
485
+ // TODO(dgryski): check fromDir == toDir?
486
+
487
+ result := fromDir .SymlinkAt (fromRelPath , toRelPath )
488
+ if err := result .Err (); err != nil {
489
+ libcErrno = uintptr (errorCodeToErrno (* err ))
490
+ return - 1
491
+ }
492
+
444
493
return 0
445
494
}
446
495
@@ -455,14 +504,39 @@ func fsync(fd int32) int32 {
455
504
// ssize_t readlink(const char *path, void *buf, size_t count);
456
505
//
457
506
//go:export readlink
458
- func readlink (path * byte , buf * byte , count uint ) int {
459
- return 0
507
+ func readlink (pathname * byte , buf * byte , count uint ) int {
508
+ path := goString (pathname )
509
+ dir , relPath := findPreopenForPath (path )
510
+
511
+ result := dir .ReadLinkAt (relPath )
512
+ if err := result .Err (); err != nil {
513
+ libcErrno = uintptr (errorCodeToErrno (* err ))
514
+ return - 1
515
+ }
516
+
517
+ s := * result .OK ()
518
+ size := uintptr (count )
519
+ if size > uintptr (len (s )) {
520
+ size = uintptr (len (s ))
521
+ }
522
+
523
+ memcpy (unsafe .Pointer (buf ), unsafe .Pointer (unsafe .StringData (s )), size )
524
+ return int (size )
460
525
}
461
526
462
527
// int unlink(const char *pathname);
463
528
//
464
529
//go:export unlink
465
530
func unlink (pathname * byte ) int32 {
531
+ path := goString (pathname )
532
+ dir , relPath := findPreopenForPath (path )
533
+
534
+ result := dir .UnlinkFileAt (relPath )
535
+ if err := result .Err (); err != nil {
536
+ libcErrno = uintptr (errorCodeToErrno (* err ))
537
+ return - 1
538
+ }
539
+
466
540
return 0
467
541
}
468
542
0 commit comments