vfs_utils.g 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # This file is part of asmc, a bootstrapping OS with minimal seed
  2. # Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  3. # https://gitlab.com/giomasce/asmc
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. fun dump_file 1 {
  15. $name
  16. @name 0 param = ;
  17. $fd
  18. @fd name vfs_open = ;
  19. while 1 {
  20. $c
  21. @c fd vfs_read = ;
  22. if c 0xffffffff == {
  23. fd vfs_close ;
  24. ret ;
  25. }
  26. c 1 platform_write_char ;
  27. }
  28. }
  29. fun dump_hex_file 1 {
  30. $name
  31. @name 0 param = ;
  32. $fd
  33. @fd name vfs_open = ;
  34. while 1 {
  35. $c
  36. @c fd vfs_read = ;
  37. if c 0xffffffff == {
  38. fd vfs_close ;
  39. ret ;
  40. }
  41. c dump_byte ;
  42. }
  43. }
  44. fun dump_debug 1 {
  45. $name
  46. @name 0 param = ;
  47. "--DUMP-- " 1 platform_log ;
  48. name 1 platform_log ;
  49. "\n" 1 platform_log ;
  50. name dump_hex_file ;
  51. "\n--END_DUMP--\n" 1 platform_log ;
  52. }
  53. fun vfs_write_string 2 {
  54. $fd
  55. $s
  56. @fd 1 param = ;
  57. @s 0 param = ;
  58. while s **c 0 != {
  59. fd s **c vfs_write ;
  60. @s s 1 + = ;
  61. }
  62. }