日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

fuse的API修改

發(fā)布時間:2024/4/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 fuse的API修改 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

fuse的API修改

這里的fuse API基于python進行修改fuse的安裝請參照fuse的安裝博客

?

在你掛載的目錄下你進行的操作才會調(diào)用到的FUSE的文件系統(tǒng),例如,你將/usr 掛載到了/opt/fuse下面,當你進入/opt/fuse下以后你使用的指令才是你寫的文件系統(tǒng)的指令

這些指令不光是由一個fuse的函數(shù)執(zhí)行而是由多個函數(shù)共同實現(xiàn)的

如:cd 操作調(diào)用到的函數(shù)由

_full_path

getattr

access

_full_path函數(shù)返回當前文件的原本路徑

getattr函數(shù)事項文件屬性的獲取

access函數(shù)實現(xiàn)當前徑的轉(zhuǎn)換

所以必須修改這兩個函數(shù)才能實現(xiàn)cd操作

修改API大多調(diào)用python中的os,os.path庫函數(shù),大家可以試著去看一看這些庫函數(shù)

如_full_path函數(shù)

def _full_path(self, partial):

? ? ? ? if partial.startswith("/"):

? ? ? ? ? ? partial = partial[1:]

? ? ? ? path = os.path.join(self.root, partial)

?

? ? ? ? return path

如getattr修改代碼:

? ? def getattr(self, path, fh=None):

? ? ? ? full_path = self._full_path(path)

? ? ? ? st = os.lstat(full_path)

? ? ? ? return dict((key, getattr(st, key)) for key in ('st_atime', 'st_ctime',

?

? ? ? ? ? ? ? ? ? ? ?'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid'))

?

如access代碼:

? ? def access(self, path, mode):

? ? ? ? full_path = self._full_path(path)

? ? ? ? if not os.access(full_path, mode):

?

? ? ? ? ? ? raise FuseOSError(errno.EACCES)

以下提供以下指令調(diào)用函數(shù)的順序

---掛載

_init_

?

---cd

?

---getattr

_full_path

access

?

_full_path

?

---ls

readdir

_full_path

getattr

_full_path

readline

_full_path

?

getattr

?

---mkdir

?

getattr

_full_path

mkdir

_full_path

getattr

?

_full_path

?

---rm

?

getattr

_full_path

getattr

_full_path

readdir

_full_path

rmdir

?

_full_path

?

---tab(鍵)

readdir

_full_path

getattr

?

_full_path

?

---cat

?

getattr

_full_path

open

_full_path

read

getattr

_full_path

flush

release

?

?

附帶一個可運行的fuse

#!/usr/bin/env python

?

from __future__ import with_statement

?

import os

import sys

import errno

?

from fuse import FUSE, FuseOSError, Operations

?

class Passthrough(Operations):

?

def __init__(self, root):

? ? ? ? self.root = root

?

? ?def _full_path(self, partial):

? ? ? ? if partial.startswith("/"):

? ? ? ? ? ? partial = partial[1:]

? ? ? ? path = os.path.join(self.root, partial)

? ? ? ? return path

?

? ? def access(self, path, mode):

? ? ? ? full_path = self._full_path(path)

? ? ? ? if not os.access(full_path, mode):

? ? ? ? ? ? raise FuseOSError(errno.EACCES)

?

? ? def getattr(self, path, fh=None):

? ? ? ? full_path = self._full_path(path)

? ? ? ? st = os.lstat(full_path)

? ? ? ? return dict((key, getattr(st, key)) for key in ('st_atime', 'st_ctime',

? ? ? ? ? ? ? ? ? ? ?'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid'))

?

? ?def readdir(self, path, fh):

? ? ? ? full_path = self._full_path(path)

?

? ? ? ? dirents = ['.', '..']

? ? ? ? if os.path.isdir(full_path):

? ? ? ? ? ? dirents.extend(os.listdir(full_path))

? ? ? ? for r in dirents:

? ? ? ? ? ? yield r

?

def main(mountpoint, root):

? ? FUSE(Passthrough(root), mountpoint, foreground=True)

?

if __name__ == '__main__':

?

? ? main(sys.argv[2], sys.argv[1])

總結(jié)

以上是生活随笔為你收集整理的fuse的API修改的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。