ubd_kern.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. /*
  2. * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. /* 2001-09-28...2002-04-17
  6. * Partition stuff by James_McMechan@hotmail.com
  7. * old style ubd by setting UBD_SHIFT to 0
  8. * 2002-09-27...2002-10-18 massive tinkering for 2.5
  9. * partitions have changed in 2.5
  10. * 2003-01-29 more tinkering for 2.5.59-1
  11. * This should now address the sysfs problems and has
  12. * the symlink for devfs to allow for booting with
  13. * the common /dev/ubd/discX/... names rather than
  14. * only /dev/ubdN/discN this version also has lots of
  15. * clean ups preparing for ubd-many.
  16. * James McMechan
  17. */
  18. #define MAJOR_NR UBD_MAJOR
  19. #define UBD_SHIFT 4
  20. #include "linux/config.h"
  21. #include "linux/module.h"
  22. #include "linux/blkdev.h"
  23. #include "linux/hdreg.h"
  24. #include "linux/init.h"
  25. #include "linux/devfs_fs_kernel.h"
  26. #include "linux/cdrom.h"
  27. #include "linux/proc_fs.h"
  28. #include "linux/ctype.h"
  29. #include "linux/capability.h"
  30. #include "linux/mm.h"
  31. #include "linux/vmalloc.h"
  32. #include "linux/blkpg.h"
  33. #include "linux/genhd.h"
  34. #include "linux/spinlock.h"
  35. #include "asm/segment.h"
  36. #include "asm/uaccess.h"
  37. #include "asm/irq.h"
  38. #include "asm/types.h"
  39. #include "asm/tlbflush.h"
  40. #include "user_util.h"
  41. #include "mem_user.h"
  42. #include "kern_util.h"
  43. #include "kern.h"
  44. #include "mconsole_kern.h"
  45. #include "init.h"
  46. #include "irq_user.h"
  47. #include "irq_kern.h"
  48. #include "ubd_user.h"
  49. #include "2_5compat.h"
  50. #include "os.h"
  51. #include "mem.h"
  52. #include "mem_kern.h"
  53. #include "cow.h"
  54. enum ubd_req { UBD_READ, UBD_WRITE };
  55. struct io_thread_req {
  56. enum ubd_req op;
  57. int fds[2];
  58. unsigned long offsets[2];
  59. unsigned long long offset;
  60. unsigned long length;
  61. char *buffer;
  62. int sectorsize;
  63. unsigned long sector_mask;
  64. unsigned long long cow_offset;
  65. unsigned long bitmap_words[2];
  66. int error;
  67. };
  68. extern int open_ubd_file(char *file, struct openflags *openflags,
  69. char **backing_file_out, int *bitmap_offset_out,
  70. unsigned long *bitmap_len_out, int *data_offset_out,
  71. int *create_cow_out);
  72. extern int create_cow_file(char *cow_file, char *backing_file,
  73. struct openflags flags, int sectorsize,
  74. int alignment, int *bitmap_offset_out,
  75. unsigned long *bitmap_len_out,
  76. int *data_offset_out);
  77. extern int read_cow_bitmap(int fd, void *buf, int offset, int len);
  78. extern void do_io(struct io_thread_req *req);
  79. static inline int ubd_test_bit(__u64 bit, unsigned char *data)
  80. {
  81. __u64 n;
  82. int bits, off;
  83. bits = sizeof(data[0]) * 8;
  84. n = bit / bits;
  85. off = bit % bits;
  86. return((data[n] & (1 << off)) != 0);
  87. }
  88. static inline void ubd_set_bit(__u64 bit, unsigned char *data)
  89. {
  90. __u64 n;
  91. int bits, off;
  92. bits = sizeof(data[0]) * 8;
  93. n = bit / bits;
  94. off = bit % bits;
  95. data[n] |= (1 << off);
  96. }
  97. /*End stuff from ubd_user.h*/
  98. #define DRIVER_NAME "uml-blkdev"
  99. static DEFINE_SPINLOCK(ubd_io_lock);
  100. static DEFINE_SPINLOCK(ubd_lock);
  101. static void (*do_ubd)(void);
  102. static int ubd_open(struct inode * inode, struct file * filp);
  103. static int ubd_release(struct inode * inode, struct file * file);
  104. static int ubd_ioctl(struct inode * inode, struct file * file,
  105. unsigned int cmd, unsigned long arg);
  106. #define MAX_DEV (8)
  107. static struct block_device_operations ubd_blops = {
  108. .owner = THIS_MODULE,
  109. .open = ubd_open,
  110. .release = ubd_release,
  111. .ioctl = ubd_ioctl,
  112. };
  113. /* Protected by the queue_lock */
  114. static request_queue_t *ubd_queue;
  115. /* Protected by ubd_lock */
  116. static int fake_major = MAJOR_NR;
  117. static struct gendisk *ubd_gendisk[MAX_DEV];
  118. static struct gendisk *fake_gendisk[MAX_DEV];
  119. #ifdef CONFIG_BLK_DEV_UBD_SYNC
  120. #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \
  121. .cl = 1 })
  122. #else
  123. #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 0, .c = 0, \
  124. .cl = 1 })
  125. #endif
  126. /* Not protected - changed only in ubd_setup_common and then only to
  127. * to enable O_SYNC.
  128. */
  129. static struct openflags global_openflags = OPEN_FLAGS;
  130. struct cow {
  131. /* This is the backing file, actually */
  132. char *file;
  133. int fd;
  134. unsigned long *bitmap;
  135. unsigned long bitmap_len;
  136. int bitmap_offset;
  137. int data_offset;
  138. };
  139. struct ubd {
  140. char *file;
  141. int count;
  142. int fd;
  143. __u64 size;
  144. struct openflags boot_openflags;
  145. struct openflags openflags;
  146. int no_cow;
  147. struct cow cow;
  148. struct platform_device pdev;
  149. };
  150. #define DEFAULT_COW { \
  151. .file = NULL, \
  152. .fd = -1, \
  153. .bitmap = NULL, \
  154. .bitmap_offset = 0, \
  155. .data_offset = 0, \
  156. }
  157. #define DEFAULT_UBD { \
  158. .file = NULL, \
  159. .count = 0, \
  160. .fd = -1, \
  161. .size = -1, \
  162. .boot_openflags = OPEN_FLAGS, \
  163. .openflags = OPEN_FLAGS, \
  164. .no_cow = 0, \
  165. .cow = DEFAULT_COW, \
  166. }
  167. struct ubd ubd_dev[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = DEFAULT_UBD };
  168. static int ubd0_init(void)
  169. {
  170. struct ubd *dev = &ubd_dev[0];
  171. if(dev->file == NULL)
  172. dev->file = "root_fs";
  173. return(0);
  174. }
  175. __initcall(ubd0_init);
  176. /* Only changed by fake_ide_setup which is a setup */
  177. static int fake_ide = 0;
  178. static struct proc_dir_entry *proc_ide_root = NULL;
  179. static struct proc_dir_entry *proc_ide = NULL;
  180. static void make_proc_ide(void)
  181. {
  182. proc_ide_root = proc_mkdir("ide", NULL);
  183. proc_ide = proc_mkdir("ide0", proc_ide_root);
  184. }
  185. static int proc_ide_read_media(char *page, char **start, off_t off, int count,
  186. int *eof, void *data)
  187. {
  188. int len;
  189. strcpy(page, "disk\n");
  190. len = strlen("disk\n");
  191. len -= off;
  192. if (len < count){
  193. *eof = 1;
  194. if (len <= 0) return 0;
  195. }
  196. else len = count;
  197. *start = page + off;
  198. return len;
  199. }
  200. static void make_ide_entries(char *dev_name)
  201. {
  202. struct proc_dir_entry *dir, *ent;
  203. char name[64];
  204. if(proc_ide_root == NULL) make_proc_ide();
  205. dir = proc_mkdir(dev_name, proc_ide);
  206. if(!dir) return;
  207. ent = create_proc_entry("media", S_IFREG|S_IRUGO, dir);
  208. if(!ent) return;
  209. ent->nlink = 1;
  210. ent->data = NULL;
  211. ent->read_proc = proc_ide_read_media;
  212. ent->write_proc = NULL;
  213. sprintf(name,"ide0/%s", dev_name);
  214. proc_symlink(dev_name, proc_ide_root, name);
  215. }
  216. static int fake_ide_setup(char *str)
  217. {
  218. fake_ide = 1;
  219. return(1);
  220. }
  221. __setup("fake_ide", fake_ide_setup);
  222. __uml_help(fake_ide_setup,
  223. "fake_ide\n"
  224. " Create ide0 entries that map onto ubd devices.\n\n"
  225. );
  226. static int parse_unit(char **ptr)
  227. {
  228. char *str = *ptr, *end;
  229. int n = -1;
  230. if(isdigit(*str)) {
  231. n = simple_strtoul(str, &end, 0);
  232. if(end == str)
  233. return(-1);
  234. *ptr = end;
  235. }
  236. else if (('a' <= *str) && (*str <= 'h')) {
  237. n = *str - 'a';
  238. str++;
  239. *ptr = str;
  240. }
  241. return(n);
  242. }
  243. static int ubd_setup_common(char *str, int *index_out)
  244. {
  245. struct ubd *dev;
  246. struct openflags flags = global_openflags;
  247. char *backing_file;
  248. int n, err, i;
  249. if(index_out) *index_out = -1;
  250. n = *str;
  251. if(n == '='){
  252. char *end;
  253. int major;
  254. str++;
  255. if(!strcmp(str, "sync")){
  256. global_openflags = of_sync(global_openflags);
  257. return(0);
  258. }
  259. major = simple_strtoul(str, &end, 0);
  260. if((*end != '\0') || (end == str)){
  261. printk(KERN_ERR
  262. "ubd_setup : didn't parse major number\n");
  263. return(1);
  264. }
  265. err = 1;
  266. spin_lock(&ubd_lock);
  267. if(fake_major != MAJOR_NR){
  268. printk(KERN_ERR "Can't assign a fake major twice\n");
  269. goto out1;
  270. }
  271. fake_major = major;
  272. printk(KERN_INFO "Setting extra ubd major number to %d\n",
  273. major);
  274. err = 0;
  275. out1:
  276. spin_unlock(&ubd_lock);
  277. return(err);
  278. }
  279. n = parse_unit(&str);
  280. if(n < 0){
  281. printk(KERN_ERR "ubd_setup : couldn't parse unit number "
  282. "'%s'\n", str);
  283. return(1);
  284. }
  285. if(n >= MAX_DEV){
  286. printk(KERN_ERR "ubd_setup : index %d out of range "
  287. "(%d devices, from 0 to %d)\n", n, MAX_DEV, MAX_DEV - 1);
  288. return(1);
  289. }
  290. err = 1;
  291. spin_lock(&ubd_lock);
  292. dev = &ubd_dev[n];
  293. if(dev->file != NULL){
  294. printk(KERN_ERR "ubd_setup : device already configured\n");
  295. goto out;
  296. }
  297. if (index_out)
  298. *index_out = n;
  299. for (i = 0; i < 4; i++) {
  300. switch (*str) {
  301. case 'r':
  302. flags.w = 0;
  303. break;
  304. case 's':
  305. flags.s = 1;
  306. break;
  307. case 'd':
  308. dev->no_cow = 1;
  309. break;
  310. case '=':
  311. str++;
  312. goto break_loop;
  313. default:
  314. printk(KERN_ERR "ubd_setup : Expected '=' or flag letter (r,s or d)\n");
  315. goto out;
  316. }
  317. str++;
  318. }
  319. if (*str == '=')
  320. printk(KERN_ERR "ubd_setup : Too many flags specified\n");
  321. else
  322. printk(KERN_ERR "ubd_setup : Expected '='\n");
  323. goto out;
  324. break_loop:
  325. err = 0;
  326. backing_file = strchr(str, ',');
  327. if (!backing_file) {
  328. backing_file = strchr(str, ':');
  329. }
  330. if(backing_file){
  331. if(dev->no_cow)
  332. printk(KERN_ERR "Can't specify both 'd' and a "
  333. "cow file\n");
  334. else {
  335. *backing_file = '\0';
  336. backing_file++;
  337. }
  338. }
  339. dev->file = str;
  340. dev->cow.file = backing_file;
  341. dev->boot_openflags = flags;
  342. out:
  343. spin_unlock(&ubd_lock);
  344. return(err);
  345. }
  346. static int ubd_setup(char *str)
  347. {
  348. ubd_setup_common(str, NULL);
  349. return(1);
  350. }
  351. __setup("ubd", ubd_setup);
  352. __uml_help(ubd_setup,
  353. "ubd<n><flags>=<filename>[(:|,)<filename2>]\n"
  354. " This is used to associate a device with a file in the underlying\n"
  355. " filesystem. When specifying two filenames, the first one is the\n"
  356. " COW name and the second is the backing file name. As separator you can\n"
  357. " use either a ':' or a ',': the first one allows writing things like;\n"
  358. " ubd0=~/Uml/root_cow:~/Uml/root_backing_file\n"
  359. " while with a ',' the shell would not expand the 2nd '~'.\n"
  360. " When using only one filename, UML will detect whether to thread it like\n"
  361. " a COW file or a backing file. To override this detection, add the 'd'\n"
  362. " flag:\n"
  363. " ubd0d=BackingFile\n"
  364. " Usually, there is a filesystem in the file, but \n"
  365. " that's not required. Swap devices containing swap files can be\n"
  366. " specified like this. Also, a file which doesn't contain a\n"
  367. " filesystem can have its contents read in the virtual \n"
  368. " machine by running 'dd' on the device. <n> must be in the range\n"
  369. " 0 to 7. Appending an 'r' to the number will cause that device\n"
  370. " to be mounted read-only. For example ubd1r=./ext_fs. Appending\n"
  371. " an 's' will cause data to be written to disk on the host immediately.\n\n"
  372. );
  373. static int udb_setup(char *str)
  374. {
  375. printk("udb%s specified on command line is almost certainly a ubd -> "
  376. "udb TYPO\n", str);
  377. return(1);
  378. }
  379. __setup("udb", udb_setup);
  380. __uml_help(udb_setup,
  381. "udb\n"
  382. " This option is here solely to catch ubd -> udb typos, which can be\n\n"
  383. " to impossible to catch visually unless you specifically look for\n\n"
  384. " them. The only result of any option starting with 'udb' is an error\n\n"
  385. " in the boot output.\n\n"
  386. );
  387. static int fakehd_set = 0;
  388. static int fakehd(char *str)
  389. {
  390. printk(KERN_INFO "fakehd : Changing ubd name to \"hd\".\n");
  391. fakehd_set = 1;
  392. return 1;
  393. }
  394. __setup("fakehd", fakehd);
  395. __uml_help(fakehd,
  396. "fakehd\n"
  397. " Change the ubd device name to \"hd\".\n\n"
  398. );
  399. static void do_ubd_request(request_queue_t * q);
  400. /* Only changed by ubd_init, which is an initcall. */
  401. int thread_fd = -1;
  402. /* Changed by ubd_handler, which is serialized because interrupts only
  403. * happen on CPU 0.
  404. */
  405. int intr_count = 0;
  406. /* call ubd_finish if you need to serialize */
  407. static void __ubd_finish(struct request *req, int error)
  408. {
  409. int nsect;
  410. if(error){
  411. end_request(req, 0);
  412. return;
  413. }
  414. nsect = req->current_nr_sectors;
  415. req->sector += nsect;
  416. req->buffer += nsect << 9;
  417. req->errors = 0;
  418. req->nr_sectors -= nsect;
  419. req->current_nr_sectors = 0;
  420. end_request(req, 1);
  421. }
  422. static inline void ubd_finish(struct request *req, int error)
  423. {
  424. spin_lock(&ubd_io_lock);
  425. __ubd_finish(req, error);
  426. spin_unlock(&ubd_io_lock);
  427. }
  428. /* Called without ubd_io_lock held */
  429. static void ubd_handler(void)
  430. {
  431. struct io_thread_req req;
  432. struct request *rq = elv_next_request(ubd_queue);
  433. int n;
  434. do_ubd = NULL;
  435. intr_count++;
  436. n = os_read_file(thread_fd, &req, sizeof(req));
  437. if(n != sizeof(req)){
  438. printk(KERN_ERR "Pid %d - spurious interrupt in ubd_handler, "
  439. "err = %d\n", os_getpid(), -n);
  440. spin_lock(&ubd_io_lock);
  441. end_request(rq, 0);
  442. spin_unlock(&ubd_io_lock);
  443. return;
  444. }
  445. ubd_finish(rq, req.error);
  446. reactivate_fd(thread_fd, UBD_IRQ);
  447. do_ubd_request(ubd_queue);
  448. }
  449. static irqreturn_t ubd_intr(int irq, void *dev, struct pt_regs *unused)
  450. {
  451. ubd_handler();
  452. return(IRQ_HANDLED);
  453. }
  454. /* Only changed by ubd_init, which is an initcall. */
  455. static int io_pid = -1;
  456. void kill_io_thread(void)
  457. {
  458. if(io_pid != -1)
  459. os_kill_process(io_pid, 1);
  460. }
  461. __uml_exitcall(kill_io_thread);
  462. static int ubd_file_size(struct ubd *dev, __u64 *size_out)
  463. {
  464. char *file;
  465. file = dev->cow.file ? dev->cow.file : dev->file;
  466. return(os_file_size(file, size_out));
  467. }
  468. static void ubd_close(struct ubd *dev)
  469. {
  470. os_close_file(dev->fd);
  471. if(dev->cow.file == NULL)
  472. return;
  473. os_close_file(dev->cow.fd);
  474. vfree(dev->cow.bitmap);
  475. dev->cow.bitmap = NULL;
  476. }
  477. static int ubd_open_dev(struct ubd *dev)
  478. {
  479. struct openflags flags;
  480. char **back_ptr;
  481. int err, create_cow, *create_ptr;
  482. dev->openflags = dev->boot_openflags;
  483. create_cow = 0;
  484. create_ptr = (dev->cow.file != NULL) ? &create_cow : NULL;
  485. back_ptr = dev->no_cow ? NULL : &dev->cow.file;
  486. dev->fd = open_ubd_file(dev->file, &dev->openflags, back_ptr,
  487. &dev->cow.bitmap_offset, &dev->cow.bitmap_len,
  488. &dev->cow.data_offset, create_ptr);
  489. if((dev->fd == -ENOENT) && create_cow){
  490. dev->fd = create_cow_file(dev->file, dev->cow.file,
  491. dev->openflags, 1 << 9, PAGE_SIZE,
  492. &dev->cow.bitmap_offset,
  493. &dev->cow.bitmap_len,
  494. &dev->cow.data_offset);
  495. if(dev->fd >= 0){
  496. printk(KERN_INFO "Creating \"%s\" as COW file for "
  497. "\"%s\"\n", dev->file, dev->cow.file);
  498. }
  499. }
  500. if(dev->fd < 0){
  501. printk("Failed to open '%s', errno = %d\n", dev->file,
  502. -dev->fd);
  503. return(dev->fd);
  504. }
  505. if(dev->cow.file != NULL){
  506. err = -ENOMEM;
  507. dev->cow.bitmap = (void *) vmalloc(dev->cow.bitmap_len);
  508. if(dev->cow.bitmap == NULL){
  509. printk(KERN_ERR "Failed to vmalloc COW bitmap\n");
  510. goto error;
  511. }
  512. flush_tlb_kernel_vm();
  513. err = read_cow_bitmap(dev->fd, dev->cow.bitmap,
  514. dev->cow.bitmap_offset,
  515. dev->cow.bitmap_len);
  516. if(err < 0)
  517. goto error;
  518. flags = dev->openflags;
  519. flags.w = 0;
  520. err = open_ubd_file(dev->cow.file, &flags, NULL, NULL, NULL,
  521. NULL, NULL);
  522. if(err < 0) goto error;
  523. dev->cow.fd = err;
  524. }
  525. return(0);
  526. error:
  527. os_close_file(dev->fd);
  528. return(err);
  529. }
  530. static int ubd_new_disk(int major, u64 size, int unit,
  531. struct gendisk **disk_out)
  532. {
  533. struct gendisk *disk;
  534. char from[sizeof("ubd/nnnnn\0")], to[sizeof("discnnnnn/disc\0")];
  535. int err;
  536. disk = alloc_disk(1 << UBD_SHIFT);
  537. if(disk == NULL)
  538. return(-ENOMEM);
  539. disk->major = major;
  540. disk->first_minor = unit << UBD_SHIFT;
  541. disk->fops = &ubd_blops;
  542. set_capacity(disk, size / 512);
  543. if(major == MAJOR_NR){
  544. sprintf(disk->disk_name, "ubd%c", 'a' + unit);
  545. sprintf(disk->devfs_name, "ubd/disc%d", unit);
  546. sprintf(from, "ubd/%d", unit);
  547. sprintf(to, "disc%d/disc", unit);
  548. err = devfs_mk_symlink(from, to);
  549. if(err)
  550. printk("ubd_new_disk failed to make link from %s to "
  551. "%s, error = %d\n", from, to, err);
  552. }
  553. else {
  554. sprintf(disk->disk_name, "ubd_fake%d", unit);
  555. sprintf(disk->devfs_name, "ubd_fake/disc%d", unit);
  556. }
  557. /* sysfs register (not for ide fake devices) */
  558. if (major == MAJOR_NR) {
  559. ubd_dev[unit].pdev.id = unit;
  560. ubd_dev[unit].pdev.name = DRIVER_NAME;
  561. platform_device_register(&ubd_dev[unit].pdev);
  562. disk->driverfs_dev = &ubd_dev[unit].pdev.dev;
  563. }
  564. disk->private_data = &ubd_dev[unit];
  565. disk->queue = ubd_queue;
  566. add_disk(disk);
  567. *disk_out = disk;
  568. return 0;
  569. }
  570. #define ROUND_BLOCK(n) ((n + ((1 << 9) - 1)) & (-1 << 9))
  571. static int ubd_add(int n)
  572. {
  573. struct ubd *dev = &ubd_dev[n];
  574. int err;
  575. if(dev->file == NULL)
  576. return(-ENODEV);
  577. if (ubd_open_dev(dev))
  578. return(-ENODEV);
  579. err = ubd_file_size(dev, &dev->size);
  580. if(err < 0)
  581. return(err);
  582. dev->size = ROUND_BLOCK(dev->size);
  583. err = ubd_new_disk(MAJOR_NR, dev->size, n, &ubd_gendisk[n]);
  584. if(err)
  585. return(err);
  586. if(fake_major != MAJOR_NR)
  587. ubd_new_disk(fake_major, dev->size, n,
  588. &fake_gendisk[n]);
  589. /* perhaps this should also be under the "if (fake_major)" above */
  590. /* using the fake_disk->disk_name and also the fakehd_set name */
  591. if (fake_ide)
  592. make_ide_entries(ubd_gendisk[n]->disk_name);
  593. ubd_close(dev);
  594. return 0;
  595. }
  596. static int ubd_config(char *str)
  597. {
  598. int n, err;
  599. str = uml_strdup(str);
  600. if(str == NULL){
  601. printk(KERN_ERR "ubd_config failed to strdup string\n");
  602. return(1);
  603. }
  604. err = ubd_setup_common(str, &n);
  605. if(err){
  606. kfree(str);
  607. return(-1);
  608. }
  609. if(n == -1) return(0);
  610. spin_lock(&ubd_lock);
  611. err = ubd_add(n);
  612. if(err)
  613. ubd_dev[n].file = NULL;
  614. spin_unlock(&ubd_lock);
  615. return(err);
  616. }
  617. static int ubd_get_config(char *name, char *str, int size, char **error_out)
  618. {
  619. struct ubd *dev;
  620. int n, len = 0;
  621. n = parse_unit(&name);
  622. if((n >= MAX_DEV) || (n < 0)){
  623. *error_out = "ubd_get_config : device number out of range";
  624. return(-1);
  625. }
  626. dev = &ubd_dev[n];
  627. spin_lock(&ubd_lock);
  628. if(dev->file == NULL){
  629. CONFIG_CHUNK(str, size, len, "", 1);
  630. goto out;
  631. }
  632. CONFIG_CHUNK(str, size, len, dev->file, 0);
  633. if(dev->cow.file != NULL){
  634. CONFIG_CHUNK(str, size, len, ",", 0);
  635. CONFIG_CHUNK(str, size, len, dev->cow.file, 1);
  636. }
  637. else CONFIG_CHUNK(str, size, len, "", 1);
  638. out:
  639. spin_unlock(&ubd_lock);
  640. return(len);
  641. }
  642. static int ubd_remove(char *str)
  643. {
  644. struct ubd *dev;
  645. int n, err = -ENODEV;
  646. n = parse_unit(&str);
  647. if((n < 0) || (n >= MAX_DEV))
  648. return(err);
  649. dev = &ubd_dev[n];
  650. if(dev->count > 0)
  651. return(-EBUSY); /* you cannot remove a open disk */
  652. err = 0;
  653. spin_lock(&ubd_lock);
  654. if(ubd_gendisk[n] == NULL)
  655. goto out;
  656. del_gendisk(ubd_gendisk[n]);
  657. put_disk(ubd_gendisk[n]);
  658. ubd_gendisk[n] = NULL;
  659. if(fake_gendisk[n] != NULL){
  660. del_gendisk(fake_gendisk[n]);
  661. put_disk(fake_gendisk[n]);
  662. fake_gendisk[n] = NULL;
  663. }
  664. platform_device_unregister(&dev->pdev);
  665. *dev = ((struct ubd) DEFAULT_UBD);
  666. err = 0;
  667. out:
  668. spin_unlock(&ubd_lock);
  669. return(err);
  670. }
  671. static struct mc_device ubd_mc = {
  672. .name = "ubd",
  673. .config = ubd_config,
  674. .get_config = ubd_get_config,
  675. .remove = ubd_remove,
  676. };
  677. static int ubd_mc_init(void)
  678. {
  679. mconsole_register_dev(&ubd_mc);
  680. return 0;
  681. }
  682. __initcall(ubd_mc_init);
  683. static struct device_driver ubd_driver = {
  684. .name = DRIVER_NAME,
  685. .bus = &platform_bus_type,
  686. };
  687. int ubd_init(void)
  688. {
  689. int i;
  690. devfs_mk_dir("ubd");
  691. if (register_blkdev(MAJOR_NR, "ubd"))
  692. return -1;
  693. ubd_queue = blk_init_queue(do_ubd_request, &ubd_io_lock);
  694. if (!ubd_queue) {
  695. unregister_blkdev(MAJOR_NR, "ubd");
  696. return -1;
  697. }
  698. if (fake_major != MAJOR_NR) {
  699. char name[sizeof("ubd_nnn\0")];
  700. snprintf(name, sizeof(name), "ubd_%d", fake_major);
  701. devfs_mk_dir(name);
  702. if (register_blkdev(fake_major, "ubd"))
  703. return -1;
  704. }
  705. driver_register(&ubd_driver);
  706. for (i = 0; i < MAX_DEV; i++)
  707. ubd_add(i);
  708. return 0;
  709. }
  710. late_initcall(ubd_init);
  711. int ubd_driver_init(void){
  712. unsigned long stack;
  713. int err;
  714. /* Set by CONFIG_BLK_DEV_UBD_SYNC or ubd=sync.*/
  715. if(global_openflags.s){
  716. printk(KERN_INFO "ubd: Synchronous mode\n");
  717. /* Letting ubd=sync be like using ubd#s= instead of ubd#= is
  718. * enough. So use anyway the io thread. */
  719. }
  720. stack = alloc_stack(0, 0);
  721. io_pid = start_io_thread(stack + PAGE_SIZE - sizeof(void *),
  722. &thread_fd);
  723. if(io_pid < 0){
  724. printk(KERN_ERR
  725. "ubd : Failed to start I/O thread (errno = %d) - "
  726. "falling back to synchronous I/O\n", -io_pid);
  727. io_pid = -1;
  728. return(0);
  729. }
  730. err = um_request_irq(UBD_IRQ, thread_fd, IRQ_READ, ubd_intr,
  731. SA_INTERRUPT, "ubd", ubd_dev);
  732. if(err != 0)
  733. printk(KERN_ERR "um_request_irq failed - errno = %d\n", -err);
  734. return(err);
  735. }
  736. device_initcall(ubd_driver_init);
  737. static int ubd_open(struct inode *inode, struct file *filp)
  738. {
  739. struct gendisk *disk = inode->i_bdev->bd_disk;
  740. struct ubd *dev = disk->private_data;
  741. int err = 0;
  742. if(dev->count == 0){
  743. err = ubd_open_dev(dev);
  744. if(err){
  745. printk(KERN_ERR "%s: Can't open \"%s\": errno = %d\n",
  746. disk->disk_name, dev->file, -err);
  747. goto out;
  748. }
  749. }
  750. dev->count++;
  751. set_disk_ro(disk, !dev->openflags.w);
  752. /* This should no more be needed. And it didn't work anyway to exclude
  753. * read-write remounting of filesystems.*/
  754. /*if((filp->f_mode & FMODE_WRITE) && !dev->openflags.w){
  755. if(--dev->count == 0) ubd_close(dev);
  756. err = -EROFS;
  757. }*/
  758. out:
  759. return(err);
  760. }
  761. static int ubd_release(struct inode * inode, struct file * file)
  762. {
  763. struct gendisk *disk = inode->i_bdev->bd_disk;
  764. struct ubd *dev = disk->private_data;
  765. if(--dev->count == 0)
  766. ubd_close(dev);
  767. return(0);
  768. }
  769. static void cowify_bitmap(__u64 io_offset, int length, unsigned long *cow_mask,
  770. __u64 *cow_offset, unsigned long *bitmap,
  771. __u64 bitmap_offset, unsigned long *bitmap_words,
  772. __u64 bitmap_len)
  773. {
  774. __u64 sector = io_offset >> 9;
  775. int i, update_bitmap = 0;
  776. for(i = 0; i < length >> 9; i++){
  777. if(cow_mask != NULL)
  778. ubd_set_bit(i, (unsigned char *) cow_mask);
  779. if(ubd_test_bit(sector + i, (unsigned char *) bitmap))
  780. continue;
  781. update_bitmap = 1;
  782. ubd_set_bit(sector + i, (unsigned char *) bitmap);
  783. }
  784. if(!update_bitmap)
  785. return;
  786. *cow_offset = sector / (sizeof(unsigned long) * 8);
  787. /* This takes care of the case where we're exactly at the end of the
  788. * device, and *cow_offset + 1 is off the end. So, just back it up
  789. * by one word. Thanks to Lynn Kerby for the fix and James McMechan
  790. * for the original diagnosis.
  791. */
  792. if(*cow_offset == ((bitmap_len + sizeof(unsigned long) - 1) /
  793. sizeof(unsigned long) - 1))
  794. (*cow_offset)--;
  795. bitmap_words[0] = bitmap[*cow_offset];
  796. bitmap_words[1] = bitmap[*cow_offset + 1];
  797. *cow_offset *= sizeof(unsigned long);
  798. *cow_offset += bitmap_offset;
  799. }
  800. static void cowify_req(struct io_thread_req *req, unsigned long *bitmap,
  801. __u64 bitmap_offset, __u64 bitmap_len)
  802. {
  803. __u64 sector = req->offset >> 9;
  804. int i;
  805. if(req->length > (sizeof(req->sector_mask) * 8) << 9)
  806. panic("Operation too long");
  807. if(req->op == UBD_READ) {
  808. for(i = 0; i < req->length >> 9; i++){
  809. if(ubd_test_bit(sector + i, (unsigned char *) bitmap))
  810. ubd_set_bit(i, (unsigned char *)
  811. &req->sector_mask);
  812. }
  813. }
  814. else cowify_bitmap(req->offset, req->length, &req->sector_mask,
  815. &req->cow_offset, bitmap, bitmap_offset,
  816. req->bitmap_words, bitmap_len);
  817. }
  818. /* Called with ubd_io_lock held */
  819. static int prepare_request(struct request *req, struct io_thread_req *io_req)
  820. {
  821. struct gendisk *disk = req->rq_disk;
  822. struct ubd *dev = disk->private_data;
  823. __u64 offset;
  824. int len;
  825. if(req->rq_status == RQ_INACTIVE) return(1);
  826. /* This should be impossible now */
  827. if((rq_data_dir(req) == WRITE) && !dev->openflags.w){
  828. printk("Write attempted on readonly ubd device %s\n",
  829. disk->disk_name);
  830. end_request(req, 0);
  831. return(1);
  832. }
  833. offset = ((__u64) req->sector) << 9;
  834. len = req->current_nr_sectors << 9;
  835. io_req->fds[0] = (dev->cow.file != NULL) ? dev->cow.fd : dev->fd;
  836. io_req->fds[1] = dev->fd;
  837. io_req->cow_offset = -1;
  838. io_req->offset = offset;
  839. io_req->length = len;
  840. io_req->error = 0;
  841. io_req->sector_mask = 0;
  842. io_req->op = (rq_data_dir(req) == READ) ? UBD_READ : UBD_WRITE;
  843. io_req->offsets[0] = 0;
  844. io_req->offsets[1] = dev->cow.data_offset;
  845. io_req->buffer = req->buffer;
  846. io_req->sectorsize = 1 << 9;
  847. if(dev->cow.file != NULL)
  848. cowify_req(io_req, dev->cow.bitmap, dev->cow.bitmap_offset,
  849. dev->cow.bitmap_len);
  850. return(0);
  851. }
  852. /* Called with ubd_io_lock held */
  853. static void do_ubd_request(request_queue_t *q)
  854. {
  855. struct io_thread_req io_req;
  856. struct request *req;
  857. int err, n;
  858. if(thread_fd == -1){
  859. while((req = elv_next_request(q)) != NULL){
  860. err = prepare_request(req, &io_req);
  861. if(!err){
  862. do_io(&io_req);
  863. __ubd_finish(req, io_req.error);
  864. }
  865. }
  866. }
  867. else {
  868. if(do_ubd || (req = elv_next_request(q)) == NULL)
  869. return;
  870. err = prepare_request(req, &io_req);
  871. if(!err){
  872. do_ubd = ubd_handler;
  873. n = os_write_file(thread_fd, (char *) &io_req,
  874. sizeof(io_req));
  875. if(n != sizeof(io_req))
  876. printk("write to io thread failed, "
  877. "errno = %d\n", -n);
  878. }
  879. }
  880. }
  881. static int ubd_ioctl(struct inode * inode, struct file * file,
  882. unsigned int cmd, unsigned long arg)
  883. {
  884. struct hd_geometry __user *loc = (struct hd_geometry __user *) arg;
  885. struct ubd *dev = inode->i_bdev->bd_disk->private_data;
  886. struct hd_driveid ubd_id = {
  887. .cyls = 0,
  888. .heads = 128,
  889. .sectors = 32,
  890. };
  891. switch (cmd) {
  892. struct hd_geometry g;
  893. struct cdrom_volctrl volume;
  894. case HDIO_GETGEO:
  895. if(!loc) return(-EINVAL);
  896. g.heads = 128;
  897. g.sectors = 32;
  898. g.cylinders = dev->size / (128 * 32 * 512);
  899. g.start = get_start_sect(inode->i_bdev);
  900. return(copy_to_user(loc, &g, sizeof(g)) ? -EFAULT : 0);
  901. case HDIO_GET_IDENTITY:
  902. ubd_id.cyls = dev->size / (128 * 32 * 512);
  903. if(copy_to_user((char __user *) arg, (char *) &ubd_id,
  904. sizeof(ubd_id)))
  905. return(-EFAULT);
  906. return(0);
  907. case CDROMVOLREAD:
  908. if(copy_from_user(&volume, (char __user *) arg, sizeof(volume)))
  909. return(-EFAULT);
  910. volume.channel0 = 255;
  911. volume.channel1 = 255;
  912. volume.channel2 = 255;
  913. volume.channel3 = 255;
  914. if(copy_to_user((char __user *) arg, &volume, sizeof(volume)))
  915. return(-EFAULT);
  916. return(0);
  917. }
  918. return(-EINVAL);
  919. }
  920. static int same_backing_files(char *from_cmdline, char *from_cow, char *cow)
  921. {
  922. struct uml_stat buf1, buf2;
  923. int err;
  924. if(from_cmdline == NULL) return(1);
  925. if(!strcmp(from_cmdline, from_cow)) return(1);
  926. err = os_stat_file(from_cmdline, &buf1);
  927. if(err < 0){
  928. printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
  929. return(1);
  930. }
  931. err = os_stat_file(from_cow, &buf2);
  932. if(err < 0){
  933. printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
  934. return(1);
  935. }
  936. if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
  937. return(1);
  938. printk("Backing file mismatch - \"%s\" requested,\n"
  939. "\"%s\" specified in COW header of \"%s\"\n",
  940. from_cmdline, from_cow, cow);
  941. return(0);
  942. }
  943. static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
  944. {
  945. unsigned long modtime;
  946. long long actual;
  947. int err;
  948. err = os_file_modtime(file, &modtime);
  949. if(err < 0){
  950. printk("Failed to get modification time of backing file "
  951. "\"%s\", err = %d\n", file, -err);
  952. return(err);
  953. }
  954. err = os_file_size(file, &actual);
  955. if(err < 0){
  956. printk("Failed to get size of backing file \"%s\", "
  957. "err = %d\n", file, -err);
  958. return(err);
  959. }
  960. if(actual != size){
  961. /*__u64 can be a long on AMD64 and with %lu GCC complains; so
  962. * the typecast.*/
  963. printk("Size mismatch (%llu vs %llu) of COW header vs backing "
  964. "file\n", (unsigned long long) size, actual);
  965. return(-EINVAL);
  966. }
  967. if(modtime != mtime){
  968. printk("mtime mismatch (%ld vs %ld) of COW header vs backing "
  969. "file\n", mtime, modtime);
  970. return(-EINVAL);
  971. }
  972. return(0);
  973. }
  974. int read_cow_bitmap(int fd, void *buf, int offset, int len)
  975. {
  976. int err;
  977. err = os_seek_file(fd, offset);
  978. if(err < 0)
  979. return(err);
  980. err = os_read_file(fd, buf, len);
  981. if(err < 0)
  982. return(err);
  983. return(0);
  984. }
  985. int open_ubd_file(char *file, struct openflags *openflags,
  986. char **backing_file_out, int *bitmap_offset_out,
  987. unsigned long *bitmap_len_out, int *data_offset_out,
  988. int *create_cow_out)
  989. {
  990. time_t mtime;
  991. unsigned long long size;
  992. __u32 version, align;
  993. char *backing_file;
  994. int fd, err, sectorsize, same, mode = 0644;
  995. fd = os_open_file(file, *openflags, mode);
  996. if(fd < 0){
  997. if((fd == -ENOENT) && (create_cow_out != NULL))
  998. *create_cow_out = 1;
  999. if(!openflags->w ||
  1000. ((fd != -EROFS) && (fd != -EACCES))) return(fd);
  1001. openflags->w = 0;
  1002. fd = os_open_file(file, *openflags, mode);
  1003. if(fd < 0)
  1004. return(fd);
  1005. }
  1006. err = os_lock_file(fd, openflags->w);
  1007. if(err < 0){
  1008. printk("Failed to lock '%s', err = %d\n", file, -err);
  1009. goto out_close;
  1010. }
  1011. if(backing_file_out == NULL) return(fd);
  1012. err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
  1013. &size, &sectorsize, &align, bitmap_offset_out);
  1014. if(err && (*backing_file_out != NULL)){
  1015. printk("Failed to read COW header from COW file \"%s\", "
  1016. "errno = %d\n", file, -err);
  1017. goto out_close;
  1018. }
  1019. if(err) return(fd);
  1020. if(backing_file_out == NULL) return(fd);
  1021. same = same_backing_files(*backing_file_out, backing_file, file);
  1022. if(!same && !backing_file_mismatch(*backing_file_out, size, mtime)){
  1023. printk("Switching backing file to '%s'\n", *backing_file_out);
  1024. err = write_cow_header(file, fd, *backing_file_out,
  1025. sectorsize, align, &size);
  1026. if(err){
  1027. printk("Switch failed, errno = %d\n", -err);
  1028. return(err);
  1029. }
  1030. }
  1031. else {
  1032. *backing_file_out = backing_file;
  1033. err = backing_file_mismatch(*backing_file_out, size, mtime);
  1034. if(err) goto out_close;
  1035. }
  1036. cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
  1037. bitmap_len_out, data_offset_out);
  1038. return(fd);
  1039. out_close:
  1040. os_close_file(fd);
  1041. return(err);
  1042. }
  1043. int create_cow_file(char *cow_file, char *backing_file, struct openflags flags,
  1044. int sectorsize, int alignment, int *bitmap_offset_out,
  1045. unsigned long *bitmap_len_out, int *data_offset_out)
  1046. {
  1047. int err, fd;
  1048. flags.c = 1;
  1049. fd = open_ubd_file(cow_file, &flags, NULL, NULL, NULL, NULL, NULL);
  1050. if(fd < 0){
  1051. err = fd;
  1052. printk("Open of COW file '%s' failed, errno = %d\n", cow_file,
  1053. -err);
  1054. goto out;
  1055. }
  1056. err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
  1057. bitmap_offset_out, bitmap_len_out,
  1058. data_offset_out);
  1059. if(!err)
  1060. return(fd);
  1061. os_close_file(fd);
  1062. out:
  1063. return(err);
  1064. }
  1065. static int update_bitmap(struct io_thread_req *req)
  1066. {
  1067. int n;
  1068. if(req->cow_offset == -1)
  1069. return(0);
  1070. n = os_seek_file(req->fds[1], req->cow_offset);
  1071. if(n < 0){
  1072. printk("do_io - bitmap lseek failed : err = %d\n", -n);
  1073. return(1);
  1074. }
  1075. n = os_write_file(req->fds[1], &req->bitmap_words,
  1076. sizeof(req->bitmap_words));
  1077. if(n != sizeof(req->bitmap_words)){
  1078. printk("do_io - bitmap update failed, err = %d fd = %d\n", -n,
  1079. req->fds[1]);
  1080. return(1);
  1081. }
  1082. return(0);
  1083. }
  1084. void do_io(struct io_thread_req *req)
  1085. {
  1086. char *buf;
  1087. unsigned long len;
  1088. int n, nsectors, start, end, bit;
  1089. int err;
  1090. __u64 off;
  1091. nsectors = req->length / req->sectorsize;
  1092. start = 0;
  1093. do {
  1094. bit = ubd_test_bit(start, (unsigned char *) &req->sector_mask);
  1095. end = start;
  1096. while((end < nsectors) &&
  1097. (ubd_test_bit(end, (unsigned char *)
  1098. &req->sector_mask) == bit))
  1099. end++;
  1100. off = req->offset + req->offsets[bit] +
  1101. start * req->sectorsize;
  1102. len = (end - start) * req->sectorsize;
  1103. buf = &req->buffer[start * req->sectorsize];
  1104. err = os_seek_file(req->fds[bit], off);
  1105. if(err < 0){
  1106. printk("do_io - lseek failed : err = %d\n", -err);
  1107. req->error = 1;
  1108. return;
  1109. }
  1110. if(req->op == UBD_READ){
  1111. n = 0;
  1112. do {
  1113. buf = &buf[n];
  1114. len -= n;
  1115. n = os_read_file(req->fds[bit], buf, len);
  1116. if (n < 0) {
  1117. printk("do_io - read failed, err = %d "
  1118. "fd = %d\n", -n, req->fds[bit]);
  1119. req->error = 1;
  1120. return;
  1121. }
  1122. } while((n < len) && (n != 0));
  1123. if (n < len) memset(&buf[n], 0, len - n);
  1124. } else {
  1125. n = os_write_file(req->fds[bit], buf, len);
  1126. if(n != len){
  1127. printk("do_io - write failed err = %d "
  1128. "fd = %d\n", -n, req->fds[bit]);
  1129. req->error = 1;
  1130. return;
  1131. }
  1132. }
  1133. start = end;
  1134. } while(start < nsectors);
  1135. req->error = update_bitmap(req);
  1136. }
  1137. /* Changed in start_io_thread, which is serialized by being called only
  1138. * from ubd_init, which is an initcall.
  1139. */
  1140. int kernel_fd = -1;
  1141. /* Only changed by the io thread */
  1142. int io_count = 0;
  1143. int io_thread(void *arg)
  1144. {
  1145. struct io_thread_req req;
  1146. int n;
  1147. ignore_sigwinch_sig();
  1148. while(1){
  1149. n = os_read_file(kernel_fd, &req, sizeof(req));
  1150. if(n != sizeof(req)){
  1151. if(n < 0)
  1152. printk("io_thread - read failed, fd = %d, "
  1153. "err = %d\n", kernel_fd, -n);
  1154. else {
  1155. printk("io_thread - short read, fd = %d, "
  1156. "length = %d\n", kernel_fd, n);
  1157. }
  1158. continue;
  1159. }
  1160. io_count++;
  1161. do_io(&req);
  1162. n = os_write_file(kernel_fd, &req, sizeof(req));
  1163. if(n != sizeof(req))
  1164. printk("io_thread - write failed, fd = %d, err = %d\n",
  1165. kernel_fd, -n);
  1166. }
  1167. }
  1168. /*
  1169. * Overrides for Emacs so that we follow Linus's tabbing style.
  1170. * Emacs will notice this stuff at the end of the file and automatically
  1171. * adjust the settings for this buffer only. This must remain at the end
  1172. * of the file.
  1173. * ---------------------------------------------------------------------------
  1174. * Local variables:
  1175. * c-file-style: "linux"
  1176. * End:
  1177. */