pos機(jī)通俗講解

 新聞資訊2  |   2023-07-14 11:32  |  投稿人:pos機(jī)之家

網(wǎng)上有很多關(guān)于pos機(jī)通俗講解,快速了解虛擬文件系統(tǒng)的知識(shí),也有很多人為大家解答關(guān)于pos機(jī)通俗講解的問(wèn)題,今天pos機(jī)之家(www.www690aa.com)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來(lái)看下吧!

本文目錄一覽:

1、pos機(jī)通俗講解

pos機(jī)通俗講解

前言

為什么 Linux 內(nèi)核的文件系統(tǒng)類型那么多,都能掛載上呢?為什么系統(tǒng)里可以直接 mount 其他文件系統(tǒng)呢?甚至能把 windows 下的文件夾掛載到 windows 上,為什么 Linux 的虛擬文件系統(tǒng)這么強(qiáng)大?這得益于它的數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì)得十分精妙。好像聽(tīng)過(guò),Linux 有什么解決不了的?加一層。

VFS 是什么

虛擬文件系統(tǒng),簡(jiǎn)稱 VFS(Virtual Filesystem),是一個(gè)內(nèi)核軟件層。

VFS 的作用

概括地講,VFS 有兩個(gè)作用:

處理與 Unix 標(biāo)準(zhǔn)文件系統(tǒng)相關(guān)的所有系統(tǒng)調(diào)用為各種文件系統(tǒng)提供一個(gè)通用的接口VFS 支持的文件系統(tǒng)類型

以下列出以下常見(jiàn)的文件系統(tǒng)類型,本文暫時(shí)不對(duì)其進(jìn)行詳細(xì)分析。

磁盤文件系統(tǒng)ext2,ext3,···網(wǎng)絡(luò)文件系統(tǒng)類型nfs,smbfs,···特殊文件系統(tǒng)tmpfs,ramfs,···偽文件系統(tǒng)procfs,sysfs,···VFS 的設(shè)計(jì)思想

VFS 設(shè)計(jì)的初衷就是要支持所有的文件系統(tǒng),所以它的設(shè)計(jì)思想其實(shí)就是以面向?qū)ο蟮姆绞剑O(shè)計(jì)一個(gè)通用的文件模型,出于效率考慮,VFS 還是 C 語(yǔ)言寫(xiě)的。在通用文件系統(tǒng)模型中,每個(gè)目錄也被當(dāng)作一個(gè)文件,可以包含若干文件和其他的子目錄。因此,Linux 有一句經(jīng)典的話:一切皆文件。

關(guān)鍵數(shù)據(jù)結(jié)構(gòu)介紹

Linux VFS 抽象出 4 種類型的數(shù)據(jù)結(jié)構(gòu),實(shí)現(xiàn)將不同類型的文件系統(tǒng)掛載到目錄結(jié)構(gòu)中。

超級(jí)塊對(duì)象

對(duì)于磁盤類文件系統(tǒng),超級(jí)塊是存放在磁盤上的文件系統(tǒng)控制塊,里面存放已安裝文件系統(tǒng)的有關(guān)信息,換句話說(shuō),一個(gè)超級(jí)塊描述了一個(gè)具體的文件系統(tǒng)信息,里面的信息十分重要,也叫元數(shù)據(jù),與普通的文件數(shù)據(jù)相比,元數(shù)據(jù)丟失會(huì)損壞整個(gè)文件系統(tǒng),導(dǎo)致無(wú)法掛載之類的問(wèn)題。當(dāng)然,不僅超級(jí)塊,inode上也有很多元數(shù)據(jù)。

struct super_block { struct list_heads_list; // 超級(jí)快鏈表指針 dev_t s_dev; // 設(shè)備表示符 unsigned chars_blocksize_bits; //以位為單位的塊的大小 unsigned longs_blocksize; //以字節(jié)為單位的塊大小 loff_t s_maxbytes;//文件大小的上限 struct file_system_type*s_type; //指向文件系統(tǒng)的file_system_type 數(shù)據(jù)結(jié)構(gòu)的指針 const struct super_operations*s_op; //超級(jí)塊方法 const struct dquot_operations*dq_op; //磁盤限額方法 const struct quotactl_ops*s_qcop; //限額控制方法 const struct export_operations *s_export_op; //導(dǎo)出方法 unsigned longs_flags; //登錄標(biāo)志 unsigned longs_magic; //文件系統(tǒng)的魔術(shù)字 struct dentry*s_root; //目錄登錄點(diǎn) struct rw_semaphores_umount; //卸載信號(hào)量 ints_count; //超級(jí)塊引用計(jì)數(shù) atomic_t s_active; //活動(dòng)引用記數(shù) #ifdef CONFIG_SECURITY void *s_security; //安全模塊 #endif const struct xattr_handler **s_xattr; struct list_head s_inodes;//把所有索引對(duì)象鏈接在一起,存放的是頭結(jié)點(diǎn) struct hlist_bl_head s_anon;//匿名目錄項(xiàng) struct list_head s_mounts;/* list of mounts; _not_ for fs use */ struct block_device*s_bdev; //相關(guān)的塊設(shè)備 struct backing_dev_info *s_bdi; struct mtd_info*s_mtd; struct hlist_nodes_instances; //該類型文件系統(tǒng) unsigned ints_quota_types;/* Bitmask of supported quota types */ struct quota_infos_dquot;//限額相關(guān)選項(xiàng) 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;};索引節(jié)點(diǎn)對(duì)象(inode)

索引節(jié)點(diǎn)存放關(guān)于具體文件的一般信息。對(duì)于磁盤類文件系統(tǒng),索引節(jié)點(diǎn)也是存放在磁盤上的文件控制塊。每個(gè)索引節(jié)點(diǎn)都有一個(gè)索引節(jié)點(diǎn)號(hào),這個(gè)節(jié)點(diǎn)號(hào)唯一地標(biāo)識(shí)了文件系統(tǒng)中的文件。

struct inode { umode_t i_mode; //訪問(wèn)權(quán)限控制 unsigned short i_opflags; kuid_t i_uid; //使用者的id kgid_t i_gid; //使用組id unsigned int i_flags; //文件系統(tǒng)標(biāo)志#ifdef CONFIG_FS_POSIX_ACL struct posix_acl *i_acl; struct posix_acl *i_default_acl;#endif const struct inode_operations*i_op; //指向索引結(jié)點(diǎn)操作結(jié)構(gòu)體的指針 struct super_block *i_sb; //指向inode所屬文件系統(tǒng)的超級(jí)塊的指針 struct address_space *i_mapping; //相關(guān)的地址映射#ifdef CONFIG_SECURITY void *i_security; //安全模塊#endif unsigned longi_ino; //索引結(jié)點(diǎn)號(hào)。通過(guò)ls -i命令可以查看文件的索引節(jié)點(diǎn)號(hào) union { const unsigned int i_nlink; //硬鏈接數(shù) unsigned int __i_nlink; };dev_ti_rdev; //實(shí)際設(shè)備標(biāo)識(shí)符號(hào)loff_t i_size; //以字節(jié)為單位struct timespec i_atime; //最后訪問(wèn)時(shí)間struct timespec i_mtime; //最后修改時(shí)間struct timespec i_ctime; //最后改變時(shí)間spinlock_t i_lock;/* i_blocks, i_bytes, maybe i_size */unsigned short i_bytes; //使用的字節(jié)數(shù)unsigned int i_blkbits; 以位為單位的塊大小blkcnt_t i_blocks; //文件的塊數(shù)#ifdef __NEED_I_SIZE_ORDEREDseqcount_t i_size_seqcount;#endifunsigned long i_state; //狀態(tài)標(biāo)志struct mutex i_mutex;unsigned long dirtied_when;//首次修改時(shí)間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; //鏈接一個(gè)文件系統(tǒng)中所有inode的鏈表union { struct hlist_head i_dentry; //目錄項(xiàng)鏈表 struct rcu_head i_rcu;};u64 i_version; //版本號(hào)atomic_t i_count; //引用計(jì)數(shù)atomic_t i_dio_count;atomic_t i_writecount; //寫(xiě)者計(jì)數(shù)#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; //設(shè)備地址映射struct list_head i_devices; //塊設(shè)備鏈表union { struct pipe_inode_info*i_pipe; //管道信息 struct block_device *i_bdev; //塊設(shè)備 struct cdev *i_cdev; //字符設(shè)備};__u32i_generation; //索引節(jié)點(diǎn)版本號(hào)#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 */};目錄項(xiàng)對(duì)象(dentry)

存放 dentry 與對(duì)應(yīng)文件鏈接的有關(guān)信息,每個(gè) dentry 代表路徑中的一個(gè)特定部分,每個(gè)磁盤類文件系統(tǒng)以自己的方式將目錄項(xiàng)信息存放在磁盤上。

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;};文件對(duì)象(file)

存放被打開(kāi)文件與進(jìn)程間交互的信息,這類信息僅當(dāng)進(jìn)程訪問(wèn)文件期間存放在內(nèi)存中。

struct file { union { struct llist_node fu_llist; //每個(gè)文件系統(tǒng)中被打開(kāi)的文件都會(huì)形成一個(gè)雙鏈表 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; //文件對(duì)象的使用計(jì)數(shù)unsigned int f_flags; //打開(kāi)文件時(shí)所指定的標(biāo)志fmode_tf_mode; //文件的訪問(wèn)模式struct mutex f_pos_lock;loff_t f_pos; //文件當(dāng)前的位移量struct fown_struct f_owner;const struct cred *f_cred;struct file_ra_statef_ra; //預(yù)讀狀態(tài)u64f_version; //版本號(hào)#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; //頁(yè)緩存映射} __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];};數(shù)據(jù)結(jié)構(gòu)組織關(guān)系圖

以上就是關(guān)于pos機(jī)通俗講解,快速了解虛擬文件系統(tǒng)的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于pos機(jī)通俗講解的知識(shí),希望能夠幫助到大家!

轉(zhuǎn)發(fā)請(qǐng)帶上網(wǎng)址:http://www.www690aa.com/newsone/84539.html

你可能會(huì)喜歡:

版權(quán)聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn),該文觀點(diǎn)僅代表作者本人。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權(quán)/違法違規(guī)的內(nèi)容, 請(qǐng)發(fā)送郵件至 babsan@163.com 舉報(bào),一經(jīng)查實(shí),本站將立刻刪除。