/[gnokii]/gnokiifs/gnokiifs.cpp
ViewVC logotype

Diff of /gnokiifs/gnokiifs.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by edrosten, Thu Mar 31 18:54:13 2005 UTC revision 1.3 by edrosten, Mon Jun 13 13:28:44 2005 UTC
# Line 34  using namespace std; Line 34  using namespace std;
34    
35  //Default values  //Default values
36  #define CODA_DEV "/dev/cfs0"  #define CODA_DEV "/dev/cfs0"
37    #define MOUNTPOINT "/mnt/phone"
38    #define MOUNTFLAGS ""
39    #define UMOUNTFLAGS "-l"
40  #define TMP_PERM 0600  #define TMP_PERM 0600
41  #define FILE_PERM 0666  #define FILE_PERM 0600
42  #define DIR_PERM 0777  #define DIR_PERM 0700
43  #define CLOSED_FILE_TIMEOUT 600 //After 10 minutes, closed files become stale  #define CLOSED_FILE_TIMEOUT 600 //After 10 minutes, closed files become stale
44    
45  #define DEBUG  #define DEBUG
# Line 95  int get_attributes(CodaFid fid); Line 98  int get_attributes(CodaFid fid);
98  int deletefile(string filename);  int deletefile(string filename);
99  int putfile(string phone, string real);  int putfile(string phone, string real);
100  int replacefile(string phone, string real);  int replacefile(string phone, string real);
101    void do_mounting(string command, pid_t pid);
102  string fetch_a_file(string fullname);  string fetch_a_file(string fullname);
103  string convert_remote_dir_to_local_file(string fullname);  string convert_remote_dir_to_local_file(string fullname);
104  static void busterminate(void);  static void busterminate(void);
105    static void umount_phone(void);
106  static void businit(void);  static void businit(void);
107    static void mount_failed(int sig);
108    
109    
110  /******************************************************************************  /******************************************************************************
111  *  *
# Line 114  static char *lockfile = NULL; Line 121  static char *lockfile = NULL;
121  //Runtime configurable data  //Runtime configurable data
122  struct  struct
123  {  {
124          bool debug;          bool debug, do_mounting;
125          long file_perm, dir_perm, closed_file_timeout;          long file_perm, dir_perm, closed_file_timeout;
126          string coda_device;          string coda_device, umount_flags;
127            string mount_point;
128  } config;  } config;
129    
130    
# Line 171  static struct coda_vattr default_vatts= Line 179  static struct coda_vattr default_vatts=
179    
180  /********************************************************************************/  /********************************************************************************/
181    
182    
183    
184    
185    
186    
187  int main(int argc, char** argv)  int main(int argc, char** argv)
188  {  {
189          do_options(argc, argv);          do_options(argc, argv);
# Line 182  int main(int argc, char** argv) Line 195  int main(int argc, char** argv)
195          union inputArgs& request=*(union inputArgs*)inbuf;          union inputArgs& request=*(union inputArgs*)inbuf;
196          union outputArgs reply;          union outputArgs reply;
197    
198            
199            TDEBUG("Opening CODA device: " << config.coda_device);
200          fd = open(config.coda_device.c_str(), O_RDWR);          fd = open(config.coda_device.c_str(), O_RDWR);
201          check_error(fd);  
202            if(fd == -1)
203            {
204                    cerr << "Failed to open CODA device: " <<       config.coda_device << ": " << strerror(errno) << endl;
205                    exit(1);
206            }
207    
208            if(config.do_mounting)
209            {
210                    TDEBUG("Mounting " << config.coda_device << " " << config.mount_point);
211                    ostringstream m;
212                    m << "mount " << config.mount_point;
213                    TDEBUG("Issuing command: " << m.str());
214    
215                    pid_t current_pid, fork_pid;
216    
217                    //we will receive USR1 if the mount fails.      
218                    signal(SIGUSR1, mount_failed);
219    
220                    current_pid = getpid();
221                    fork_pid = fork();
222    
223                    if(fork_pid == 0)
224                            do_mounting(m.str(), current_pid);
225                    else if(fork_pid == -1)
226                    {      
227                            cerr << "Could not create process to mount filesystem: " << strerror(errno) << endl;
228                            exit(1);
229                    }
230    
231            }
232    
233          TDEBUG("sizeof(request) = " <<  sizeof(request));          TDEBUG("sizeof(request) = " <<  sizeof(request));
234          TDEBUG("Starting loop");          TDEBUG("Starting loop");
# Line 220  int main(int argc, char** argv) Line 265  int main(int argc, char** argv)
265                                  {                                  {
266                                          businit();                                          businit();
267                                          bus_inited=true;                                          bus_inited=true;
268                                            atexit(umount_phone);
269                                  }                                  }
270    
271                                  TDEBUG("Command = root");                                  TDEBUG("Command = root");
# Line 520  int main(int argc, char** argv) Line 566  int main(int argc, char** argv)
566    
567    
568  /* GNOKII library deinitialisztion copied from gnokii.c */  /* GNOKII library deinitialisztion copied from gnokii.c */
   
569  static void busterminate(void)  static void busterminate(void)
570  {  {
571          TDEBUG("Terminating bus");          TDEBUG("Terminating bus");
# Line 528  static void busterminate(void) Line 573  static void busterminate(void)
573          if (lockfile) gn_device_unlock(lockfile);          if (lockfile) gn_device_unlock(lockfile);
574  }  }
575    
   
576  /* Shutdown cleanly, shudtown functions registered with atexit */  /* Shutdown cleanly, shudtown functions registered with atexit */
577    static void mount_failed(int sig)
578    {
579            TDEBUG("Mount failed.");
580            cerr << "Could not mount phone on " << config.mount_point << ". Terminating...\n";
581            interrupted(sig);
582    }
583    
584    //Unmount phone
585    static void umount_phone()
586    {
587            TDEBUG("Unmounting phone");
588            string umount = "umount " + config.umount_flags + " " + config.mount_point;
589            if(system(umount.c_str()) != 0)
590            {
591                    cerr << "Failed to unmount phone.\n";
592            }
593    }
594    
595    /* Shutdown cleanly, shudtown functions registered with atexit */
596  static void interrupted(int sig)  static void interrupted(int sig)
597  {  {
598          signal(sig, SIG_IGN);          signal(sig, SIG_IGN);
# Line 959  string  convert_remote_dir_to_local_file Line 1021  string  convert_remote_dir_to_local_file
1021          return convert_dir_listing_to_local_file(listing);          return convert_dir_listing_to_local_file(listing);
1022  }  }
1023    
1024    void do_mounting(string mount_command, pid_t parent_pid)
1025    {
1026            if(system(mount_command.c_str()) != 0)
1027            {      
1028                    //If mount failed, then signal the gnokiifs process about it.
1029                    kill(parent_pid, SIGUSR1);
1030            }
1031    
1032            exit(0);
1033    }
1034    
1035  //Delete a remote file  //Delete a remote file
1036  int deletefile(string filename)  int deletefile(string filename)
1037  {  {
# Line 1063  void do_options(int argc, char** argv) Line 1136  void do_options(int argc, char** argv)
1136          config.dir_perm = DIR_PERM;          config.dir_perm = DIR_PERM;
1137          config.coda_device = CODA_DEV;          config.coda_device = CODA_DEV;
1138          config.closed_file_timeout = CLOSED_FILE_TIMEOUT;          config.closed_file_timeout = CLOSED_FILE_TIMEOUT;
1139            config.mount_point = MOUNTPOINT;
1140            config.umount_flags = UMOUNTFLAGS;
1141            config.do_mounting = 1;
1142    
1143          char* opts =  "f:d:t:c:hD";          char* opts =  "f:d:t:c:M:hnD";
1144          char* prog = strrchr(argv[0], '/');          char* prog = strrchr(argv[0], '/');
1145          if(!prog)          if(!prog)
1146                  prog = argv[0];                  prog = argv[0];
1147          else          else
1148                  prog++;                  prog++;
1149    
1150          string help =          ostringstream helps;
1151  " [-f X | -d X | -c X | -t X | -h | -d]\n"          helps <<
1152    " [-f X ] [-d X ] [-c X ] [-t X ] [-M X] [-U X] [-hnD]\n"
1153  " -f X = file permission bits (use 0nnn for octal)\n"  " -f X = file permission bits (use 0nnn for octal)\n"
1154    "            default is: " << oct << config.file_perm << endl <<
1155  " -d X = directory permission bits\n"  " -d X = directory permission bits\n"
1156  " -c X = coda device file\n"  " -c X = coda device file\n"
1157    "            default is: " << oct << config.dir_perm << dec << endl <<
1158  " -t X = Time after which closed files are flushed from the cache in seconds.\n"  " -t X = Time after which closed files are flushed from the cache in seconds.\n"
1159    "            default is: " << config.closed_file_timeout << " seconds\n"
1160    " -M X = Mountpoint to mount filesystem.\n"
1161    "            default is: " << config.mount_point << endl <<
1162    " -U X = Unmount flags.\n"
1163    "            default is: " << config.umount_flags << endl <<
1164    " -n Do NOT perform filesystem mounting and unmounting.\n"
1165  " -D print very verbose debug messages (only if compiled in)\n"  " -D print very verbose debug messages (only if compiled in)\n"
1166  " -h print this message\n\n";  " -h print this message\n\n";
1167    
1168            string help = helps.str();
1169            
1170          while((opt = getopt(argc, argv, opts)) != -1)          while((opt = getopt(argc, argv, opts)) != -1)
1171          {          {
1172                  switch(opt)                  switch(opt)
# Line 1111  void do_options(int argc, char** argv) Line 1196  void do_options(int argc, char** argv)
1196                                  TDEBUG("Debugging output now enabled.");                                  TDEBUG("Debugging output now enabled.");
1197                                  break;                                    break;  
1198    
1199                            case 'M':
1200                                    config.mount_point = optarg;
1201                                    TDEBUG("Mount point is now: " <<  optarg << endl);
1202                                    break;
1203    
1204                            case 'U':
1205                                    config.umount_flags = optarg;
1206                                    TDEBUG("Umount flags are now: " << optarg << endl);
1207                                    break;
1208    
1209                            case 'n':
1210                                    config.do_mounting = 0;
1211                                    TDEBUG("Auto (un)mounting now disabled.");
1212                                    break;
1213    
1214                          case 'h':                          case 'h':
1215                                  cout << prog << help;                                  cout << prog << help;
1216                                  exit(0);                                  exit(0);

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26