JIndex SyGGetMountPointLargeIcon ( const JCharacter* path, SyGFileTreeList* fileList, JXPM* plainIcon, JXPM* selectedIcon ) { JMountType type; const JBoolean isMP = theApplication->IsMountPoint(path, &type); if (!isMP) { JBoolean writable, isTop; JString device, fsTypeString; JFileSystemType fsType; if (JIsMounted(path, &writable, &isTop, &device, &fsType, &fsTypeString)) { type = JGetUserMountPointType(path, device, fsTypeString); } else { type = kJHardDisk; } } const JBoolean writable = JDirectoryWritable(path); JString dir; if (JGetHomeDirectory(&dir) && JSameDirEntry(dir, path)) { *plainIcon = syg_home_folder_large; *selectedIcon = syg_home_folder_selected_large; return 1; } else if (SyGIsTrashDirectory(path)) { (fileList->GetSyGFileTree())->Update(); if (fileList->IsEmpty()) { *plainIcon = jx_trash_can_empty_large; *selectedIcon = jx_trash_can_empty_selected_large; return 2; } else { *plainIcon = jx_trash_can_full_large; *selectedIcon = jx_trash_can_full_selected_large; return 3; } } else if (!isMP && type == kJFloppyDisk && !writable) { *plainIcon = syg_floppy_folder_read_only_large; *selectedIcon = syg_floppy_folder_read_only_large; return 4; } else if (!isMP && type == kJFloppyDisk) { *plainIcon = syg_floppy_folder_large; *selectedIcon = syg_floppy_folder_large; return 5; } else if (!isMP && type == kJCDROM && !writable) { *plainIcon = syg_cdrom_folder_read_only_large; *selectedIcon = syg_cdrom_folder_read_only_large; return 4; } else if (!isMP && type == kJCDROM) { *plainIcon = syg_cdrom_folder_large; *selectedIcon = syg_cdrom_folder_large; return 5; } else if (!isMP && !writable) { *plainIcon = jx_folder_read_only_large; *selectedIcon = jx_folder_read_only_selected_large; return 6; } else if (!isMP) { *plainIcon = jx_folder_large; *selectedIcon = jx_folder_selected_large; return 7; } else if (type == kJFloppyDisk) { *plainIcon = jx_floppy_disk_large; *selectedIcon = jx_floppy_disk_selected_large; return 8; } else if (type == kJCDROM) { *plainIcon = jx_cdrom_disk_large; *selectedIcon = jx_cdrom_disk_selected_large; return 9; } else { *plainIcon = jx_hard_disk_large; *selectedIcon = jx_hard_disk_selected_large; return 11; } }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(kAvailInfoName, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } FILE* f = setmntent(kAvailInfoName, "r"); if (f == NULL) { return kJTrue; // did clear list } const JBoolean isRoot = JI2B( getuid() == 0 ); ACE_stat stbuf; while (const mntent* info = getmntent(f)) { if (!(isRoot || hasmntopt(info, "user") != NULL || hasmntopt(info, "users") != NULL || hasmntopt(info, "pamconsole") != NULL || (jUserOwnsDevice(info->mnt_fsname) && hasmntopt(info, "owner") != NULL)) || JIsRootDirectory(info->mnt_dir) || strcmp(info->mnt_type, MNTTYPE_SWAP) == 0) { continue; } const JMountType type = JGetUserMountPointType(info->mnt_dir, info->mnt_fsname, info->mnt_type); if (type == kJUnknownMountType || ACE_OS::stat(info->mnt_dir, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info->mnt_type, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info->mnt_dir); assert( path != NULL ); JString* devicePath = jnew JString(info->mnt_fsname); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } endmntent(f); return kJTrue; }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(_PATH_FSTAB, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } endfsent(); const JBoolean isRoot = JI2B( getuid() == 0 ); if (isRoot) { ACE_stat stbuf; while (const fstab* info = getfsent()) { if (JIsRootDirectory(info->fs_file) || strcmp(info->fs_type, FSTAB_SW) == 0) // swap partition { continue; } const JMountType type = JGetUserMountPointType(info->fs_file, info->fs_spec, info->fs_vfstype); if (type == kJUnknownMountType || ACE_OS::stat(info->fs_file, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (options.Contains("vfat")) { fsType = kVFATType; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info->fs_vfstype, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info->fs_file); assert( path != NULL ); JString* devicePath = jnew JString(info->fs_spec); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } } endfsent(); return kJTrue; }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(kAvailInfoName, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } FILE* f = fopen(kAvailInfoName, "r"); if (f == NULL) { return kJTrue; // did clear list } const JBoolean isRoot = JI2B( getuid() == 0 ); if (isRoot) { ACE_stat stbuf; vfstab info; while (getvfsent(f, &info) == 0) { if (JIsRootDirectory(info.vfs_mountp) || strcmp(info.vfs_fstype, "swap") == 0) { continue; } const JMountType type = JGetUserMountPointType(info.vfs_mountp, info.vfs_special, info.vfs_fstype); if (type == kJUnknownMountType || ACE_OS::stat(info.vfs_mountp, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info.fs_vfstype, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info.vfs_mountp); assert( path != NULL ); JString* devicePath = jnew JString(info.vfs_special); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } } fclose(f); return kJTrue; }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { JProcess* p; int outFD; const JError err = JProcess::Create(&p, kMountCmd, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJIgnoreConnection, NULL); if (!err.OK()) { if (state != NULL) { jdelete state->mountCmdOutput; state->mountCmdOutput = NULL; } return kJFalse; } JString mountData; JReadAll(outFD, &mountData); p->WaitUntilFinished(); const JBoolean success = p->SuccessfulFinish(); jdelete p; p = NULL; if (!success) { if (state != NULL) { jdelete state->mountCmdOutput; state->mountCmdOutput = NULL; } return kJFalse; } if (state != NULL && state->mountCmdOutput != NULL && mountData == *(state->mountCmdOutput)) { return kJFalse; } list->CleanOut(); if (state != NULL && state->mountCmdOutput == NULL) { state->mountCmdOutput = jnew JString(mountData); assert( state->mountCmdOutput != NULL ); } else if (state != NULL) { *(state->mountCmdOutput) = mountData; } JIndexRange r; JArray<JIndexRange> matchList; JString options; ACE_stat stbuf; while (theLinePattern.MatchAfter(mountData, r, &matchList)) { r = matchList.GetFirstElement(); options = mountData.GetSubstring(matchList.GetElement(4)); if (options.Contains("nobrowse")) { continue; } JString* path = jnew JString(mountData.GetSubstring(matchList.GetElement(3))); assert( path != NULL ); JString* devicePath = jnew JString(mountData.GetSubstring(matchList.GetElement(2))); assert( devicePath != NULL ); const JMountType type = JGetUserMountPointType(*path, *devicePath, ""); if (type == kJUnknownMountType || ACE_OS::stat(*path, &stbuf) != 0) { jdelete path; jdelete devicePath; continue; } JFileSystemType fsType = kOtherFSType; if (options.Contains("msdos")) { fsType = kVFATType; } list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } return kJTrue; }