Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * \author ...
- */
- #include "syscalls.h"
- #include "syscalls.bin.h"
- #include "../../dealers/itdealer/itdealer.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <inttypes.h>
- #include <stdbool.h>
- #include <errno.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/statvfs.h>
- #include <sys/stat.h>
- #include <time.h>
- #include <utime.h>
- #include <libgen.h>
- #include <string.h>
- #include "direntry.h"
- #include "probing.h"
- #include "exception.h"
- #include "datatypes.h"
- #include "../ilayers/direntries/direntries.h"
- #include "../ilayers/fileclusters/fileclusters.h"
- /*
- * \brief Read a directory entry from a directory.
- *
- * It tries to emulate <em>getdents</em> system call, but it reads a single directory entry at a time.
- *
- * Only the field <em>name</em> is read.
- *
- * \remark The returned value is the number of bytes read from the directory in order to get the next in use
- * directory entry.
- * The point is that the system (through FUSE) uses the returned value to update file position.
- *
- * \param path path to the file
- * \param buff pointer to the buffer where data to be read is to be stored
- * \param pos starting [byte] position in the file data continuum where data is to be read from
- *
- * \return 0 on success;
- * -errno in case of error, being errno the system error that better represents the cause of failure
- */
- int soReaddir(const char *path, void *buff, int32_t pos)
- {
- soProbe(234, "soReaddir(\"%s\", %p, %u)\n", path, buff, pos);
- try
- {
- uint32_t inodeNumber, var;
- SODirEntry dir[DirentriesPerCluster];
- char *pathdup = strdup(path);
- inodeNumber = soTraversePath(pathdup);
- uint32_t nodeHandler = iOpen(inodeNumber);
- SOInode *Node = iGetPointer(nodeHandler);
- if(!S_ISDIR(Node->mode))
- {
- iClose(nodeHandler);
- throw SOException(ENOTDIR, __FUNCTION__);
- }
- var = pos/sizeof(SODirEntry);
- soReadFileCluster(nodeHandler,var/DirentriesPerCluster,dir);
- iClose(nodeHandler);
- memcpy(buff, dir[var%DirentriesPerCluster].name,sizeof(dir[var%DirentriesPerCluster].name));
- if(strcmp("\0",dir[var%DirentriesPerCluster].name)==0) return 0;
- return(sizeof(SODirEntry));
- }
- catch(SOException & err)
- {
- return -err.en;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement