FireBirdLib - Topfield TMS PVR TAP Programming Library
HDD_FindMountPointDevice.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <mntent.h>
4#include <string.h>
5#include "libFireBird.h"
6
7bool HDD_FindMountPointDevice(const char *File, char *MountPoint, char *MountDevice)
8{
10
11 struct mntent *ent;
12 FILE *aFile;
13 char AbsFile[FBLIB_DIR_SIZE], Root[FBLIB_DIR_SIZE], Dev[FBLIB_DIR_SIZE];
14 char *x;
15
16 Root[0] = '\0';
17 Dev[0] = '\0';
18 AbsFile[0] = '\0';
19 ConvertPathType(File, AbsFile, PF_LinuxPathOnly);
20 if(*AbsFile)
21 {
22 aFile = setmntent("/proc/mounts", "r");
23 if(aFile != NULL)
24 {
25 while(NULL != (ent = getmntent(aFile)))
26 {
27 x = ansicstr(ent->mnt_dir, strlen(ent->mnt_dir), 0, NULL, NULL);
28 if(x)
29 {
30 if((strstr(AbsFile, x) == AbsFile) && (strlen(x) > strlen(Root)))
31 {
32 strcpy(Root, x);
33 strcpy(Dev, ent->mnt_fsname);
34 }
35 TAP_MemFree(x);
36 }
37 else if((strstr(AbsFile, ent->mnt_dir) == AbsFile) && (strlen(ent->mnt_dir) > strlen(Root)))
38 {
39 strcpy(Root, ent->mnt_dir);
40 strcpy(Dev, ent->mnt_fsname);
41 }
42 }
43 endmntent(aFile);
44 }
45 }
46
47 if(*Root && (Root[strlen(Root) - 1] != '/')) strcat(Root, "/");
48 if(*Dev && (Dev[strlen(Dev) - 1] != '/')) strcat(Dev, "/");
49
50 if(MountPoint) strcpy(MountPoint, Root);
51 if(MountDevice) strcpy(MountDevice, Dev);
52
53 TRACEEXIT();
54 return (Root[0] != '\0' || Dev[0] != '\0');
55}
void ConvertPathType(const char *Source, char *Dest, tPathFormat DestFormat)
struct __STDIO_FILE_STRUCT FILE
Definition: FBLib_hdd.h:137
bool HDD_FindMountPointDevice(const char *File, char *MountPoint, char *MountDevice)
char * ansicstr(const char *string, int len, int flags, int *sawc, int *rlen)
Definition: ansicstr.c:32
#define FBLIB_DIR_SIZE
Definition: libFireBird.h:1871
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
@ PF_LinuxPathOnly
Definition: libFireBird.h:1924