示例#1
0
文件: rcopy.c 项目: brkt/fuse-xfs
void copy_tree(xfs_mount_t *mp, char *parent, char *local, xfs_inode_t *inode) {
    xfs_off_t ofs;
    int r, fd;
    struct filldir_data filldata;
    char *buffer[BUFSIZE];
    off_t offset;

    if (xfs_is_dir(inode)) {
        mkdir(local, 0770);
        filldata.mp = mp;
        filldata.base = parent;
        filldata.local = local;
        ofs = 0;
        r = xfs_readdir(inode, (void *)&filldata, 102400, &ofs, copy_filldir);
        if (r != 0) {
            printf("Not a directory\n");
        }
    } else if (!xfs_is_link(inode)) {
        r = 10;
        offset = 0;
        fd = open(local, O_WRONLY|O_CREAT, 0660);
        if (fd < 0) {
            printf("Failed to open local file\n");
        } else {
            while (r) {
                r = xfs_readfile(inode, buffer, offset, BUFSIZE, NULL);
                if (r) {
                    write(fd, buffer, r);
                    offset += r;
                }
           }
        }
        close(fd);
    }
}
示例#2
0
文件: rcopy.c 项目: brkt/fuse-xfs
int copy_filldir(void *dirents, const char *name, int namelen, off_t offset, uint64_t inumber, unsigned flags) {
    char dname[256];
    char lname[256];
    int r;
    xfs_inode_t *inode=NULL;
    struct stat fstats;
    char mode[]="rwxrwxrwx";
    int tests[]={S_IRUSR,S_IWUSR,S_IXUSR,S_IRGRP,S_IWGRP,S_IXGRP,S_IROTH,S_IWOTH,S_IXOTH};

    struct filldir_data *data = (struct filldir_data *) dirents;

    strcpy(dname, data->base);
    strcat(dname, "/");
    strncat(dname, name, namelen);

    strcpy(lname, data->local);
    strcat(lname, "/");
    strncat(lname, name, namelen);

    r = libxfs_iget(data->mp, NULL, inumber, 0, &inode, 0);
    if (r) printf("Panic! %d\n", r);
    r = xfs_stat(inode, &fstats);
    if (r) printf("Panic! stats %d\n", r);
    if (xfs_is_dir(inode)) {
        printf("d");
    } else if (xfs_is_link(inode)) {
        printf("l");
    } else printf("-");

    for (r=0; r<9; r++) {
        if (fstats.st_mode & tests[r]) {
            printf("%c", mode[r]);
        } else {
            printf("-");
        }
    }
    
    printf(" %s -> %s\n", dname, lname);
    if (strncmp(name, ".", namelen) == 0)
        libxfs_iput(inode, 0);
    else if (strncmp(name, "..", namelen) == 0)
        libxfs_iput(inode, 0);
    else {
        copy_tree(data->mp, dname, lname, inode);
        libxfs_iput(inode, 0);
    }
    return 0;
}
示例#3
0
int cli_ls_xfs_filldir(void *dirents, const char *name, int namelen, off_t offset, uint64_t inumber, unsigned flags) {
    char dname[256];
    char symlink[256];
    int r;
    xfs_inode_t *inode=NULL;
    struct stat fstats;
    char mode[]="rwxrwxrwx";
    int tests[]={S_IRUSR,S_IWUSR,S_IXUSR,S_IRGRP,S_IWGRP,S_IXGRP,S_IROTH,S_IWOTH,S_IXOTH};

    struct filldir_data *data = (struct filldir_data *) dirents;
    memcpy(dname, name, namelen);
    dname[namelen] = '\0';
    r = libxfs_iget(data->mp, NULL, inumber, 0, &inode, 0);
    if (r) printf("Panic! %d\n", r);
    r = xfs_stat(inode, &fstats);
    if (r) printf("Panic! stats %d\n", r);
    if (xfs_is_dir(inode)) {
        printf("d");
    } else if (xfs_is_link(inode)) {
        printf("l");
    } else printf("-");

    for (r=0; r<9; r++) {
        if (fstats.st_mode & tests[r]) {
            printf("%c", mode[r]);
        } else {
            printf("-");
        }
    }
    
    print_int(fstats.st_uid, 6);
    print_int(fstats.st_gid, 6);
    print_int(fstats.st_size, 12);
    
    printf(" %s", dname);
    if (xfs_is_link(inode)) {
        r = xfs_readlink(inode, symlink, 0, 255, NULL);
        if (r > 0) {
            symlink[r] = '\0';
            printf("->%s", symlink);
        }
    }
    printf("\n");
    libxfs_iput(inode, 0);
    return 0;
}
示例#4
0
文件: fuse_xfs.c 项目: brkt/fuse-xfs
static int
fuse_xfs_fgetattr(const char *path, struct stat *stbuf,
                  struct fuse_file_info *fi) {
    log_debug("fgetattr %s\n", path);
    
    int r;
    xfs_inode_t *inode=NULL;
    
    r = find_path(current_xfs_mount(), path, &inode);
    if (r) {
        return -ENOENT;
    }
    xfs_stat(inode, stbuf);

    if (xfs_is_dir(inode)) {
        log_debug("directory %s\n", path);
    }
    
    return 0;
}
示例#5
0
int main(int argc, char *argv[]) {
    xfs_mount_t	*mp;
    xfs_inode_t *inode = NULL;
    xfs_off_t ofs;
    struct filldir_data filldata;
    char *progname;
    char *source_name;
    int r, fd;
    char *line;
    char path[FILENAME_MAX] = "/";
    char newpath[FILENAME_MAX] = "/";
    char *buffer[BUFSIZE];
    off_t offset;

    if (argc != 2) {
        printf("Usage: xfs-cli raw_device\n");
        return 1;
    }
    progname = argv[0];
    source_name = argv[1];
    
    mp = mount_xfs(progname, source_name);
    
    if (mp == NULL) 
        return 1;
    
    while (line == fetchline(mp, path)) {
        inode = NULL;
        strip(line, ' ');
        if (strncmp(line, "cd ", 3) == 0) {
            if (strcmp(line+3, "..") == 0) {
                goto_parent(path);
            } else {
                strcpy(newpath, path);
                strcat(newpath, line+3);
                r = find_path(mp, newpath, &inode);
                if ((!r) && (xfs_is_dir(inode))) {
                    //TODO: check if it is a directory
                    strcpy(path, newpath);
                    strcat(path, "/");
                    printf("%s\n", path);
                } else {
                    if (r) {
                        printf("No such directory\n");
                    } else {
                        printf("Not a directory\n");
                    }
                }
            }
        }
        else if (strcmp(line, "ls") == 0) {
            r = find_path(mp, path, &inode);
            if (!r) {
                //TODO: check if it is a directory
                ofs=0;
                filldata.mp = mp;
                filldata.base = inode;
                r = xfs_readdir(inode, (void *)&filldata, 102400, &ofs, cli_ls_xfs_filldir);
                if (r != 0) {
                    printf("Not a directory\n");
                }
            } else {
                printf("No such directory\n");
            }
        }
        else if (strncmp(line, "cat ", 4) == 0) {
            strcpy(newpath, path);
            strcat(newpath, line+4);
            r = find_path(mp, newpath, &inode);
            if (r)
                printf("File not found\n");
            else if (xfs_is_regular(inode)) {
                //TODO: check if it is a file
                r = 10;
                offset = 0;
                while (r) {
                    r = xfs_readfile(inode, buffer, offset, BUFSIZE, NULL);
                    if (r) {
                        write(1, buffer, r);
                        offset += r;
                    }
                }
            } else if (xfs_is_link(inode)) {
                r = 10;
                offset = 0;
                while (r) {
                    r = xfs_readlink(inode, buffer, offset, BUFSIZE, NULL);
                    if (r) {
                        write(1, buffer, r);
                        offset += r;
                    }
                }
            } else {
                printf("Not a regular file\n");
            }
        }
        else if (strncmp(line, "get ", 4) == 0) {
            strcpy(newpath, path);
            strcat(newpath, line+4);
            r = find_path(mp, newpath, &inode);
            if ((!r) && (xfs_is_regular(inode))) {
                //TODO: check if it is a file
                r = 10;
                offset = 0;
                fd = open(line+4, O_WRONLY|O_CREAT, 0660);
                if (fd < 0) {
                    printf("Failed to open local file\n");
                } else {
                    while (r) {
                        r = xfs_readfile(inode, buffer, offset, BUFSIZE, NULL);
                        if (r) {
                            write(fd, buffer, r);
                            offset += r;
                        }
                    }
                    close(fd);
                    printf("Retrieved %ld bytes\n", offset);
                }
            } else {
                if (r) 
                    printf("File not found\n");
                else
                    printf("Not a regular file\n");
            }
        }
        else if (strcmp(line, "exit") == 0) {
            libxfs_umount(mp);
            return 0;
        }
        else if (strcmp(line, "pwd") == 0) {
            printf("%s\n", path);
        } else {
            printf("Unknown command\n");
        }
        free(line);
        if (inode) {
            libxfs_iput(inode, 0);
        }
    }
    libxfs_umount(mp);
    return 0;
}