Пример #1
0
 def access(self, path, mode):
     if mode & (os.R_OK | os.W_OK) == 0:
         return
     ctx = fuse.FuseGetContext()
     entry = self.perm_cache.get(ctx['uid'], path)
     if (mode & entry) != mode:
         return -errno.EACCES
Пример #2
0
    def getattr(self, path):
        sefs = file1()
        st = fuse.Stat()
        c = fuse.FuseGetContext()

        ret = sefs.search(path)
        print "Already present =", ret
        if ret is True:
            st.st_ino = int(sefs.getinode(path))
            st.st_uid, st.st_gid = (c['uid'], c['gid'])
            st.st_mode = sefs.getmode(path)
            st.st_nlink = sefs.getlinkcount(path)

            if sefs.getlength(path) is not None:
                st.st_size = int(sefs.getlength(path))
            else:
                st.st_size = 0

            tup = sefs.getutime(path)
            st.st_mtime = int(tup[0].strip().split('.')[0])
            st.st_ctime = int(tup[1].strip().split('.')[0])
            st.st_atime = int(tup[2].strip().split('.')[0])

            print "inode numder = %d" % st.st_ino

            return st
        else:
            return -errno.ENOENT
Пример #3
0
    def getattr(self, path):
        sefs = seFS()
        st = fuse.Stat()
        c = fuse.FuseGetContext()
        print c
        print "getattr called path= %s", path
        if path == '/':
            st.st_nlink = 2
            st.st_mode = stat.S_IFDIR | 0755
        else:
            print "For a regular file %s" % path
            st.st_mode = stat.S_IFREG | 0777
            st.st_nlink = 1

        st.st_uid, st.st_gid = (c['uid'], c['gid'])

        ret = sefs.search(path)
        print "From database getattr ret=", ret
        if ret is True:
            tup = sefs.getutime(path)
            print tup
            st.st_mtime = int(tup[0].strip().split('.')[0])
            st.st_ctime = int(tup[1].strip().split('.')[0])
            st.st_atime = int(tup[2].strip().split('.')[0])

            st.st_ino = int(sefs.getinode(path))
            print "inode = %d" % st.st_ino
            if sefs.getlength(path) is not None:
                st.st_size = int(sefs.getlength(path))
            else:
                st.st_size = 0
            return st
        else:
            return -errno.ENOENT
Пример #4
0
  def __insertNewNode(self, path, mode, size, dev=0, isSoftLink=False):
    """
    - To insert to new file/folder in metadata. Consists of three steps:
    - 1. Insert in inodes table.
    - 2. Insert in fileFolderNames table
    - 3. Link file/folder with parent by inserting in hierarchy table.
    - returns insertedInode and parent_inode
    """
    #self.__write_log("insertnewnode","called")
    parent, child = os.path.split(path)
    parent_hid, parent_inodeNum = self.__getHidAndInode(parent)
    if mode & stat.S_IFDIR:
      nlink = 2     #2 links '.' and '..' by default for folder
    else:
      nlink = 1     #1 link by default for other file types

    t = time.time()
    context = fuse.FuseGetContext()

    query = 'INSERT INTO inodes (nlink, mode, uid, gid, dev, size, atime, mtime, ctime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'
    self.conn.execute(query, (nlink, mode, context['uid'], context['gid'], dev, size, t, t, t))
    insertedInodeNum = self.conn.execute('SELECT last_insert_rowid() as a').fetchone()[0]
    insertedFnameId = self.__GetFnameIdFromName(child)

    query = 'INSERT INTO hierarchy (parenthid, fnameId, inodeNum) VALUES (?, ?, ?)'
    self.conn.execute(query, (parent_hid, insertedFnameId, insertedInodeNum,))

    #if new file is created then insert record in logs table for lazy deduplication to pickup.
    #if nlink == 1 and not isSoftLink:
    #  query = 'INSERT INTO logs(inodeNum, path) VALUES (?, ?)'
    #  self.conn.execute(query, (insertedInodeNum, sqlite3.Binary(path),))
    #self.__write_log("insertnewnode","ended")
    return insertedInodeNum, parent_inodeNum
Пример #5
0
    def getattr(self, path):
        debug('vfs getattr', path)
        virtual_file = self.get_file(path)
        debug('vfs getattr', virtual_file)

        if virtual_file == None:
            return E_NO_SUCH_FILE

        result = fuse.Stat()

        if virtual_file.is_read_only():
            result.st_mode = stat.S_IFREG | 0444
        else:
            result.st_mode = stat.S_IFREG | 0644

        # Always 1 for now (seems to be safe for files and dirs)
        result.st_nlink = 1

        result.st_size = virtual_file.size()

        # Must return seconds-since-epoch timestamps
        result.st_atime = virtual_file.atime()
        result.st_mtime = virtual_file.mtime()
        result.st_ctime = virtual_file.ctime()

        # You can set these to anything, they're set by FUSE
        result.st_dev = 1
        result.st_ino = 1

        # GetContext() returns uid/gid of the process that
        # initiated the syscall currently being handled
        context = fuse.FuseGetContext()
        if virtual_file.uid() == None:
            result.st_uid = context['uid']
        else:
            result.st_uid = virtual_file.uid()

        if virtual_file.gid() == None:
            result.st_gid = context['gid']
        else:
            result.st_gid = virtual_file.gid()

        return result
Пример #6
0
def fake_stat(virtual_file):
    """Create fuse stat from file."""
    if virtual_file is None:
        return E_NO_SUCH_FILE

    result = fuse.Stat()

    if virtual_file.is_read_only():
        result.st_mode = stat.S_IFREG | 0o444
    else:
        result.st_mode = stat.S_IFREG | 0o644

    # Always 1 for now (seems to be safe for files and dirs)
    result.st_nlink = 1

    result.st_size = virtual_file.size()

    # Must return seconds-since-epoch timestamps
    result.st_atime = virtual_file.atime()
    result.st_mtime = virtual_file.mtime()
    result.st_ctime = virtual_file.ctime()

    # You can set these to anything, they're set by FUSE
    result.st_dev = 1
    result.st_ino = 1

    # GetContext() returns uid/gid of the process that
    # initiated the syscall currently being handled
    context = fuse.FuseGetContext()
    if virtual_file.uid() is None:
        result.st_uid = context['uid']
    else:
        result.st_uid = virtual_file.uid()

    if virtual_file.gid() is None:
        result.st_gid = context['gid']
    else:
        result.st_gid = virtual_file.gid()

    return result
Пример #7
0
  def __checkAccessInMetaData(self, inodeNum, flags):
    """
    Check if the access stored in metadata for this user is consistent with flags
    """
    #self.__write_log("CheckAccessInMetadata","called")
    #get uid and gid from fuse method
    context = fuse.FuseGetContext()
    #get values stored in database.
    query = 'SELECT mode, uid, gid FROM inodes WHERE inodeNum = ?'
    result = self.conn.execute(query, (inodeNum,)).fetchone();

    o = context['uid'] == result['uid']    #check if owner
    g = context['gid'] == result['gid'] and not o   #check if same group but not owner
    w = not (o or g)    #implies neither owner nor beloging to same group
    m = result['mode']
    #self.__write_log("o="+str(o) + " g="+str(g) + " w="+str(w) + " m="+str(m),"called")

    output = (not (flags & os.R_OK) or ((o and (m & 0400)) or (g and (m & 0040)) or (w and (m & 0004)))) \
         and (not (flags & os.W_OK) or ((o and (m & 0200)) or (g and (m & 0020)) or (w and (m & 0002)))) \
         and (not (flags & os.X_OK) or ((o and (m & 0100)) or (g and (m & 0010)) or (w and (m & 0001))))

    #self.__write_log("checkAccessinMetadata","ended with output:" + str(output))
    return output
Пример #8
0
 def _pid(self):
     return fuse.FuseGetContext()['pid']
Пример #9
0
 def _gid(self):
     return fuse.FuseGetContext()['gid']
Пример #10
0
 def _uid(self):
     return fuse.FuseGetContext()['uid']