⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fs_tree.c

📁 WiiFuse is a FUSE filesystem module for Linux and Mac OS X. It will let you mount a Wii disc ISO an
💻 C
字号:
/* *  Copyright (C) 2008 dhewg, #wiidev efnet *    based on code by: *  Copyright (C) 2006 Mike Melanson (mike at multimedia.cx) * *  this file is part of wiifuse *  http://wiibrew.org/index.php?title=Wiifuse * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <sys/types.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <errno.h>#include "global.h"#include "io.h"#include "tree.h"#include "fs_tree.h"int fs_tree_getattr (const char *path, struct stat *stbuf) {        struct image_file *image = (struct image_file *)                                   fuse_get_context ()->private_data;        struct tree *node;        node = tree_find_entry (image->tree, path);        if (!node)                return -ENOENT;        memset (stbuf, 0, sizeof (struct stat));        switch (node->type) {        case TREE_DIR:                stbuf->st_mode = S_IFDIR |                                 S_IRUSR | S_IRGRP | S_IROTH |                                 S_IXUSR | S_IXGRP | S_IXOTH;                stbuf->st_nlink = 2 + node->nsubdirs;                break;        case TREE_RAW_FILE:        case TREE_FILE:        case TREE_MEM:        case TREE_UINT:        case TREE_HEX_UINT8:        case TREE_HEX_UINT16:        case TREE_HEX_UINT32:        case TREE_HEX_UINT64:        case TREE_CHAR:        case TREE_STRING:                stbuf->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;                stbuf->st_nlink = 1;                stbuf->st_size = node->v2;                stbuf->st_blocks = node->v2 / 512;                break;        case TREE_SYMLINK:                stbuf->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;                stbuf->st_nlink = 1;                stbuf->st_size = node->v2;                break;        }        stbuf->st_uid = image->st.st_uid;        stbuf->st_gid = image->st.st_gid;        stbuf->st_atime = image->st.st_atime;        stbuf->st_mtime = image->st.st_mtime;        stbuf->st_ctime = image->st.st_ctime;        return 0;}int fs_tree_open (const char *path, struct fuse_file_info *fi) {        struct image_file *image = (struct image_file *)                                   fuse_get_context ()->private_data;        struct tree *node;        if (fi->flags & O_WRONLY)                return -EROFS;        node = tree_find_entry (image->tree, path);        if (!node)                return -ENOENT;        return 0;}int fs_tree_read (const char *path, char *buf, size_t size,                  off_t offset, struct fuse_file_info *fi) {        struct image_file *image = (struct image_file *)                                   fuse_get_context ()->private_data;        struct tree *node;        u64 pos;        int ret = 0;        (void) fi;        node = tree_find_entry (image->tree, path);        if (!node)                return -ENOENT;        if (node->type == TREE_DIR)                return -EISDIR;        if (offset >= node->v2)                return 0;        pos = node->v1 + offset;        if (offset + size > node->v2)                size = node->v2 - offset;        switch (node->type) {        case TREE_RAW_FILE:                pthread_mutex_lock (&image->mutex);                ret = io_read (buf, size, image,                               image->parts[node->part].offset + pos);                pthread_mutex_unlock (&image->mutex);                break;        case TREE_FILE:                pthread_mutex_lock (&image->mutex);                ret = io_read_part (buf, size, image, node->part, pos);                pthread_mutex_unlock (&image->mutex);                break;        case TREE_UINT:                sprintf (buf, "%llu\n", node->v1);                ret = strlen (buf);                break;        case TREE_HEX_UINT8:                sprintf (buf, "0x%02x\n", (u8) node->v1);                ret = strlen (buf);                break;        case TREE_HEX_UINT16:                sprintf (buf, "0x%04x\n", (u16) node->v1);                ret = strlen (buf);                break;        case TREE_HEX_UINT32:                sprintf (buf, "0x%08x\n", (u32) node->v1);                ret = strlen (buf);                break;        case TREE_HEX_UINT64:                sprintf (buf, "0x%016llx\n", node->v1);                ret = strlen (buf);                break;        case TREE_MEM:                memcpy (buf, pos, size);                ret = size;                break;        case TREE_CHAR:                buf[0] = (char) node->v1;                buf[1] = '\n';                ret = 2;                break;        case TREE_STRING:                memcpy (buf, pos, size);                buf[size - 1] = '\n';                ret = size;                break;        case TREE_SYMLINK:                strcpy (buf, pos);                ret = 5;                break;        case TREE_DIR:                break;        }        return ret;}int fs_tree_readlink (const char *path, char *buf, size_t size) {        struct image_file *image = (struct image_file *)                                   fuse_get_context ()->private_data;        struct tree *node;        node = tree_find_entry (image->tree, path);        if (!node)                return -ENOENT;        if (node->type != TREE_SYMLINK)                return -EINVAL;        strncpy (buf, node->v1, size);        buf[size - 1] = 0;        return 0;}int fs_tree_opendir (const char *path, struct fuse_file_info *fi) {        struct image_file *image = (struct image_file *)                                   fuse_get_context ()->private_data;        struct tree *node = tree_find_entry (image->tree, path);        (void) fi;        if (!node)                return -ENOENT;        if (node->type != TREE_DIR)                return -ENOTDIR;        return 0;}int fs_tree_readdir (const char *path, void *buf, fuse_fill_dir_t filler,                     off_t offset, struct fuse_file_info *fi) {        struct image_file *image = (struct image_file *)                                   fuse_get_context ()->private_data;        struct tree *node;        (void) offset;        (void) fi;        node = tree_find_entry (image->tree, path);        if (!node)                return -ENOENT;        if (node->type != TREE_DIR)                return -ENOTDIR;        filler (buf, ".", NULL, 0);        filler (buf, "..", NULL, 0);        node = node->sub;        while (node) {                filler (buf, node->name, NULL, 0);                node = node->next;        }        return 0;}int fs_tree_statfs (const char *path, struct statvfs *svfs) {        struct image_file *image = (struct image_file *)                                   fuse_get_context ()->private_data;        (void) path;        memset (svfs, 0, sizeof (struct statvfs));        svfs->f_bsize = 1;        svfs->f_blocks = image->nbytes;        svfs->f_files = image->nfiles;        return 0;}void fs_tree_get_ops (struct fuse_operations *fs_ops) {        memset (fs_ops, 0, sizeof (struct fuse_operations));        fs_ops->getattr = fs_tree_getattr;        fs_ops->open = fs_tree_open;        fs_ops->read = fs_tree_read;        fs_ops->opendir = fs_tree_opendir;        fs_ops->readdir = fs_tree_readdir;        fs_ops->readlink = fs_tree_readlink;        fs_ops->statfs = fs_tree_statfs;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -