網上有很多關于pos機通俗講解,快速了解虛擬文件系統的知識,也有很多人為大家解答關于pos機通俗講解的問題,今天pos機之家(m.51zrwd.com)為大家整理了關于這方面的知識,讓我們一起來看下吧!
本文目錄一覽:
1、pos機通俗講解
pos機通俗講解
前言為什么 Linux 內核的文件系統類型那么多,都能掛載上呢?為什么系統里可以直接 mount 其他文件系統呢?甚至能把 windows 下的文件夾掛載到 windows 上,為什么 Linux 的虛擬文件系統這么強大?這得益于它的數據結構設計得十分精妙。好像聽過,Linux 有什么解決不了的?加一層。
VFS 是什么虛擬文件系統,簡稱 VFS(Virtual Filesystem),是一個內核軟件層。
VFS 的作用概括地講,VFS 有兩個作用:
處理與 Unix 標準文件系統相關的所有系統調用為各種文件系統提供一個通用的接口VFS 支持的文件系統類型以下列出以下常見的文件系統類型,本文暫時不對其進行詳細分析。
磁盤文件系統ext2,ext3,···網絡文件系統類型nfs,smbfs,···特殊文件系統tmpfs,ramfs,···偽文件系統procfs,sysfs,···VFS 的設計思想VFS 設計的初衷就是要支持所有的文件系統,所以它的設計思想其實就是以面向對象的方式,設計一個通用的文件模型,出于效率考慮,VFS 還是 C 語言寫的。在通用文件系統模型中,每個目錄也被當作一個文件,可以包含若干文件和其他的子目錄。因此,Linux 有一句經典的話:一切皆文件。
關鍵數據結構介紹Linux VFS 抽象出 4 種類型的數據結構,實現將不同類型的文件系統掛載到目錄結構中。
超級塊對象對于磁盤類文件系統,超級塊是存放在磁盤上的文件系統控制塊,里面存放已安裝文件系統的有關信息,換句話說,一個超級塊描述了一個具體的文件系統信息,里面的信息十分重要,也叫元數據,與普通的文件數據相比,元數據丟失會損壞整個文件系統,導致無法掛載之類的問題。當然,不僅超級塊,inode上也有很多元數據。
struct super_block { struct list_heads_list; // 超級快鏈表指針 dev_t s_dev; // 設備表示符 unsigned chars_blocksize_bits; //以位為單位的塊的大小 unsigned longs_blocksize; //以字節為單位的塊大小 loff_t s_maxbytes;//文件大小的上限 struct file_system_type*s_type; //指向文件系統的file_system_type 數據結構的指針 const struct super_operations*s_op; //超級塊方法 const struct dquot_operations*dq_op; //磁盤限額方法 const struct quotactl_ops*s_qcop; //限額控制方法 const struct export_operations *s_export_op; //導出方法 unsigned longs_flags; //登錄標志 unsigned longs_magic; //文件系統的魔術字 struct dentry*s_root; //目錄登錄點 struct rw_semaphores_umount; //卸載信號量 ints_count; //超級塊引用計數 atomic_t s_active; //活動引用記數 #ifdef CONFIG_SECURITY void *s_security; //安全模塊 #endif const struct xattr_handler **s_xattr; struct list_head s_inodes;//把所有索引對象鏈接在一起,存放的是頭結點 struct hlist_bl_head s_anon;//匿名目錄項 struct list_head s_mounts;/* list of mounts; _not_ for fs use */ struct block_device*s_bdev; //相關的塊設備 struct backing_dev_info *s_bdi; struct mtd_info*s_mtd; struct hlist_nodes_instances; //該類型文件系統 unsigned ints_quota_types;/* Bitmask of supported quota types */ struct quota_infos_dquot;//限額相關選項 struct sb_writerss_writers; char s_id[32]; /* Informational name */ u8 s_uuid[16]; /* UUID */ void *s_fs_info; /* Filesystem private info */ unsigned int s_max_links; fmode_t s_mode; u32s_time_gran; struct mutex s_vfs_rename_mutex;/* Kludge */ char *s_subtype; char __rcu *s_options; const struct dentry_operations *s_d_op; /* default d_op for dentries */ int cleancache_poolid; struct shrinker s_shrink;/* per-sb shrinker handle */ atomic_long_t s_remove_count; int s_readonly_remount; struct workqueue_struct *s_dio_done_wq; struct hlist_head s_pins; struct list_lrus_dentry_lru ____cacheline_aligned_in_smp; struct list_lrus_inode_lru ____cacheline_aligned_in_smp; struct rcu_headrcu; int s_stack_depth;};索引節點對象(inode)
索引節點存放關于具體文件的一般信息。對于磁盤類文件系統,索引節點也是存放在磁盤上的文件控制塊。每個索引節點都有一個索引節點號,這個節點號唯一地標識了文件系統中的文件。
struct inode { umode_t i_mode; //訪問權限控制 unsigned short i_opflags; kuid_t i_uid; //使用者的id kgid_t i_gid; //使用組id unsigned int i_flags; //文件系統標志#ifdef CONFIG_FS_POSIX_ACL struct posix_acl *i_acl; struct posix_acl *i_default_acl;#endif const struct inode_operations*i_op; //指向索引結點操作結構體的指針 struct super_block *i_sb; //指向inode所屬文件系統的超級塊的指針 struct address_space *i_mapping; //相關的地址映射#ifdef CONFIG_SECURITY void *i_security; //安全模塊#endif unsigned longi_ino; //索引結點號。通過ls -i命令可以查看文件的索引節點號 union { const unsigned int i_nlink; //硬鏈接數 unsigned int __i_nlink; };dev_ti_rdev; //實際設備標識符號loff_t i_size; //以字節為單位struct timespec i_atime; //最后訪問時間struct timespec i_mtime; //最后修改時間struct timespec i_ctime; //最后改變時間spinlock_t i_lock;/* i_blocks, i_bytes, maybe i_size */unsigned short i_bytes; //使用的字節數unsigned int i_blkbits; 以位為單位的塊大小blkcnt_t i_blocks; //文件的塊數#ifdef __NEED_I_SIZE_ORDEREDseqcount_t i_size_seqcount;#endifunsigned long i_state; //狀態標志struct mutex i_mutex;unsigned long dirtied_when;//首次修改時間unsigned long dirtied_time_when;struct hlist_node i_hash; //散列表struct list_head i_wb_list;/* backing dev IO list */struct list_head i_lru;/* inode LRU list */struct list_head i_sb_list; //鏈接一個文件系統中所有inode的鏈表union { struct hlist_head i_dentry; //目錄項鏈表 struct rcu_head i_rcu;};u64 i_version; //版本號atomic_t i_count; //引用計數atomic_t i_dio_count;atomic_t i_writecount; //寫者計數#ifdef CONFIG_IMAatomic_t i_readcount; /* struct files open RO */#endifconst struct file_operations *i_fop;/* former ->i_op->default_file_ops */struct file_lock_context *i_flctx;struct address_space i_data; //設備地址映射struct list_head i_devices; //塊設備鏈表union { struct pipe_inode_info*i_pipe; //管道信息 struct block_device *i_bdev; //塊設備 struct cdev *i_cdev; //字符設備};__u32i_generation; //索引節點版本號#ifdef CONFIG_FSNOTIFY __u32i_fsnotify_mask; /* all events this inode cares about */ struct hlist_head i_fsnotify_marks;#endifvoid *i_private; /* fs or device private pointer */};目錄項對象(dentry)
存放 dentry 與對應文件鏈接的有關信息,每個 dentry 代表路徑中的一個特定部分,每個磁盤類文件系統以自己的方式將目錄項信息存放在磁盤上。
struct dentry { /* RCU lookup touched fields */unsigned int d_flags; /* protected by d_lock */seqcount_t d_seq; /* per dentry seqlock */struct hlist_bl_node d_hash; /* lookup hash list */struct dentry *d_parent; /* parent directory */struct qstr d_name;struct inode *d_inode; /* Where the name belongs to - NULL is negative */unsigned char d_iname[DNAME_INLINE_LEN]; /* small names *//* Ref lookup also touches following */struct lockref d_lockref;/* per-dentry lock and refcount */const struct dentry_operations *d_op;struct super_block *d_sb;/* The root of the dentry tree */unsigned long d_time; /* used by d_revalidate */void *d_fsdata;/* fs-specific data */struct list_head d_lru; /* LRU list */struct list_head d_child;/* child of parent list */struct list_head d_subdirs;/* our children *//* * d_alias and d_rcu can share memory */union { struct hlist_node d_alias; /* inode alias list */ struct rcu_head d_rcu;} d_u;};文件對象(file)
存放被打開文件與進程間交互的信息,這類信息僅當進程訪問文件期間存放在內存中。
struct file { union { struct llist_node fu_llist; //每個文件系統中被打開的文件都會形成一個雙鏈表 struct rcu_head fu_rcuhead; } f_u;struct path f_path;struct inode *f_inode;/* cached value */const struct file_operations *f_op; //指向文件操作表的指針spinlock_t f_lock;atomic_long_tf_count; //文件對象的使用計數unsigned int f_flags; //打開文件時所指定的標志fmode_tf_mode; //文件的訪問模式struct mutex f_pos_lock;loff_t f_pos; //文件當前的位移量struct fown_struct f_owner;const struct cred *f_cred;struct file_ra_statef_ra; //預讀狀態u64f_version; //版本號#ifdef CONFIG_SECURITY void *f_security; //安全模塊#endif/* needed for tty driver, and maybe others */void *private_data;#ifdef CONFIG_EPOLL /* Used by fs/eventpoll.c to link all the hooks to this file */ struct list_headf_ep_links; struct list_headf_tfile_llink;#endif /* #ifdef CONFIG_EPOLL */struct address_space*f_mapping; //頁緩存映射} __attribute__((aligned(4)));/* lest something weird decides that 2 is OK */struct file_handle {__u32 handle_bytes;int handle_type;/* file identifier */unsigned char f_handle[0];};數據結構組織關系圖
以上就是關于pos機通俗講解,快速了解虛擬文件系統的知識,后面我們會繼續為大家整理關于pos機通俗講解的知識,希望能夠幫助到大家!









