Skip to content

Commit 0b46e2e

Browse files
committed
--
1 parent b02b16f commit 0b46e2e

15 files changed

+4030
-3154
lines changed

Makefile

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
all: lib mtnd fuse tool test
1+
all: lib mtnd mtnfs tool test
2+
3+
lib: libmtn.c libmtn.h
4+
gcc -c -Wall libmtn.c
5+
ar r libmtn.a libmtn.o
26

37
mtnd: mtnd.c lib
4-
gcc -DMODULE_NAME=\"mtnd\" -o mtnd mtnd.c libmtnfs.a
8+
gcc -DMODULE_NAME=\"mtnd\" -o mtnd -Wall mtnd.c common.c libmtn.a
59

6-
fuse: mtnmount.c lib
7-
gcc -DMODULE_NAME=\"mtnmount\" -lfuse -o mtnmount mtnmount.c libmtnfs.a -I/usr/klab/app/fuse/include -L/usr/klab/app/fuse/lib
10+
mtnfs: mtnfs.c lib
11+
gcc -DMODULE_NAME=\"mtnfs\" -o mtnfs -Wall -l fuse mtnfs.c common.c libmtn.a -I. -I/usr/klab/app/fuse/include -L/usr/klab/app/fuse/lib
812

913
tool: mtntool.c lib
10-
gcc -DMODULE_NAME=\"mtntool\" -o mtntool mtntool.c libmtnfs.a
11-
12-
lib: libmtnfs.c common.c mtnfs.h common.h
13-
gcc -c common.c
14-
gcc -c libmtnfs.c
15-
ar r libmtnfs.a libmtnfs.o common.o
14+
gcc -DMODULE_NAME=\"mtntool\" -o mtntool -I. mtntool.c libmtn.a
1615

1716
test: mtntest.c mtnd fuse
18-
gcc -DMODULE_NAME=\"mtntest\" -o mtntest mtntest.c libmtnfs.a
17+
gcc -DMODULE_NAME=\"mtntest\" -o mtntest -I. mtntest.c libmtn.a
1918

2019
clean:
21-
rm -f mtnd mtntool mtnmount libmtnfs.a mtntest *.o
20+
rm -f libmtn.a mtnd mtnfs mtntool mtntest *.o
2221

2322
sync:
2423
rsync -a *.c *.h Makefile adc:LOCAL/mtnfs/
2524
ssh adc "cd LOCAL/mtnfs/;make"
2625

2726
install:
28-
rsync -a mtnd /usr/klab/sbin/mtnd
29-
rsync -a mtnmount /usr/klab/sbin/mtnmount
30-
rsync -a mtntool /usr/klab/sbin/mtntool
31-
chown root:root /usr/klab/sbin/mtnd
32-
chown root:root /usr/klab/sbin/mtnmount
33-
chown root:root /usr/klab/sbin/mtntool
27+
rsync -a mtnd /usr/klab/sbin/mtnd
28+
rsync -a mtnfs /usr/klab/sbin/mtnfs
29+
rsync -a mtntool /usr/klab/sbin/mtntool
30+
chown root:root /usr/klab/sbin/mtnd
31+
chown root:root /usr/klab/sbin/mtnfs
32+
chown root:root /usr/klab/sbin/mtntool

common.c

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* common.c
3+
* Copyright (C) 2011 KLab Inc.
4+
*/
5+
#define _GNU_SOURCE
6+
#define _FILE_OFFSET_BITS 64
7+
#include "mtn.h"
8+
#include "libmtn.h"
9+
#include "common.h"
10+
11+
void dirbase(const char *path, char *d, char *f)
12+
{
13+
char b[PATH_MAX];
14+
if(d){
15+
strcpy(b, path);
16+
strcpy(d, dirname(b));
17+
}
18+
if(f){
19+
strcpy(b, path);
20+
strcpy(f, basename(b));
21+
}
22+
}
23+
24+
int mkpidfile(char *path)
25+
{
26+
FILE *fd;
27+
if(strlen(path)){
28+
if((fd = fopen(path, "w"))){
29+
fprintf(fd, "%d\n", getpid());
30+
fclose(fd);
31+
}else{
32+
mtnlogger(NULL, 0, "[error] %s: %s %s\n", __func__, strerror(errno), path);
33+
return(1);
34+
}
35+
}
36+
return(0);
37+
}
38+
39+
int rmpidfile(char *pidfile)
40+
{
41+
if(strlen(pidfile)){
42+
unlink(pidfile);
43+
}
44+
return(0);
45+
}
46+
47+
uint64_t atoikmg(char *str)
48+
{
49+
int unit = 1;
50+
uint64_t val;
51+
char buff[1024];
52+
char *p = buff;
53+
strcpy(buff, str);
54+
while(*p){
55+
if((*p >= '0') && (*p <= '9')){
56+
p++;
57+
continue;
58+
}
59+
switch(*p){
60+
case 'K':
61+
unit = 1024;
62+
break;
63+
case 'M':
64+
unit = 1024 * 1024;
65+
break;
66+
case 'G':
67+
unit = 1024 * 1024 * 1024;
68+
break;
69+
}
70+
*p = 0;
71+
}
72+
val = atoi(buff);
73+
return(val * unit);
74+
}
75+
76+
int mkdir_ex(const char *path)
77+
{
78+
struct stat st;
79+
char d[PATH_MAX];
80+
char f[PATH_MAX];
81+
dirbase(path,d,f);
82+
if(stat(path, &st) == 0){
83+
return(0);
84+
}
85+
if(stat(d, &st) == -1){
86+
if(mkdir_ex(d) == -1){
87+
return(-1);
88+
}
89+
}
90+
return(mkdir(path, 0755));
91+
}
92+

common.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* common.h
3+
* Copyright (C) 2011 KLab Inc.
4+
*/
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <stdint.h>
8+
#include <unistd.h>
9+
#include <limits.h>
10+
#include <string.h>
11+
#include <libgen.h>
12+
#include <errno.h>
13+
#include <sys/stat.h>
14+
#include <sys/types.h>
15+
void dirbase(const char *path, char *d, char *f);
16+
int mkpidfile(char *path);
17+
int rmpidfile(char *path);
18+
uint64_t atoikmg(char *str);
19+
int mkdir_ex(const char *path);

0 commit comments

Comments
 (0)