summaryrefslogtreecommitdiff
path: root/volname.c
blob: a8de754e8ab9eb0dd51cde9d94ca9d6fc5d04ff1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * dvdswitch plugin for VDR (C++)
 *
 * (C) 2010 Andreas Brachold <vdr07 AT deltab de>
 *
 * This dvdswitch plugin is free software: you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as published 
 * by the Free Software Foundation, version 2 of the License.
 *
 * See the files README and COPYING for details.
 *
 */

#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int volname(const char* device, char* volname, size_t volsize)
{
  int fd;
  int status;
  char buffer[PATH_MAX];

  if(!realpath(device, buffer)) {
    return errno;
  }

  fd = open(device, O_RDONLY);
  if (fd == -1) {
    return errno;
  }

  status = lseek(fd, 32808, SEEK_SET);
  if (status == -1) {
    status = errno;
    close(fd);
    return status;
  }

  status = read(fd, volname, volsize > 32 ? 32 : volsize);
  if (status == -1) {
    status = errno;
    close(fd);
    return status;
  }

  close(fd);
  return 0;
}