static int /* ERRNO if error, 0 if successful. */ sam_error_call( void *arg, /* Pointer to arguments. */ int size, cred_t *credp) { sam_fserror_arg_t args; sam_mount_t *mp; int error = 0; /* * Validate and copyin the arguments. */ if (size != sizeof (args) || copyin(arg, (caddr_t)&args, sizeof (args))) { return (EFAULT); } /* * If the mount point is not found or umounting. */ if ((mp = find_mount_point(args.handle.fseq)) == NULL) { return (ECANCELED); } if (secpolicy_fs_config(credp, mp->mi.m_vfsp)) { error = EINVAL; } else { syscall_error_response(mp, &args, credp); } SAM_SYSCALL_DEC(mp, 0); return (error); }
static int /* ERRNO if error, 0 if successful. */ sam_get_iocount( void *arg, /* Pointer to arguments. */ int size, rval_t *rvp) /* to return a value */ { sam_fsiocount_arg_t args; sam_mount_t *mp; sam_node_t *ip; /* pointer to rm inode */ int error = 0; if (size != sizeof (args) || copyin(arg, (caddr_t)&args, sizeof (args))) { return (EFAULT); } if ((mp = find_mount_point(args.handle.fseq)) == NULL) { return (ECANCELED); } if ((ip = syscall_valid_ino(mp, &args.handle)) != NULL) { rvp->r_val1 = ip->io_count; if (ip->rdev == 0) { error = ECANCELED; } VN_RELE(SAM_ITOV(ip)); } else { error = ECANCELED; } SAM_SYSCALL_DEC(mp, 0); return (error); }
/* work out the location of the snapshot for this share */ static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle) { const char *snapdir; char *mount_point; const char *ret; snapdir = lp_parm_const_string(SNUM(handle->conn), "shadow", "snapdir", NULL); if (snapdir == NULL) { return NULL; } /* if its an absolute path, we're done */ if (*snapdir == '/') { return snapdir; } /* other its relative to the filesystem mount point */ mount_point = find_mount_point(mem_ctx, handle); if (mount_point == NULL) { return NULL; } ret = talloc_asprintf(mem_ctx, "%s/%s", mount_point, snapdir); talloc_free(mount_point); return ret; }
static int jffs2_reset(struct volume *v, int reset) { char *mp; mp = find_mount_point(v->blk, 1); if (mp) { ULOG_INFO("%s is mounted as %s, only erasing files\n", v->blk, mp); fs_state_set("/overlay", FS_STATE_PENDING); overlay_delete(mp, false); mount(mp, "/", NULL, MS_REMOUNT, 0); } else { ULOG_INFO("%s is not mounted\n", v->blk); return jffs2_mark(v); } if (reset) { sync(); sleep(2); reboot(RB_AUTOBOOT); while (1) ; } return 0; }
plfs_filetype plfs_get_filetype(const char *path) { bool found = false; PlfsConf *pconf = get_plfs_conf(); PlfsMount *pmount = find_mount_point(pconf, path, found); return ((found && pmount) ? pmount->file_type : PFT_UNKNOWN); }
/* work out the location of the base directory for snapshots of this share */ static const char *shadow_copy2_find_basedir(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle) { const char *basedir = lp_parm_const_string(SNUM(handle->conn), "shadow", "basedir", NULL); /* other its the filesystem mount point */ if (basedir == NULL) { basedir = find_mount_point(mem_ctx, handle); } return basedir; }
LogicalFileSystem * plfs_get_logical_fs(const char *path) { mlog(PLFS_DBG, "ENTER %s: %s\n", __FUNCTION__,path); bool found = false; PlfsConf *pconf = get_plfs_conf(); PlfsMount *pmount = find_mount_point(pconf, path, found); if (!found || pmount == NULL) { return NULL; } return pmount->fs_ptr; }
void write_mtab(char *blockDevice, char *directory, char *filesystemType, long flags, char *string_flags) { FILE *mountTable = setmntent(mtab_file, "a+"); struct mntent m; if (mountTable == 0) { perror_msg("%s", mtab_file); return; } if (mountTable) { int length = strlen(directory); if (length > 1 && directory[length - 1] == '/') directory[length - 1] = '\0'; if (filesystemType == 0) { struct mntent *p = find_mount_point(blockDevice, "/proc/mounts"); if (p && p->mnt_type) filesystemType = p->mnt_type; } m.mnt_fsname = blockDevice; m.mnt_dir = directory; m.mnt_type = filesystemType ? filesystemType : "default"; if (*string_flags) { m.mnt_opts = string_flags; } else { if ((flags | MS_RDONLY) == flags) m.mnt_opts = "ro"; else m.mnt_opts = "rw"; } m.mnt_freq = 0; m.mnt_passno = 0; addmntent(mountTable, &m); endmntent(mountTable); } }
int eject_main(int argc, char **argv) { unsigned long flags; char *device; struct mntent *m; flags = bb_getopt_ulflags(argc, argv, "t"); device = argv[optind] ? : DEFAULT_CDROM; if ((m = find_mount_point(device, bb_path_mtab_file))) { if (umount(m->mnt_dir)) { bb_error_msg_and_die("Can't umount"); } else if (ENABLE_FEATURE_MTAB_SUPPORT) { erase_mtab(m->mnt_fsname); } } if (ioctl(bb_xopen(device, (O_RDONLY | O_NONBLOCK)), (flags ? CDROMCLOSETRAY : CDROMEJECT))) { bb_perror_msg_and_die("%s", device); } return (EXIT_SUCCESS); }
static int /* ERRNO if error, 0 if successful. */ sam_mount_call( void *arg, /* Pointer to arguments. */ int size, cred_t *credp) { sam_fsmount_arg_t args; sam_mount_t *mp; int error; /* * Validate and copyin the arguments. */ if (size != sizeof (args) || copyin(arg, (caddr_t)&args, sizeof (args))) { return (EFAULT); } /* * If the mount point is mounted, process mount request. */ if ((mp = find_mount_point(args.handle.fseq)) == NULL) { return (ECANCELED); } if (secpolicy_fs_config(credp, mp->mi.m_vfsp)) { error = EINVAL; } else { error = syscall_mount_response(mp, &args); } /* * Decrement syscall count, the vnode count should be incremented by * now. */ SAM_SYSCALL_DEC(mp, 0); return (error); }
int df_main(int argc, char **argv) { long blocks_used; long blocks_percent_used; #ifdef CONFIG_FEATURE_HUMAN_READABLE unsigned long df_disp_hr = 1024; #endif int status = EXIT_SUCCESS; unsigned opt; FILE *mount_table; struct mntent *mount_entry; struct statfs s; static const char hdr_1k[] = "1k-blocks"; /* default display is kilobytes */ const char *disp_units_hdr = hdr_1k; #ifdef CONFIG_FEATURE_HUMAN_READABLE opt_complementary = "h-km:k-hm:m-hk"; opt = getopt32(argc, argv, "hmk"); if (opt & 1) { df_disp_hr = 0; disp_units_hdr = " Size"; } if (opt & 2) { df_disp_hr = 1024*1024; disp_units_hdr = "1M-blocks"; } #else opt = getopt32(argc, argv, "k"); #endif printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n", "", disp_units_hdr); mount_table = NULL; argv += optind; if (optind >= argc) { mount_table = setmntent(bb_path_mtab_file, "r"); if (!mount_table) { bb_perror_msg_and_die(bb_path_mtab_file); } } do { const char *device; const char *mount_point; if (mount_table) { mount_entry = getmntent(mount_table); if (!mount_entry) { endmntent(mount_table); break; } } else { mount_point = *argv++; if (!mount_point) { break; } mount_entry = find_mount_point(mount_point, bb_path_mtab_file); if (!mount_entry) { bb_error_msg("%s: can't find mount point", mount_point); SET_ERROR: status = EXIT_FAILURE; continue; } } device = mount_entry->mnt_fsname; mount_point = mount_entry->mnt_dir; if (statfs(mount_point, &s) != 0) { bb_perror_msg("%s", mount_point); goto SET_ERROR; } if ((s.f_blocks > 0) || !mount_table){ blocks_used = s.f_blocks - s.f_bfree; blocks_percent_used = 0; if (blocks_used + s.f_bavail) { blocks_percent_used = (((long long) blocks_used) * 100 + (blocks_used + s.f_bavail)/2 ) / (blocks_used + s.f_bavail); } if (strcmp(device, "rootfs") == 0) { continue; } else if (strcmp(device, "/dev/root") == 0) { /* Adjusts device to be the real root device, * or leaves device alone if it can't find it */ device = find_block_device("/"); if (!device) { goto SET_ERROR; } } #ifdef CONFIG_FEATURE_HUMAN_READABLE printf("%-20s %9s ", device, make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr)); printf("%9s ", make_human_readable_str( (s.f_blocks - s.f_bfree), s.f_bsize, df_disp_hr)); printf("%9s %3ld%% %s\n", make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr), blocks_percent_used, mount_point); #else printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", device, kscale(s.f_blocks, s.f_bsize), kscale(s.f_blocks-s.f_bfree, s.f_bsize), kscale(s.f_bavail, s.f_bsize), blocks_percent_used, mount_point); #endif } } while (1); fflush_stdout_and_exit(status); }
static int /* ERRNO if error, 0 if successful. */ sam_drop_call( void *arg, /* Pointer to arguments. */ int size, cred_t *credp) { sam_fsdropds_arg_t args; sam_mount_t *mp; sam_node_t *ip = NULL; /* pointer to rm inode */ int error; if (size != sizeof (args) || copyin(arg, (caddr_t)&args, sizeof (args))) { return (EFAULT); } /* * If the mount point is mounted, process releaser request. */ if ((mp = find_mount_point(args.fseq)) == NULL) { return (ECANCELED); } if (secpolicy_fs_config(credp, mp->mi.m_vfsp)) { error = EINVAL; goto out; } if ((error = sam_find_ino(mp->mi.m_vfsp, IG_EXISTS, &args.id, &ip))) { goto droperr; } RW_LOCK_OS(&ip->inode_rwl, RW_WRITER); /* * Don't release file if it is staging, archiving, or release_n set. */ if (ip->flags.b.staging || ip->arch_count) { error = EBUSY; dcmn_err((CE_NOTE, "SAM-QFS: %s: Cannot release file:" " %d.%d, flag=%x ac=%d pid=%d.%d.%d.%d", mp->mt.fi_name, ip->di.id.ino, ip->di.id.gen, ip->flags.bits, ip->arch_count, ip->arch_pid[0], ip->arch_pid[1], ip->arch_pid[2], ip->arch_pid[3])); } else if ((args.shrink == 0) && (ip->di.status.b.nodrop || ip->di.status.b.archnodrop || ip->flags.b.accessed)) { error = EINVAL; } else if (args.shrink && ip->di.arch_status == 0) { error = EBADE; } else { int bof_online; RW_UNLOCK_OS(&ip->inode_rwl, RW_WRITER); RW_LOCK_OS(&ip->data_rwl, RW_WRITER); RW_LOCK_OS(&ip->inode_rwl, RW_WRITER); if (args.shrink) { bof_online = ip->di.status.b.bof_online; ip->di.status.b.bof_online = 0; } error = sam_drop_ino(ip, credp); if (args.shrink) { ip->di.status.b.bof_online = bof_online; } RW_UNLOCK_OS(&ip->data_rwl, RW_WRITER); } RW_UNLOCK_OS(&ip->inode_rwl, RW_WRITER); sam_rele_ino(ip); /* * Wait until all the blocks released on the list. */ mutex_enter(&mp->mi.m_inode.mutex); while (mp->mi.m_next != NULL || mp->mi.m_inode.busy) { mp->mi.m_inode.wait++; if (sam_cv_wait_sig(&mp->mi.m_inode.get_cv, &mp->mi.m_inode.mutex) == 0) { mp->mi.m_inode.wait--; error = EINTR; break; } mp->mi.m_inode.wait--; } mutex_exit(&mp->mi.m_inode.mutex); droperr: /* * Return blks now free */ args.freeblocks = mp->mi.m_sbp->info.sb.space; if (size != sizeof (args) || copyout((caddr_t)&args, arg, sizeof (args))) { error = EFAULT; } out: SAM_SYSCALL_DEC(mp, 0); return (error); }
static int /* ERRNO if error, 0 if successful. */ sam_cancel_call( void *arg, /* Pointer to arguments. */ int size, cred_t *credp) { sam_handle_t *fhandle; sam_fserror_arg_t args; sam_mount_t *mp; sam_node_t *ip; /* pointer to rm inode */ int error; /* * Validate and copyin the arguments. */ if (size != sizeof (args) || copyin(arg, (caddr_t)&args, sizeof (args))) { return (EFAULT); } /* * If the mount point is mounted, process cancel request. */ if ((mp = find_mount_point(args.handle.fseq)) == NULL) { return (ECANCELED); } if (secpolicy_fs_config(credp, mp->mi.m_vfsp)) { error = EINVAL; goto cancelerror; } fhandle = (sam_handle_t *)&args.handle; if ((ip = syscall_valid_ino(mp, fhandle)) == NULL) { error = ECANCELED; goto cancelerror; } TRACE(T_SAM_DAEMON_CAN, SAM_ITOV(ip), ip->di.id.ino, ip->rdev, args.ret_err); RW_LOCK_OS(&ip->data_rwl, RW_WRITER); /* Wait until I/O done */ RW_LOCK_OS(&ip->inode_rwl, RW_WRITER); if (ip->rdev && (fhandle->pid == ip->rm_pid)) { ip->rm_err = args.ret_err; RW_UNLOCK_OS(&ip->data_rwl, RW_WRITER); error = sam_unload_rm(ip, FWRITE, 0, 0, credp); if (ip->rm_err == 0) { ip->rm_err = error; } } else { cmn_err(CE_NOTE, "SAM-QFS: %s: sam_cancel_call:" " SC_fscancel error: rdev: %d rm_pid: %d fh_pid: %d", mp->mt.fi_name, (int)ip->rdev, ip->rm_pid, fhandle->pid); error = ECANCELED; RW_UNLOCK_OS(&ip->data_rwl, RW_WRITER); } RW_UNLOCK_OS(&ip->inode_rwl, RW_WRITER); VN_RELE(SAM_ITOV(ip)); /* * Decrement syscall count, the vnode count should be incremented by * now. */ cancelerror: SAM_SYSCALL_DEC(mp, 0); return (error); }
static int /* ERRNO if error, 0 if successful. */ sam_position_call( void *arg, /* Pointer to arguments. */ int size, cred_t *credp) { sam_position_arg_t args; sam_mount_t *mp; sam_handle_t *fhandle; sam_fs_fifo_ctl_t *fifo_ctl; sam_node_t *ip; /* pointer to rm inode */ int error = 0; /* validate and copyin the arguments */ if (size != sizeof (args) || copyin(arg, (caddr_t)&args, sizeof (args))) { return (EFAULT); } /* If the mount point is not found or umounting */ if ((mp = find_mount_point(args.handle.fseq)) == NULL) { return (ECANCELED); } if (secpolicy_fs_config(credp, mp->mi.m_vfsp)) { error = EINVAL; } else { fhandle = (sam_handle_t *)&args.handle; fifo_ctl = (sam_fs_fifo_ctl_t *)fhandle->fifo_cmd.ptr; if ((ip = syscall_valid_ino(mp, fhandle))) { TRACE(T_SAM_IOCTL_POS, SAM_ITOV(ip), ip->di.id.ino, args.ret_err, ip->rdev); /* Is this inode still waiting for the command? */ mutex_enter(&ip->daemon_mutex); if (ip->daemon_busy) { if (fhandle->pid == ip->rm_pid) { if (fifo_ctl && fifo_ctl->fifo.magic == FS_FIFO_MAGIC) { fifo_ctl->ret_err = args.ret_err; if (args.position != 0) { ip->di.rm.info.rm.position = (uint_t)args.position; } } ip->daemon_busy = 0; cv_signal(&ip->daemon_cv); } } mutex_exit(&ip->daemon_mutex); VN_RELE(SAM_ITOV(ip)); } } /* * Decrement syscall count (incremented in find_mount_point()). */ SAM_SYSCALL_DEC(mp, 0); return (error); }
extern int df_main(int argc, char **argv) { long blocks_used; long blocks_percent_used; #ifdef CONFIG_FEATURE_HUMAN_READABLE unsigned long df_disp_hr = KILOBYTE; #endif int status = EXIT_SUCCESS; unsigned long opt; FILE *mount_table; struct mntent *mount_entry; struct statfs s; static const char hdr_1k[] = "1k-blocks"; /* default display is kilobytes */ const char *disp_units_hdr = hdr_1k; char df_entry[200] = {0}; // Added by Nick Wang, 01/05/2005 int entry_len = 0; // Added by Nick Wang, 01/05/2005 printf("busybox df_main: start\n"); #ifdef CONFIG_FEATURE_HUMAN_READABLE bb_opt_complementaly = "h-km:k-hm:m-hk"; opt = bb_getopt_ulflags(argc, argv, "hmk"); if(opt & 1) { df_disp_hr = 0; disp_units_hdr = " Size"; } if(opt & 2) { df_disp_hr = MEGABYTE; disp_units_hdr = "1M-blocks"; } #else opt = bb_getopt_ulflags(argc, argv, "k"); #endif bb_printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n", "", disp_units_hdr); mount_table = NULL; argv += optind; if (optind >= argc) { if (!(mount_table = setmntent(bb_path_mtab_file, "r"))) { bb_perror_msg_and_die(bb_path_mtab_file); } } do { const char *device; const char *mount_point; if (mount_table) { if (!(mount_entry = getmntent(mount_table))) { endmntent(mount_table); break; } } else { if (!(mount_point = *argv++)) { break; } if (!(mount_entry = find_mount_point(mount_point, bb_path_mtab_file))) { bb_error_msg("%s: can't find mount point.", mount_point); SET_ERROR: status = EXIT_FAILURE; continue; } } device = mount_entry->mnt_fsname; mount_point = mount_entry->mnt_dir; if (statfs(mount_point, &s) != 0) { bb_perror_msg("%s", mount_point); goto SET_ERROR; } if ((s.f_blocks > 0) || !mount_table){ blocks_used = s.f_blocks - s.f_bfree; blocks_percent_used = 0; if (blocks_used + s.f_bavail) { blocks_percent_used = (((long long) blocks_used) * 100 + (blocks_used + s.f_bavail)/2 ) / (blocks_used + s.f_bavail); } if (strcmp(device, "rootfs") == 0) { continue; } else if (strcmp(device, "/dev/root") == 0) { /* Adjusts device to be the real root device, * or leaves device alone if it can't find it */ if ((device = find_real_root_device_name(device)) == NULL) { goto SET_ERROR; } } #ifdef CONFIG_FEATURE_HUMAN_READABLE bb_printf("%-21s%9s ", device, make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr)); sprintf(df_entry, "%-21s%9s ", device, make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr)); entry_len = strlen(df_entry); bb_printf("%9s ", make_human_readable_str( (s.f_blocks - s.f_bfree), s.f_bsize, df_disp_hr)); sprintf(df_entry + entry_len, "%9s ", make_human_readable_str( (s.f_blocks - s.f_bfree), s.f_bsize, df_disp_hr)); entry_len = strlen(df_entry); bb_printf("%9s %3ld%% %s\n", make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr), blocks_percent_used, mount_point); sprintf(df_entry + entry_len, "%9s %3ld%% %s\n", make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr), blocks_percent_used, mount_point); entry_len = strlen(df_entry); // output df table to file, Added By Nick Wang, 01/05/02005 { FILE *fp; if ((fp = fopen("/var/.sys-df", "a")) != NULL) fprintf(fp, "%s\n", df_entry); (void) fclose(fp); } // Added End #else bb_printf("%-21s%9ld %9ld %9ld %3ld%% %s\n", device, kscale(s.f_blocks, s.f_bsize), kscale(s.f_blocks-s.f_bfree, s.f_bsize), kscale(s.f_bavail, s.f_bsize), blocks_percent_used, mount_point); #endif } } while (1); bb_fflush_stdout_and_exit(status); }