Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. /*
  2. * \author ...
  3. */
  4.  
  5. #include "syscalls.h"
  6. #include "syscalls.bin.h"
  7. #include "../../dealers/itdealer/itdealer.h"
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <inttypes.h>
  11. #include <stdbool.h>
  12. #include <errno.h>
  13. #include <unistd.h>
  14. #include <fcntl.h>
  15. #include <sys/types.h>
  16. #include <sys/statvfs.h>
  17. #include <sys/stat.h>
  18. #include <time.h>
  19. #include <utime.h>
  20. #include <libgen.h>
  21. #include <string.h>
  22. #include "direntry.h"
  23. #include "probing.h"
  24. #include "exception.h"
  25. #include "datatypes.h"
  26. #include "../ilayers/direntries/direntries.h"
  27. #include "../ilayers/fileclusters/fileclusters.h"
  28.  
  29. /*
  30. * \brief Read a directory entry from a directory.
  31. *
  32. * It tries to emulate <em>getdents</em> system call, but it reads a single directory entry at a time.
  33. *
  34. * Only the field <em>name</em> is read.
  35. *
  36. * \remark The returned value is the number of bytes read from the directory in order to get the next in use
  37. * directory entry.
  38. * The point is that the system (through FUSE) uses the returned value to update file position.
  39. *
  40. * \param path path to the file
  41. * \param buff pointer to the buffer where data to be read is to be stored
  42. * \param pos starting [byte] position in the file data continuum where data is to be read from
  43. *
  44. * \return 0 on success;
  45. * -errno in case of error, being errno the system error that better represents the cause of failure
  46. */
  47. int soReaddir(const char *path, void *buff, int32_t pos)
  48. {
  49. soProbe(234, "soReaddir(\"%s\", %p, %u)\n", path, buff, pos);
  50.  
  51. try
  52. {
  53. uint32_t inodeNumber, var;
  54. SODirEntry dir[DirentriesPerCluster];
  55. char *pathdup = strdup(path);
  56. inodeNumber = soTraversePath(pathdup);
  57. uint32_t nodeHandler = iOpen(inodeNumber);
  58. SOInode *Node = iGetPointer(nodeHandler);
  59.  
  60. if(!S_ISDIR(Node->mode))
  61. {
  62. iClose(nodeHandler);
  63. throw SOException(ENOTDIR, __FUNCTION__);
  64. }
  65. var = pos/sizeof(SODirEntry);
  66. soReadFileCluster(nodeHandler,var/DirentriesPerCluster,dir);
  67.  
  68. iClose(nodeHandler);
  69. memcpy(buff, dir[var%DirentriesPerCluster].name,sizeof(dir[var%DirentriesPerCluster].name));
  70. if(strcmp("\0",dir[var%DirentriesPerCluster].name)==0) return 0;
  71. return(sizeof(SODirEntry));
  72.  
  73. }
  74. catch(SOException & err)
  75. {
  76. return -err.en;
  77. }
  78.  
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement