~cyphermox/mtp/images

« back to all changes in this revision

Viewing changes to server/server.cpp

  • Committer: Mathieu Trudel-Lapierre
  • Date: 2013-09-11 14:40:53 UTC
  • Revision ID: mathieu-tl@ubuntu.com-20130911144053-l909kntbwpyxgqq9
Un-hardcode paths and user info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#include <sys/stat.h>
11
11
#include <fcntl.h>
12
12
#include <unistd.h>
 
13
#include <pwd.h>
13
14
 
14
15
namespace
15
16
{
16
17
struct FileSystemConfig
17
18
{
18
 
    static const int file_group = 32011; // phablet user.
19
19
    static const int file_perm = 0664;
20
20
    static const int directory_perm = 0755;
21
21
};
22
22
 
23
 
android::MtpStorage* home_storage = new android::MtpStorage(
24
 
    MTP_STORAGE_FIXED_RAM, 
25
 
    "/home/phablet",
26
 
    "Local storage", 
27
 
    1024 * 1024 * 100,  /* 100 MB reserved space, to avoid filling the disk */
28
 
    false,
29
 
    1024 * 1024 * 1024 * 2  /* 2GB arbitrary max file size */);
 
23
android::MtpStorage* home_storage;
 
24
 
30
25
}
31
26
 
32
27
int main(int argc, char** argv)
33
28
{
 
29
    struct passwd *userdata = getpwuid (getuid());
34
30
    int fd = open("/dev/mtp_usb", O_RDWR);
35
31
    
36
32
    if (fd < 0)
38
34
        std::cout << "Error opening /dev/mtp_usb, aborting now..." << std::endl;
39
35
    }
40
36
        
 
37
    home_storage = new android::MtpStorage(
 
38
        MTP_STORAGE_FIXED_RAM, 
 
39
        userdata->pw_dir,
 
40
        userdata->pw_name, 
 
41
        1024 * 1024 * 100,  /* 100 MB reserved space, to avoid filling the disk */
 
42
        false,
 
43
        1024 * 1024 * 1024 * 2  /* 2GB arbitrary max file size */);
 
44
 
41
45
    std::shared_ptr<android::MtpServer> server
42
46
    {
43
47
        new android::MtpServer(
44
48
            fd, 
45
 
            new android::UbuntuMtpDatabase(),
 
49
            new android::UbuntuMtpDatabase(userdata->pw_dir),
46
50
            false, 
47
 
            FileSystemConfig::file_group, 
 
51
            userdata->pw_gid, 
48
52
            FileSystemConfig::file_perm, 
49
53
            FileSystemConfig::directory_perm)
50
54
    };