Alloc fd

Retired DISLab
(버전 사이의 차이)
이동: 둘러보기, 찾기
 
15번째 줄: 15번째 줄:
 
462        fdt = files_fdtable(files);
 
462        fdt = files_fdtable(files);
 
463        fd = start;
 
463        fd = start;
464        if (fd < files->next_fd)
+
464        if (fd < files->next_fd) //file descriptor fd가 file structure구조체 files의 next_fd(비어있는 fd)보다 작다면
465                fd = files->next_fd;
+
465                fd = files->next_fd; //next_fd를 fd에 할당
 
466  
 
466  
467        if (fd < fdt->max_fds)
+
467        if (fd < fdt->max_fds) //fd index보다 fd가 작다면(정상적인 경우)
468                fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, fd);
+
468                fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, fd); //bitmap에서 bit가 0으로 되어있는 offset을 찾아 할당
 
469  
 
469  
 
470        /*
 
470        /*
25번째 줄: 25번째 줄:
 
472          * will limit the total number of files that can be opened.
 
472          * will limit the total number of files that can be opened.
 
473          */
 
473          */
474        error = -EMFILE;
+
474        error = -EMFILE; //Too many open file
 
475        if (fd >= end)
 
475        if (fd >= end)
 
476                goto out;
 
476                goto out;
 
477  
 
477  
478        error = expand_files(files, fd);
+
478        error = expand_files(files, fd); //fdt가 부족하여 files_struct구조체를 추가하는경우
479        if (error < 0)
+
479        if (error < 0) //nothing done
 
480                goto out;
 
480                goto out;
 
481  
 
481  
37번째 줄: 37번째 줄:
 
484          * might have blocked - try again.
 
484          * might have blocked - try again.
 
485          */
 
485          */
486        if (error)
+
486        if (error) //files were expanded
 
487                goto repeat;
 
487                goto repeat;
 
488  
 
488  
43번째 줄: 43번째 줄:
 
490                files->next_fd = fd + 1;
 
490                files->next_fd = fd + 1;
 
491  
 
491  
492        __set_open_fd(fd, fdt);
+
492        __set_open_fd(fd, fdt); //set bit
 
493        if (flags & O_CLOEXEC)
 
493        if (flags & O_CLOEXEC)
 
494                __set_close_on_exec(fd, fdt);
 
494                __set_close_on_exec(fd, fdt);

2014년 4월 30일 (수) 19:36 현재 판

450 /*
451  * allocate a file descriptor, mark it busy.
452  */
453 int __alloc_fd(struct files_struct *files,  //struct files_struct : open file table structure
454                unsigned start, unsigned end, unsigned flags)
455 {
456         unsigned int fd;
457         int error;
458         struct fdtable *fdt;
459 
460         spin_lock(&files->file_lock);
461 repeat:
462         fdt = files_fdtable(files);
463         fd = start;
464         if (fd < files->next_fd)  //file descriptor fd가 file structure구조체 files의 next_fd(비어있는 fd)보다 작다면
465                 fd = files->next_fd;  //next_fd를 fd에 할당
466 
467         if (fd < fdt->max_fds) //fd index보다 fd가 작다면(정상적인 경우)
468                 fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, fd);  //bitmap에서 bit가 0으로 되어있는 offset을 찾아 할당
469 
470         /*
471          * N.B. For clone tasks sharing a files structure, this test
472          * will limit the total number of files that can be opened.
473          */
474         error = -EMFILE;  //Too many open file
475         if (fd >= end)
476                 goto out;
477 
478         error = expand_files(files, fd);  //fdt가 부족하여 files_struct구조체를 추가하는경우
479         if (error < 0)  //nothing done
480                 goto out;
481 
482         /*
483          * If we needed to expand the fs array we
484          * might have blocked - try again.
485          */
486         if (error)  //files were expanded
487                 goto repeat;
488 
489         if (start <= files->next_fd)
490                 files->next_fd = fd + 1;
491 
492         __set_open_fd(fd, fdt);  //set bit
493         if (flags & O_CLOEXEC)
494                 __set_close_on_exec(fd, fdt);
495         else
496                 __clear_close_on_exec(fd, fdt);
497         error = fd;
498 #if 1
499         /* Sanity check */
500         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
501                 printk(KERN_WARNING "alloc_fd: slot %d not NULL!\n", fd);
502                 rcu_assign_pointer(fdt->fd[fd], NULL);
503         }
504 #endif
505 
506 out:
507         spin_unlock(&files->file_lock);
508         return error;
509 }
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기