fusetest.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. {
  2. Test for FUSE Freepascal bindings.
  3. Copyright (C) 2008 Danny Milosavljevic <[email protected]>
  4. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  5. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  7. }
  8. {$MODE OBJFPC}{$H+} // octal
  9. uses BaseUNIX, Strings, FUSE;
  10. const
  11. hello_path : String = '/hello';
  12. hello_str : String = 'Hello World!'#10;
  13. function hello_getattr(const aNameC : PChar;var aStat : tStat) : cint; cdecl;
  14. var
  15. aName : String;
  16. begin
  17. Result := 0;
  18. aName := aNameC;
  19. FillChar(aStat, Sizeof(TStat), 0);
  20. if (aName = '/') then begin
  21. aSTAT.st_mode := S_IFDIR or &0755; // 0755;
  22. aSTAT.st_nlink := 2;
  23. end else if aName = hello_path then begin
  24. aSTAT.st_mode := S_IFREG or &0444; // 0444;
  25. aSTAT.st_nlink := 1;
  26. aSTAT.st_size := Length(hello_str);
  27. end else
  28. Result := -ESysENOENT;
  29. end;
  30. var
  31. xx : PChar = 'hello';
  32. function hello_readdir(const ANameC : PChar; aBuffer : Pointer; filler : TFUseFillDir; aFileOffset : off_t; aFileInfo : PFuseFileInfo) : Integer; cdecl;
  33. begin
  34. if (aNameC[0] <> '/') or (aNameC[1] <> #0) then
  35. Result := -ESysENOENT
  36. else begin
  37. filler(aBuffer, '.', nil, 0);
  38. filler(aBuffer, '..', nil, 0);
  39. filler(aBuffer, xx, nil, 0); // PChar(hello_path) + 1, nil, 0);
  40. Result := 0;
  41. end;
  42. end;
  43. function hello_open(const aNameC : PChar; aFileInfo : PFuseFileInfo) : cint; cdecl;
  44. var
  45. aName : String;
  46. begin
  47. aName := aNameC;
  48. if aName <> hello_path then
  49. Result := -ESysENOENT
  50. else begin
  51. if ((aFileInfo^.flags and 3) <> O_RDONLY) then
  52. Result := -ESysEACCES
  53. else
  54. Result := 0;
  55. end;
  56. end;
  57. function hello_read(const aNameC : PChar; aBuffer : Pointer; aBufferSize : size_t; aFileOffset : off_t; aFileInfo : PFuseFileInfo) : Integer; cdecl;
  58. var
  59. len : size_t;
  60. aName : String;
  61. begin
  62. aName := aNameC;
  63. if aName <> hello_path then
  64. Result := -ESysENOENT
  65. else begin
  66. len := Length(hello_str);
  67. if (aFileOffset < len) then begin
  68. if (aFileOffset + aBufferSize > len) then
  69. aBufferSize := len - aFileOffset;
  70. move((PChar(hello_str) + aFileOffset)^,ABuffer^, aBufferSize);
  71. end else
  72. aBufferSize := 0;
  73. Result := aBufferSize;
  74. end;
  75. end;
  76. var
  77. hello_oper : TFuseOperations = (
  78. getattr : @hello_getattr;
  79. readlink : nil;
  80. getdir : nil;
  81. mknod : nil;
  82. mkdir : nil;
  83. unlink : nil;
  84. rmdir : nil;
  85. symlink : nil;
  86. rename : nil;
  87. link : nil;
  88. chmod : nil;
  89. chown : nil;
  90. truncate : nil;
  91. utime : nil;
  92. open : @hello_open;
  93. read : @hello_read;
  94. write : nil;
  95. statfs : nil;
  96. flush : nil;
  97. release : nil;
  98. fsync : nil;
  99. setxattr : nil;
  100. getxattr : nil;
  101. listxattr : nil;
  102. removexattr : nil;
  103. opendir : nil;
  104. readdir : @hello_readdir;
  105. releasedir : nil;
  106. fsyncdir : nil;
  107. init : nil;
  108. destroy : nil;
  109. access : nil;
  110. create : nil;
  111. ftruncate : nil;
  112. fgetattr : nil;
  113. lock : nil;
  114. utimens : nil;
  115. bmap : nil;
  116. );
  117. begin
  118. Halt(fuse_main(argc, argv, @hello_oper, Sizeof(hello_oper), nil));
  119. end.