• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ endmntent函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中endmntent函数的典型用法代码示例。如果您正苦于以下问题:C++ endmntent函数的具体用法?C++ endmntent怎么用?C++ endmntent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了endmntent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ToolsDaemonTcloMountHGFS

gboolean
ToolsDaemonTcloMountHGFS(RpcInData *data) // IN
{
   VixError err = VIX_OK;
   static char resultBuffer[DEFAULT_RESULT_MSG_MAX_LENGTH];

#if defined(linux)
   /*
    * Look for a vmhgfs mount at /mnt/hgfs. If one exists, nothing
    * else needs to be done.  If one doesn't exist, then mount at
    * that location.
    */
   FILE *mtab;
   struct mntent *mnt;
   Bool vmhgfsMntFound = FALSE;
   if ((mtab = setmntent(_PATH_MOUNTED, "r")) == NULL) {
      err = VIX_E_FAIL;
   } else {
      while ((mnt = getmntent(mtab)) != NULL) {
         if ((strcmp(mnt->mnt_fsname, ".host:/") == 0) &&
             (strcmp(mnt->mnt_type, HGFS_NAME) == 0) &&
             (strcmp(mnt->mnt_dir, "/mnt/hgfs") == 0)) {
             vmhgfsMntFound = TRUE;
             break;
         }
      }
      endmntent(mtab);
   }

   if (!vmhgfsMntFound) {
   /*
    * We need to call the mount program, not the mount system call. The
    * mount program does several additional things, like compute the mount
    * options from the contents of /etc/fstab, and invoke custom mount
    * programs like the one needed for HGFS.
    */
      int ret = system("mount -t vmhgfs .host:/ /mnt/hgfs");
      if (ret == -1 || WIFSIGNALED(ret) ||
          (WIFEXITED(ret) && WEXITSTATUS(ret) != 0)) {
         err = VIX_E_FAIL;
      }
   }
#endif

   /*
    * All tools commands return results that start with an error
    * and a guest-OS-specific error.
    */
   Str_Sprintf(resultBuffer,
               sizeof(resultBuffer),
               "%"FMT64"d %d",
               err,
               Err_Errno());
   RPCIN_SETRETVALS(data, resultBuffer, TRUE);

   return TRUE;
} // ToolsDaemonTcloMountHGFS
开发者ID:mirzawaqasahmed,项目名称:open-vm-tools,代码行数:57,代码来源:foundryToolsDaemon.c


示例2: fs_map_load

FSMap *
fs_map_load(void)
{
	FSMap *map = NULL;
	FILE *fp;

	fp = setmntent("/proc/mounts", "r");

	if(fp)
	{
		/* store available mount points in array */
		map = utils_new(1, FSMap);
		map->mps = utils_new(32, MountPoint *);
		map->size = 32;
		map->len = 0;

		struct mntent *ent = getmntent(fp);

		while(ent)
		{
			if(map->len == map->size - 1)
			{
				if(map->size > SIZE_MAX / 2)
				{
					FATAL("misc", "Integer overflow.");

					fprintf(stderr, _("Couldn't allocate memory.\n"));

					abort();
				}

				map->size *= 2;
				map->mps = utils_renew(map->mps, map->size, MountPoint *);
			}

			map->mps[map->len] = utils_new(1, MountPoint);

			memset(map->mps[map->len]->fs, 0, FS_NAME_MAX);
			strncpy(map->mps[map->len]->fs, ent->mnt_type, FS_NAME_MAX - 1);

			memset(map->mps[map->len]->path, 0, PATH_MAX);
			strncpy(map->mps[map->len]->path, ent->mnt_dir, PATH_MAX - 1);

			++map->len;
			ent = getmntent(fp);
		}

		endmntent(fp);

		/* sort array by path in descending order */
		if(map->len)
		{
			qsort(map->mps, map->len, sizeof(MountPoint *), &_fs_map_compare_entries);
		}
	}
	else
	{
开发者ID:20centaurifux,项目名称:efind,代码行数:57,代码来源:fs.c


示例3: mount_it_now

static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
{
	int rc;

	if (fakeIt) { return 0; }

	// Mount, with fallback to read-only if necessary.

	for(;;) {
		rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
				vfsflags, filteropts);
		if(!rc || (vfsflags&MS_RDONLY) || (errno!=EACCES && errno!=EROFS))
			break;
		bb_error_msg("%s is write-protected, mounting read-only",
				mp->mnt_fsname);
		vfsflags |= MS_RDONLY;
	}

	// Abort entirely if permission denied.

	if (rc && errno == EPERM)
		bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);

	/* If the mount was successful, and we're maintaining an old-style
	 * mtab file by hand, add the new entry to it now. */

	if(ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc) {
		FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
		int i;

		if(!mountTable)
			bb_error_msg("No %s\n",bb_path_mtab_file);

		// Add vfs string flags

		for(i=0; mount_options[i].flags != MS_REMOUNT; i++)
			if (mount_options[i].flags > 0)
				append_mount_options(&(mp->mnt_opts),
// Shut up about the darn const.  It's not important.  I don't care.
						(char *)mount_options[i].name);

		// Remove trailing / (if any) from directory we mounted on

		i = strlen(mp->mnt_dir);
		if(i>1 && mp->mnt_dir[i-1] == '/') mp->mnt_dir[i-1] = 0;

		// Write and close.

		if(!mp->mnt_type || !*mp->mnt_type) mp->mnt_type="--bind";
		addmntent(mountTable, mp);
		endmntent(mountTable);
		if (ENABLE_FEATURE_CLEAN_UP)
			if(strcmp(mp->mnt_type,"--bind")) mp->mnt_type = 0;
	}

	return rc;
}
开发者ID:blueprintmrk,项目名称:stablebox,代码行数:57,代码来源:mount.c


示例4: setmntent

const char *mntpoint(const char *devname)
{
    FILE *f;
    struct mntent *mnt;
    
    f = setmntent("/etc/mtab", "r");
    if (f) {
        while (mnt = getmntent(f)) {
            if (strcmp(mnt->mnt_fsname, devname) == 0) {
                endmntent(f);
                return strdup(mnt->mnt_dir);
            }
        }
        endmntent(f);
    }

    return "???";
}
开发者ID:EtchedPixels,项目名称:FUZIX,代码行数:18,代码来源:df.c


示例5: VBoxServiceAutoMountShareIsMounted

/** @todo Integrate into RTFsQueryMountpoint().  */
static bool VBoxServiceAutoMountShareIsMounted(const char *pszShare,
                                               char *pszMountPoint, size_t cbMountPoint)
{
    AssertPtrReturn(pszShare, VERR_INVALID_PARAMETER);
    AssertPtrReturn(pszMountPoint, VERR_INVALID_PARAMETER);
    AssertReturn(cbMountPoint, VERR_INVALID_PARAMETER);

    bool fMounted = false;
    /* @todo What to do if we have a relative path in mtab instead
     *       of an absolute one ("temp" vs. "/media/temp")?
     * procfs contains the full path but not the actual share name ...
     * FILE *pFh = setmntent("/proc/mounts", "r+t"); */
#ifdef RT_OS_SOLARIS
    FILE *pFh = fopen(_PATH_MOUNTED, "r");
    if (!pFh)
        VBoxServiceError("VBoxServiceAutoMountShareIsMounted: Could not open mount tab \"%s\"!\n",
                         _PATH_MOUNTED);
    else
    {
        mnttab mntTab;
        while ((getmntent(pFh, &mntTab)))
        {
            if (!RTStrICmp(mntTab.mnt_special, pszShare))
            {
                fMounted = RTStrPrintf(pszMountPoint, cbMountPoint, "%s", mntTab.mnt_mountp)
                         ? true : false;
                break;
            }
        }
        fclose(pFh);
    }
#else
    FILE *pFh = setmntent(_PATH_MOUNTED, "r+t");
    if (pFh == NULL)
        VBoxServiceError("VBoxServiceAutoMountShareIsMounted: Could not open mount tab \"%s\"!\n",
                         _PATH_MOUNTED);
    else
    {
        mntent *pMntEnt;
        while ((pMntEnt = getmntent(pFh)))
        {
            if (!RTStrICmp(pMntEnt->mnt_fsname, pszShare))
            {
                fMounted = RTStrPrintf(pszMountPoint, cbMountPoint, "%s", pMntEnt->mnt_dir)
                         ? true : false;
                break;
            }
        }
        endmntent(pFh);
    }
#endif

    VBoxServiceVerbose(4, "VBoxServiceAutoMountShareIsMounted: Share \"%s\" at mount point \"%s\" = %s\n",
                       pszShare, fMounted ? pszMountPoint : "<None>", fMounted ? "Yes" : "No");
    return fMounted;
}
开发者ID:VirtualMonitor,项目名称:VirtualMonitor,代码行数:57,代码来源:VBoxServiceAutoMount.cpp


示例6: fsal_internal_path2fsname

int fsal_internal_path2fsname(char *rpath, char *fs_spec)
{
  FILE *fp;
  struct mntent mnt;
  struct mntent *pmnt;
  char work[MAXPATHLEN];
  char mntdir[MAXPATHLEN];

  size_t pathlen, outlen;
  int rc = -1;

  pathlen = 0;
  outlen = 0;

  if(!rpath || !fs_spec)
    return -1;

  fp = setmntent(MOUNTED, "r");

  if(fp == NULL)
    return -1;

  while((pmnt = getmntent_r(fp, &mnt, work, MAXPATHLEN)) != NULL)
    {
      /* get the longer path that matches export path */
      if(mnt.mnt_dir != NULL)
        {
          pathlen = strlen(mnt.mnt_dir);

          if((pathlen > outlen) && !strcmp(mnt.mnt_dir, "/"))
            {
              outlen = pathlen;
              strncpy(mntdir, mnt.mnt_dir, MAXPATHLEN);
              strncpy(fs_spec, mnt.mnt_fsname, MAXPATHLEN);
            }
          /* in other cases, the filesystem must be <mountpoint>/<smthg> or <mountpoint>\0 */
          else if((pathlen > outlen) &&
                  !strncmp(rpath, mnt.mnt_dir, pathlen) &&
                  ((rpath[pathlen] == '/') || (rpath[pathlen] == '\0')))
            {
              /* LogFullDebug(COMPONENT_FSAL, "%s is under mountpoint %s, type=%s, fs=%s\n", 
                 rpath, mnt.mnt_dir, mnt.mnt_type, mnt.mnt_fsname); */

              outlen = pathlen;
              strncpy(mntdir, mnt.mnt_dir, MAXPATHLEN);
              strncpy(fs_spec, mnt.mnt_fsname, MAXPATHLEN);
              rc = 0;
            }
        }

    }

  endmntent(fp);
  return rc;
}                               /* fsal_internal_path2fsname */
开发者ID:alangenfeld,项目名称:cloud-nfs,代码行数:55,代码来源:fsal_internal.c


示例7: loki_getmountpoint

/* Code to determine the mount point of a CD-ROM */
int loki_getmountpoint( const char *device, char *mntpt, int max_size ){
	char devpath[PATH_MAX], mntdevpath[PATH_MAX];
	FILE * mountfp;
	struct mntent *mntent;
	int mounted;

	/* Nothing to do with no device file */
	if ( device == NULL ) {
		*mntpt = '\0';
		return -1;
	}

	/* Get the fully qualified path of the CD-ROM device */
	if ( realpath( device, devpath ) == NULL ) {
		perror( "realpath() on your CD-ROM failed" );
		return( -1 );
	}

	/* Get the mount point */
	mounted = -1;
	memset( mntpt, 0, max_size );
	mountfp = setmntent( _PATH_MNTTAB, "r" );
	if ( mountfp != NULL ) {
		mounted = 0;
		while ( ( mntent = getmntent( mountfp ) ) != NULL )
		{
			char *tmp, mntdev[1024];

			strcpy( mntdev, mntent->mnt_fsname );
			if ( strcmp( mntent->mnt_type, "supermount" ) == 0 ) {
				tmp = strstr( mntent->mnt_opts, "dev=" );
				if ( tmp ) {
					strcpy( mntdev, tmp + strlen( "dev=" ) );
					tmp = strchr( mntdev, ',' );
					if ( tmp ) {
						*tmp = '\0';
					}
				}
			}
			if ( strncmp( mntdev, "/dev", 4 ) ||
				 realpath( mntdev, mntdevpath ) == NULL ) {
				continue;
			}
			if ( strcmp( mntdevpath, devpath ) == 0 ) {
				mounted = 1;
				assert( (int)strlen( mntent->mnt_dir ) < max_size );
				strncpy( mntpt, mntent->mnt_dir, max_size - 1 );
				mntpt[max_size - 1] = '\0';
				break;
			}
		}
		endmntent( mountfp );
	}
	return( mounted );
}
开发者ID:Barbatos,项目名称:GtkRadiant,代码行数:56,代码来源:main.cpp


示例8: rpi_storage_get_list

json_t * rpi_storage_get_list(duda_request_t *dr, int parameter)
{
    struct mntent *ent;
    FILE *f;
    json_t *array;
    json_t *mount_object;
    char *full_path;
    struct statvfs svfs;
    double fragment_size, size, used, available, use;
    
    array = json->create_array();
    
    f = setmntent("/proc/mounts", "r");
    if (f == NULL) {
        return array;
    }
    
    while (NULL != (ent = getmntent(f))) {
        mount_object = json->create_object();
        json->add_to_array(array, mount_object);
        
        /* resolve symlinks in device names */
        full_path = NULL;
        if (ent->mnt_fsname[0] == '/') {
            full_path = realpath(ent->mnt_fsname, full_path);
        }
        if (full_path != NULL) {
            json->add_to_object(mount_object, "device", json->create_string(full_path));
            free(full_path);
        }
        else {
            json->add_to_object(mount_object, "device", json->create_string(ent->mnt_fsname));
        }
        json->add_to_object(mount_object, "mount", json->create_string(ent->mnt_dir));
        json->add_to_object(mount_object, "filesystem", json->create_string(ent->mnt_type));
        
        /* try to get usage data */
        if ((statvfs(ent->mnt_dir, &svfs) == 0) && (svfs.f_blocks != 0)) {
            fragment_size = (double)svfs.f_frsize;
            size = fragment_size*((double)svfs.f_blocks);
            used = size - fragment_size*((double)svfs.f_bfree);
            available = fragment_size*((double)svfs.f_bavail);
            use = (size - available)/size;
            
            json->add_to_object(mount_object, "size", json->create_number(size));
            json->add_to_object(mount_object, "used", json->create_number(used));
            json->add_to_object(mount_object, "available", json->create_number(available));
            json->add_to_object(mount_object, "use", json->create_number(use));
        }
    }
    
    endmntent(f);
    
    return array;
}
开发者ID:Cloudinnovates,项目名称:rpi-dashboard,代码行数:55,代码来源:rpi_storage.c


示例9: get_disk_partitions

/*
 * Return disk mounted partitions as a list of tuples including device,
 * mount point and filesystem type
 */
static PyObject*
get_disk_partitions(PyObject* self, PyObject* args)
{
    FILE *file = NULL;
    struct mntent *entry;
    PyObject* py_retlist = PyList_New(0);
    PyObject* py_tuple = NULL;

    // MOUNTED constant comes from mntent.h and it's == '/etc/mtab'
    Py_BEGIN_ALLOW_THREADS
    file = setmntent(MOUNTED, "r");
    Py_END_ALLOW_THREADS
    if ((file == 0) || (file == NULL)) {
        PyErr_SetFromErrno(PyExc_OSError);
        goto error;
    }

    while ((entry = getmntent(file))) {
        if (entry == NULL) {
            PyErr_Format(PyExc_RuntimeError, "getmntent() failed");
            goto error;
        }
        py_tuple = Py_BuildValue("(ssss)", entry->mnt_fsname,  // device
                                           entry->mnt_dir,     // mount point
                                           entry->mnt_type,    // fs type
                                           entry->mnt_opts);   // options
        if (! py_tuple)
            goto error;
        if (PyList_Append(py_retlist, py_tuple))
            goto error;
        Py_DECREF(py_tuple);
    }
    endmntent(file);
    return py_retlist;

error:
    if (file != NULL)
        endmntent(file);
    Py_XDECREF(py_tuple);
    Py_DECREF(py_retlist);
    return NULL;
}
开发者ID:AshishNamdev,项目名称:mozilla-central,代码行数:46,代码来源:_psutil_linux.c


示例10: disks_refresh

/* refresh t_mount_info infos in a GPtrArray containing struct t_disk * elements */
void disks_refresh(GPtrArray * pdisks)
{
	/* using getmntent to get filesystems mount information */
	
	FILE * fmtab = NULL ; // file /etc/mtab
	struct mntent * pmntent = NULL; // struct for mnt info
	struct statfs * pstatfs = NULL ;
	
	t_mount_info * mount_info ;
	t_disk * pdisk ;
	
	/*remove t_mount_info for all devices */
	disks_free_mount_info(pdisks);
	
	/*allocate new struct statfs */
	pstatfs = g_new0(struct statfs,1);
	
	/*open file*/
	fmtab = setmntent(MTAB,"r"); 
	
	/* start looking for mounted devices */
	for(pmntent = getmntent(fmtab) ; pmntent!=NULL ; pmntent = getmntent(fmtab))
	{
		/*getstat on disk */
		if (statfs(pmntent->mnt_dir,pstatfs)==0 && (pstatfs->f_blocks != 0))
		{	/*if we got the stat and they block number is non zero */
			
			/* get pointer on disk from pdisks */
			/*CHANGED to reflect change in disk_search*/
			pdisk = disks_search(pdisks,pmntent->mnt_dir);
			if (pdisk == NULL) //if disk is not found in pdisks
			{
				/*create a new struct t_disk and add it to pdisks */
				/* test for "/dev/" and mnt_dir != none */
				if ( !g_str_has_prefix(pmntent->mnt_fsname,"/dev/") || (g_ascii_strcasecmp(pmntent->mnt_dir,"none") == 0) ) {
					if ( g_strrstr(pmntent->mnt_fsname,":") == NULL)
					 continue ; }
		
				pdisk = disk_new(pmntent->mnt_fsname,pmntent->mnt_dir);
				g_ptr_array_add(pdisks,pdisk);
			}
			
			/* create new t_mount_info */	
			mount_info = mount_info_new_from_stat(pstatfs, pmntent->mnt_type, pmntent->mnt_dir) ;
			/* add it to pdisk */
			pdisk->mount_info = mount_info ;
		
		}
	}
	
	g_free(pstatfs);
	endmntent(fmtab); //close file
	return ;
}
开发者ID:stop-n-drink,项目名称:pancake,代码行数:55,代码来源:devices.c


示例11: ecryptfs_private_is_mounted

/* Check if an ecryptfs private device or mount point is mounted.
 * Return 1 if a filesystem in mtab matches dev && mnt && sig.
 * Return 0 otherwise.
 */
int ecryptfs_private_is_mounted(char *dev, char *mnt, char *sig, int mounting) {
	FILE *fh = NULL;
	struct mntent *m = NULL;
	char *opt = NULL;
	int mounted;
	if (sig && asprintf(&opt, "ecryptfs_sig=%s", sig) < 0) {
		perror("asprintf");
		return 0;
	}
	fh = setmntent("/proc/mounts", "r");
	if (fh == NULL) {
		perror("setmntent");
		return 0;
	}
	mounted = 0;
	flockfile(fh);
	while ((m = getmntent(fh)) != NULL) {
		if (strcmp(m->mnt_type, "ecryptfs") != 0)
			/* Skip if this entry is not an ecryptfs mount */
			continue;
		if (mounting == 1) {
			/* If mounting, return "already mounted" if EITHER the
 			 * dev or the mnt dir shows up in mtab/mounts;
 			 * regardless of the signature of such mounts;
 			 */
			if (dev != NULL && strcmp(m->mnt_fsname, dev) == 0) {
				mounted = 1;
				break;
			}
			if (mnt != NULL && strcmp(m->mnt_dir, mnt) == 0) {
				mounted = 1;
				break;
			}
		} else {
			/* Otherwise, we're unmounting, and we need to be
			 * very conservative in finding a perfect match
			 * to unmount.  The device, mountpoint, and signature
			 * must *all* match perfectly.
			 */
			if (
			    strcmp(m->mnt_fsname, dev) == 0 &&
			    strcmp(m->mnt_dir, mnt) == 0 &&
			    (!opt || hasmntopt(m, opt) != NULL)
			) {
				mounted = 1;
				break;
			}
		}
	}
	endmntent(fh);
	if (opt != NULL)
		free(opt);
	return mounted;
}
开发者ID:Distrotech,项目名称:ecryptfs-utils,代码行数:58,代码来源:main.c


示例12: setmntent

int CollectorLinux::getDiskListByFs(const char *pszPath, DiskList& listUsage, DiskList& listLoad)
{
    FILE *mtab = setmntent("/etc/mtab", "r");
    if (mtab)
    {
        struct mntent *mntent;
        while ((mntent = getmntent(mtab)))
        {
            /* Skip rootfs entry, there must be another root mount. */
            if (strcmp(mntent->mnt_fsname, "rootfs") == 0)
                continue;
            if (strcmp(pszPath, mntent->mnt_dir) == 0)
            {
                char szDevName[128];
                char szFsName[1024];
                /* Try to resolve symbolic link if necessary. Yes, we access the file system here! */
                int rc = RTPathReal(mntent->mnt_fsname, szFsName, sizeof(szFsName));
                if (RT_FAILURE(rc))
                    continue; /* something got wrong, just ignore this path */
                /* check against the actual mtab entry, NOT the real path as /dev/mapper/xyz is
                 * often a symlink to something else */
                if (!strncmp(mntent->mnt_fsname, RT_STR_TUPLE("/dev/mapper")))
                {
                    /* LVM */
                    getDiskName(szDevName, sizeof(szDevName), mntent->mnt_fsname, false /*=fTrimDigits*/);
                    addVolumeDependencies(szDevName, listUsage);
                    listLoad = listUsage;
                }
                else if (!strncmp(szFsName, RT_STR_TUPLE("/dev/md")))
                {
                    /* Software RAID */
                    getDiskName(szDevName, sizeof(szDevName), szFsName, false /*=fTrimDigits*/);
                    listUsage.push_back(RTCString(szDevName));
                    addRaidDisks(szDevName, listLoad);
                }
                else
                {
                    /* Plain disk partition. Trim the trailing digits to get the drive name */
                    getDiskName(szDevName, sizeof(szDevName), szFsName, true /*=fTrimDigits*/);
                    listUsage.push_back(RTCString(szDevName));
                    listLoad.push_back(RTCString(szDevName));
                }
                if (listUsage.empty() || listLoad.empty())
                {
                    LogRel(("Failed to retrive disk info: getDiskName(%s) --> %s\n",
                           mntent->mnt_fsname, szDevName));
                }
                break;
            }
        }
        endmntent(mtab);
    }
    return VINF_SUCCESS;
}
开发者ID:bayasist,项目名称:vbox,代码行数:54,代码来源:PerformanceLinux.cpp


示例13: erase_mtab

void erase_mtab(const char *name)
{
	struct mntent entries[20];
	int count = 0;
	FILE *mountTable = setmntent(mtab_file, "r");
	struct mntent *m;

	/* Check if reading the mtab file failed */
	if (mountTable == 0
			/* Bummer.  fall back on trying the /proc filesystem */
			&& (mountTable = setmntent("/proc/mounts", "r")) == 0) {
		perror_msg("%s", mtab_file);
		return;
	}

	while ((m = getmntent(mountTable)) != 0) {
		entries[count].mnt_fsname = strdup(m->mnt_fsname);
		entries[count].mnt_dir = strdup(m->mnt_dir);
		entries[count].mnt_type = strdup(m->mnt_type);
		entries[count].mnt_opts = strdup(m->mnt_opts);
		entries[count].mnt_freq = m->mnt_freq;
		entries[count].mnt_passno = m->mnt_passno;
		count++;
	}
	endmntent(mountTable);
	if ((mountTable = setmntent(mtab_file, "w"))) {
		int i;

		for (i = 0; i < count; i++) {
			int result = (strcmp(entries[i].mnt_fsname, name) == 0
						  || strcmp(entries[i].mnt_dir, name) == 0);

			if (result)
				continue;
			else
				addmntent(mountTable, &entries[i]);
		}
		endmntent(mountTable);
	} else if (errno != EROFS)
		perror_msg("%s", mtab_file);
}
开发者ID:jhbsz,项目名称:actiontec_opensource_mi424wr-rev-acd-56-0-10-14-4,代码行数:41,代码来源:mtab.c


示例14: erase_mtab

void FAST_FUNC erase_mtab(const char *name)
{
	struct mntent *entries;
	int i, count;
	FILE *mountTable;
	struct mntent *m;

	mountTable = setmntent(bb_path_mtab_file, "r");
	/* Bummer. Fall back on trying the /proc filesystem */
	if (!mountTable) mountTable = setmntent("/proc/mounts", "r");
	if (!mountTable) {
		bb_perror_msg(bb_path_mtab_file);
		return;
	}

	entries = NULL;
	count = 0;
	while ((m = getmntent(mountTable)) != 0) {
		entries = xrealloc_vector(entries, 3, count);
		entries[count].mnt_fsname = xstrdup(m->mnt_fsname);
		entries[count].mnt_dir = xstrdup(m->mnt_dir);
		entries[count].mnt_type = xstrdup(m->mnt_type);
		entries[count].mnt_opts = xstrdup(m->mnt_opts);
		entries[count].mnt_freq = m->mnt_freq;
		entries[count].mnt_passno = m->mnt_passno;
		count++;
	}
	endmntent(mountTable);

//TODO: make update atomic
	mountTable = setmntent(bb_path_mtab_file, "w");
	if (mountTable) {
		for (i = 0; i < count; i++) {
			if (strcmp(entries[i].mnt_fsname, name) != 0
			 && strcmp(entries[i].mnt_dir, name) != 0)
				addmntent(mountTable, &entries[i]);
		}
		endmntent(mountTable);
	} else if (errno != EROFS)
		bb_perror_msg(bb_path_mtab_file);
}
开发者ID:dzo,项目名称:busybox,代码行数:41,代码来源:mtab.c


示例15: parse_fstab

static int parse_fstab(void) {
        FILE *f;
        int r = 0;
        struct mntent *me;

        errno = 0;
        f = setmntent("/etc/fstab", "r");
        if (!f) {
                if (errno == ENOENT)
                        return 0;

                log_error("Failed to open /etc/fstab: %m");
                return -errno;
        }

        while ((me = getmntent(f))) {
                char *where, *what;
                int k;

                what = fstab_node_to_udev_node(me->mnt_fsname);
                if (!what) {
                        r = log_oom();
                        goto finish;
                }

                where = strdup(me->mnt_dir);
                if (!where) {
                        r = log_oom();
                        free(what);
                        goto finish;
                }

                if (is_path(where))
                        path_kill_slashes(where);

                log_debug("Found entry what=%s where=%s type=%s", what, where, me->mnt_type);

                if (streq(me->mnt_type, "swap"))
                        k = add_swap(what, me);
                else
                        k = add_mount(what, where, me);

                free(what);
                free(where);

                if (k < 0)
                        r = k;
        }

finish:
        endmntent(f);
        return r;
}
开发者ID:intgr,项目名称:systemd,代码行数:53,代码来源:fstab-generator.c


示例16: fs_table_initialise_mounts

/*
 * If *path is NULL, initialize the fs table with all xfs mount points in mtab
 * If *path is specified, search for that path in mtab
 */
static int
fs_table_initialise_mounts(
	char		*path)
{
	struct mntent	*mnt;
	FILE		*mtp;
	char		*fslog, *fsrt;
	int		error, found;
	char		*rpath = NULL;

	error = found = 0;
	fslog = fsrt = NULL;

	if (!mtab_file) {
		mtab_file = PROC_MOUNTS;
		if (access(mtab_file, R_OK) != 0)
			mtab_file = MOUNTED;
	}

	if ((mtp = setmntent(mtab_file, "r")) == NULL)
		return ENOENT;

	/* Use realpath to resolve symlinks, relative paths, etc */
	if (path)
		if ((rpath = realpath(path, NULL)) == NULL)
			return ENOENT;

	while ((mnt = getmntent(mtp)) != NULL) {
		if (strcmp(mnt->mnt_type, "xfs") != 0)
			continue;
		if (path &&
		    ((strcmp(path, mnt->mnt_dir) != 0) &&
		     (strcmp(path, mnt->mnt_fsname) != 0) &&
		     (strcmp(rpath, mnt->mnt_dir) != 0) &&
		     (strcmp(rpath, mnt->mnt_fsname) != 0)))
			continue;
		if (fs_extract_mount_options(mnt, &fslog, &fsrt))
			continue;
		(void) fs_table_insert(mnt->mnt_dir, 0, FS_MOUNT_POINT,
					mnt->mnt_fsname, fslog, fsrt);
		if (path) {
			found = 1;
			break;
		}
	}
	endmntent(mtp);
	free(rpath);

	if (path && !found)
		error = ENXIO;

	return error;
}
开发者ID:Fleurer,项目名称:xfsprogs,代码行数:57,代码来源:paths.c


示例17: sys_path_to_bdev

static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
{
	int ret = -1;
	SMB_STRUCT_STAT S;
	FILE *fp;
	struct mntent *mnt;
	SMB_DEV_T devno;

	/* find the block device file */

	if (!path||!mntpath||!bdev||!fs)
		smb_panic("sys_path_to_bdev: called with NULL pointer");

	(*mntpath) = NULL;
	(*bdev) = NULL;
	(*fs) = NULL;
	
	if ( sys_stat(path, &S) == -1 )
		return (-1);

	devno = S.st_dev ;

	fp = setmntent(MOUNTED,"r");
	if (fp == NULL) {
		return -1;
	}
  
	while ((mnt = getmntent(fp))) {
		if ( sys_stat(mnt->mnt_dir,&S) == -1 )
			continue ;

		if (S.st_dev == devno) {
			(*mntpath) = SMB_STRDUP(mnt->mnt_dir);
			(*bdev) = SMB_STRDUP(mnt->mnt_fsname);
			(*fs)   = SMB_STRDUP(mnt->mnt_type);
			if ((*mntpath)&&(*bdev)&&(*fs)) {
				ret = 0;
			} else {
				SAFE_FREE(*mntpath);
				SAFE_FREE(*bdev);
				SAFE_FREE(*fs);
				ret = -1;
			}

			break;
		}
	}

	endmntent(fp) ;

	return ret;
}
开发者ID:jameshilliard,项目名称:WECB-BH-GPL,代码行数:52,代码来源:sysquotas.c


示例18: glibtop_get_mountlist_s

glibtop_mountentry *
glibtop_get_mountlist_s(glibtop *server, glibtop_mountlist *buf, int all_fs)
{
  const struct mntent *mnt;
  FILE *fp;
  GArray* entries;
  IgnoreList* ig = NULL;

  memset(buf, 0, sizeof(glibtop_mountlist));

  /* wild guess, preallocate 8 entries
     on a desktop, almost everyone has / and a tmpfs for udev
     if all_fs, there are also proc, sys, fuse, binfmt, etc */
  entries = g_array_sized_new(FALSE, FALSE, sizeof(glibtop_mountentry), 8);

  if (!(fp = setmntent(MOUNTED, "r"))) {
      glibtop_warn_io_r(server, "Could not open %s", MOUNTED);
      goto out;
    }

  while ((mnt = getmntent(fp)))
    {
      glibtop_mountentry *me;
      gsize len;

      if (!all_fs && ignore_fs(mnt->mnt_type, &ig))
	continue;

      len = entries->len;
      g_array_set_size(entries, len + 1);
      me = &g_array_index(entries, glibtop_mountentry, len);

      g_strlcpy(me->devname, mnt->mnt_fsname, sizeof me->devname);
      g_strlcpy(me->mountdir, mnt->mnt_dir, sizeof me->mountdir);
      g_strlcpy(me->type, mnt->mnt_type, sizeof me->type);
    }

    endmntent(fp);


  out:
    ignore_list_delete(ig);

    buf->size = sizeof(glibtop_mountentry);
    buf->number = entries->len;
    buf->total = buf->number * buf->size;
    buf->flags = (1 << GLIBTOP_MOUNTLIST_SIZE)
    | (1 << GLIBTOP_MOUNTLIST_NUMBER)
    | (1 << GLIBTOP_MOUNTLIST_TOTAL);

  return (glibtop_mountentry*) g_array_free(entries, FALSE);
}
开发者ID:GNOME,项目名称:libgtop,代码行数:52,代码来源:mountlist.c


示例19: setmntent

bool ManagerWindow::checkUmProc()
{
    FILE *fp = setmntent("/proc/mounts","r");
    struct mntent *fs;
    bool umproc_loaded = false;
    while ((fs = getmntent(fp))  !=  NULL) /* detect if /proc/mounts is mounted by umproc */
    {
      if(!(strcmp(fs->mnt_fsname,"none") || strcmp(fs->mnt_dir,"/proc/mounts") || strcmp(fs->mnt_type,"proc")))
                      umproc_loaded = true;
    }
    endmntent(fp);
    return umproc_loaded;
}
开发者ID:Morgawr,项目名称:ViewFS-Manager,代码行数:13,代码来源:managerwindow.cpp


示例20: check_mtab_entry

int check_mtab_entry(char *spec1, char *spec2, char *mtpt, char *type)
{
	FILE *fp;
	struct mntent *mnt;

	fp = setmntent(MOUNTED, "r");
	if (fp == NULL)
		return 0;

	while ((mnt = getmntent(fp)) != NULL) {
		if ((strcmp(mnt->mnt_fsname, spec1) == 0 ||
		     strcmp(mnt->mnt_fsname, spec2) == 0) &&
		    (mtpt == NULL || strcmp(mnt->mnt_dir, mtpt) == 0) &&
		    (type == NULL || strcmp(mnt->mnt_type, type) == 0)) {
			endmntent(fp);
			return(EEXIST);
		}
	}
	endmntent(fp);

	return 0;
}
开发者ID:dinatale2,项目名称:lustre-stable,代码行数:22,代码来源:mount_utils.c



注:本文中的endmntent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ endpoint函数代码示例发布时间:2022-05-30
下一篇:
C++ endlog函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap