header.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include "sky.h"
  13. #define JUKEFS "tcp!jukefs" /* dial string for jukebox; was il!jukefs */
  14. struct
  15. {
  16. char name[9];
  17. char offset;
  18. } Hproto[] =
  19. {
  20. "ppo1", Pppo1,
  21. "ppo2", Pppo2,
  22. "ppo3", Pppo3,
  23. "ppo4", Pppo4,
  24. "ppo5", Pppo5,
  25. "ppo6", Pppo6,
  26. "amdx1", Pamdx1,
  27. "amdx2", Pamdx2,
  28. "amdx3", Pamdx3,
  29. "amdx4", Pamdx4,
  30. "amdx5", Pamdx5,
  31. "amdx6", Pamdx6,
  32. "amdx7", Pamdx7,
  33. "amdx8", Pamdx8,
  34. "amdx9", Pamdx9,
  35. "amdx10", Pamdx10,
  36. "amdx11", Pamdx11,
  37. "amdx12", Pamdx12,
  38. "amdx13", Pamdx13,
  39. "amdx14", Pamdx14,
  40. "amdx15", Pamdx15,
  41. "amdx16", Pamdx16,
  42. "amdx17", Pamdx17,
  43. "amdx18", Pamdx18,
  44. "amdx19", Pamdx19,
  45. "amdx20", Pamdx20,
  46. "amdy1", Pamdy1,
  47. "amdy2", Pamdy2,
  48. "amdy3", Pamdy3,
  49. "amdy4", Pamdy4,
  50. "amdy5", Pamdy5,
  51. "amdy6", Pamdy6,
  52. "amdy7", Pamdy7,
  53. "amdy8", Pamdy8,
  54. "amdy9", Pamdy9,
  55. "amdy10", Pamdy10,
  56. "amdy11", Pamdy11,
  57. "amdy12", Pamdy12,
  58. "amdy13", Pamdy13,
  59. "amdy14", Pamdy14,
  60. "amdy15", Pamdy15,
  61. "amdy16", Pamdy16,
  62. "amdy17", Pamdy17,
  63. "amdy18", Pamdy18,
  64. "amdy19", Pamdy19,
  65. "amdy20", Pamdy20,
  66. "pltscale", Ppltscale,
  67. "xpixelsz", Pxpixelsz,
  68. "ypixelsz", Pypixelsz,
  69. "pltrah", Ppltrah,
  70. "pltram", Ppltram,
  71. "pltras", Ppltras,
  72. "pltdecd", Ppltdecd,
  73. "pltdecm", Ppltdecm,
  74. "pltdecs", Ppltdecs,
  75. };
  76. Header*
  77. getheader(char *rgn)
  78. {
  79. char rec[81], name[81], value[81];
  80. char *p;
  81. Biobuf *bin;
  82. Header hd, *h;
  83. int i, j, decsn, dss;
  84. dss = 0;
  85. sprint(rec, "/lib/sky/dssheaders/%s.hhh", rgn);
  86. bin = Bopen(rec, OREAD);
  87. if(bin == 0) {
  88. dss = 102;
  89. sprint(rec, "/n/juke/dss/dss.102/headers/%s.hhh", rgn);
  90. bin = Bopen(rec, OREAD);
  91. }
  92. if(bin == 0) {
  93. dss = 61;
  94. sprint(rec, "/n/juke/dss/dss.061/headers/%s.hhh", rgn);
  95. bin = Bopen(rec, OREAD);
  96. }
  97. if(bin == 0) {
  98. fprint(2, "cannot open %s\n", rgn);
  99. exits("file");
  100. }
  101. if(debug)
  102. Bprint(&bout, "reading %s\n", rec);
  103. if(dss)
  104. Bprint(&bout, "warning: reading %s from jukebox\n", rec);
  105. memset(&hd, 0, sizeof(hd));
  106. j = 0;
  107. decsn = 0;
  108. for(;;) {
  109. if(dss) {
  110. if(Bread(bin, rec, 80) != 80)
  111. break;
  112. rec[80] = 0;
  113. } else {
  114. p = Brdline(bin, '\n');
  115. if(p == 0)
  116. break;
  117. p[Blinelen(bin)-1] = 0;
  118. strcpy(rec, p);
  119. }
  120. p = strchr(rec, '/');
  121. if(p)
  122. *p = 0;
  123. p = strchr(rec, '=');
  124. if(p == 0)
  125. continue;
  126. *p++ = 0;
  127. if(getword(name, rec) == 0)
  128. continue;
  129. if(getword(value, p) == 0)
  130. continue;
  131. if(strcmp(name, "pltdecsn") == 0) {
  132. if(strchr(value, '-'))
  133. decsn = 1;
  134. continue;
  135. }
  136. for(i=0; i<nelem(Hproto); i++) {
  137. j++;
  138. if(j >= nelem(Hproto))
  139. j = 0;
  140. if(strcmp(name, Hproto[j].name) == 0) {
  141. hd.param[Hproto[j].offset] = atof(value);
  142. break;
  143. }
  144. }
  145. }
  146. Bterm(bin);
  147. hd.param[Ppltra] = RAD(hd.param[Ppltrah]*15 +
  148. hd.param[Ppltram]/4 + hd.param[Ppltras]/240);
  149. hd.param[Ppltdec] = RAD(hd.param[Ppltdecd] +
  150. hd.param[Ppltdecm]/60 + hd.param[Ppltdecs]/3600);
  151. if(decsn)
  152. hd.param[Ppltdec] = -hd.param[Ppltdec];
  153. hd.amdflag = 0;
  154. for(i=Pamdx1; i<=Pamdx20; i++)
  155. if(hd.param[i] != 0) {
  156. hd.amdflag = 1;
  157. break;
  158. }
  159. h = malloc(sizeof(*h));
  160. *h = hd;
  161. return h;
  162. }
  163. void
  164. getplates(void)
  165. {
  166. char rec[81], *q;
  167. Plate *p;
  168. Biobuf *bin;
  169. int c, i, dss;
  170. dss = 0;
  171. sprint(rec, "/lib/sky/dssheaders/lo_comp.lis");
  172. bin = Bopen(rec, OREAD);
  173. if(bin == 0) {
  174. dss = 102;
  175. sprint(rec, "%s/headers/lo_comp.lis", dssmount(dss));
  176. bin = Bopen(rec, OREAD);
  177. }
  178. if(bin == 0) {
  179. dss = 61;
  180. sprint(rec, "%s/headers/lo_comp.lis", dssmount(dss));
  181. bin = Bopen(rec, OREAD);
  182. }
  183. if(bin == 0) {
  184. fprint(2, "can't open lo_comp.lis; try 9fs juke\n");
  185. exits("open");
  186. }
  187. if(debug)
  188. Bprint(&bout, "reading %s\n", rec);
  189. if(dss)
  190. Bprint(&bout, "warning: reading %s from jukebox\n", rec);
  191. for(nplate=0;;) {
  192. if(dss) {
  193. if(Bread(bin, rec, 80) != 80)
  194. break;
  195. rec[80] = 0;
  196. } else {
  197. q = Brdline(bin, '\n');
  198. if(q == 0)
  199. break;
  200. q[Blinelen(bin)-1] = 0;
  201. strcpy(rec, q);
  202. }
  203. if(rec[0] == '#')
  204. continue;
  205. if(nplate < nelem(plate)) {
  206. p = &plate[nplate];
  207. memmove(p->rgn, rec+0, 5);
  208. if(p->rgn[4] == ' ')
  209. p->rgn[4] = 0;
  210. for(i=0; c=p->rgn[i]; i++)
  211. if(c >= 'A' && c <= 'Z')
  212. p->rgn[i] += 'a'-'A';
  213. p->ra = RAD(atof(rec+12)*15 +
  214. atof(rec+15)/4 +
  215. atof(rec+18)/240);
  216. p->dec = RAD(atof(rec+26) +
  217. atof(rec+29)/60 +
  218. atof(rec+32)/3600);
  219. if(rec[25] == '-')
  220. p->dec = -p->dec;
  221. p->disk = atoi(rec+53);
  222. if(p->disk == 0)
  223. continue;
  224. }
  225. nplate++;
  226. }
  227. Bterm(bin);
  228. if(nplate >= nelem(plate))
  229. fprint(2, "nplate too small %d %d\n", nelem(plate), nplate);
  230. if(debug)
  231. Bprint(&bout, "%d plates\n", nplate);
  232. }
  233. char*
  234. dssmount(int dskno)
  235. {
  236. char dssname[100];
  237. int s1, s2, count;
  238. static int sdiskno = -1;
  239. if(sdiskno == dskno)
  240. goto out;
  241. count = 0;
  242. loop:
  243. unmount(nil, "/n/njuke");
  244. unmount(nil, "/n/dss");
  245. sprint(dssname, "/n/njuke/juke/dss/dss.%.3d", dskno);
  246. /*
  247. * start nfs jukebox server
  248. */
  249. s1 = open("/srv/" JUKEFS, ORDWR);
  250. if(s1 < 0) {
  251. if(fork() == 0) {
  252. execl("/bin/srv", "srv", "-q", JUKEFS, nil);
  253. exits(0);
  254. }
  255. waitpid();
  256. s1 = open("/srv/" JUKEFS, ORDWR);
  257. if(s1 < 0) {
  258. Bprint(&bout, "can't open /srv/%s: %r\n", JUKEFS);
  259. goto out;
  260. }
  261. }
  262. /*
  263. * mount nfs jukebox server
  264. */
  265. if(mount(s1, -1, "/n/njuke", 0, "", 'M') < 0) {
  266. close(s1);
  267. Bprint(&bout, "\"mount /srv/%s /n/juke\" failed: %r\n", JUKEFS);
  268. goto out;
  269. }
  270. /*
  271. * run 9660 server
  272. */
  273. s2 = open("/srv/9660", ORDWR);
  274. if(s2 < 0) {
  275. if(fork() == 0) {
  276. execl("/bin/9660srv", "9660srv", nil);
  277. exits(0);
  278. }
  279. waitpid();
  280. s2 = open("/srv/9660", ORDWR);
  281. if(s2 < 0) {
  282. Bprint(&bout, "can't open /srv/9660: %r\n");
  283. goto out;
  284. }
  285. }
  286. /*
  287. * mount 9660 server
  288. */
  289. if(mount(s2, -1, "/n/dss", 0, dssname, 'M') < 0) {
  290. close(s2);
  291. if(count == 0) {
  292. // do it again so /n/njuke is in 9660's namespace
  293. remove("/srv/9660");
  294. remove("/srv/" JUKEFS);
  295. count = 1;
  296. goto loop;
  297. }
  298. Bprint(&bout, "\"mount /srv/9660 /n/dss %s\" failed %r\n", dssname);
  299. goto out;
  300. }
  301. // print("mount %s\n", dssname);
  302. sdiskno = dskno;
  303. out:
  304. return "/n/dss";
  305. }