static int tmpfs_dump(struct mount_info *pm) { int ret = -1; char tmpfs_path[PATH_MAX]; int fd, fd_img = -1; DIR *fdir = NULL; fdir = open_mountpoint(pm); if (fdir == NULL) return -1; fd = dirfd(fdir); if (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) & ~FD_CLOEXEC) == -1) { pr_perror("Can not drop FD_CLOEXEC"); goto out; } fd_img = open_image(CR_FD_TMPFS, O_DUMP, pm->mnt_id); if (fd_img < 0) goto out; snprintf(tmpfs_path, sizeof(tmpfs_path), "/proc/self/fd/%d", fd); ret = cr_system(-1, fd_img, -1, "tar", (char *[]) { "tar", "--create", "--gzip", "--check-links", "--preserve-permissions", "--sparse", "--numeric-owner", "--directory", tmpfs_path, ".", NULL });
/* Load a file, open a directory or run an application. Or, if 'edit' is set: * edit a file, open an application, follow a symlink or mount a device. * * filer_window is the window to use for displaying a directory. * NULL will always use a new directory when needed. * src_window is the window to copy options from, or NULL. * * Returns TRUE on success. */ gboolean run_diritem(const guchar *full_path, DirItem *item, FilerWindow *filer_window, FilerWindow *src_window, gboolean edit) { if (item->flags & ITEM_FLAG_SYMLINK && edit) return follow_symlink(full_path, filer_window, src_window); switch (item->base_type) { case TYPE_DIRECTORY: if (item->flags & ITEM_FLAG_APPDIR && !edit) { run_app(full_path); return TRUE; } if (item->flags & ITEM_FLAG_MOUNT_POINT) { open_mountpoint(full_path, item, filer_window, src_window, edit); } else if (filer_window) filer_change_to(filer_window, full_path, NULL); else filer_opendir(full_path, src_window, NULL); return TRUE; case TYPE_FILE: if (EXECUTABLE_FILE(item) && !edit) { const char *argv[] = {NULL, NULL}; guchar *dir = filer_window ? filer_window->sym_path : NULL; if (item->mime_type == application_x_desktop) return run_desktop(full_path, NULL, dir); else argv[0] = full_path; return rox_spawn(dir, argv) != 0; } return open_file(full_path, edit ? text_plain : item->mime_type); case TYPE_ERROR: delayed_error(_("File doesn't exist, or I can't " "access it: %s"), full_path); return FALSE; default: delayed_error( _("I don't know how to open '%s'"), full_path); return FALSE; } }
FAR DIR *opendir(FAR const char *path) { FAR struct inode *inode = NULL; FAR struct fs_dirent_s *dir; FAR const char *relpath; bool isroot = false; int ret; /* If we are given 'nothing' then we will interpret this as * request for the root inode. */ inode_semtake(); if (!path || *path == 0 || strcmp(path, "/") == 0) { inode = root_inode; isroot = true; relpath = NULL; } else { /* We don't know what to do with relative pathes */ if (*path != '/') { ret = -ENOTDIR; goto errout_with_semaphore; } /* Find the node matching the path. */ inode = inode_search(&path, (FAR struct inode**)NULL, (FAR struct inode**)NULL, &relpath); } /* Did we get an inode? */ if (!inode) { /* 'path' is not a does not exist.*/ ret = ENOTDIR; goto errout_with_semaphore; } /* Allocate a type DIR -- which is little more than an inode * container. */ dir = (FAR struct fs_dirent_s *)kuzalloc(sizeof(struct fs_dirent_s)); if (!dir) { /* Insufficient memory to complete the operation.*/ ret = ENOMEM; goto errout_with_semaphore; } /* Populate the DIR structure and return it to the caller. The way that * we do this depends on whenever this is a "normal" pseudo-file-system * inode or a file system mountpoint. */ dir->fd_position = 0; /* This is the position in the read stream */ /* First, handle the special case of the root inode. This must be * special-cased here because the root inode might ALSO be a mountpoint. */ if (isroot) { /* Whatever payload the root inode carries, the root inode is always * a directory inode in the pseudo-file system */ open_pseudodir(inode, dir); } /* Is this a node in the pseudo filesystem? Or a mountpoint? If the node * is the root (isroot == TRUE), then this is a special case. */ #ifndef CONFIG_DISABLE_MOUNTPOINT else if (INODE_IS_MOUNTPT(inode)) { /* Yes, the node is a file system mountpoint */ dir->fd_root = inode; /* Save the inode where we start */ /* Open the directory at the relative path */ ret = open_mountpoint(inode, relpath, dir); if (ret != OK) { goto errout_with_direntry; } } #endif else { /* The node is part of the root pseudo file system. Does the inode * have a child? If so that the child would be the 'root' of a list * of nodes under the directory. */ FAR struct inode *child = inode->i_child; if (child) { /* It looks we have a valid pseudo-filesystem directory node. */ open_pseudodir(child, dir); } else if (!inode->u.i_ops) { /* This is a dangling node with no children and no operations. Set * up to enumerate an empty directory. */ open_emptydir(dir); } else { ret = ENOTDIR; goto errout_with_direntry; } } inode_semgive(); return ((DIR*)dir); /* Nasty goto's make error handling simpler */ errout_with_direntry: kufree(dir); errout_with_semaphore: inode_semgive(); set_errno(ret); return NULL; }