Linux目录结构:
根目录"/"
/bin 可执行文件目录
/boot 内核引导文件:vmlinuz,initrd.img等
/dev 设备文件存储目录,应用程序对这些文件读写和控制可访问实际设备
/etc 系统配置和一些服务器配置文件的位置,如帐号及密码配置文件。
/home 普通用户目录
/lib 库文件目录
/lost+found Ext2,Ext3文件系统中当系统意外崩溃或意外关机时产生的文件碎片位置
/mnt 存放挂载的存储设备目录,如cdrom,/etc/fstab中有相关定义
/opt 某些软件包被安装在这里,用户自己编译的软件包也可安装在此。
/root Linux超级权限用户root的home目录
/sbin 存放可执行文件,大多为系统管理命令,是root用户可执行命令存放地,它与/usr/sbin , usr/local/sbin相似。
/tmp 用户运程程序产生的临时文件存放处
/usr 系统存放程序的目录,如命令,帮助文档,Linux发行版提供的软件包大多被安装在这里。
/var 此目录内容经常变动,如/var/log用来存储系统日志。
/sys 内核所支持的sysfs文件系统被映射在此。总线,驱动和设备都可在sysfs文件系统中找到对应节点,当内核检测到新设备,内核会在 sysfs文件系统中为该新设备生成一项新的记录。
/initrd 若启动时使用了initrd映像作为临时根文件系统,则在执行完其上的/linuxrc挂接真正的根文件系统后,原来初始RAM文件系统被映射到此。
Linux中虚拟文件系统、磁盘文件及一般设备文件与设备驱动关系.
应用程序->VFS->(特殊文件|磁盘文件|设备文件)
磁盘文件->磁盘驱动->磁盘
设备文件->其他设备驱动->其他设备
对于块存储设备,ext2,fat,jffs2等会实现针对VFS的file_operations成员函数,设备驱动层将看不到file_operations的存在,设备驱动重要的结构体 file,inode.
struct file {
/*
* fu_list becomes invalid after file_free is called and queued via
* fu_rcuhead for RCU freeing
*/
union {
struct list_head fu_list;
struct rcu_head fu_rcuhead;
} f_u;
struct path f_path;
#define f_dentry f_path.dentry
#define f_vfsmnt f_path.mnt
const struct file_operations *f_op;
atomic_long_t f_count;
unsigned int f_flags;
fmode_t f_mode;
loff_t f_pos;
struct fown_struct f_owner;
const struct cred *f_cred;
struct file_ra_state f_ra;
u64 f_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_head f_ep_links;
spinlock_t f_ep_lock;
#endif /* #ifdef CONFIG_EPOLL */
struct address_space *f_mapping;
#ifdef CONFIG_DEBUG_WRITECOUNT
unsigned long f_mnt_write_state;
#endif
};
struct inode {
struct hlist_node i_hash;
struct list_head i_list;
struct list_head i_sb_list;
struct list_head i_dentry;
unsigned long i_ino;
atomic_t i_count;
unsigned int i_nlink;
uid_t i_uid;
gid_t i_gid;
dev_t i_rdev;
u64 i_version;
loff_t i_size;
#ifdef __NEED_I_SIZE_ORDERED
seqcount_t i_size_seqcount;
#endif
struct timespec i_atime;
struct timespec i_mtime;
struct timespec i_ctime;
unsigned int i_blkbits;
blkcnt_t i_blocks;
unsigned short i_bytes;
umode_t i_mode;
spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
struct mutex i_mutex;
struct rw_semaphore i_alloc_sem;
const struct inode_operations *i_op;
const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
struct super_block *i_sb;
struct file_lock *i_flock;
struct address_space *i_mapping;
struct address_space i_data;
#ifdef CONFIG_QUOTA
struct dquot *i_dquot[MAXQUOTAS];
#endif
struct list_head i_devices;
union {
struct pipe_inode_info *i_pipe;
struct block_device *i_bdev;
struct cdev *i_cdev;
};
int i_cindex;
__u32 i_generation;
#ifdef CONFIG_DNOTIFY
unsigned long i_dnotify_mask; /* Directory notify events */
struct dnotify_struct *i_dnotify; /* for directory notifications */
#endif
#ifdef CONFIG_INOTIFY
struct list_head inotify_watches; /* watches on this inode */
struct mutex inotify_mutex; /* protects the watches list */
#endif
unsigned long i_state;
unsigned long dirtied_when; /* jiffies of first dirtying */
unsigned int i_flags;
atomic_t i_writecount;
#ifdef CONFIG_SECURITY
void *i_security;
#endif
void *i_private; /* fs or device private pointer */
};